示例#1
0
        /// <summary>
        /// Fills a new doctor with common useful data: default medical-certificates and a default health-insurance.
        /// </summary>
        /// <param name="doctor">The new doctor to receive some useful objects to work with.</param>
        public static void FillNewDoctorUtilityBelt(Doctor doctor)
        {
            {
                var medicalCertificate = new ModelMedicalCertificate
                {
                    Name = "Comparecimento em consulta",
                    Text = "O paciente <%Paciente%> compareceu a uma consulta no horário de <%HoraInicio%> até <%HoraFim%>.",
                    PracticeId = doctor.PracticeId,
                };
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "HoraInicio", PracticeId = doctor.PracticeId, });
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "HoraFim", PracticeId = doctor.PracticeId, });

                doctor.ModelMedicalCertificates.Add(medicalCertificate);
            }

            {
                var medicalCertificate = new ModelMedicalCertificate
                {
                    Name = "Paciente necessita repouso",
                    Text = "O paciente <%Paciente%> necessita de repouso do dia <%DiaInicio%> até o dia <%DiaFim%>.",
                    PracticeId = doctor.PracticeId,
                };
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "DiaInicio", PracticeId = doctor.PracticeId, });
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "DiaFim", PracticeId = doctor.PracticeId, });

                doctor.ModelMedicalCertificates.Add(medicalCertificate);
            }

            doctor.HealthInsurances.Add(new HealthInsurance
            {
                Name = "Particular",
                IsParticular = true,
                IsActive = true,
                PracticeId = doctor.PracticeId,
                ReturnTimeInterval = 30,
            });
        }
        public void Delete_WhenTheresAMedicalCertificate()
        {
            PatientsController controller;
            Doctor doctor;
            Patient patient;

            try
            {
                doctor = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                var mr = new MockRepository(true);
                controller = mr.CreateController<PatientsController>();
                Firestarter.CreateFakePatients(doctor, this.db, 1);

                // we now have 1 patient
                patient = this.db.Patients.FirstOrDefault();
                Assert.IsNotNull(patient);

                var certificateModel = new Cerebello.Model.ModelMedicalCertificate()
                {
                    DoctorId = doctor.Id,
                    Name = "model1",
                    Text = "model1",
                    PracticeId = doctor.PracticeId,
                };

                certificateModel.Fields.Add(new ModelMedicalCertificateField()
                {
                    Name = "field1",
                    PracticeId = doctor.PracticeId,
                });

                var certificate = new Cerebello.Model.MedicalCertificate()
                {
                    ModelMedicalCertificate = certificateModel,
                    Patient = patient,
                    Text = "text",
                    CreatedOn = DateTime.UtcNow,
                    PracticeId = doctor.PracticeId,
                };

                certificate.Fields.Add(new MedicalCertificateField()
                {
                    Name = "field1",
                    Value = "value",
                    PracticeId = doctor.PracticeId,
                });

                this.db.MedicalCertificates.AddObject(certificate);
                this.db.SaveChanges();
            }
            catch
            {
                Assert.Inconclusive("Test initialization has failed.");
                return;
            }

            controller.Delete(patient.Id);

            // this patient must have been deleted
            patient = this.db.Patients.FirstOrDefault(p => p.Id == patient.Id);
            Assert.IsNull(patient);
        }
        public ActionResult Edit(ModelMedicalCertificateViewModel formModel)
        {
            if (this.ModelState.IsValid)
            {
                ModelMedicalCertificate certificateModel = null;

                if (formModel.Id != null)
                    certificateModel = this.db.ModelMedicalCertificates.First(m => m.Id == formModel.Id);
                else
                {
                    certificateModel = new ModelMedicalCertificate { PracticeId = this.DbUser.PracticeId, };
                    this.db.ModelMedicalCertificates.AddObject(certificateModel);
                }

                certificateModel.Name = formModel.Name;
                certificateModel.Text = formModel.Text;
                certificateModel.Doctor = this.Doctor;
                certificateModel.PracticeId = this.DbPractice.Id;

                var fieldsFoundInText =
                    Regex.Matches(formModel.Text, @"\<%([^%]+?)%\>", RegexOptions.IgnoreCase)
                        .Cast<Match>().Select(m => m.Groups[1].Value.Trim()).ToList();

                // delete fields found in the DB that don't have a matching field in text
                var itemsToDelete = certificateModel.Fields
                    .Where(dbField => fieldsFoundInText.All(f => f != dbField.Name))
                    .ToList();

                foreach (var itemToDelete in itemsToDelete)
                    this.db.ModelMedicalCertificateFields.DeleteObject(itemToDelete);

                // add new fields to the DB
                foreach (var field in fieldsFoundInText
                    .Where(field => certificateModel.Fields.All(f => f.Name != field))
                    .Where(field => StringHelper.RemoveDiacritics(field).ToLower() != "paciente"))
                {
                    certificateModel.Fields.Add(
                        new ModelMedicalCertificateField
                            {
                                PracticeId = this.DbUser.PracticeId,
                                Name = field
                            });
                }

                this.db.SaveChanges();

                return this.Redirect(this.Url.Action("Details", new { id = certificateModel.Id }));
            }

            return this.View("Edit", formModel);
        }
