private bool UpdatePregnancyStatus(string dfn)
        {
            bool returnVal = false;

            PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentPregnancy(dfn);

            if (!pregResult.Success)
            {
                this.Error(pregResult.Message);
            }
            else if (pregResult.Pregnancy == null)
            {
                PregnancyDetails newPreg = new PregnancyDetails();
                newPreg.PatientDfn = dfn;
                newPreg.RecordType = PregnancyRecordType.Current;

                BrokerOperationResult result = this.DashboardRepository.Pregnancy.SavePregnancy(newPreg);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                {
                    returnVal = true;
                }
            }

            return(returnVal);
        }
        public IenResult SavePregnancy(PregnancyDetails pregnancy)
        {
            // *** Saves pregnancy data ***

            IenResult result = new IenResult();

            // *** Create the dsio pregnancy string data ***
            DsioPregnancy dsioPregnancy = CreateDsioPregnancy(pregnancy);

            // *** Create RPC command ***
            DsioSavePregDetailsCommand command = new DsioSavePregDetailsCommand(this.broker);

            // *** Add command arguments ***
            command.AddCommandArguments(dsioPregnancy, false);

            // *** Execute the command ***
            RpcResponse response = command.Execute();

            // *** Add response data to result ***
            result.SetResult(response.Status == RpcResponseStatus.Success, response.InformationalMessage);

            if (result.Success)
            {
                result.Ien = command.Ien;
            }

            return(result);
        }
        //private IDashboardRepository DashboardRepository { get; set; }

        //public PregnancyUtilities(IDashboardRepository repo)
        //{
        //    this.DashboardRepository = repo;
        //}

        public static PregnancyDetails GetWorkingPregnancy(IDashboardRepository repo, string dfn, string pregIen)
        {
            PregnancyDetails returnVal = null;

            // *** First try the pregnancy ien passed in ***
            if (!string.IsNullOrWhiteSpace(pregIen))
            {
                PregnancyListResult pregResult = repo.Pregnancy.GetPregnancies(dfn, pregIen);

                if (pregResult.Success)
                {
                    if (pregResult.Pregnancies != null)
                    {
                        if (pregResult.Pregnancies.Count > 0)
                        {
                            returnVal = pregResult.Pregnancies[0];
                        }
                    }
                }
            }

            // *** Then try to get the current/most-recent ***
            if (returnVal == null)
            {
                PregnancyResult pregResult = repo.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

                if (pregResult.Success)
                {
                    returnVal = pregResult.Pregnancy;
                }
            }

            return(returnVal);
        }
        public ActionResult PatientIndex(string dfn, string page)
        {
            // TODO: Make education items pregnancy specific?
            // TODO: Allow passed in pregnancy

            PatientEducationIndex model = new PatientEducationIndex();

            model.Patient = this.CurrentPatient;

            //PregnancyUtilities util = new PregnancyUtilities(this.DashboardRepository);

            PregnancyDetails preg = PregnancyUtilities.GetWorkingPregnancy(this.DashboardRepository, dfn, "");

            if (preg != null)
            {
                if ((preg.EDD != DateTime.MinValue) || (preg.EndDate != DateTime.MinValue))
                {
                    GetMergedList(model, preg);
                }
                else
                {
                    GetPatientEducationItemList(model);
                }
            }
            else
            {
                GetPatientEducationItemList(model);
            }

            return(View(model));
        }
        public static PregnancyDetails GetPregnancy(IDashboardRepository repo, string patientDfn, string pregIen)
        {
            PregnancyDetails returnVal = null;

            // *** Get pregnancy ***
            PregnancyListResult pregResult = repo.Pregnancy.GetPregnancies(patientDfn, pregIen);

            // *** Check result ***
            if (pregResult.Success)
            {
                if (pregResult.Pregnancies != null)
                {
                    if (pregResult.Pregnancies.Count == 1)
                    {
                        returnVal = pregResult.Pregnancies[0];
                    }
                }
            }

            // *** Also, get lmp, fetus count ***
            if (returnVal != null)
            {
                PregnancyDetails tempPreg = GetPregnancyObservationData(repo, patientDfn, pregIen);

                returnVal.Lmp            = tempPreg.Lmp;
                returnVal.LmpDateType    = tempPreg.LmpDateType;
                returnVal.FetusBabyCount = tempPreg.FetusBabyCount;

                // *** Will return EDD Basis and Is Final ***
                returnVal.EddBasis   = tempPreg.EddBasis;
                returnVal.EddIsFinal = tempPreg.EddIsFinal;
            }

            return(returnVal);
        }
        public AddBabyResult AddBabyToPregnancy(string patientDfn, string pregnancyIen)
        {
            AddBabyResult returnResult = new AddBabyResult();

            PregnancyListResult pregResult = this.GetPregnancies(patientDfn, pregnancyIen);

            if (!pregResult.Success)
            {
                returnResult.SetResult(pregResult.Success, pregResult.Message);
            }
            else if (pregResult.Pregnancies != null)
            {
                if (pregResult.Pregnancies.Count == 1)
                {
                    PregnancyDetails pregDetail = pregResult.Pregnancies[0];

                    bool okToAdd = true;

                    // *** Do we have a babies object ? ***
                    if (pregDetail.Babies != null)
                    {
                        if (pregDetail.Babies.Count >= 9)
                        {
                            returnResult.SetResult(false, "This pregnancy already has 9 babies.  You cannot add more than 9 babies to a pregnancy.");
                            okToAdd = false;
                        }
                    }

                    if (okToAdd)
                    {
                        // *** Create the save command ***
                        DsioSavePregDetailsCommand saveCommand = new DsioSavePregDetailsCommand(this.broker);

                        // *** Create the dsio pregnancy ***
                        DsioPregnancy dsioPreg = CreateDsioPregnancy(pregDetail);

                        // *** Add the command arguments, addBaby = true ***
                        saveCommand.AddCommandArguments(dsioPreg, true);

                        // *** Execute the command ***
                        RpcResponse response = saveCommand.Execute();

                        returnResult.SetResult(pregResult.Success, pregResult.Message);

                        // *** Check the status ***
                        if (response.Status == RpcResponseStatus.Success)
                        {
                            //int newBabyNum = -1;
                            //int.TryParse(saveCommand.BabyNumber, out newBabyNum);
                            //pregDetail.Babies.Add(new Baby() { BabyNum = newBabyNum, Ien = saveCommand.BabyIen });
                            returnResult.NewBabyIen    = saveCommand.BabyIen;
                            returnResult.NewBabyNumber = saveCommand.BabyNumber;
                        }
                    }
                }
            }

            return(returnResult);
        }
        public ActionResult PregnancyIndex(string dfn, string pregIen, string page)
        {
            PregnancyChecklistIndex model = new PregnancyChecklistIndex();

            model.Patient = this.CurrentPatient;

            // TODO: In future add ability to view checklist for a specific pregnancy passed in as parameter
            //       Add a pregnancy selection and display
            //PregnancyDetails preg = PregnancyUtilities.GetWorkingPregnancy(this.DashboardRepository, dfn, pregIen);

            PregnancyDetails preg = PregnancyUtilities.GetWorkingPregnancy(this.DashboardRepository, dfn, "");

            if (preg == null)
            {
                model.NoPregnancies = true;
            }
            else
            {
                if ((preg.EDD == DateTime.MinValue) && (preg.EndDate == DateTime.MinValue))
                {
                    model.NoPregnancyDate = true;
                }

                model.Pregnancy = preg;

                //PregnancyChecklistItemsResult result = this.DashboardRepository.Checklist.GetPregnancyItems(dfn, preg.Ien, "");

                //if (!result.Success)
                //    this.Error(result.Message);
                //else
                //{
                //    model.Items = new PregnancyChecklistItemList();
                //    model.Items.AddRange(result.Items);

                //    model.Items.AddPregnancyDates(preg.EDD, preg.EndDate);

                //    model.Items.Sort(delegate(PregnancyChecklistItem x, PregnancyChecklistItem y)
                //    {
                //        return x.DueDate.CompareTo(y.DueDate);
                //    });
                //}

                PregnancyChecklistItemsResult result = ChecklistUtility.GetSortedPregnancyChecklist(this.DashboardRepository, dfn, preg, DsioChecklistCompletionStatus.Unknown);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                {
                    model.Items.AddRange(result.Items);
                }
            }

            // TODO: Paging...

            return(View(model));
        }
        public PregnancyResult GetCurrentOrMostRecentPregnancy(string patientDfn)
        {
            // *** Returns the current pregnancy information ***

            PregnancyResult result = new PregnancyResult();

            // *** Get all pregnancies ***
            PregnancyListResult listResult = GetPregnancies(patientDfn, "");

            // *** Add results to return ***
            result.SetResult(listResult.Success, listResult.Message);

            if (result.Success)
            {
                // *** If we have pregnancies, look for a current ***
                if (listResult.Pregnancies != null)
                {
                    if (listResult.Pregnancies.Count > 0)
                    {
                        PregnancyDetails mostRecent = null;
                        foreach (PregnancyDetails preg in listResult.Pregnancies)
                        {
                            if (preg.RecordType == PregnancyRecordType.Current)
                            {
                                result.Pregnancy = preg;
                            }

                            if (mostRecent == null)
                            {
                                mostRecent = preg;
                            }
                            else if (mostRecent.EndDate < preg.EndDate)
                            {
                                mostRecent = preg;
                            }
                        }

                        if (result.Pregnancy == null)
                        {
                            if (mostRecent != null)
                            {
                                result.Pregnancy = mostRecent;
                            }
                        }
                    }
                }

                // *** Add result/message if no current ***
                if (result.Pregnancy == null)
                {
                    result.SetResult(true, "No Pregnancy Data Found");
                }
            }

            return(result);
        }
        public PregnancyListResult GetPregnancies(string patientDfn, string pregnancyIen)
        {
            PregnancyListResult result = new PregnancyListResult();

            // *** Create the command ***
            DsioGetPregDetailsCommand command = new DsioGetPregDetailsCommand(this.broker);

            // *** Add arguments...gets all ***
            command.AddCommandArguments(patientDfn, pregnancyIen);

            // *** Execute command ***
            RpcResponse response = command.Execute();

            // *** Add response to result ***
            result.SetResult(response.Status == RpcResponseStatus.Success, response.InformationalMessage);

            // *** Check for success ***
            if (result.Success)
            {
                // *** Loop through the list and create strongly typed pregnancy list ***
                if (command.PregnancyList != null)
                {
                    foreach (DsioPregnancy dsioPreg in command.PregnancyList)
                    {
                        if (result.Pregnancies == null)
                        {
                            result.Pregnancies = new List <PregnancyDetails>();
                        }

                        PregnancyDetails tempPregnancy = CreatePregnancy(dsioPreg);

                        result.Pregnancies.Add(tempPregnancy);
                    }
                }

                // *** If no pregnancies, then nothing found ***
                if (result.Pregnancies == null)
                {
                    result.SetResult(true, "No Pregnancy Data Found");
                }
            }

            return(result);
        }
