コード例 #1
0
        public static MedicalCertificateViewModel GetViewModel(MedicalCertificate model, Func<DateTime, DateTime> toLocal)
        {
            var viewModel = new MedicalCertificateViewModel
                {
                    Id = model.Id,
                    PatientId = model.PatientId,
                    ModelName = model.ModelMedicalCertificate != null ? model.ModelMedicalCertificate.Name : null,
                    IssuanceDate = toLocal(model.IssuanceDate),
                    Fields = (from f in model.Fields
                              select new MedicalCertificateFieldViewModel()
                                  {
                                      Id = f.Id,
                                      Name = f.Name,
                                      Value = f.Value
                                  }).ToList()
                };

            return viewModel;
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        public ActionResult Edit(MedicalCertificateViewModel[] medicalCertificates)
        {
            var formModel = medicalCertificates.Single();

            ModelMedicalCertificate certificateModel = null;

            // validates the existence and the compliance of the certificate model
            if (formModel.ModelId.HasValue)
            {
                certificateModel = this.db.ModelMedicalCertificates.FirstOrDefault(mmc => mmc.Id == formModel.ModelId);
                if (certificateModel == null)
                    this.ModelState.AddModelError<MedicalCertificateViewModel>(m => m.ModelId, "O modelo de atestado informado não é válido");
                else
                {
                    // for each field in the model, all must exist in the formModel
                    if (certificateModel.Fields.Any(field => formModel.Fields.All(f => f.Name.ToLower() != field.Name.ToLower())))
                        this.ModelState.AddModelError<MedicalCertificateViewModel>(m => m.Fields, "Dados inválidos. As informações recebidas não condizem com o modelo de atestado especificado");

                    // #KNOWN ISSUE# The next statements shouldn't exist. The REQUIRED attribute should work :(
                    // for all fields existing in the formModel, all must have a value
                    for (var i = 0; i < formModel.Fields.Count; i++)
                    {
                        var field = formModel.Fields[i];
                        if (string.IsNullOrEmpty(field.Value))
                            this.ModelState.AddModelError("Fields[" + i + "]", "O valor do campo é requerido");
                    }
                }
            }

            if (!formModel.ModelId.HasValue && !formModel.Id.HasValue)
                this.ModelState.AddModelError<MedicalCertificateViewModel>(m => m.ModelId, "É necessário informar o modelo do atestado");

            // validates the existence of the patient
            if (formModel.PatientId.HasValue && !this.db.Patients.Any(m => m.Id == formModel.PatientId))
                this.ModelState.AddModelError<MedicalCertificateViewModel>(m => m.ModelId, "O paciente informado não é válido");

            if (this.ModelState.IsValid)
            {
                MedicalCertificate certificate = null;
                if (formModel.Id == null)
                {
                    certificate = new MedicalCertificate()
                    {
                        CreatedOn = this.GetUtcNow(),
                        PatientId = formModel.PatientId.Value,
                        PracticeId = this.DbUser.PracticeId,
                    };
                    this.db.MedicalCertificates.AddObject(certificate);
                }
                else
                {
                    certificate = this.db.MedicalCertificates.FirstOrDefault(r => r.Id == formModel.Id);
                    if (certificate == null)
                        return this.ObjectNotFound();
                }

                if (certificateModel != null)
                {
                    certificate.ModelMedicalCertificateId = certificateModel.Id;
                    certificate.Text = certificateModel.Text;
                }
                else
                    certificate.ModelMedicalCertificateId = null;

                certificate.Patient.IsBackedUp = false;
                certificate.Fields.Update(
                        formModel.Fields,
                        (vm, m) => vm.Name == m.Name,
                        (vm, m) =>
                        {
                            m.Name = vm.Name;
                            m.Value = vm.Value;
                            m.PracticeId = this.DbUser.PracticeId;
                        },
                        (m) => this.db.MedicalCertificateFields.DeleteObject(m));

                certificate.IssuanceDate = this.ConvertToUtcDateTime(formModel.IssuanceDate.Value);
                this.db.SaveChanges();

                // todo: use GetViewModel method:
                //var viewModel = GetViewModel(certificate);

                var viewModel = new MedicalCertificateViewModel
                {
                    Id = certificate.Id,
                    ModelId = certificate.ModelMedicalCertificateId,
                    // the only situation in which ModelName will be null is when the model certificate has been removed
                    ModelName = certificate.ModelMedicalCertificate != null ? certificate.ModelMedicalCertificate.Name : null,
                    PatientId = certificate.PatientId,
                    IssuanceDate = this.ConvertToLocalDateTime(certificate.IssuanceDate),
                    Fields = (from f in certificate.Fields
                              select new MedicalCertificateFieldViewModel()
                              {
                                  Id = f.Id,
                                  Name = f.Name,
                                  Value = f.Value,
                              }).ToList(),
                };

                return this.View("Details", viewModel);
            }

            formModel.ModelOptions = this.db.ModelMedicalCertificates.ToList().Select(mmc => new SelectListItem() { Text = mmc.Name, Value = mmc.Id.ToString() }).ToList();
            return this.View("Edit", formModel);
        }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the MedicalCertificates EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMedicalCertificates(MedicalCertificate medicalCertificate)
 {
     base.AddObject("MedicalCertificates", medicalCertificate);
 }
コード例 #6
0
 /// <summary>
 /// Create a new MedicalCertificate object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="patientId">Initial value of the PatientId property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="practiceId">Initial value of the PracticeId property.</param>
 /// <param name="issuanceDate">Initial value of the IssuanceDate property.</param>
 public static MedicalCertificate CreateMedicalCertificate(global::System.Int32 id, global::System.Int32 patientId, global::System.DateTime createdOn, global::System.String text, global::System.Int32 practiceId, global::System.DateTime issuanceDate)
 {
     MedicalCertificate medicalCertificate = new MedicalCertificate();
     medicalCertificate.Id = id;
     medicalCertificate.PatientId = patientId;
     medicalCertificate.CreatedOn = createdOn;
     medicalCertificate.Text = text;
     medicalCertificate.PracticeId = practiceId;
     medicalCertificate.IssuanceDate = issuanceDate;
     return medicalCertificate;
 }