Пример #1
0
 public static ExaminationResultViewModel GetViewModel(ExaminationResult examResult, Func<DateTime, DateTime> toLocal)
 {
     return new ExaminationResultViewModel
         {
             Id = examResult.Id,
             PatientId = examResult.PatientId,
             Text = examResult.Text,
             MedicalProcedureCode = examResult.MedicalProcedureCode,
             MedicalProcedureName = examResult.MedicalProcedureName,
             ExaminationDate = toLocal(examResult.ExaminationDate),
             ReceiveDate = toLocal(examResult.ReceiveDate),
         };
 }
        public void Delete_WhenTheresAnExamResult()
        {
            PatientsController controller;
            int patientId;
            Patient patient;

            try
            {
                var 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);

                patientId = patient.Id;

                var examResult = new ExaminationResult()
                {
                    MedicalProcedureCode = "mcode",
                    MedicalProcedureName = "mname",
                    PatientId = patientId,
                    CreatedOn = DateTime.UtcNow,
                    Text = "tudo deu certo",
                    PracticeId = doctor.PracticeId,
                };

                this.db.SYS_MedicalProcedure.AddObject(
                    new SYS_MedicalProcedure()
                        {
                            Code = "mcode",
                            Name = "mname"
                        });

                this.db.ExaminationResults.AddObject(examResult);

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

            controller.Delete(patientId);

            // this patient must have been deleted
            patient = this.db.Patients.FirstOrDefault(p => p.Id == patientId);
            Assert.IsNull(patient);
        }
 /// <summary>
 /// Create a new ExaminationResult object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="patientId">Initial value of the PatientId property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 /// <param name="medicalProcedureName">Initial value of the MedicalProcedureName property.</param>
 /// <param name="practiceId">Initial value of the PracticeId property.</param>
 /// <param name="examinationDate">Initial value of the ExaminationDate property.</param>
 /// <param name="receiveDate">Initial value of the ReceiveDate property.</param>
 public static ExaminationResult CreateExaminationResult(global::System.Int32 id, global::System.String text, global::System.Int32 patientId, global::System.DateTime createdOn, global::System.String medicalProcedureName, global::System.Int32 practiceId, global::System.DateTime examinationDate, global::System.DateTime receiveDate)
 {
     ExaminationResult examinationResult = new ExaminationResult();
     examinationResult.Id = id;
     examinationResult.Text = text;
     examinationResult.PatientId = patientId;
     examinationResult.CreatedOn = createdOn;
     examinationResult.MedicalProcedureName = medicalProcedureName;
     examinationResult.PracticeId = practiceId;
     examinationResult.ExaminationDate = examinationDate;
     examinationResult.ReceiveDate = receiveDate;
     return examinationResult;
 }
Пример #4
0
        public ActionResult Edit(ExaminationResultViewModel[] examResults)
        {
            var formModel = examResults.Single();

            ExaminationResult dbObject;

            if (formModel.Id == null)
            {
                dbObject = new ExaminationResult
                {
                    CreatedOn = this.GetUtcNow(),
                    PatientId = formModel.PatientId.Value,
                    PracticeId = this.DbUser.PracticeId,
                };

                this.db.ExaminationResults.AddObject(dbObject);
            }
            else
            {
                var practiceId = this.DbUser.PracticeId;

                dbObject = this.db.ExaminationResults
                    .Where(r => r.Id == formModel.Id)
                    .FirstOrDefault(r => r.Patient.Doctor.Users.FirstOrDefault().PracticeId == practiceId);

                // If modelObj is null, we must tell the user that this object does not exist.
                if (dbObject == null)
                    return View("NotFound", formModel);

                // Security issue... must check current user practice against the practice of the edited objects.
                var currentUser = this.DbUser;
                if (currentUser.PracticeId != dbObject.Patient.Doctor.Users.First().PracticeId)
                    return View("NotFound", formModel);
            }

            if (this.ModelState.IsValid)
            {
                dbObject.Patient.IsBackedUp = false;
                dbObject.Text = formModel.Text;
                dbObject.MedicalProcedureName = formModel.MedicalProcedureName;
                dbObject.MedicalProcedureCode = formModel.MedicalProcedureId.HasValue
                    ? this.db.SYS_MedicalProcedure.Where(mp => mp.Id == formModel.MedicalProcedureId).Select(mp => mp.Code).FirstOrDefault()
                    : formModel.MedicalProcedureCode;
                dbObject.ExaminationDate = this.ConvertToUtcDateTime(formModel.ExaminationDate.Value);
                dbObject.ReceiveDate = this.ConvertToUtcDateTime(formModel.ReceiveDate.Value);

                this.db.SaveChanges();

                return this.View("Details", GetViewModel(dbObject, this.GetToLocalDateTimeConverter()));
            }

            return this.View("Edit", formModel);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ExaminationResults EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToExaminationResults(ExaminationResult examinationResult)
 {
     base.AddObject("ExaminationResults", examinationResult);
 }