示例#4
0
        public void Delete_WhenTheresAMedicalCertificate()
        {
            PatientsController controller;
            Doctor             doctor;
            Patient            patient;

            try
            {
                doctor = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                var mr = new MockRepository(true);
                controller = mr.CreateController <PatientsController>();
                Firestarter.CreateFakePatients(doctor, this.db, 1);

                // we now have 1 patient
                patient = this.db.Patients.FirstOrDefault();
                Assert.IsNotNull(patient);

                var certificateModel = new Cerebello.Model.ModelMedicalCertificate()
                {
                    DoctorId   = doctor.Id,
                    Name       = "model1",
                    Text       = "model1",
                    PracticeId = doctor.PracticeId,
                };

                certificateModel.Fields.Add(new ModelMedicalCertificateField()
                {
                    Name       = "field1",
                    PracticeId = doctor.PracticeId,
                });

                var certificate = new Cerebello.Model.MedicalCertificate()
                {
                    ModelMedicalCertificate = certificateModel,
                    Patient    = patient,
                    Text       = "text",
                    CreatedOn  = DateTime.UtcNow,
                    PracticeId = doctor.PracticeId,
                };

                certificate.Fields.Add(new MedicalCertificateField()
                {
                    Name       = "field1",
                    Value      = "value",
                    PracticeId = doctor.PracticeId,
                });

                this.db.MedicalCertificates.AddObject(certificate);
                this.db.SaveChanges();
            }
            catch
            {
                Assert.Inconclusive("Test initialization has failed.");
                return;
            }

            controller.Delete(patient.Id);

            // this patient must have been deleted
            patient = this.db.Patients.FirstOrDefault(p => p.Id == patient.Id);
            Assert.IsNull(patient);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ModelMedicalCertificates EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToModelMedicalCertificates(ModelMedicalCertificate modelMedicalCertificate)
 {
     base.AddObject("ModelMedicalCertificates", modelMedicalCertificate);
 }
 /// <summary>
 /// Create a new ModelMedicalCertificate object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="doctorId">Initial value of the DoctorId property.</param>
 /// <param name="practiceId">Initial value of the PracticeId property.</param>
 public static ModelMedicalCertificate CreateModelMedicalCertificate(global::System.Int32 id, global::System.String name, global::System.String text, global::System.Int32 doctorId, global::System.Int32 practiceId)
 {
     ModelMedicalCertificate modelMedicalCertificate = new ModelMedicalCertificate();
     modelMedicalCertificate.Id = id;
     modelMedicalCertificate.Name = name;
     modelMedicalCertificate.Text = text;
     modelMedicalCertificate.DoctorId = doctorId;
     modelMedicalCertificate.PracticeId = practiceId;
     return modelMedicalCertificate;
 }