예제 #10
0
        private bool UpdatePregnancyStatus(string dfn, CreateTrackingEntry newTrackingEntry)
        {
            bool returnVal = false;

            PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentPregnancy(dfn);

            if (!pregResult.Success)
            {
                this.Error(pregResult.Message);
            }
            else if (pregResult.Pregnancy == null)
            {
                PregnancyDetails newPreg = new PregnancyDetails();
                newPreg.PatientDfn = dfn;
                newPreg.RecordType = PregnancyRecordType.Current;
                bool pregnancyValue = true;
                newPreg.Lmp = newTrackingEntry.LMP;
                newPreg.EDD = VistaDates.ParseDateString(newTrackingEntry.EDD, VistaDates.VistADateOnlyFormat);

                BrokerOperationResult wvrpcorResult = this.DashboardRepository.Pregnancy.SaveWvrpcorPregnancy(newPreg, newPreg.PatientDfn, pregnancyValue);
                if (!wvrpcorResult.Success)
                {
                    this.Error(wvrpcorResult.Message);
                }
                else
                {
                    BrokerOperationResult result = this.DashboardRepository.Pregnancy.SavePregnancy(newPreg);

                    if (!result.Success)
                    {
                        this.Error(result.Message);
                    }
                    else
                    {
                        returnVal = true;
                    }
                }
            }

            return(returnVal);
        }
