//Edit Patient Records public ActionResult Edit(Guid id) { var patientRecord = _context.PatientRecords.SingleOrDefault(p => p.Id == id); var patient = _context.Patients.SingleOrDefault(pa => pa.PatientRecordId == id); if (patientRecord == null) { return(HttpNotFound()); } else { var viewModel = new PatientRecordsFormViewModel { PatientRecord = patientRecord, Patient = patient, Doctor = _context.Doctors.ToList(), Workload = _context.Workloads.ToList(), Limitations = _context.Limitations.ToList(), Diagnosis = _context.Diagnosis.ToList(), DoctorId = patientRecord.DoctorId, TriageLevel = _context.TriageLevels.ToList(), TriageType = _context.TriageType.ToList() }; return(View("PatientRecordsForm", viewModel)); } }
public ActionResult New(Guid patientId) { var triageLevels = _context.TriageLevels.ToList(); var triageTypes = _context.TriageType.ToList(); var diagnosis = _context.Diagnosis.ToList(); var patientRecord = new PatientRecord(); var viewModel = new PatientRecordsFormViewModel(); return(View("PatientRecordsForm", viewModel)); }
public ActionResult Save(PatientRecordsFormViewModel formViewModel) { if (!ModelState.IsValid) { var viewModel = new PatientRecordsFormViewModel { PatientRecord = formViewModel.PatientRecord }; return(View("PatientRecordsForm", viewModel)); } if (formViewModel.PatientRecord.Id == Guid.Empty) { _context.PatientRecords.Add(formViewModel.PatientRecord); } else { var patientRecordInDb = _context.PatientRecords.Single(c => c.Id == formViewModel.PatientRecord.Id); //Change to AutoMapper patientRecordInDb.DiagnosisId = formViewModel.PatientRecord.DiagnosisId; patientRecordInDb.DateReceived = formViewModel.PatientRecord.DateReceived; patientRecordInDb.ClinicalTrials = formViewModel.PatientRecord.ClinicalTrials; patientRecordInDb.ConsultDate = formViewModel.PatientRecord.ConsultDate; patientRecordInDb.DoctorId = formViewModel.PatientRecord.DoctorId; patientRecordInDb.LimitationsId = formViewModel.PatientRecord.LimitationsId; patientRecordInDb.PathReview = formViewModel.PatientRecord.PathReview; patientRecordInDb.WorkloadId = formViewModel.PatientRecord.WorkloadId; patientRecordInDb.Comment = formViewModel.PatientRecord.Comment; patientRecordInDb.ContactWithPatient = formViewModel.PatientRecord.ContactWithPatient; patientRecordInDb.ReferMD = formViewModel.PatientRecord.ReferMD; patientRecordInDb.TriageLevelId = formViewModel.PatientRecord.TriageLevelId; patientRecordInDb.TriageTypeId = formViewModel.PatientRecord.TriageTypeId; } _context.SaveChanges(); if (formViewModel.DoctorId != formViewModel.PatientRecord.DoctorId) { //Send Email to Doctor if new patientRecord created or doctor changed. //Get Patient details var patientDetails = _context.Patients.Single(p => p.PatientRecordId == formViewModel.PatientRecord.Id); //Get Doctor details var doctorDetails = _context.Doctors.Single(d => d.Id == formViewModel.PatientRecord.DoctorId); Execute(patientDetails, doctorDetails).Wait(); } return(RedirectToAction("Index", "Patients")); }