public static PregnancyOutcomeType GetPregnancyOutcome(IDashboardRepository repo, string patientDfn, string pregIen)
        {
            PregnancyOutcomeType returnVal = PregnancyOutcomeType.Unknown;

            ObservationListResult obsResult = repo.Observations.GetObservations(patientDfn, pregIen, "", "", "", "", "Outcome", 0, 0);

            if (obsResult.Success)
            {
                if (obsResult.Observations != null)
                {
                    foreach (Observation obs in obsResult.Observations)
                    {
                        if (obs.Code == ObservationsFactory.OutcomeTypeCode)
                        {
                            PregnancyOutcomeType outType = PregnancyOutcomeType.Unknown;
                            if (Enum.TryParse <PregnancyOutcomeType>(obs.Value, true, out outType))
                            {
                                returnVal = outType;
                            }
                        }
                    }
                }
            }

            return(returnVal);
        }
        public ObservationListResult GetObservations(string patientDfn, string pregnancyIen, string babyIen, string fromDate, string toDate, string category, int page, int itemsPerPage)
        {
            // *** Get a list of observations matching criteria ***

            ObservationListResult result = new ObservationListResult();

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

            // *** Add command arguments ***
            command.AddCommandArguments(patientDfn, "", pregnancyIen, babyIen, "", fromDate, toDate, category, page, itemsPerPage);

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

            // *** Add response to result ***
            result.Success = response.Status == RpcResponseStatus.Success;
            result.Message = response.InformationalMessage;

            // *** Add observations ***
            if (result.Success)
            {
                result.TotalResults = command.TotalResults;

                if (command.ObservationsList != null)
                {
                    if (command.ObservationsList.Count > 0)
                    {
                        //result.Observations.AddRange(command.ObservationsList);

                        foreach (DsioObservation dsioObs in command.ObservationsList)
                        {
                            Observation obs = ObservationUtility.GetObservation(dsioObs);

                            if (obs != null)
                            {
                                result.Observations.Add(obs);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        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);
        }
Example #4
0
        public CdaSourceResult GetSource(CdaOptions options)
        {
            // *** Collect the source data in a source object ***

            CdaSourceResult returnVal = new CdaSourceResult();

            // *** Create new document id ***
            returnVal.Source.DocumentId = Guid.NewGuid().ToString("B");

            // *** Get CDA settings ***
            CdaSettingsResult result = this.dashboardRepository.Settings.GetCdaSettings();

            // *** Add results to return ***
            returnVal.Success = result.Success;
            returnVal.Message = result.Message;

            if (result.Success)
            {
                // *** Add CDA settings to return ***
                returnVal.Source.ManufacturerModelName     = result.ManufacturerModelName;
                returnVal.Source.SoftwareName              = result.SoftwareName;
                returnVal.Source.ProviderOrganizationPhone = result.ProviderOrganizationPhone;

                //// *** Get the VPR data ***
                //VprOperationResult vprResult = this.dashboardRepository.Vpr.GetVprData(options);

                //// *** Add results to return ***
                //returnVal.Success = vprResult.Success;
                //returnVal.Message = vprResult.Message;

                //// *** Add vpr data to return ***
                //if (result.Success)
                //    returnVal.Source.VprData = vprResult.VprData;

                // *** Add options to return ***
                returnVal.Source.Options = options;

                // *** Add pregnancies ***
                string pregIen = (options.DocumentType == CDA.IheDocumentType.PPVS) ? options.SelectedItemIen : "";

                PregnancyListResult pregResult = this.dashboardRepository.Pregnancy.GetPregnancies(options.Patient.Dfn, pregIen);

                if (pregResult.Success)
                {
                    returnVal.Source.Pregnancies = pregResult.Pregnancies;
                }
                else
                {
                    returnVal.SetResult(false, pregResult.Message);
                }

                // *** Add pregnancy status ***
                PatientDemographicsResult patResult = this.dashboardRepository.Patients.GetPatientDemographics(options.Patient.Dfn);

                if (patResult.Success)
                {
                    returnVal.Source.Patient = patResult.Patient;
                }
                else if (returnVal.Success)
                {
                    returnVal.SetResult(false, patResult.Message);
                }

                // *** Get Observations By Date Range ***

                string tiuIen   = "";
                string fromDate = "";
                string toDate   = "";

                if (options.DocumentType == CDA.IheDocumentType.PPVS)
                {
                    // TODO: Add date range when working...

                    // *** Translate a pregnancy into a date range ***
                    // *** The date range should include the postpartum period ***
                    //options.SelectedDateRange = CdaOptions.DateRange.Custom;
                    //options.FromDate = returnVal.Source.Pregnancies[0].EndDate.AddDays(-1);
                    //TimeSpan ts = DateTime.Now - options.FromDate;

                    //if (ts.TotalDays > 60)
                    //    options.ToDate = options.FromDate.AddDays(42);
                    //else
                    //    options.ToDate = DateTime.Now.AddDays(1);

                    //toDate = options.ToDate.ToString(VistaDates.VistADateOnlyFormat);
                    //fromDate = options.FromDate.ToString(VistaDates.VistADateOnlyFormat);

                    // TODO: Clear pregIen ?
                    //pregIen = "";
                }
                else if (options.SelectedItemIen == "-1")
                {
                    tiuIen = "";
                    if (options.FromDate != DateTime.MinValue)
                    {
                        fromDate = options.FromDate.ToString(VistaDates.VistADateOnlyFormat);
                    }

                    if (options.ToDate != DateTime.MinValue)
                    {
                        toDate = options.ToDate.ToString(VistaDates.VistADateOnlyFormat);
                    }
                }
                else
                {
                    tiuIen = options.SelectedItemIen;
                }

                ObservationListResult observationsResult = this.dashboardRepository.Observations.GetObservations(options.Patient.Dfn, pregIen, "", tiuIen, fromDate, toDate, "", -1, -1);

                if (observationsResult.Success)
                {
                    returnVal.Source.Observations = observationsResult.Observations;

                    // *** For PPVS remove observations which belong to pregnancies other than the one chosen by the user ***
                    if (options.DocumentType == CDA.IheDocumentType.PPVS)
                    {
                        returnVal.Source.Observations = returnVal.Source.Observations
                                                        .Where(o => o.PregnancyIen == "" || o.PregnancyIen == options.SelectedItemIen)
                                                        .ToList();
                    }
                }

                // *** Get the VPR data ***
                VprOperationResult vprResult = this.dashboardRepository.Vpr.GetVprData(options);

                // *** Add results to return ***
                returnVal.Success = vprResult.Success;
                returnVal.Message = vprResult.Message;

                // *** Add vpr data to return ***
                if (result.Success)
                {
                    returnVal.Source.VprData = vprResult.VprData;
                }

                ValueSetType[] valueSets = null;

                if (options.DocumentType == CDA.IheDocumentType.APHP)
                {
                    // *** Get Value Sets Needed for APHP ***
                    valueSets = new ValueSetType[]
                    {
                        ValueSetType.AntepartumEducation,
                        ValueSetType.HistoryOfInfection,
                        ValueSetType.HistoryOfPastIllness,
                        ValueSetType.AntepartumFamilyHistory,
                        ValueSetType.MenstrualHistory
                    };
                }
                else if (options.DocumentType == CDA.IheDocumentType.APE)
                {
                    valueSets = new ValueSetType[] { ValueSetType.AntepartumEducation };

                    returnVal.Source.EducationItems = this.GetEducationItems(options.Patient.Dfn, options.FromDate, options.ToDate);
                }

                if (valueSets != null)
                {
                    foreach (var valueSetType in valueSets)
                    {
                        CdaValueSetResult vsResult = this.dashboardRepository.CdaDocuments.GetValueSet(valueSetType);
                        if (vsResult.Success)
                        {
                            returnVal.Source.ValueSets.Add(valueSetType, vsResult.ValueSet);
                        }
                    }
                }

                if (options.DocumentType == CDA.IheDocumentType.XDR_I)
                {
                    // *** Get Radiology Reports ***
                    RadiologyReportsResult radResult = this.dashboardRepository.Radiology.GetReports(options.Patient.Dfn);

                    if (radResult.Success)
                    {
                        if (radResult.Items.Count > 0)
                        {
                            string   tempDate = Util.Piece(options.SelectedItemIen, "|", 1);
                            string   tempProc = Util.Piece(options.SelectedItemIen, "|", 2);
                            DateTime selected;
                            if (DateTime.TryParse(tempDate, out selected))
                            {
                                RadiologyReport rpt = radResult.Items.FirstOrDefault(r => r.ExamDateTime == selected && r.Procedure == tempProc);

                                returnVal.Source.ImageReportText = rpt.Detail;
                            }
                        }
                    }
                }
            }

            return(returnVal);
        }