コード例 #1
0
        /// <summary>
        /// Creates and saves the given number of fake patients
        /// </summary>
        public static List<Patient> CreateFakePatients(Doctor doctor, CerebelloEntities db, int count)
        {
            var maleFirstNames = new[]
                {
                    "André",
                    "Anderson",
                    "Alan",
                    "Artur",
                    "Bruno",
                    "Carlos",
                    "Daniel",
                    "Danilo",
                    "Ernani",
                    "Fabiano",
                    "Fábio",
                    "Guilherme",
                    "Hélcio",
                    "Jorge",
                    "Leonardo",
                    "Marcelo",
                    "Miguel", // po cara! eu tb! // blz! haha
                    "Nelson",
                    "Osvaldo",
                    "Patrício",
                    "Roberto",
                    "Ronan",
                    "Thiago"
                };

            var femaleFirstNames = new[]
                {
                    "Alice",
                    "Aline",
                    "Bianca",
                    "Bruna",
                    "Carla",
                    "Daniela",
                    "Elaine",
                    "Fabíola",
                    "Fabiana",
                    "Giovana",
                    "Íngridi",
                    "Jaqueline",
                    "Larissa",
                    "Marcela",
                    "Natália",
                    "Paula",
                    "Quelen",
                    "Renata",
                    "Silvana",
                    "Tatiana",
                    "Valquíria",
                    "Zilá"
                };

            var middleNames = new[]
                {
                    "Albuquerque",
                    "Almeida",
                    "Bastos",
                    "Queiróz",
                    "Teixeira",
                    "Silva",
                    "Rodrigues",
                    "Santos",
                    "Pena",
                    "Bicudo",
                    "Gonçalves",
                    "Machado",
                    "Vianna",
                    "Souza",
                    "Moreira",
                    "Vieira",
                    "Correia",
                    "Reis",
                    "Delgado"
                };

            var professions = new[]
                {
                    "Pedreiro(a)",
                    "Arquiteto(a)",
                    "Programador(a)",
                    "Economista",
                    "Engenheiro(a)",
                    "Padeiro(a)",
                    "Eletricista",
                    "Vendedor(a)",
                    "Consultor(a)",
                    "Biólogo(a)",
                    "Carpinteiro(a)",
                    "Advogado(a)"
                };

            using (var rc = RandomContext.Create())
            {
                var random = rc.Random;
                var result = new List<Patient>();

                for (var i = 0; i < count; i++)
                {
                    // gender (random upper bound is exclusive)
                    var gender = random.Next(0, 2);

                    // first name
                    var possibleFirstNames = gender == 0 ? maleFirstNames : femaleFirstNames;
                    var firstName = possibleFirstNames[random.Next(possibleFirstNames.Length)];

                    // middle names
                    var chosenMiddleNames = new string[random.Next(2, 4)];
                    for (var j = 0; j < chosenMiddleNames.Length; j++)
                        chosenMiddleNames[j] = middleNames[random.Next(middleNames.Length)];

                    var birthDate = new DateTime(
                        random.Next(1950, 2000),
                        random.Next(1, 13),
                        random.Next(1, 29),
                        00,
                        00,
                        000,
                        DateTimeKind.Utc);

                    var patient = new Patient
                        {
                            Person = new Person
                                {
                                    FullName = firstName + " " + string.Join(" ", chosenMiddleNames),
                                    Gender = (short)gender,
                                    DateOfBirth = birthDate,
                                    MaritalStatus = (short?)random.Next(0, 4),
                                    BirthPlace = "Brasileiro(a)",
                                    CPF = "87324128910",
                                    Profession = professions[random.Next(professions.Length)],
                                    CreatedOn = Firestarter.UtcNow,
                                    PracticeId = doctor.PracticeId,
                                },

                            Doctor = doctor,
                            PracticeId = doctor.PracticeId,
                        };

                    // it's important do remove diacritics because StmpClient crashes on non-ascii characters
                    patient.Person.Email =  StringHelper.RemoveDiacritics((firstName + string.Join("", chosenMiddleNames)).ToLower() + "@fakemail.com");
                    Debug.Assert(!patient.Person.Addresses.Any());
                    patient.Person.Addresses.Add(
                        new Address
                            {
                                CEP = random.Next(36000000, 37000000).ToString(CultureInfo.InvariantCulture),
                                StateProvince = "MG",
                                City = "Juiz de Fora",
                                Neighborhood = "Centro",
                                Street =
                                    "Rua " + middleNames[random.Next(middleNames.Length)] + " " +
                                    middleNames[random.Next(middleNames.Length)],
                                Complement = "",
                                PracticeId = doctor.PracticeId,
                            });

                    result.Add(patient);
                    db.Patients.AddObject(patient);
                }

                db.SaveChanges();
                return result;
            }
        }
