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));
        }
Beispiel #2
0
        public void updateExaminationResult(ExaminationResult ExaminationResult)
        {
            var record = db.ExaminationResults.Where(x => x.ExaminationResultID == ExaminationResult.ExaminationResultID).FirstOrDefault();

            // record.DoctorID = ExaminationResult.DoctorID;
            record.DispenserID = ExaminationResult.DispenserID;
            //  record.Time = ExaminationResult.Time;
            //  record.Result = ExaminationResult.Result;
            //  record.PatientID = ExaminationResult.PatientID;
            //  record.Description = ExaminationResult.Description;
            db.SubmitChanges();
        }
Beispiel #3
0
        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);
        }
 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),
     });
 }
Beispiel #5
0
 public bool updateExaminationResult(eExaminationResult e)
 {
     try
     {
         ExaminationResult temp = new ExaminationResult();
         temp.Description         = e.Description;
         temp.DispenserID         = Convert.ToInt32(e.DispenserID);
         temp.DoctorID            = e.DoctorID;
         temp.ExaminationResultID = e.ExaminationResultID;
         temp.PatientID           = e.PatientID;
         temp.Time   = e.Time;
         temp.Result = e.Result;
         erdal.updateExaminationResult(temp);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public int insertExaminationResult(eExaminationResult e)
 {
     try
     {
         ExaminationResult temp = new ExaminationResult();
         temp.Description = e.Description;
         temp.DispenserID = null;
         temp.DoctorID    = e.DoctorID;
         temp.PatientID   = e.PatientID;
         temp.Time        = DateTime.Now;
         temp.Result      = e.Result;
         int           id  = erdal.insertExaminationResult(temp);
         PartientOfDay pod = new PartientOfDay();
         pod.PartientID = temp.PatientID;
         pod.Status     = true;
         potdal.updatePartientOfDay(pod);
         return(id);
     }
     catch
     {
         return(0);
     }
 }
Beispiel #7
0
 public int insertExaminationResult(ExaminationResult ExaminationResult)
 {
     db.ExaminationResults.InsertOnSubmit(ExaminationResult);
     db.SubmitChanges();
     return(ExaminationResult.ExaminationResultID);
 }
 public Task AddAsync(ExaminationResult result)
 {
     resultsDataSet.Add(result);
     return(dbContext.SaveChangesAsync());
 }
 public void insertExaminationResult(ExaminationResult ExaminationResult)
 {
     db.ExaminationResults.InsertOnSubmit(ExaminationResult);
     db.SubmitChanges();
 }