Beispiel #1
0
        private List <TrackingEntry> GetTrackingEntries(List <DsioTrackingItem> commandEntries)
        {
            // *** Gets a list of tracking entries from dsio tracking items ***

            List <TrackingEntry> returnEntries = new List <TrackingEntry>();

            // *** Check that we have something to work with ***
            if (commandEntries != null)
            {
                if (commandEntries.Count > 0)
                {
                    // *** Go through each ***
                    foreach (DsioTrackingItem dsioItem in commandEntries)
                    {
                        // *** Create the entry ***
                        TrackingEntry newEntry = new TrackingEntry()
                        {
                            PatientDfn  = dsioItem.Dfn,
                            Comment     = dsioItem.Comment,
                            EntryId     = dsioItem.Id,
                            Reason      = dsioItem.Reason,
                            PatientName = dsioItem.PatientName,
                            Source      = dsioItem.Source,
                            UserName    = dsioItem.User
                        };

                        // *** Convert from fileman date time ***
                        //newEntry.EntryDateTime = Util.GetDateTime(dsioItem.TrackingItemDateTime);
                        //CultureInfo enUS = new CultureInfo("en-US");
                        //DateTime tempDateTime;
                        //if (DateTime.TryParseExact(dsioItem.TrackingItemDateTime,VistaDates.VistADateFormatTwo, enUS,DateTimeStyles.None, out tempDateTime))
                        //    newEntry.EntryDateTime = tempDateTime;

                        // *** Use VistaDates parser ***
                        // *** Try with seconds and then without ***
                        DateTime tempDateTime = VistaDates.ParseDateString(dsioItem.TrackingItemDateTime, VistaDates.VistADateFormatFour);
                        if (tempDateTime == DateTime.MinValue)
                        {
                            tempDateTime = VistaDates.ParseDateString(dsioItem.TrackingItemDateTime, VistaDates.VistADateFormatEight);
                        }

                        if (tempDateTime != DateTime.MinValue)
                        {
                            newEntry.EntryDateTime = tempDateTime;
                        }

                        // *** Add entry type ***
                        if (IsValidEntryType(dsioItem.TrackingType))
                        {
                            newEntry.EntryType = GetEntryType(dsioItem.TrackingType);
                        }

                        // *** Add to list ***
                        returnEntries.Add(newEntry);
                    }
                }
            }

            return(returnEntries);
        }
        /// <summary>
        /// Creates an observation where the value is a date
        /// </summary>
        /// <param name="observation"></param>
        /// <returns></returns>
        public static CdaDateObservation CreateDateObservation(Observation observation)
        {
            CdaDateObservation returnVal;

            // TODO: What if this date is in another format ?

            // *** Attempt to parse the date ***
            DateTime tempDate = VistaDates.ParseDateString(observation.Value, VistaDates.VistADateOnlyFormat);

            // *** Check if we have a date ***
            if (tempDate == DateTime.MinValue)
            {
                returnVal = null;
            }
            else
            {
                // *** Create the observation ***
                returnVal = new CdaDateObservation();

                // *** Add the date ***
                returnVal.Value = tempDate;

                // *** Add Id, Status ***
                returnVal.Id     = Guid.NewGuid().ToString(); //observation.Ien;
                returnVal.Status = Hl7ProblemActStatus.completed;

                // *** Create code ***
                returnVal.Code = new CdaCode()
                {
                    CodeSystem = observation.CodeSystem, Code = observation.Code, DisplayName = observation.Description
                };
            }

            return(returnVal);
        }
Beispiel #3
0
        public static string GetEddFromDate(EddItemType itemType, string valPiece1)
        {
            string returnVal = "";

            DateTime tempDate = VistaDates.ParseDateString(valPiece1, VistaDates.VistADateOnlyFormat);

            DateTime edd = DateTime.MinValue;

            if (tempDate != DateTime.MinValue)
            {
                switch (itemType)
                {
                case EddItemType.LMP:
                    edd = tempDate.AddDays(280);
                    break;

                case EddItemType.Conception:
                    edd = tempDate.AddDays(266);
                    break;

                case EddItemType.Embryo:
                    edd = tempDate.AddDays(262);
                    break;
                }

                returnVal = edd.ToString(VistaDates.VistADateOnlyFormat);
            }

            return(returnVal);
        }