コード例 #2
0
        public void LookupEverything_1_ShouldSearchPatients()
        {
            var doctor = this.db.Doctors.First();

            // create some fake patients
            // patient 1
            Patient patient1 = new Patient()
            {
                Person = new Person()
                {
                    FullName = "Joao Manuel da Silva",
                    Gender = (int)TypeGender.Male,
                    DateOfBirth = Firestarter.ConvertFromDefaultToUtc(new DateTime(1982, 10, 12)),
                    MaritalStatus = (int)TypeMaritalStatus.Casado,
                    BirthPlace = "Brasileiro",
                    CPF = "87324128910",
                    CPFOwner = (int)TypeCpfOwner.PatientItself,
                    Profession = "Encarregado de Obras",
                    CreatedOn = DateTime.UtcNow,
                    PracticeId = doctor.PracticeId,
                },
                Doctor = doctor,
                PracticeId = doctor.PracticeId,
            };
            patient1.Person.Email = "*****@*****.**";
            patient1.Person.Addresses.Add(
                new Address
                    {
                        CEP = "602500330",
                        StateProvince = "RJ",
                        City = "Rio de Janeiro",
                        Neighborhood = "Jacarepaguá",
                        Street = "Rua Estrada do Pau Ferro 329",
                        Complement = "",
                        PracticeId = doctor.PracticeId,
                    });

            db.Patients.AddObject(patient1);

            Patient patient2 = new Patient()
            {
                Person = new Person()
                {
                    FullName = "Manuela Moreira da Silva",
                    Gender = (int)TypeGender.Female,
                    DateOfBirth = Firestarter.ConvertFromDefaultToUtc(new DateTime(1982, 10, 12)),
                    MaritalStatus = (int)TypeMaritalStatus.Casado,
                    BirthPlace = "Brasileiro",
                    CPF = "87324128910",
                    CPFOwner = (int)TypeCpfOwner.PatientItself,
                    Profession = "Encarregado de Obras",
                    CreatedOn = DateTime.UtcNow,
                    PracticeId = doctor.PracticeId,
                },
                Doctor = doctor
            };
            patient1.Person.Email = "*****@*****.**";
            patient1.Person.Addresses.Add(
                new Address
                    {
                        CEP = "602500330",
                        StateProvince = "RJ",
                        City = "Rio de Janeiro",
                        Neighborhood = "Jacarepaguá",
                        Street = "Rua Estrada do Pau Ferro 329",
                        Complement = "",
                        PracticeId = doctor.PracticeId,
                    });

            db.Patients.AddObject(patient2);

            this.db.SaveChanges();

            var mr = new MockRepository(true);
            var controller = mr.CreateController<AppController>();
            var controllerResult = controller.LookupEverything("Joao", 20, 1, this.db.Doctors.First().Id);

            var controllerResultAsLookupResult = (AutocompleteJsonResult)controllerResult.Data;

            Assert.AreEqual(1, controllerResultAsLookupResult.Rows.Count);
            Assert.IsInstanceOfType(controllerResultAsLookupResult.Rows[0], typeof(GlobalSearchViewModel));

            Assert.AreEqual(patient1.Person.FullName, ((GlobalSearchViewModel)controllerResultAsLookupResult.Rows[0]).Value);
            Assert.AreEqual(patient1.Id, ((GlobalSearchViewModel)controllerResultAsLookupResult.Rows[0]).Id);
        }
