public ActionResult AddEdit(string dfn, string pregIen) { // *** Create the model *** PatientOutcomeAddEdit model = new PatientOutcomeAddEdit(); // *** Make sure patient is set *** model.Patient = this.CurrentPatient; if (!string.IsNullOrWhiteSpace(pregIen)) { // *** Keep pregnancy ien in model *** model.PregnancyIen = pregIen; // *** Get the outcome type *** PregnancyOutcomeType outcomeType = PregnancyUtilities.GetPregnancyOutcome(this.DashboardRepository, dfn, pregIen); // *** Get the outcome details *** model.OutcomeDetails = PregnancyUtilities.GetOutcomeDetails(this.DashboardRepository, dfn, pregIen, outcomeType); // *** Add outcome type to the model *** model.OutcomeDetails.OutcomeType = outcomeType; // *** Get the pregnancy details *** PregnancyDetails pregDetails = PregnancyUtilities.GetPregnancy(this.DashboardRepository, dfn, pregIen); // *** Set the outcome date *** if (pregDetails != null) { model.OutcomeDetails.OutcomeDate = pregDetails.DisplayEndDate; // *** This is needed for GA in delivery details *** model.Edd = pregDetails.EDD; } } return(View(model)); }
public ActionResult AddEdit(PatientOutcomeAddEdit model) { ActionResult returnResult = null; // *** Make sure patient is current *** this.CurrentPatientDfn = model.Patient.Dfn; model.Patient = this.CurrentPatient; bool ok = true; // *** Add pregnancy record if it does not exist *** if (string.IsNullOrWhiteSpace(model.PregnancyIen)) { PregnancyDetails newDetails = new PregnancyDetails() { PatientDfn = this.CurrentPatientDfn, RecordType = PregnancyRecordType.Historical }; IenResult saveResult = this.DashboardRepository.Pregnancy.SavePregnancy(newDetails); if (saveResult.Success) { model.PregnancyIen = saveResult.Ien; } else { this.Error(saveResult.Message); } } if (!string.IsNullOrWhiteSpace(model.PregnancyIen)) { string normalizedOutcomeDate = ""; if (!string.IsNullOrWhiteSpace(model.OutcomeDetails.OutcomeDate)) { normalizedOutcomeDate = VistaDates.StandardizeDateFormat(model.OutcomeDetails.OutcomeDate); } // *** Update outcome observation *** List <Observation> outcomeList = ObservationsFactory.CreateOutcomeObservations ( model.Patient.Dfn, model.OutcomeDetails.OutcomeType, normalizedOutcomeDate, model.PregnancyIen ); BrokerOperationResult obsResult = this.DashboardRepository.Observations.SaveSingletonObservations(outcomeList); if (!obsResult.Success) { this.Error(obsResult.Message); ok = false; } if (ok) { if (!string.IsNullOrWhiteSpace(normalizedOutcomeDate)) { // *** Update pregnancy end date *** PregnancyDetails preg = PregnancyUtilities.GetPregnancy(this.DashboardRepository, model.Patient.Dfn, model.PregnancyIen); if (preg != null) { // *** Update date *** preg.DisplayEndDate = normalizedOutcomeDate; // *** Save updated pregnancy *** BrokerOperationResult savePregResult = this.DashboardRepository.Pregnancy.SavePregnancy(preg); // *** Check result *** if (!savePregResult.Success) { this.Error(savePregResult.Message); ok = false; } } } } // *** Get observations from the model *** ObservationConstructable details = model.OutcomeDetails.SelectedDetails; if (details != null) { List <Observation> obsList = details.GetObservations(model.Patient.Dfn, model.PregnancyIen, ""); if (obsList != null) { if (obsList.Count > 0) { // *** If we have any, save them *** BrokerOperationResult result = this.DashboardRepository.Observations.SaveSingletonObservationsByCategory(obsList); if (!result.Success) { this.Error(result.Message); ok = false; } } } } } if (ok) { returnResult = RedirectToAction("PregnancyView", "Pregnancy", new { dfn = model.Patient.Dfn, pregIen = model.PregnancyIen }); } else { returnResult = View(model); } return(returnResult); }