Beispiel #4
0
        //private DueCalculationType GetDueCalculationType(string dsioCalcType)
        //{
        //    DueCalculationType returnVal = DueCalculationType.Unknown;

        //    Dictionary<string, DueCalculationType> lookup = new Dictionary<string, DueCalculationType>();

        //    lookup.Add(DsioChecklistItem.InitialCalcType, DueCalculationType.Initial);
        //    lookup.Add(DsioChecklistItem.WeeksGaCalcType, DueCalculationType.WeeksGa);
        //    lookup.Add(DsioChecklistItem.TrimesterGaCalcType, DueCalculationType.TrimesterGa);
        //    lookup.Add(DsioChecklistItem.WeeksPostpartumCalcType, DueCalculationType.WeeksPostpartum);

        //    if (lookup.ContainsKey(dsioCalcType))
        //        returnVal = lookup[dsioCalcType];

        //    return returnVal;
        //}

        //private ChecklistItemType GetChecklistItemType(string dsioItemType)
        //{
        //    ChecklistItemType returnVal = ChecklistItemType.Unknown;

        //    Dictionary<string, ChecklistItemType> lookup = new Dictionary<string, ChecklistItemType>();

        //    lookup.Add(DsioChecklistItem.MccCallType, ChecklistItemType.MccCall);
        //    lookup.Add(DsioChecklistItem.EdItemType, ChecklistItemType.EducationItem);
        //    lookup.Add(DsioChecklistItem.LabType, ChecklistItemType.Lab);
        //    lookup.Add(DsioChecklistItem.UltrasoundType, ChecklistItemType.Ultrasound);
        //    lookup.Add(DsioChecklistItem.ConsultType, ChecklistItemType.Consult);
        //    lookup.Add(DsioChecklistItem.CdaExchangeType, ChecklistItemType.CdaExchange);
        //    lookup.Add(DsioChecklistItem.VisitType, ChecklistItemType.Visit);
        //    lookup.Add(DsioChecklistItem.OtherType, ChecklistItemType.Other);

        //    if (lookup.ContainsKey(dsioItemType))
        //        returnVal = lookup[dsioItemType];

        //    return returnVal;
        //}

        private PregnancyChecklistItem GetPatientChecklistItem(DsioPatientChecklistItem dsioItem)
        {
            PregnancyChecklistItem returnItem;

            ChecklistItem baseItem = this.GetChecklistItem(dsioItem);

            returnItem = new PregnancyChecklistItem(baseItem);

            returnItem.PatientDfn       = dsioItem.PatientDfn;
            returnItem.PregnancyIen     = dsioItem.PregnancyIen;
            returnItem.ItemDate         = VistaDates.ParseDateString(dsioItem.ItemDate, VistaDates.VistADateFormatSix);
            returnItem.SpecificDueDate  = VistaDates.ParseDateString(dsioItem.SpecificDueDate, VistaDates.VistADateOnlyFormat);
            returnItem.CompletionStatus = dsioItem.CompletionStatus;

            returnItem.CompleteDate = VistaDates.ParseDateString(dsioItem.CompleteDate, VistaDates.VistADateFormatFour);
            if (returnItem.CompleteDate == DateTime.MinValue)
            {
                if (!string.IsNullOrWhiteSpace(dsioItem.CompleteDate))
                {
                    returnItem.CompleteDate = VistaDates.ParseDateString(dsioItem.CompleteDate, VistaDates.VistADateFormatSeven);
                }
            }

            returnItem.CompletionLink = dsioItem.CompletionLink;
            returnItem.CompletedBy    = dsioItem.CompletedBy;
            returnItem.StoredNote     = dsioItem.Note;
            returnItem.User           = dsioItem.User;
            returnItem.InProgress     = (dsioItem.InProgress == "1") ? true : false;

            returnItem.EducationItemIen = dsioItem.EducationIen;

            return(returnItem);
        }
        private TiuNote GetDashboardNote(TiuDocument doc)
        {
            TiuNote returnVal = new TiuNote();

            returnVal.Ien = doc.Ien;

            switch (doc.SignatureStatus)
            {
            case "UNSIGNED":
                returnVal.SignatureStatus = TiuNoteSignatureStatus.Unsigned;
                break;

            case "COMPLETED":
                returnVal.SignatureStatus = TiuNoteSignatureStatus.Completed;
                break;

            default:
                returnVal.SignatureStatus = TiuNoteSignatureStatus.Unknown;
                break;
            }

            returnVal.Author = doc.Author;

            //CultureInfo enUS = new CultureInfo("en-US");
            //DateTime tempDateTime = DateTime.MinValue;
            //if (DateTime.TryParseExact(doc.DocumentDateTime, RepositoryDates.VistADateFormatOne, enUS, DateTimeStyles.None, out tempDateTime))
            //    returnVal.DocumentDateTime = tempDateTime;

            returnVal.DocumentDateTime = VistaDates.ParseDateString(doc.DocumentDateTime, VistaDates.VistADateFormatFour);

            if (returnVal.DocumentDateTime == DateTime.MinValue)
            {
                returnVal.DocumentDateTime = VistaDates.ParseDateString(doc.DocumentDateTime, VistaDates.VistADateFormatEight);
            }

            returnVal.Location = doc.Location;

            returnVal.ParentIen = doc.ParentIen;
            returnVal.Subject   = doc.Subject;

            returnVal.Title = doc.Title;

            // *** Split list of addenda iens ***
            if (!string.IsNullOrWhiteSpace(doc.AddendaIen))
            {
                if (doc.AddendaIen.Contains("|"))
                {
                    returnVal.AddendaIens.AddRange(doc.AddendaIen.Split("|".ToCharArray()));
                }
                else
                {
                    returnVal.AddendaIens.Add(doc.AddendaIen);
                }
            }

            returnVal.PregnancyIen = doc.PregnancyIen;

            return(returnVal);
        }