コード例 #3
0
 /// <summary>
 /// Create a new Patient object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="doctorId">Initial value of the DoctorId property.</param>
 /// <param name="personId">Initial value of the PersonId property.</param>
 /// <param name="practiceId">Initial value of the PracticeId property.</param>
 /// <param name="isBackedUp">Initial value of the IsBackedUp property.</param>
 public static Patient CreatePatient(global::System.Int32 id, global::System.Int32 doctorId, global::System.Int32 personId, global::System.Int32 practiceId, global::System.Boolean isBackedUp)
 {
     Patient patient = new Patient();
     patient.Id = id;
     patient.DoctorId = doctorId;
     patient.PersonId = personId;
     patient.PracticeId = practiceId;
     patient.IsBackedUp = isBackedUp;
     return patient;
 }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Patients EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPatients(Patient patient)
 {
     base.AddObject("Patients", patient);
 }
コード例 #5
0
        public static List<SessionViewModel> GetSessionViewModels(Practice practice, Patient patient, DateTimeInterval? filterUtcInterval)
        {
            var eventDates = new List<DateTime>();

            var utcDateFilterStart = filterUtcInterval.HasValue ? filterUtcInterval.Value.Start : (DateTime?)null;
            var utcDateFilterEnd = filterUtcInterval.HasValue ? filterUtcInterval.Value.End : (DateTime?)null;

            // anamneses
            var anamneses = filterUtcInterval.HasValue
                ? patient.Anamneses.Where(x => x.MedicalRecordDate >= utcDateFilterStart && x.MedicalRecordDate < utcDateFilterEnd)
                : patient.Anamneses;
            var anamnesesByDate =
                (from avm in
                     (from r in anamneses
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, r.MedicalRecordDate),
                                     Id = r.Id
                                 })
                 group avm by avm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(anamnesesByDate.Keys);

            // physical examinations
            var physicalExaminations = filterUtcInterval.HasValue
                ? patient.PhysicalExaminations.Where(x => x.MedicalRecordDate >= utcDateFilterStart && x.MedicalRecordDate < utcDateFilterEnd)
                : patient.PhysicalExaminations;
            var physicalExaminationsByDate =
                (from pe in
                     (from r in physicalExaminations
                      select new SessionEvent
                      {
                          LocalDate = ConvertToLocalDateTime(practice, r.MedicalRecordDate),
                          Id = r.Id
                      })
                 group pe by pe.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(physicalExaminationsByDate.Keys);

            // diagnostic hipotheses
            var diagnosticHypotheses = filterUtcInterval.HasValue
                ? patient.DiagnosticHypotheses.Where(x => x.MedicalRecordDate >= utcDateFilterStart && x.MedicalRecordDate < utcDateFilterEnd)
                : patient.DiagnosticHypotheses;
            var diagnosticHypothesesByDate =
                (from pe in
                     (from r in diagnosticHypotheses
                      select new SessionEvent
                      {
                          LocalDate = ConvertToLocalDateTime(practice, r.MedicalRecordDate),
                          Id = r.Id
                      })
                 group pe by pe.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(diagnosticHypothesesByDate.Keys);

            // receipts
            var receipts = filterUtcInterval.HasValue
                ? patient.Receipts.Where(x => x.IssuanceDate >= utcDateFilterStart && x.IssuanceDate < utcDateFilterEnd)
                : patient.Receipts;
            var receiptsByDate =
                (from rvm in
                     (from r in receipts
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, r.IssuanceDate),
                                     Id = r.Id
                                 })
                 group rvm by rvm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(receiptsByDate.Keys);

            // certificates
            var certificates = filterUtcInterval.HasValue
                ? patient.MedicalCertificates.Where(x => x.IssuanceDate >= utcDateFilterStart && x.IssuanceDate < utcDateFilterEnd)
                : patient.MedicalCertificates;
            var certificatesByDate =
                (from cvm in
                     (from c in certificates
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, c.IssuanceDate),
                                     Id = c.Id
                                 })
                 group cvm by cvm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(certificatesByDate.Keys);

            // exam requests
            var examRequests = filterUtcInterval.HasValue
                ? patient.ExaminationRequests.Where(x => x.RequestDate >= utcDateFilterStart && x.RequestDate < utcDateFilterEnd)
                : patient.ExaminationRequests;
            var examRequestsByDate =
                (from ervm in
                     (from c in examRequests
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, c.RequestDate),
                                     Id = c.Id
                                 })
                 group ervm by ervm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(examRequestsByDate.Keys);

            // exam results
            var examResults = filterUtcInterval.HasValue
                ? patient.ExaminationResults.Where(x => x.ReceiveDate >= utcDateFilterStart && x.ReceiveDate < utcDateFilterEnd)
                : patient.ExaminationResults;
            var examResultsByDate =
                (from ervm in
                     (from c in examResults
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, c.ReceiveDate),
                                     Id = c.Id
                                 })
                 group ervm by ervm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(examResultsByDate.Keys);

            // diagnosis
            var diagnosis = filterUtcInterval.HasValue
                ? patient.Diagnoses.Where(x => x.MedicalRecordDate >= utcDateFilterStart && x.MedicalRecordDate < utcDateFilterEnd)
                : patient.Diagnoses;
            var diagnosisByDate =
                (from dvm in
                     (from d in diagnosis
                      select new SessionEvent
                                 {
                                     LocalDate = ConvertToLocalDateTime(practice, d.MedicalRecordDate),
                                     Id = d.Id
                                 })
                 group dvm by dvm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(diagnosisByDate.Keys);

            // patientFiles
            var patientFiles = filterUtcInterval.HasValue
                ? patient.PatientFileGroups.Where(x => x.ReceiveDate >= utcDateFilterStart && x.ReceiveDate < utcDateFilterEnd)
                : patient.PatientFileGroups;
            var patientFilesByDate =
                (from dvm in
                     (from d in patientFiles
                      select new SessionEvent
                      {
                          LocalDate = ConvertToLocalDateTime(practice, d.ReceiveDate),
                          Id = d.Id
                      })
                 group dvm by dvm.LocalDate.Date
                     into g
                     select g).ToDictionary(g => g.Key, g => g.ToList());

            eventDates.AddRange(patientFilesByDate.Keys);

            // discover what dates have events
            eventDates = eventDates.Distinct().OrderBy(dt => dt).ToList();

            // creating sessions
            var sessions = eventDates.Select(
                eventDate => new SessionViewModel
                                 {
                                     PatientId = patient.Id,
                                     Date = eventDate,
                                     AnamneseIds =
                                         anamnesesByDate.ContainsKey(eventDate)
                                             ? anamnesesByDate[eventDate].Select(a => a.Id).ToList()
                                             : new List<int>(),
                                     PhysicalExaminationIds =
                                        physicalExaminationsByDate.ContainsKey(eventDate)
                                            ? physicalExaminationsByDate[eventDate].Select(a => a.Id).ToList()
                                    : new List<int>(),
                                     DiagnosticHipothesesId =
                                     diagnosticHypothesesByDate.ContainsKey(eventDate)
                                     ? diagnosticHypothesesByDate[eventDate].Select(a => a.Id).ToList()
                                     : new List<int>(),
                                     ReceiptIds =
                                         receiptsByDate.ContainsKey(eventDate)
                                             ? receiptsByDate[eventDate].Select(v => v.Id).ToList()
                                             : new List<int>(),
                                     MedicalCertificateIds =
                                         certificatesByDate.ContainsKey(eventDate)
                                             ? certificatesByDate[eventDate].Select(c => c.Id).ToList()
                                             : new List<int>(),
                                     ExaminationRequestIds =
                                         examRequestsByDate.ContainsKey(eventDate)
                                             ? examRequestsByDate[eventDate].Select(v => v.Id).ToList()
                                             : new List<int>(),
                                     ExaminationResultIds =
                                         examResultsByDate.ContainsKey(eventDate)
                                             ? examResultsByDate[eventDate].Select(v => v.Id).ToList()
                                             : new List<int>(),
                                     DiagnosisIds =
                                         diagnosisByDate.ContainsKey(eventDate)
                                             ? diagnosisByDate[eventDate].Select(v => v.Id).ToList()
                                             : new List<int>(),
                                     PatientFiles =
                                         patientFilesByDate.ContainsKey(eventDate)
                                             ? patientFilesByDate[eventDate].Select(v => v.Id).ToList()
                                             : new List<int>()
                                 }).ToList();

            return sessions;
        }