예제 #11
0
        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));
        }
예제 #12
0
        public ActionResult Index(string dfn, LabResultType labType, bool pregFilter, string page)
        {
            // *** Create the model ***
            LabModel model = new LabModel();

            // *** Set the patient ***
            model.Patient = this.CurrentPatient;

            // *** Get the page value ***
            int pageVal = this.GetPage(page);

            // *** Create date range dates ***
            DateTime fromDate = DateTime.MinValue;
            DateTime toDate   = DateTime.MinValue;

            // *** Add the filters to the model ***
            model.LabTypeFilter = labType.ToString();

            PregnancyDetails pregDetails = null;

            PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

            if (pregResult.Success)
            {
                if (pregResult.Pregnancy != null)
                {
                    pregDetails = pregResult.Pregnancy;
                }
            }

            if (pregDetails != null)
            {
                if (pregDetails.RecordType == Data.Models.Pregnancy.PregnancyRecordType.Current)
                {
                    model.PregnancyFilterDescription = "Current Pregnancy";
                }
                else
                {
                    model.PregnancyFilterDescription = "Most Recent Pregnancy";
                }

                if (pregFilter)
                {
                    // *** Set the date range dates ***
                    fromDate = pregDetails.StartDate;
                    toDate   = pregDetails.EndDate;

                    // *** Create an approximate date/time for fromDate if needed ***
                    if (fromDate == DateTime.MinValue)
                    {
                        if (toDate != DateTime.MinValue)
                        {
                            fromDate = toDate.AddDays(-280);
                        }
                    }

                    model.FilteredByPregnancy = true;
                }

                model.CanFilterByPregnancy = true;
            }
            else
            {
                model.PregnancyFilterDescription = "Current Pregnancy";
                model.CanFilterByPregnancy       = false;
                model.FilteredByPregnancy        = false;
            }

            // *** Get the list of labs ***
            LabItemsResult labsResult = this.DashboardRepository.Labs.GetList(dfn, labType, pregFilter, fromDate, toDate, pageVal, LabItemsPerPage);

            if (!labsResult.Success)
            {
                this.Error(labsResult.Message);
            }
            else
            if (labsResult.Labs == null)
            {
                model.Items = new List <LabItem>();
            }
            else
            {
                // *** Add lab items ***
                model.Items = labsResult.Labs;

                // *** Paging ***
                model.Paging.SetPagingData(LabItemsPerPage, pageVal, labsResult.TotalResults);
                model.Paging.BaseUrl = Url.Action("Index", new { dfn = dfn, labtype = labType, pregFilter = pregFilter, page = "" });
            }

            return(View(model));
        }
        public static PregnancyChecklistItemsResult GetSortedPregnancyChecklist(IDashboardRepository repo, string patientDfn, PregnancyDetails pregnancy, DsioChecklistCompletionStatus status)
        {
            PregnancyChecklistItemsResult result = new PregnancyChecklistItemsResult();

            PregnancyChecklistItemsResult chkResult = repo.Checklist.GetPregnancyItems(patientDfn, pregnancy.Ien, "", status);

            result.SetResult(chkResult.Success, chkResult.Message);

            if (result.Success)
            {
                PregnancyChecklistItemList tempList = new PregnancyChecklistItemList();

                tempList.AddRange(chkResult.Items);

                tempList.AddPregnancyDates(pregnancy.EDD, pregnancy.EndDate);

                tempList.Sort(delegate(PregnancyChecklistItem x, PregnancyChecklistItem y)
                {
                    return(x.DueDate.CompareTo(y.DueDate));
                });

                result.Items = tempList;
            }

            return(result);
        }
        public ActionResult Summary(string dfn)
        {
            // *** Create new model ***
            PatientSummary model = new PatientSummary();

            // *** Get patient demographics ***
            model.Patient = this.CurrentPatient;

            // *** Check for success ***
            if (!model.Patient.NotFound)
            {
                PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

                if (pregResult.Success)
                {
                    if (pregResult.Pregnancy != null)
                    {
                        if (pregResult.Pregnancy.RecordType == PregnancyRecordType.Current)
                        {
                            model.CurrentPregnancy = pregResult.Pregnancy;

                            PregnancyDetails tempDetails = PregnancyUtilities.GetPregnancyObservationData(this.DashboardRepository, dfn, model.CurrentPregnancy.Ien);

                            model.CurrentPregnancy.Lmp            = tempDetails.Lmp;
                            model.CurrentPregnancy.FetusBabyCount = tempDetails.FetusBabyCount;

                            model.CurrentPregnancy.EddBasis   = tempDetails.EddBasis;
                            model.CurrentPregnancy.EddIsFinal = tempDetails.EddIsFinal;
                        }
                        else
                        {
                            // TODO: Show most recent pregnancy ?
                        }

                        // *** Get pregnancy checklist ***
                        UpdateChecklistSummary(model, dfn, pregResult);
                    }
                }

                // *** Get Pregnancy History ***
                PregnancyHistoryResult histResult = this.DashboardRepository.Pregnancy.GetPregnancyHistory(dfn);

                if (histResult.Success)
                {
                    model.PregnancyHistory = histResult.PregnancyHistory;
                }
                else
                {
                    model.PregnancyHistory = new PregnancyHistory();
                    this.Error(histResult.Message);
                }
            }

            // *** Set return url ***
            if (TempData.ContainsKey(LastPatientListUrl))
            {
                model.ReturnUrl = TempData[LastPatientListUrl].ToString();

                TempData.Keep(LastPatientListUrl);

                // *** Indicate how to get back here ***
                TempData[ReturnUrl] = Url.Action("Summary", "Patient", new { dfn = dfn });
            }

            return(View("Summary2", model));
        }
        private void GetMergedList(PatientEducationIndex model, PregnancyDetails preg)
        {
            PregnancyChecklistItemsResult result = this.DashboardRepository.Checklist.GetPregnancyItems(model.Patient.Dfn, preg.Ien, "");

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else
            {
                // *** Create view items ***

                if (result.Items != null)
                {
                    foreach (PregnancyChecklistItem item in result.Items)
                    {
                        if (item.ItemType == DsioChecklistItemType.EducationItem)
                        {
                            PatientEducationChecklistItem newItem = new PatientEducationChecklistItem();
                            newItem.PregnancyChecklistItem = item;
                            model.ItemList.Add(newItem);
                        }
                    }
                }

                // *** Get patient education items ***

                PatientEducationItemsResult edResult = this.DashboardRepository.Education.GetPatientItems(
                    model.Patient.Dfn,
                    "",
                    DateTime.MinValue,
                    DateTime.MinValue,
                    EducationItemType.Unknown,
                    1,
                    1000
                    );

                if (!edResult.Success)
                {
                    this.Error(edResult.Message);
                }
                else
                {
                    Dictionary <string, PatientEducationItem> patEdItems = new Dictionary <string, PatientEducationItem>();

                    // *** Place patient education items in dictionary for lookup ***

                    if (edResult.Items != null)
                    {
                        foreach (PatientEducationItem patEdItem in edResult.Items)
                        {
                            patEdItems.Add(patEdItem.Ien, patEdItem);
                        }
                    }

                    // *** Go through checklist to find links to patient education ***

                    foreach (PatientEducationChecklistItem finalItem in model.ItemList)
                    {
                        if (finalItem.PregnancyChecklistItem != null)
                        {
                            if (finalItem.PregnancyChecklistItem.CompletionStatus == DsioChecklistCompletionStatus.Complete)
                            {
                                if (!string.IsNullOrWhiteSpace(finalItem.PregnancyChecklistItem.CompletionLink))
                                {
                                    if (patEdItems.ContainsKey(finalItem.PregnancyChecklistItem.CompletionLink))
                                    {
                                        // *** If found add to final ***
                                        finalItem.PatientEducationItem = patEdItems[finalItem.PregnancyChecklistItem.CompletionLink];

                                        // *** Remove since already added ***
                                        patEdItems.Remove(finalItem.PregnancyChecklistItem.CompletionLink);
                                    }
                                }
                            }
                        }
                    }

                    // *** Now that we've added all items that are linked, add remainder ***
                    foreach (PatientEducationItem patEdItem in patEdItems.Values)
                    {
                        PatientEducationChecklistItem newItem = new PatientEducationChecklistItem();
                        newItem.PatientEducationItem = patEdItem;
                        model.ItemList.Add(newItem);
                    }

                    // *** Finally get education items linked by a checklist but incomplete ***
                    foreach (PatientEducationChecklistItem finalItem in model.ItemList)
                    {
                        if (finalItem.PregnancyChecklistItem != null)
                        {
                            if (finalItem.PregnancyChecklistItem.CompletionStatus != DsioChecklistCompletionStatus.Complete)
                            {
                                if (!string.IsNullOrWhiteSpace(finalItem.Link))
                                {
                                    EducationItemsResult edItemsResult = this.DashboardRepository.Education.GetEducationItems(finalItem.Link, "", EducationItemType.Unknown, 0, 0, EducationItemSort.Type);

                                    if (edItemsResult.Success)
                                    {
                                        if (edItemsResult.EducationItems != null)
                                        {
                                            if (edItemsResult.EducationItems.Count > 0)
                                            {
                                                finalItem.EducationItem = edItemsResult.EducationItems[0];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                model.ItemList.AddPregnancyDates(preg.EDD, preg.EndDate);

                model.ItemList.Sort(delegate(PatientEducationChecklistItem x, PatientEducationChecklistItem y)
                {
                    return(x.CompareDate.CompareTo(y.CompareDate));
                });
            }
        }
        public static PregnancyDetails GetPregnancyObservationData(IDashboardRepository repo, string patientDfn, string pregIen)
        {
            PregnancyDetails returnVal = new PregnancyDetails();

            // NOTE: Only populates LMP and FetusBabyCount ***

            // *** Also, get lmp, fetus count ***
            ObservationListResult obsResult = repo.Observations.GetObservations(patientDfn, pregIen, "", "", "", "", "", 0, 0);

            if (obsResult.Success)
            {
                if (obsResult.Observations != null)
                {
                    //// *** 10/28/2014 Add sort so that newest gets applied last ***
                    //obsResult.Observations.Sort(delegate(DsioObservation o, DsioObservation p)
                    //{
                    //    DateTime oDate = VistaDates.ParseDateString(o.Date, VistaDates.VistADateFormatFour);
                    //    DateTime pDate = VistaDates.ParseDateString(p.Date, VistaDates.VistADateFormatFour);

                    //    return oDate.CompareTo(pDate);
                    //});
                    DateTime newestIsFinalEddDate = DateTime.MinValue;

                    foreach (Observation tempObs in obsResult.Observations)
                    {
                        if ((tempObs.Code == EddUtility.LmpDateCode) || (tempObs.Code == EddUtility.LmpDateCodeSnomed))
                        {
                            if (tempObs.Value.Contains("|"))
                            {
                                returnVal.Lmp = Util.Piece(tempObs.Value, "|", 1);

                                if (Util.Piece(tempObs.Value, "|", 2) == "A")
                                {
                                    returnVal.LmpDateType = ClinicalDateType.Approximate;
                                }
                                else
                                {
                                    returnVal.LmpDateType = ClinicalDateType.Known;
                                }
                            }
                            else if (string.IsNullOrWhiteSpace(tempObs.Value))
                            {
                                returnVal.LmpDateType = ClinicalDateType.Unknown;
                                returnVal.Lmp         = "";
                            }
                            else
                            {
                                returnVal.LmpDateType = ClinicalDateType.Known;
                                returnVal.Lmp         = tempObs.Value;
                            }

                            //if (string.IsNullOrWhiteSpace(returnVal.Lmp))
                            //    returnVal.LmpDateType = ClinicalDateType.Unknown;
                        }
                        else if (tempObs.Code == ObservationsFactory.FetusBabyCountCode)
                        {
                            int count;
                            if (int.TryParse(tempObs.Value, out count))
                            {
                                returnVal.FetusBabyCount = count;
                            }
                        }
                        else if (string.Equals(tempObs.Category, "EDD", StringComparison.InvariantCultureIgnoreCase))
                        {
                            EddHistoryItem eddItem = EddUtility.GetHistoryItem(tempObs);

                            if (tempObs.EntryDate > newestIsFinalEddDate)
                            {
                                if (eddItem.IsFinal)
                                {
                                    returnVal.EddBasis   = eddItem.Criteria;
                                    returnVal.EddIsFinal = eddItem.IsFinal;
                                    newestIsFinalEddDate = tempObs.EntryDate;
                                }
                            }
                        }
                    }
                }
            }

            return(returnVal);
        }
예제 #17
0
        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);
        }
        private PregnancyDetails CreatePregnancy(DsioPregnancy dsioPregnancy)
        {
            // *** Creates a strongly typed Pregnancy object ***

            PregnancyDetails returnVal = new PregnancyDetails();

            // *** Parse the end date ***
            returnVal.EndDate = VistaDates.ParseDateString(dsioPregnancy.EndDate, VistaDates.VistADateOnlyFormat);

            // *** Parse the EDD ***
            returnVal.EDD = VistaDates.ParseDateString(dsioPregnancy.EDD, VistaDates.VistADateOnlyFormat);
            //returnVal.EDD = VistaDates.ParseDateString(dsioPregnancy.EDD, VistaDates.VistADateFormatSix);

            // *** Set FOF and IEN ***
            returnVal.FatherOfFetusIen = dsioPregnancy.FatherOfFetusIen;
            if (!string.IsNullOrWhiteSpace(dsioPregnancy.FatherOfFetus))
            {
                returnVal.FatherOfFetus = dsioPregnancy.FatherOfFetus;
            }

            // *** Set pregnancy IEN ***
            returnVal.Ien = dsioPregnancy.Ien;

            // *** Set OB and IEN ***
            returnVal.ObstetricianIen = dsioPregnancy.ObstetricianIen;
            if (!string.IsNullOrWhiteSpace(dsioPregnancy.Obstetrician))
            {
                returnVal.Obstetrician = dsioPregnancy.Obstetrician;
            }

            // *** Set patient DFN ***
            returnVal.PatientDfn = dsioPregnancy.PatientDfn;

            // *** Set L&D and IEN ***
            returnVal.PlannedLaborDeliveryFacilityIen = dsioPregnancy.LDFacilityIen;
            if (!string.IsNullOrWhiteSpace(dsioPregnancy.LDFacility))
            {
                returnVal.PlannedLaborDeliveryFacility = dsioPregnancy.LDFacility;
            }

            // *** Determine record type ***
            //returnVal.RecordType = (dsioPregnancy.RecordType == DsioPregnancy.CurrentPregnancyType) ? PregnancyRecordType.Current : PregnancyRecordType.Historical;

            if (dsioPregnancy.RecordType == DsioPregnancy.CurrentPregnancyType)
            {
                returnVal.RecordType = PregnancyRecordType.Current;
            }
            else if (dsioPregnancy.RecordType == DsioPregnancy.CurrentPregnancyType.Substring(0, 1))
            {
                returnVal.RecordType = PregnancyRecordType.Current;
            }
            else if (dsioPregnancy.RecordType == DsioPregnancy.HistoricalPregnancyType)
            {
                returnVal.RecordType = PregnancyRecordType.Historical;
            }
            else if (dsioPregnancy.RecordType == DsioPregnancy.HistoricalPregnancyType.Substring(0, 1))
            {
                returnVal.RecordType = PregnancyRecordType.Historical;
            }

            // *** Parse start date ***
            returnVal.StartDate = VistaDates.ParseDateString(dsioPregnancy.StartDate, VistaDates.VistADateOnlyFormat);

            // *** Create babies on pregnancy object ***
            foreach (DsioBaby dsioBaby in dsioPregnancy.Babies)
            {
                int babyNum = -1;
                int.TryParse(dsioBaby.Number, out babyNum);

                Baby baby = new Baby()
                {
                    Ien = dsioBaby.Ien, BabyNum = babyNum
                };

                returnVal.Babies.Add(baby);
            }

            // *** High Risk ***
            returnVal.HighRisk        = (dsioPregnancy.HighRisk == "1");
            returnVal.HighRiskDetails = dsioPregnancy.HighRiskDetails;

            // *** Created ***
            returnVal.Created = VistaDates.ParseDateString(dsioPregnancy.Created, VistaDates.VistADateFormatFour);

            returnVal.GestationalAgeAtDelivery = dsioPregnancy.GestationalAgeAtDelivery;
            returnVal.LengthOfLabor            = dsioPregnancy.LengthOfLabor;
            returnVal.TypeOfDelivery           = dsioPregnancy.TypeOfDelivery;
            returnVal.Anesthesia      = dsioPregnancy.Anesthesia;
            returnVal.PretermDelivery = dsioPregnancy.PretermDelivery;
            returnVal.Outcome         = dsioPregnancy.Outcome;
            returnVal.Comment         = dsioPregnancy.Comment;

            return(returnVal);
        }
        private DsioPregnancy CreateDsioPregnancy(PregnancyDetails pregnancy)
        {
            DsioPregnancy dsioPregnancy = new DsioPregnancy();

            // *** Convert EDD ***
            if (pregnancy.EDD != DateTime.MinValue)
            {
                dsioPregnancy.EDD = pregnancy.EDD.ToString(VistaDates.VistADateOnlyFormat);
            }

            // *** Convert End Date ***
            if (pregnancy.EndDate != DateTime.MinValue)
            {
                dsioPregnancy.EndDate = pregnancy.EndDate.ToString(VistaDates.VistADateOnlyFormat);
            }

            // *** Convert FOF ***
            if (pregnancy.FatherOfFetusIen != null)
            {
                dsioPregnancy.FatherOfFetusIen = pregnancy.FatherOfFetusIen;
            }

            // *** Set Ien ***
            dsioPregnancy.Ien = pregnancy.Ien;

            // *** Set OB ***
            if (pregnancy.ObstetricianIen != null)
            {
                dsioPregnancy.ObstetricianIen = pregnancy.ObstetricianIen;
            }

            // *** Set planned delivery facility ***
            if (pregnancy.PlannedLaborDeliveryFacilityIen != null)
            {
                dsioPregnancy.LDFacilityIen = pregnancy.PlannedLaborDeliveryFacilityIen;
            }

            // *** Set patient dfn ***
            dsioPregnancy.PatientDfn = pregnancy.PatientDfn;

            // *** Set record type ***
            //dsioPregnancy.RecordType = (pregnancy.RecordType == PregnancyRecordType.Current) ? DsioPregnancy.CurrentPregnancyType : DsioPregnancy.HistoricalPregnancyType;
            dsioPregnancy.RecordType = (pregnancy.RecordType == PregnancyRecordType.Current) ? DsioPregnancy.CurrentPregnancyType.Substring(0, 1) : DsioPregnancy.HistoricalPregnancyType.Substring(0, 1);

            // *** Set start date ***
            if (pregnancy.StartDate != DateTime.MinValue)
            {
                dsioPregnancy.StartDate = pregnancy.StartDate.ToString(VistaDates.VistADateOnlyFormat);
            }

            // *** High Risk ***
            dsioPregnancy.HighRisk        = (pregnancy.HighRisk) ? "1" : "0";
            dsioPregnancy.HighRiskDetails = pregnancy.HighRiskDetails;

            dsioPregnancy.GestationalAgeAtDelivery = pregnancy.GestationalAgeAtDelivery;
            dsioPregnancy.LengthOfLabor            = pregnancy.LengthOfLabor;
            dsioPregnancy.TypeOfDelivery           = pregnancy.TypeOfDelivery;
            dsioPregnancy.Anesthesia      = pregnancy.Anesthesia;
            dsioPregnancy.PretermDelivery = pregnancy.PretermDelivery;
            dsioPregnancy.Outcome         = pregnancy.Outcome;
            dsioPregnancy.Comment         = pregnancy.Comment;

            return(dsioPregnancy);
        }