Beispiel #6
0
        public static string GetLmpFromEdd(string edd)
        {
            string returnVal = "";

            DateTime tempDate = VistaDates.ParseDateString(edd, VistaDates.VistADateOnlyFormat);

            if (tempDate != DateTime.MinValue)
            {
                DateTime lmp = tempDate.AddDays(-280);
                returnVal = lmp.ToString(VistaDates.VistADateOnlyFormat);
            }

            return(returnVal);
        }
Beispiel #7
0
        private RadiologyReport GetRadiologyReport(OrwrpReport orwrpReport)
        {
            RadiologyReport returnReport = new RadiologyReport()
            {
                Location        = orwrpReport.Location,
                Procedure       = orwrpReport.Procedure,
                ReportStatus    = orwrpReport.ReportStatus,
                CptCode         = orwrpReport.CptCode,
                ReasonForStudy  = orwrpReport.ReasonForStudy,
                ClinicalHistory = orwrpReport.ClinicalHistory,
                Impression      = orwrpReport.Impression,
                ReportText      = orwrpReport.ReportText
            };

            returnReport.ExamDateTime = VistaDates.ParseDateString(orwrpReport.ExamDateTime, VistaDates.VistADateFormatFive);

            return(returnReport);
        }
Beispiel #8
0
 public CdaDateObservation(POCD_MT000040Observation pocdObs) : base(pocdObs)
 {
     if (pocdObs.value != null)
     {
         if (pocdObs.value.Length > 0)
         {
             if (pocdObs.value[0] is TS)
             {
                 TS       temp = (TS)pocdObs.value[0];
                 DateTime val  = VistaDates.ParseDateString(temp.value, RawCdaDocument.CdaDateFormat);
                 if (val != DateTime.MinValue)
                 {
                     this.Value = val;
                 }
             }
         }
     }
 }
        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);
        }
Beispiel #10
0
        private CdaDocumentData GetDocumentData(DsioCdaDocument dsioDoc)
        {
            // *** Gets strongly typed Cda data from Dsio data ***
            CdaDocumentData returnDocument = new CdaDocumentData();

            // *** Convert Create Date to DateTime ***
            //CultureInfo enUS = new CultureInfo("en-US");
            //DateTime tempDateTime;
            //if (DateTime.TryParseExact(dsioDoc.CreatedOn, RepositoryDates.VistADateFormatOne, enUS, DateTimeStyles.None, out tempDateTime))
            //    returnDocument.CreationDateTime = tempDateTime;
            returnDocument.CreationDateTime = VistaDates.ParseDateString(dsioDoc.CreatedOn, VistaDates.VistADateFormatFour);

            // *** Convert Import/Export to DateTime ***
            //if (DateTime.TryParseExact(dsioDoc.ImportExportDate, RepositoryDates.VistADateFormatOne, enUS, DateTimeStyles.None, out tempDateTime))
            //    returnDocument.ImportDateTime = tempDateTime;
            returnDocument.ImportDateTime = VistaDates.ParseDateString(dsioDoc.ImportExportDate, VistaDates.VistADateFormatFour);

            // *** Get index of value which will match enum ***
            int idx = Array.IndexOf(CdaUtility.DocumentTypeAbbreviation, dsioDoc.DocumentType);

            // *** Convert to enum ***
            if (idx > -1)
            {
                returnDocument.DocumentType = (IheDocumentType)idx;
            }

            // *** Determine if in/out ***
            returnDocument.ExchangeDirection = (dsioDoc.Direction == "IN") ? ExchangeDirection.Inbound : ExchangeDirection.Outbound;

            // *** Populate id's as is ***
            returnDocument.Id  = dsioDoc.Id;
            returnDocument.Ien = dsioDoc.Ien;

            // *** Populate as is ***
            returnDocument.IntendedRecipient = dsioDoc.IntendedRecipient;
            returnDocument.Sender            = dsioDoc.Sender;
            returnDocument.Title             = dsioDoc.Title;

            return(returnDocument);
        }