コード例 #6
0
        public ActionResult Edit(PatientViewModel formModel)
        {
            // if this account has a patient limit, then we should tell the user if he/she blows up the limit
            var patientLimit = this.DbPractice.AccountContract.PatientsLimit;

            // verify patient limit
            if (patientLimit != null)
            {
                var patientCount = this.db.Patients.Count(p => p.PracticeId == this.DbPractice.Id);
                if (patientCount + 1 > patientLimit)
                {
                    this.ModelState.Clear();
                    this.ModelState.AddModelError(
                        "PatientsLimit",
                        "Não é possível adicionar mais pacientes, pois já foi atingido o limite de {0} pacientes de sua conta.",
                        patientLimit);
                }
            }

            // Verify if the patient code is valid
            if (formModel.Code != null)
            {
                var patientCodeAsInt = default(int);
                int.TryParse(formModel.Code, out patientCodeAsInt);
                if (patientCodeAsInt != default(int) && this.db.Patients.Any(p => p.Code == patientCodeAsInt))
                    this.ModelState.AddModelError<PatientViewModel>(
                        model => model.Code, "O código do paciente informado pertence a outro paciente");
            }

            if (ModelState.IsValid)
            {
                var isEditing = formModel.Id != null;

                Patient patient;
                if (isEditing)
                    patient = this.db.Patients.First(p => p.Id == formModel.Id);
                else
                {
                    patient = new Patient
                                  {
                                      Person = new Person { PracticeId = this.DbUser.PracticeId, },
                                      PracticeId = this.DbUser.PracticeId,
                                  };
                    this.db.Patients.AddObject(patient);
                }

                patient.Doctor = this.Doctor;

                patient.IsBackedUp = false;
                Debug.Assert(formModel.Code != null, "formModel.Code != null");
                patient.Code = int.Parse(formModel.Code);
                patient.Person.BirthPlace = formModel.BirthPlace;
                patient.Person.CPF = formModel.Cpf;
                patient.Person.RG = formModel.Rg;
                patient.Person.Ethnicity = (int?)formModel.Ethnicity;
                patient.Person.Schooling = (int?)formModel.Schooling;
                patient.Person.FatherName = formModel.FatherName;
                patient.Person.FatherProfession = formModel.FatherProfession;
                patient.Person.MotherName = formModel.MotherName;
                patient.Person.MotherProfession = formModel.MotherProfession;
                patient.Person.CreatedOn = this.GetUtcNow();
                Debug.Assert(formModel.DateOfBirth != null, "formModel.DateOfBirth != null");
                patient.Person.DateOfBirth = ConvertToUtcDateTime(this.DbPractice, formModel.DateOfBirth.Value);
                patient.Person.FullName = formModel.FullName;
                patient.Person.Gender = (short)formModel.Gender;
                patient.Person.MaritalStatus = formModel.MaritalStatus;
                patient.Person.Observations = formModel.Observations;
                patient.Person.Profession = formModel.Profissao;
                patient.Person.Email = !string.IsNullOrEmpty(formModel.Email) ? formModel.Email.ToLower() : null;
                patient.Person.EmailGravatarHash = GravatarHelper.GetGravatarHash(formModel.Email);
                patient.Person.PhoneLand = formModel.PhoneLand;
                patient.Person.PhoneCell = formModel.PhoneCell;

                // handle patient address
                if (!patient.Person.Addresses.Any())
                    patient.Person.Addresses.Add(new Address { PracticeId = this.DbUser.PracticeId });

                var patientAddress = patient.Person.Addresses.First();
                patientAddress.CEP = formModel.Address.CEP;
                patientAddress.City = formModel.Address.City;
                patientAddress.Complement = formModel.Address.Complement;
                patientAddress.Neighborhood = formModel.Address.Neighborhood;
                patientAddress.StateProvince = formModel.Address.StateProvince;
                patientAddress.Street = formModel.Address.Street;

                this.db.SaveChanges();
                return this.RedirectToAction("Details", new { id = patient.Id });
            }

            return this.View("Edit", formModel);
        }