Beispiel #11
0
        public static string GetEddFromGA(string obsDate, string gaDays)
        {
            string returnVal = "";

            DateTime tempDate = VistaDates.ParseDateString(obsDate, VistaDates.VistADateOnlyFormat);

            if (tempDate != DateTime.MinValue)
            {
                int gaTotalDays = -1;
                if (int.TryParse(gaDays, out gaTotalDays))
                {
                    // 40 weeks, 0 days = 280 days
                    // 280 days - GA
                    int remainDays = 280 - gaTotalDays;

                    // Add remain days to entered date
                    DateTime edd = tempDate.AddDays(remainDays);

                    returnVal = edd.ToString(VistaDates.VistADateOnlyFormat);
                }
            }

            return(returnVal);
        }
        //public PatientDemographicsResult GetPatientDemographicsX(string dfn)
        //{
        //    // *** NOTE: Uses ORWPT SELECT...

        //    PatientDemographicsResult result = new PatientDemographicsResult();

        //    OrwptSelectCommand command = new OrwptSelectCommand(this.broker);

        //    command.AddDfnArgument(dfn);

        //    RpcResponse response = command.Execute();

        //    result.Success = (response.Status == RpcResponseStatus.Success);
        //    result.Message = response.InformationalMessage;

        //    if (result.Success)
        //    {
        //        result.Patient = new BasePatient();
        //        result.Patient.Dfn = command.Patient.Dfn;
        //        result.Patient.LastName = Util.Piece(command.Patient.PatientName, ",", 1);
        //        result.Patient.FirstName = Util.Piece(command.Patient.PatientName, ",",2);

        //        result.Patient.DateOfBirth = Util.GetDateTime(command.Patient.DOB);

        //        if (result.Patient.DateOfBirth == DateTime.MinValue)
        //            result.Patient.DateOfBirthInexact = Util.GetInexactDateFromFM(command.Patient.DOB);

        //        result.Patient.FullSSN = command.Patient.SSN;

        //        int length = result.Patient.FullSSN.Length;

        //        if (length == 9)
        //            result.Patient.Last4 = result.Patient.FullSSN.Substring(5);
        //        else if (length == 10)
        //            if (result.Patient.FullSSN.EndsWith("P"))
        //                result.Patient.Last4 = result.Patient.FullSSN.Substring(5, 4);

        //    }

        //    return result;
        //}

        public PatientDemographicsResult GetPatientDemographics(string dfn)
        {
            PatientDemographicsResult result = new PatientDemographicsResult();

            DsioGetPatientInformationCommand command = new DsioGetPatientInformationCommand(this.broker);

            command.AddCommandArguments(dfn);

            RpcResponse response = command.Execute();

            result.Success = (response.Status == RpcResponseStatus.Success);
            result.Message = response.InformationalMessage;

            if (result.Success)
            {
                result.Patient = new BasePatient();

                // *** Dfn ***
                result.Patient.Dfn = command.Patient.Dfn;

                // *** Name ***
                result.Patient.LastName  = Util.Piece(command.Patient.PatientName, ",", 1);
                result.Patient.FirstName = Util.Piece(command.Patient.PatientName, ",", 2);

                // *** SSN ***
                result.Patient.FullSSN = command.Patient.SSN;

                int length = result.Patient.FullSSN.Length;

                if (length == 9)
                {
                    result.Patient.Last4 = result.Patient.FullSSN.Substring(5);
                }
                else if (length == 10)
                {
                    if (result.Patient.FullSSN.EndsWith("P"))
                    {
                        result.Patient.Last4 = result.Patient.FullSSN.Substring(5, 4);
                    }
                }

                // *** DOB ***
                result.Patient.DateOfBirth = VistaDates.ParseDateString(command.Patient.DOB, VistaDates.VistADateOnlyFormat);

                // *** Gravida Para ***
                if (string.IsNullOrWhiteSpace(command.Patient.GravidaPara))
                {
                    result.Patient.GravidaPara = "G? P????";
                }
                else
                {
                    result.Patient.GravidaPara = command.Patient.GravidaPara;
                }

                result.Patient.Pregnant = (command.Patient.Pregnant == "YES") ? true : false;

                // *** Last Live Birth ***
                if (!string.IsNullOrWhiteSpace(command.Patient.LastLiveBirth))
                {
                    result.Patient.LastLiveBirth = VistaDates.ParseDateString(command.Patient.LastLiveBirth, VistaDates.VistADateOnlyFormat);
                }

                // *** Lactating ***
                result.Patient.Lactating = (command.Patient.Lactating == "YES") ? true : false;

                // *** Add phone numbers ***
                result.Patient.HomePhone   = command.Patient.HomePhone;
                result.Patient.WorkPhone   = command.Patient.WorkPhone;
                result.Patient.MobilePhone = command.Patient.MobilePhone;

                // *** Contact dates ***
                // TODO: Should last contact have time?
                result.Patient.LastContactDate = VistaDates.ParseDateString(command.Patient.LastContactDate, VistaDates.VistADateOnlyFormat);
                result.Patient.NextContactDue  = VistaDates.ParseDateString(command.Patient.NextContactDue, VistaDates.VistADateOnlyFormat);

                // *** Checklist Date ***
                result.Patient.NextChecklistDue = VistaDates.ParseDateString(command.Patient.NextChecklistDue, VistaDates.VistADateOnlyFormat);

                // *** LMP ***
                result.Patient.Lmp = VistaDates.ParseDateString(command.Patient.Lmp, VistaDates.VistADateOnlyFormat);

                // *** Current Pregnancy High Risk ***
                result.Patient.CurrentPregnancyHighRisk = (command.Patient.CurrentPregnancyHighRisk == "TRUE");
                result.Patient.HighRiskDetails          = command.Patient.HighRiskDetails;

                // *** Zip, Email ***
                result.Patient.ZipCode = command.Patient.ZipCode;
                result.Patient.Email   = command.Patient.Email;

                // *** Text4Baby ***
                if (command.Patient.Text4BabyStatus.Equals("enrolled", StringComparison.CurrentCultureIgnoreCase))
                {
                    result.Patient.Text4BabyStatus = Text4BabyStatus.Enrolled;
                }
                else if (command.Patient.Text4BabyStatus.Equals("not interested", StringComparison.CurrentCultureIgnoreCase))
                {
                    result.Patient.Text4BabyStatus = Text4BabyStatus.NotInterested;
                }

                result.Patient.Text4BabyStatusUpdatedOn = VistaDates.FlexParse(command.Patient.Text4BabyDate);
            }

            return(result);
        }
Beispiel #13
0
        public ActionResult Dashboard(Outcomes outcomes)
        {
            DashboardModel model = new DashboardModel();

            // *** Get tracked patients ***
            TrackedPatientsResult trackedResult = this.DashboardRepository.Patients.GetTrackedPatients(1, 9999);

            if (trackedResult.Success)
            {
                // *** Add to the model ***
                model.TrackedPatients = trackedResult.TotalResults;

                // *** Check if we have something to work with ***
                if (trackedResult.Patients != null)
                {
                    // *** Get the day of the week as integer ***
                    int day = (int)DateTime.Now.DayOfWeek;

                    // *** Calculate Babies Due This Week ***
                    DateTime weekStart = DateTime.Now.Date.AddDays(-1 * day);
                    DateTime weekEnd   = DateTime.Now.Date.AddDays(6 - day);

                    model.DueThisWeek = trackedResult.Patients.Count(p => p.EDD.Date >= weekStart && p.EDD.Date <= weekEnd);

                    // *** Calculate number of high-risk pregnancies ***
                    model.HighRisk = trackedResult.Patients.Count(p => p.CurrentPregnancyHighRisk == true);

                    // *** Get data for trimester pie chart ***
                    model.Tri1       = trackedResult.Patients.Count(p => p.Trimester == 1);
                    model.Tri2       = trackedResult.Patients.Count(p => p.Trimester == 2);
                    model.Tri3       = trackedResult.Patients.Count(p => p.Trimester == 3);
                    model.TriUnknown = trackedResult.Patients.Count(p => p.Trimester == -1);

                    // *** Get data for T4B pie chart ***
                    model.T4BEnrolled      = trackedResult.Patients.Count(p => p.Text4BabyStatus == Text4BabyStatus.Enrolled);
                    model.T4BNotInterested = trackedResult.Patients.Count(p => p.Text4BabyStatus == Text4BabyStatus.NotInterested);
                    model.T4BUnknown       = trackedResult.Patients.Count(p => p.Text4BabyStatus == Text4BabyStatus.Unknown);

                    // *** Get 10 patients with items due ***
                    model.NextDueList = trackedResult.Patients
                                        .Where(p => p.NextChecklistDue != DateTime.MinValue)
                                        .OrderBy(p => p.NextChecklistDue)
                                        .Take(10)
                                        .ToList();
                }
            }

            // *** Get count of flagged patients ***
            FlaggedPatientsResult flaggedResult = this.DashboardRepository.Patients.GetFlaggedPatients(1, 1);

            if (flaggedResult.Success)
            {
                model.FlaggedPatients = flaggedResult.TotalResults;
            }

            // *** Get bar chart data ***
            BarData outcomesBarData = GetOutcomesBarData();
            BarData upcomingBarData = GetUpcomingBarData(trackedResult.Patients);
            //BarData historical = GetHistoricalBarData();

            // *** Set up serializer ***
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver = new LowerCaseContractResolver();

            // *** Serialize as JSON ***
            model.OutcomesJson            = JsonConvert.SerializeObject(outcomesBarData, settings);
            model.UpcomingPregnanciesJson = JsonConvert.SerializeObject(upcomingBarData, settings);

            DateTime fromDate = DateTime.MinValue;
            DateTime toDate   = DateTime.Now;

            if (outcomes != null)
            {
                if (!outcomes.AllDates)
                {
                    model.Outcomes.FromDate = VistaDates.StandardizeDateFormat(outcomes.FromDate);

                    if (!string.IsNullOrWhiteSpace(model.Outcomes.FromDate))
                    {
                        fromDate = VistaDates.ParseDateString(model.Outcomes.FromDate, VistaDates.VistADateOnlyFormat);
                    }

                    model.Outcomes.ToDate = VistaDates.StandardizeDateFormat(outcomes.ToDate);
                    if (!string.IsNullOrWhiteSpace(model.Outcomes.ToDate))
                    {
                        toDate = VistaDates.ParseDateString(model.Outcomes.ToDate, VistaDates.VistADateOnlyFormat);
                    }
                }

                model.Outcomes.AllDates = outcomes.AllDates;
            }

            PregnancyOutcomeResult pregResult = this.DashboardRepository.Pregnancy.GetPregnancyOutcomes(fromDate, toDate, 1, 1000);

            if (pregResult.Success)
            {
                model.Outcomes.PregnancyOutcomes = pregResult.PregnancyOutcomes;
            }

            return(View(model));
        }
        public PregnancyHistoryResult GetPregnancyHistory(string patientDfn)
        {
            // *** Gets pregnancy history ***

            PregnancyHistoryResult result = new PregnancyHistoryResult();

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

            // *** Add command arguments ***
            command.AddCommandArguments(patientDfn, "", "", "", "", "", "", "Pregnancy History", 1, 1000);

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

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

            // *** Create pregnancy history ***
            if (result.Success)
            {
                // *** Check that there are observations ***
                if (command.ObservationsList != null)
                {
                    if (command.ObservationsList.Count > 0)
                    {
                        // *** Create a dictionary to hold only most recent ***
                        Dictionary <string, DsioObservation> mostRecentList = new Dictionary <string, DsioObservation>();

                        // *** Loop through the list, if it does not exist add it, or if it is newer, replace ***
                        foreach (DsioObservation dsioObservation in command.ObservationsList)
                        {
                            if (!mostRecentList.ContainsKey(dsioObservation.Code.Code))
                            {
                                mostRecentList.Add(dsioObservation.Code.Code, dsioObservation);
                            }
                            else
                            {
                                // *** Get dates to compare ***
                                DateTime existingDate = VistaDates.ParseDateString(mostRecentList[dsioObservation.Code.Code].EntryDate, VistaDates.VistADateFormatTwo);
                                DateTime newDate      = VistaDates.ParseDateString(dsioObservation.EntryDate, VistaDates.VistADateFormatTwo);

                                // *** If newer replace ***
                                if (newDate > existingDate)
                                {
                                    mostRecentList[dsioObservation.Code.Code] = dsioObservation;
                                }
                            }
                        }

                        // *** Loop through most recent and add to pregnancy history ***
                        foreach (DsioObservation dsioObservation in mostRecentList.Values)
                        {
                            if (!string.IsNullOrWhiteSpace(dsioObservation.Code.Code))
                            {
                                Observation tempObs = ObservationUtility.GetObservation(dsioObservation);
                                result.PregnancyHistory.Observations[dsioObservation.Code.Code] = tempObs;
                                //result.PregnancyHistory.SetValue(dsioObservation.Code, dsioObservation.Value);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        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 Person GetPerson(DsioLinkedPerson dsioPerson)
        {
            // *** Translates a dsio person to a strongly typed Person ***

            Person newPerson = new Person();

            // ** Parse the name ***
            newPerson.LastName  = Util.Piece(dsioPerson.Name, ",", 1);
            newPerson.FirstName = Util.Piece(dsioPerson.Name, ",", 2);

            // *** Ien ***
            newPerson.Ien = dsioPerson.Ien;

            // *** Spouse ***
            if (dsioPerson.Ien == "S")
            {
                newPerson.Spouse = true;
            }

            // *** Use standard DOB format ***
            DateTime tempDate = VistaDates.ParseDateString(dsioPerson.DOB, VistaDates.VistADateOnlyFormat);

            if (tempDate != DateTime.MinValue)
            {
                newPerson.DOB = tempDate;
            }

            // *** Years school ***
            int yrs = -1;

            if (int.TryParse(dsioPerson.YearsSchool, out yrs))
            {
                newPerson.YearsSchool = yrs;
            }

            // *** Address ***
            newPerson.Address = new Address();
            newPerson.Address.StreetAddress1 = dsioPerson.Address.StreetLine1;
            newPerson.Address.StreetAddress2 = dsioPerson.Address.StreetLine2;
            newPerson.Address.City           = dsioPerson.Address.City;
            newPerson.Address.State          = dsioPerson.Address.State;
            newPerson.Address.ZipCode        = dsioPerson.Address.ZipCode;

            // *** Loop through telephone numbers and add ***
            foreach (DsioTelephone tel in dsioPerson.TelephoneList)
            {
                switch (tel.Usage)
                {
                case DsioTelephone.HomePhoneUsage:
                    newPerson.HomePhone = tel.Number;
                    break;

                case DsioTelephone.WorkPhoneUsage:
                    newPerson.WorkPhone = tel.Number;
                    break;

                case DsioTelephone.MobilePhoneUsage:
                    newPerson.MobilePhone = tel.Number;
                    break;
                }
            }

            return(newPerson);
        }
        public PregnancyOutcomeResult GetPregnancyOutcomes(DateTime fromDate, DateTime toDate, int page, int itemsPerPage)
        {
            PregnancyOutcomeResult returnResult = new PregnancyOutcomeResult();

            DsioGetPregHistoryRangeCommand command = new DsioGetPregHistoryRangeCommand(this.broker);

            command.AddCommandArguments(fromDate, toDate, page, itemsPerPage);

            RpcResponse response = command.Execute();

            returnResult.Success = response.Status == RpcResponseStatus.Success;

            if (response.Status != RpcResponseStatus.Success)
            {
                returnResult.Message = response.InformationalMessage;
            }
            else if (command.HistoricalPregnancies != null)
            {
                foreach (var item in command.HistoricalPregnancies)
                {
                    PregnancyOutcome pregOutcome = new PregnancyOutcome();

                    pregOutcome.EndDate = VistaDates.ParseDateString(item.EndDate, VistaDates.VistADateOnlyFormat);

                    PregnancyOutcomeType tempType;

                    if (Enum.TryParse <PregnancyOutcomeType>(item.OutcomeType, out tempType))
                    {
                        pregOutcome.OutcomeType = tempType;
                    }

                    //switch (item.OutcomeType)
                    //{
                    //    case "U":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.Unknown;
                    //        break;
                    //    case "F":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.FullTermDelivery;
                    //        break;
                    //    case "P":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.PretermDelivery;
                    //        break;
                    //    case "AS":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.SpontaneousAbortion;
                    //        break;
                    //    case "S":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.StillBirth;
                    //        break;
                    //    case "AI":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.PregnancyTermination;
                    //        break;
                    //    case "E":
                    //        pregOutcome.OutcomeType = PregnancyOutcomeType.Ectopic;
                    //        break;
                    //}

                    returnResult.PregnancyOutcomes.Add(pregOutcome);
                }
            }

            return(returnResult);
        }
        protected override void ProcessResponse()
        {
            string lmpText       = "LMP: ";
            string eddText       = "EDD: ";
            string enteredByText = "Entered by: ";
            string enteredOnText = "Entered on: ";

            if (this.ProcessSaveResponse())
            {
                //----------------------------------------------------------------
                //Returned message when the Pregnancy status is "Yes"
                //               LMP: Oct 10, 2017
                //               EDD: Jul 17, 2018
                //
                //Entered by: FREY,ALINA
                //Entered on: Mar 05, 2018@10:06

                //----------------------------------------------------------------
                //Returned message when the Pregnancy status is "No"
                //<empty line>
                //Entered by: FREY,ALINA (Physician)
                //Entered on: Mar 08, 2018@15:17

                //----------------------------------------------------------------
                //Returned messages when the the pregnancy status is "Not Applicable"
                //Case 1: "The patient's age is outside of the age range 10 to 52 years old."
                //Case 2: "No data on file." - That seems to be the case when the patient was never pregnant
                //Case 3: The case when the patient is not able to conceive: The returned message is a string containing
                //any combination of the following: Hysterectomy, menopause, permanent female sterilization and
                //other comments, then the Entered by and Entered on lines.
                if (this.Response.Lines != null)
                {
                    foreach (string line in this.Response.Lines)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            if (line.IndexOf(lmpText) > -1)
                            {
                                string lmpDate = Util.Piece(line, lmpText, 2);
                                this.LMP = VistaDates.StandardizeDateFormat(lmpDate);
                            }
                            if (line.IndexOf(eddText) > -1)
                            {
                                string eddDate = Util.Piece(line, eddText, 2);
                                this.EDD = VistaDates.StandardizeDateFormat(eddDate);
                            }
                            if (line.IndexOf(enteredByText) > -1)
                            {
                                this.EnteredBy = Util.Piece(line, enteredByText, 2);
                            }
                            if (line.IndexOf(enteredOnText) > -1)
                            {
                                string enteredOn = Util.Piece(line, enteredOnText, 2);
                                this.Created = VistaDates.ParseDateString(enteredOn, VistaDates.VistADateFormatSeven);
                            }
                        }
                    }
                }

                this.Response.Status = RpcResponseStatus.Success;
            }
        }
        public TrackedPatient GetTrackedPatient(DsioTrackedPatient dsioPatient)
        {
            // *** Converts dsio patient to strongly typed patient ***

            TrackedPatient returnPatient = new TrackedPatient();

            // *** Add values ***
            returnPatient.Dfn       = dsioPatient.Dfn;
            returnPatient.LastName  = dsioPatient.LastName;
            returnPatient.FirstName = dsioPatient.FirstName;

            if (dsioPatient.Last4.Length > 4)
            {
                if (dsioPatient.Last4.ToUpper().Contains("SENSITIVE"))
                {
                    returnPatient.Last4 = "XXXX";
                }
                else
                {
                    returnPatient.Last4 = dsioPatient.Last4.Substring(5, 4);
                }
            }
            else
            {
                returnPatient.Last4 = dsioPatient.Last4;
            }

            // *** Process/Parse dob ***
            DateTime dob;

            if (DateTime.TryParse(dsioPatient.DateOfBirth, out dob))
            {
                returnPatient.DateOfBirth = dob;
            }
            else
            {
                returnPatient.DateOfBirthInexact = Util.GetInexactDate(dsioPatient.DateOfBirth);
            }

            returnPatient.HomePhone = dsioPatient.HomePhone;

            returnPatient.NonVaObstetrician       = dsioPatient.Obstetrician;
            returnPatient.PlannedDeliveryFacility = dsioPatient.LDFacility;

            // *** Process/Parse EDD ***
            returnPatient.EDD = VistaDates.ParseDateString(dsioPatient.EDD, VistaDates.VistADateOnlyFormat);

            returnPatient.Pregnant = (dsioPatient.Pregnant == "YES") ? true : false;

            returnPatient.Lactating = (dsioPatient.Lactating == "YES") ? true : false;

            // *** Add dates ***
            //returnPatient.NextChecklistDue = VistaDates.ParseDateString(dsioPatient.NextChecklistDue, VistaDates.VistADateFormatSix);
            //returnPatient.LastContactDate = VistaDates.ParseDateString(dsioPatient.LastContactDate, VistaDates.VistADateFormatSix);
            //returnPatient.NextContactDue = VistaDates.ParseDateString(dsioPatient.NextContactDue, VistaDates.VistADateFormatSix);
            returnPatient.NextChecklistDue = VistaDates.ParseDateString(dsioPatient.NextChecklistDue, VistaDates.VistADateOnlyFormat);
            returnPatient.LastContactDate  = VistaDates.ParseDateString(dsioPatient.LastContactDate, VistaDates.VistADateOnlyFormat);
            returnPatient.NextContactDue   = VistaDates.ParseDateString(dsioPatient.NextContactDue, VistaDates.VistADateOnlyFormat);

            // *** Current Pregnancy High Risk ***
            returnPatient.CurrentPregnancyHighRisk = (dsioPatient.CurrentPregnancyHighRisk == "TRUE");
            returnPatient.HighRiskDetails          = dsioPatient.HighRiskDetails;

            // *** Text4Baby ***
            if (dsioPatient.Text4BabyStatus.Equals("enrolled", StringComparison.CurrentCultureIgnoreCase))
            {
                returnPatient.Text4BabyStatus = Text4BabyStatus.Enrolled;
            }
            else if (dsioPatient.Text4BabyStatus.Equals("not interested", StringComparison.CurrentCultureIgnoreCase))
            {
                returnPatient.Text4BabyStatus = Text4BabyStatus.NotInterested;
            }

            return(returnPatient);
        }