private List <Observation> AwvaaaObservations(Customer customer, Event theEventData)
        {
            ITestResultRepository testResultRepository = new AwvAaaTestRepository();
            var isNewResultFlow = theEventData.EventDate >= _settings.ResultFlowChangeDate;
            var testResult      = (AwvAaaTestResult)testResultRepository.GetTestResults(customer.CustomerId, theEventData.Id, isNewResultFlow);

            var observation = new List <Observation>();

            if (testResult != null && (testResult.TestNotPerformed == null || testResult.TestNotPerformed.TestNotPerformedReasonId <= 0) && (testResult.UnableScreenReason == null || testResult.UnableScreenReason.Count == 0))
            {
                if (testResult.AortaSize != null)
                {
                    var asize = testResult.AortaSize != null ? testResult.AortaSize.Reading != null?testResult.AortaSize.Reading.ToString() : "" : "";

                    var aaaLargestSagittalMeasurement = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaLargestSagittalMeasurement).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaLargestSagittalMeasurement).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = asize, Unit = "cm"
                        }
                    };
                    observation.Add(aaaLargestSagittalMeasurement);
                }

                if (testResult.AortaRangeSaggitalView != null)
                {
                    var aortaRangeSaggitalView     = string.Join(",", testResult.AortaRangeSaggitalView != null ? testResult.AortaRangeSaggitalView.Select(s => s.Label).ToArray() : new[] { "" });
                    var aaaLargestSagittalLocation = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaLargestSagittalLocation).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaLargestSagittalLocation).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = aortaRangeSaggitalView, Unit = ""
                        }
                    };
                    observation.Add(aaaLargestSagittalLocation);
                }

                if (testResult.TransverseView != null)
                {
                    var reading = testResult.TransverseView != null ? testResult.TransverseView.FirstValue != null?testResult.TransverseView.FirstValue.Reading.ToString() : "" : "";

                    var transverseView = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaLargestTransverseMeasurement1).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaLargestTransverseMeasurement1).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(transverseView);
                }

                if (testResult.TransverseView != null)
                {
                    var reading = testResult.TransverseView != null ? testResult.TransverseView.SecondValue != null?testResult.TransverseView.SecondValue.Reading.ToString() : "" : "";

                    var transverseView = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaLargestTransverseMeasurement2).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaLargestTransverseMeasurement2).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(transverseView);
                }

                if (testResult.AortaRangeTransverseView != null)
                {
                    var reading        = string.Join(",", testResult.AortaRangeTransverseView != null ? testResult.AortaRangeTransverseView.Select(s => s.Label).ToArray() : new[] { "" });
                    var transverseView = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaLargestMeasurementTransverseLocation).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaLargestMeasurementTransverseLocation).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(transverseView);
                }

                if (testResult.PeakSystolicVelocity != null)
                {
                    var reading = testResult.PeakSystolicVelocity != null ? testResult.PeakSystolicVelocity.Reading != null?testResult.PeakSystolicVelocity.Reading.ToString() : "" : "";

                    var transverseView = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaPeakSystolicVelocityMeasurement).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaPeakSystolicVelocityMeasurement).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(transverseView);
                }

                if (testResult.PeakSystolicVelocityStandardFindings != null)
                {
                    var reading = string.Join(",", testResult.PeakSystolicVelocityStandardFindings != null ? testResult.PeakSystolicVelocityStandardFindings.Select(s => s.Label).ToArray() : new[] { "" });
                    var peakSystolicVelocityStandardFindings = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaPeakSystolicVelocityLocation).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaPeakSystolicVelocityLocation).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(peakSystolicVelocityStandardFindings);
                }

                if (testResult.ResidualLumenStandardFindings != null)
                {
                    var reading = testResult.ResidualLumenStandardFindings != null ? testResult.ResidualLumenStandardFindings.SecondValue != null?testResult.ResidualLumenStandardFindings.SecondValue.Reading.ToString() : "" : "";

                    var residualLumenStandardFindings = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaResidualLumenMeasurement2).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaResidualLumenMeasurement2).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(residualLumenStandardFindings);
                }

                if (testResult.ResidualLumenStandardFindings != null)
                {
                    var reading = testResult.ResidualLumenStandardFindings != null ? testResult.ResidualLumenStandardFindings.SecondValue != null?testResult.ResidualLumenStandardFindings.SecondValue.Reading.ToString() : "" : "";

                    var residualLumenStandardFindings = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaResidualLumenMeasurement2).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaResidualLumenMeasurement2).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(residualLumenStandardFindings);
                }

                if (testResult.AorticDissection != null)
                {
                    var reading          = (testResult.AorticDissection.Reading ? "Yes" : string.Empty);
                    var aorticDissection = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaAorticDissection).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaAorticDissection).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(aorticDissection);
                }

                if (testResult.Plaque != null)
                {
                    var reading = (testResult.Plaque.Reading ? "Yes" : string.Empty);
                    var plaque  = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaPlaque).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaPlaque).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(plaque);
                }

                if (testResult.Thrombus != null)
                {
                    var reading  = (testResult.Thrombus.Reading ? "Yes" : string.Empty);
                    var thrombus = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvAaa).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AaaThrombus).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AaaThrombus).SecondValue,
                        //Reference = " <reference value='#DiastolicBP_1'/>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = ""
                        }
                    };
                    observation.Add(thrombus);
                }
            }
            return(observation);
        }
Esempio n. 2
0
        public void Create(IEnumerable <EventCustomerResultEntity> eventCustomerResultEntities, IEnumerable <OrderedPair <long, long> > orgRoleUserIdUserIdPairs, IEnumerable <UserEntity> userEntities,
                           IEnumerable <Address> addresses, IEnumerable <CustomerProfileEntity> customerProfileEntities, IEnumerable <EventsEntity> eventsEntities, IEnumerable <CustomerHealthInfoEntity> customerHealthInfoEntities,
                           IEnumerable <OrderedPair <long, long> > eventIdPodIdPairs, IEnumerable <PodDetailsEntity> podDetailsEntities, IEnumerable <OrderedPair <long, long> > eventIdHospitalPartnerIdPairs,
                           IEnumerable <OrderedPair <long, string> > hospitalPartnerIdNamePairs, IEnumerable <EventCustomerBasicBioMetricEntity> basicBioMetricEntities, IEnumerable <EventCustomersEntity> eventCustomersEntities,
                           IEnumerable <EventAppointmentEntity> eventAppointmentEntities, IEnumerable <HospitalPartnerCustomerEntity> hospitalPartnerCustomerEntities, IEnumerable <OrderedPair <long, string> > careCoordinatorIdNamePair,
                           IEnumerable <CustomerPrimaryCarePhysicianEntity> primaryCarePhysicianEntities, string destinationPath, IEnumerable <long> hafQuestionIds)
        {
            long totalRecords = eventCustomerResultEntities.Count();
            long counter      = 1;

            PcpResultExportHelper.Questions = PcpResultExportHelper.AllQuestions.Where(aq => hafQuestionIds.Contains(aq.FirstValue)).Select(aq => aq).ToArray();

            _logger.Info("Total Records : " + totalRecords);

            WriteCsvHeader(destinationPath);

            foreach (var eventCustomerResultEntity in eventCustomerResultEntities)
            {
                try
                {
                    _logger.Info(string.Format("Creating Model for event {0} and customer {1}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId));

                    var userId = orgRoleUserIdUserIdPairs.Where(oru => oru.FirstValue == eventCustomerResultEntity.CustomerId).Select(oru => oru.SecondValue).Single();

                    var user = userEntities.Where(u => u.UserId == userId).Select(u => u).Single();

                    var address = addresses.Where(a => a.Id == user.HomeAddressId).Select(a => a).Single();

                    var customer = customerProfileEntities.Where(cp => cp.CustomerId == eventCustomerResultEntity.CustomerId).Select(cp => cp).Single();

                    var eventData = eventsEntities.Where(e => e.EventId == eventCustomerResultEntity.EventId).Select(e => e).Single();

                    var podIds = eventIdPodIdPairs.Where(ep => ep.FirstValue == eventData.EventId).Select(ep => ep.SecondValue).ToArray();

                    var podName = string.Join(",", podDetailsEntities.Where(pd => podIds.Contains(pd.PodId)).Select(pd => pd.Name).ToArray());

                    var hospitalPartnerId = eventIdHospitalPartnerIdPairs.Where(ehp => ehp.FirstValue == eventData.EventId).Select(ehp => ehp.SecondValue).SingleOrDefault();

                    var hopitalPartnerName = hospitalPartnerIdNamePairs.Where(hp => hp.FirstValue == hospitalPartnerId).Select(hp => hp.SecondValue).SingleOrDefault();

                    var eventCustomer = eventCustomersEntities.Where(ec => ec.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(ec => ec).Single();

                    var eventAppointment = eventAppointmentEntities.Where(ea => ea.AppointmentId == eventCustomer.AppointmentId).Select(ea => ea).Single();

                    var primaryCarePhysician = primaryCarePhysicianEntities.Where(pcp => pcp.CustomerId == eventCustomerResultEntity.CustomerId).Select(pcp => pcp).FirstOrDefault();

                    var basicBimetric = basicBioMetricEntities.Where(bb => bb.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(bb => bb).FirstOrDefault();

                    var hafAnswers = customerHealthInfoEntities.Where(chi => chi.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(chi => chi).ToArray();

                    var answers = new List <OrderedPair <long, string> >();

                    foreach (var question in PcpResultExportHelper.Questions)
                    {
                        var hafAnswer = hafAnswers.Where(ha => ha.CustomerHealthQuestionId == question.FirstValue).Select(ha => ha).FirstOrDefault();

                        if (hafAnswer != null)
                        {
                            answers.Add(new OrderedPair <long, string>(question.FirstValue, hafAnswer.HealthQuestionAnswer));
                        }
                        else
                        {
                            answers.Add(new OrderedPair <long, string>(question.FirstValue, ""));
                        }
                    }

                    var age = string.Empty;
                    if (user.Dob.HasValue)
                    {
                        var now = DateTime.Now;
                        var checkCurrentLeapYear = new DateTime(now.Year, 3, 1);
                        var birth = user.Dob.Value;
                        var checkBirthLeapYear = new DateTime(birth.Year, 3, 1);

                        var currentDayOfYear = now.DayOfYear;
                        if (checkCurrentLeapYear.DayOfYear == 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear != 61)
                        {
                            currentDayOfYear = now.DayOfYear - 1;
                        }
                        else if (checkCurrentLeapYear.DayOfYear != 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear == 61)
                        {
                            currentDayOfYear = now.DayOfYear + 1;
                        }

                        var years  = now.Year - birth.Year - ((currentDayOfYear < birth.DayOfYear) ? 1 : 0);
                        var months = (12 + now.Month - birth.Month - ((now.Day < birth.Day) ? 1 : 0)) % 12;
                        var days   = now.Day - birth.Day;
                        if (days < 0)
                        {
                            days = new DateTime(now.Year, now.Month, 1).AddDays(-1).AddDays(days).Day;
                        }

                        age = years.ToString();
                    }
                    var ssn = "N/A";
                    if (!string.IsNullOrEmpty(user.Ssn))
                    {
                        ssn = _cryptographyService.Decrypt(user.Ssn);
                        if (ssn.Length >= 9)
                        {
                            ssn = ssn.Substring(0, 3) + "-" + ssn.Substring(3, 2) + "-" + ssn.Substring(ssn.Length - 4);
                        }
                    }

                    var model = new PcpResultExportModel
                    {
                        CustomerId            = customer.CustomerId,
                        FirstName             = user.FirstName,
                        LastName              = user.LastName,
                        Address1              = address.StreetAddressLine1,
                        City                  = address.City,
                        State                 = address.State,
                        Zip                   = address.ZipCode.Zip,
                        Dob                   = user.Dob,
                        Age                   = age,
                        Height                = customer.Height,
                        Weight                = customer.Weight > 0 ? customer.Weight.ToString() : "",
                        Gender                = customer.Gender,
                        Race                  = customer.Race != "-1" ? customer.Race : "",
                        Email                 = user.Email1,
                        Phone                 = user.PhoneHome,
                        Ssn                   = ssn,
                        MemberId              = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId,
                        Hicn                  = string.IsNullOrEmpty(customer.Hicn) ? "" : customer.Hicn,
                        EventId               = eventData.EventId,
                        EventDate             = eventData.EventDate,
                        Pod                   = podName,
                        HospitalPartner       = hopitalPartnerName,
                        Hipaa                 = ((RegulatoryState)eventCustomer.Hipaastatus).GetDescription(),
                        CheckinTime           = eventAppointment.CheckinTime.HasValue ? eventAppointment.CheckinTime.Value.ToShortTimeString() : "",
                        CheckoutTime          = eventAppointment.CheckoutTime.HasValue ? eventAppointment.CheckoutTime.Value.ToShortTimeString() : "",
                        HealthAssesmentAnswer = answers,
                        ResultSummary         = eventCustomerResultEntity.ResultSummary.HasValue ? ((ResultInterpretation)eventCustomerResultEntity.ResultSummary).GetDescription() : ""
                    };
                    if (primaryCarePhysician != null)
                    {
                        model.PrimaryPhysicianName = new Name(primaryCarePhysician.FirstName, primaryCarePhysician.MiddleName, primaryCarePhysician.LastName).FullName;
                    }
                    if (hospitalPartnerId > 0)
                    {
                        model.PartnerRelease = eventCustomer.PartnerRelease > 0 ? ((RegulatoryState)eventCustomer.PartnerRelease).GetDescription() : "";
                        var hospitalPartnerCustomer = hospitalPartnerCustomerEntities.LastOrDefault(hpc => hpc.EventId == eventCustomerResultEntity.EventId && hpc.CustomerId == eventCustomerResultEntity.CustomerId);
                        model.CareCoordinatorStatus = hospitalPartnerCustomer != null
                            ? ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status).GetDescription()
                            : HospitalPartnerCustomerStatus.NotCalled.GetDescription();
                        model.CareCoordinatorOutcome = hospitalPartnerCustomer != null
                            ? ((HospitalPartnerCustomerOutcome)hospitalPartnerCustomer.Outcome).GetDescription()
                            : HospitalPartnerCustomerOutcome.NotScheduledNotInterested.GetDescription();
                        model.CareCoordinator = hospitalPartnerCustomer != null
                            ? careCoordinatorIdNamePair.First(cc => cc.FirstValue == hospitalPartnerCustomer.CareCoordinatorOrgRoleUserId).SecondValue
                            : "N/A";

                        model.CareCoordinatorNotes = hospitalPartnerCustomer != null
                            ? hospitalPartnerCustomer.Notes
                            : "";
                    }
                    else
                    {
                        model.PartnerRelease         = "N/A";
                        model.CareCoordinatorStatus  = "N/A";
                        model.CareCoordinatorOutcome = "N/A";
                        model.CareCoordinator        = "N/A";
                        model.CareCoordinatorNotes   = "N/A";
                    }

                    if (model.EventId > 0)
                    {
                        var theEvent = _eventRepository.GetById(model.EventId);
                        if (theEvent.AccountId.HasValue && theEvent.AccountId > 0)
                        {
                            var organization = _organizationRepository.GetOrganizationbyId(theEvent.AccountId.Value);
                            model.CorporateAccount = organization.Name;
                        }

                        if (theEvent.HostId > 0)
                        {
                            var host = _hostRepository.GetHostForEvent(theEvent.Id);
                            model.EventLocation = host.OrganizationName + " @ " + host.Address;
                        }
                    }

                    if (basicBimetric != null)
                    {
                        model.BloodPressure = (basicBimetric.SystolicPressure.HasValue ? basicBimetric.SystolicPressure.Value.ToString() : "0") + "/" + (basicBimetric.DiastolicPressure.HasValue ? basicBimetric.DiastolicPressure.Value.ToString() : "0");

                        model.PulseRate = basicBimetric.PulseRate.HasValue ? basicBimetric.PulseRate.Value.ToString() : "";

                        model.IsAbnormalBloodPressure = basicBimetric.IsBloodPressureElevated.HasValue && basicBimetric.IsBloodPressureElevated.Value ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString;
                    }
                    ITestResultRepository testResultRepository;

                    var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvAAA);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Awv Aaa  data.");

                        testResultRepository = new AwvAaaTestRepository();
                        var awvAaaTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvAaaTestResult != null)
                        {
                            model = _awvAaaFactory.SetAwvAaaData(model, awvAaaTestResult as AwvAaaTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEcho);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Awv Echo  data.");

                        testResultRepository = new AwvEchocardiogramTestRepository();
                        var awvEchoTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvEchoTestResult != null)
                        {
                            model = _awvEchoFactory.SetAwvEchoData(model, awvEchoTestResult as AwvEchocardiogramTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvCarotid);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Awv Carotid data.");

                        testResultRepository = new AwvCarotidTestRepository();
                        var awvCarotidTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvCarotidTestResult != null)
                        {
                            model = _awvCarotidFactory.SetAwvCarotidData(model, awvCarotidTestResult as AwvCarotidTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvSpiro);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting AWV Spiro data.");

                        testResultRepository = new AwvSpiroTestRepository();
                        var awvSpiroTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvSpiroTestResult != null)
                        {
                            model = _awvSpiroFactory.SetAwvSpiroData(model, awvSpiroTestResult as AwvSpiroTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvABI);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Awv ABI data.");

                        testResultRepository = new AwvAbiTestRepository();
                        var awvAbiTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvAbiTestResult != null)
                        {
                            model = _awvAbiFactory.SetAwvAbiData(model, awvAbiTestResult as AwvAbiTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEkg);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Awv EKG data.");

                        testResultRepository = new AwvEkgTestRepository();
                        var awvEkgTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (awvEkgTestResult != null)
                        {
                            model = _awvEkgFactory.SetAwvEkgData(model, awvEkgTestResult as AwvEkgTestResult);
                        }
                    }

                    isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.Vision);
                    if (isTestPurchased)
                    {
                        _logger.Info("Setting Vision data.");

                        testResultRepository = new VisionTestRepository();
                        var visionTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId);
                        if (visionTestResult != null)
                        {
                            model = _visionFactory.SetVisionData(model, visionTestResult as VisionTestResult);
                        }
                    }

                    WriteCsv(model, destinationPath);
                    _logger.Info(counter + " completed out of " + totalRecords);

                    //if (counter > 10)
                    //    break;
                    counter++;
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("\n\nFor Event {0} and Customer {1} \n Error:{2}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId, ex.Message));
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This can be rerun any time. The service updates the last run time and will continue
        /// </summary>
        public void Sync()
        {
            try
            {
                if (!_settings.SyncWithHra)
                {
                    _logger.Info("Syncing with HRA is off ");
                    return;
                }
                //get all tags for IsHealthPlan is true
                var tags = _organizationRepository.GetMedicareSites().Where(x => x.ShowHraQuestionnaire);
                if (tags != null && tags.Any())
                {
                    foreach (var tag in tags)
                    {
                        var newLastTransactionDate = DateTime.Now; //   use the time when exporting for this tag starts, as start date for next day.
                        _logger.Info("Medicare CustomerResult Sync for tag : " + tag.Alias);
                        var path           = _medicareSyncCustomSettingsPath + "MedicareCustomerResultSync" + tag.Alias + ".xml";
                        var customSettings = _customSettingManager.Deserialize(path);

                        if (customSettings == null || !customSettings.LastTransactionDate.HasValue)
                        {
                            customSettings = new CustomSettings {
                                LastTransactionDate = DateTime.Now.AddHours(-2)
                            };
                        }

                        if (customSettings.LastTransactionDate != null)
                        {
                            var exportFromTime = customSettings.LastTransactionDate.Value;
                            var customerIds    = _customerRepository.GetRecentResultUpdatedForMedicareSync(exportFromTime, tag.Alias).ToArray();
                            if (customerIds.Any())
                            {
                                var events = customerIds.Select(x => x.EventId).Distinct().ToArray();
                                var eventIdsWithMammogramTest       = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.Mammogram).ToArray();
                                var eventIdsWithEchocardiogram      = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvEcho).ToArray();
                                var eventIdsWithAwvLipid            = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvLipid).ToArray();
                                var eventIdsWithAwvSpiro            = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvSpiro).ToArray();
                                var eventIdsWithDiabeticRetinopathy = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.DiabeticRetinopathy).ToArray();
                                var eventIdsWithUrineMicroalbumin   = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.UrineMicroalbumin).ToArray();
                                var eventIdsWithAwvEkg       = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvEkg).ToArray();
                                var eventIdsWithAwvHba1C     = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvHBA1C).ToArray();
                                var eventIdsWithAwvAaa       = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvAAA).ToArray();
                                var eventIdsWithAwvAbi       = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.AwvABI).ToArray();
                                var eventIdsWithQuantaFloAbi = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.QuantaFloABI).ToArray();
                                var eventIdsWithLead         = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.Lead).ToArray();
                                var eventIdsWithBp           = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.Hypertension).ToArray();
                                var eventList = _eventRepository.GetEvents(events).ToArray();
                                //var eventIdsWithMonoFilament = _customerRepository.GetEventWithTest(events, tag.Alias, (long)TestType.Monofilament).ToArray();
                                const int pageSize   = 25;
                                var       totalPages = Math.Ceiling((double)(customerIds.Count()) / pageSize);
                                for (int i = 0; i < totalPages; i++)
                                {
                                    var currentList = customerIds.Skip(i * pageSize).Take(pageSize).ToArray();
                                    try
                                    {
                                        foreach (var medicareResultEditModel in currentList)
                                        {
                                            var eventData       = eventList.First(e => e.Id == medicareResultEditModel.EventId);
                                            var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate;

                                            var evaluatingPhysicians = _physicianEvaluationRepsoitory.GetPhysicianEvaluation(medicareResultEditModel.EventCustomerId);
                                            if (evaluatingPhysicians != null)
                                            {
                                                var primaryEvalRecord = evaluatingPhysicians != null?evaluatingPhysicians.Where(p => p.IsPrimaryEvaluator).OrderByDescending(p => p.EvaluationEndTime ?? p.EvaluationStartTime).FirstOrDefault() : null;

                                                var primaryPhysicianId  = primaryEvalRecord != null ? primaryEvalRecord.PhysicianId : 0;
                                                var overreadPhysicianId = primaryEvalRecord != null?evaluatingPhysicians.Where(p => !p.IsPrimaryEvaluator && p.EvaluationStartTime > primaryEvalRecord.EvaluationStartTime).OrderByDescending(
                                                    p => p.EvaluationEndTime ?? p.EvaluationStartTime).Select(p => p.PhysicianId).FirstOrDefault() : 0;

                                                medicareResultEditModel.PhysicianOruId = overreadPhysicianId > 0 ? overreadPhysicianId : primaryPhysicianId;
                                            }



                                            if (eventIdsWithBp.Contains(medicareResultEditModel.EventId)) //1
                                            {
                                                // Blood Pressure Evaluation Test or  Hypertension
                                                var testResultRepository = new HypertensionTestRepository();
                                                var aaaTestResult        = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var aaaTest = ((Core.Medical.Domain.HypertensionTestResult)aaaTestResult);
                                                if (aaaTest != null && aaaTest.TestNotPerformed == null &&
                                                    aaaTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.BpReading           = new MedicareResultEditModel.Bp();
                                                    medicareResultEditModel.BpReading.Systolic  = aaaTest.Systolic != null ? aaaTest.Systolic.Reading : null;
                                                    medicareResultEditModel.BpReading.Diastolic = aaaTest.Diastolic != null ? aaaTest.Diastolic.Reading : null;
                                                }
                                            }
                                            if (eventIdsWithAwvAaa.Contains(medicareResultEditModel.EventId)) //1
                                            {
                                                // Update the AAA result
                                                var testResultRepository = new AwvAaaTestRepository();
                                                var aaaTestResult        = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var aaaTest = ((Core.Medical.Domain.AwvAaaTestResult)aaaTestResult);
                                                if (aaaTest != null && aaaTest.Finding != null && aaaTest.TestNotPerformed == null &&
                                                    aaaTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AaaResult                  = new MedicareResultEditModel.AaaReadings();
                                                    medicareResultEditModel.AaaResult.AortaSize        = aaaTest.Finding != null ? aaaTest.Finding.Label : null;
                                                    medicareResultEditModel.AaaResult.AorticDissection = aaaTest.AorticDissection != null && aaaTest.AorticDissection.Reading;
                                                    medicareResultEditModel.AaaResult.Plaque           = aaaTest.Plaque != null && aaaTest.Plaque.Reading;
                                                    medicareResultEditModel.AaaResult.Thrombus         = aaaTest.Thrombus != null && aaaTest.Thrombus.Reading;

                                                    if (aaaTest.IncidentalFindings != null)
                                                    {
                                                        foreach (var standardFinding in aaaTest.IncidentalFindings)
                                                        {
                                                            if (standardFinding.Label == "Aortic Stenosis")
                                                            {
                                                                medicareResultEditModel.AaaResult.AorticStenosis = true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            if (eventIdsWithAwvAbi.Contains(medicareResultEditModel.EventId))//2
                                            {
                                                // AwvAbi
                                                var testResultRepository = new AwvAbiTestRepository();
                                                var padTestResult        = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var aaaTest = ((Core.Medical.Domain.AwvAbiTestResult)padTestResult);
                                                if (aaaTest != null && aaaTest.Finding != null && aaaTest.TestNotPerformed == null &&
                                                    aaaTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.PadReading         = new MedicareResultEditModel.PadTestReadings();
                                                    medicareResultEditModel.PadReading.Finding = aaaTest.Finding.Label;
                                                }
                                            }
                                            if (eventIdsWithQuantaFloAbi.Contains(medicareResultEditModel.EventId))//3
                                            {
                                                // QuantaFlo Abi
                                                var testResultRepository = new QuantaFloABITestRepository();
                                                var padTestResult        = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var aaaTest = ((Core.Medical.Domain.QuantaFloABITestResult)padTestResult);
                                                if (aaaTest != null && aaaTest.Finding != null && aaaTest.TestNotPerformed == null &&
                                                    aaaTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.QuantaFloReading         = new MedicareResultEditModel.QuantaFloReadings();
                                                    medicareResultEditModel.QuantaFloReading.Finding = aaaTest.Finding.Label;
                                                }
                                            }
                                            if (eventIdsWithLead.Contains(medicareResultEditModel.EventId))//5
                                            {
                                                // Lead
                                                var testResultRepository = new LeadTestRepository();
                                                var leadTestResult       = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var leadTest             = ((Core.Medical.Domain.LeadTestResult)leadTestResult);
                                                if (leadTest != null && leadTest.TestNotPerformed == null &&
                                                    leadTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.LeadReading = new MedicareResultEditModel.LeadReadings();
                                                    if (leadTest.LeftResultReadings != null)
                                                    {
                                                        medicareResultEditModel.LeadReading.LNoVisualPlaque             = leadTest.LeftResultReadings.NoVisualPlaque != null && leadTest.LeftResultReadings.NoVisualPlaque.Reading.HasValue && leadTest.LeftResultReadings.NoVisualPlaque.Reading.Value;
                                                        medicareResultEditModel.LeadReading.LVisuallyDemonstratedPlaque = leadTest.LeftResultReadings.VisuallyDemonstratedPlaque != null && leadTest.LeftResultReadings.VisuallyDemonstratedPlaque.Reading.HasValue && leadTest.LeftResultReadings.VisuallyDemonstratedPlaque.Reading.Value;
                                                        medicareResultEditModel.LeadReading.LModerateStenosis           = leadTest.LeftResultReadings.ModerateStenosis != null && leadTest.LeftResultReadings.ModerateStenosis.Reading.HasValue && leadTest.LeftResultReadings.ModerateStenosis.Reading.Value;
                                                        medicareResultEditModel.LeadReading.LPossibleOcclusion          = leadTest.LeftResultReadings.PossibleOcclusion != null && leadTest.LeftResultReadings.PossibleOcclusion.Reading.HasValue && leadTest.LeftResultReadings.PossibleOcclusion.Reading.Value;
                                                    }
                                                    if (leadTest.LowVelocityLeft != null)
                                                    {
                                                        medicareResultEditModel.LeadReading.LowVelocityLeft = true;
                                                    }
                                                    if (leadTest.RightResultReadings != null)
                                                    {
                                                        medicareResultEditModel.LeadReading.RNoVisualPlaque             = leadTest.RightResultReadings.NoVisualPlaque != null && leadTest.RightResultReadings.NoVisualPlaque.Reading.HasValue && leadTest.RightResultReadings.NoVisualPlaque.Reading.Value;
                                                        medicareResultEditModel.LeadReading.RVisuallyDemonstratedPlaque = leadTest.RightResultReadings.VisuallyDemonstratedPlaque != null && leadTest.RightResultReadings.VisuallyDemonstratedPlaque.Reading.HasValue && leadTest.RightResultReadings.VisuallyDemonstratedPlaque.Reading.Value;
                                                        medicareResultEditModel.LeadReading.RModerateStenosis           = leadTest.RightResultReadings.ModerateStenosis != null && leadTest.RightResultReadings.ModerateStenosis.Reading.HasValue && leadTest.RightResultReadings.ModerateStenosis.Reading.Value;
                                                        medicareResultEditModel.LeadReading.RPossibleOcclusion          = leadTest.RightResultReadings.PossibleOcclusion != null && leadTest.RightResultReadings.PossibleOcclusion.Reading.HasValue && leadTest.RightResultReadings.PossibleOcclusion.Reading.Value;
                                                    }
                                                    if (leadTest.LowVelocityRight != null)
                                                    {
                                                        medicareResultEditModel.LeadReading.LowVelocityRight = true;
                                                    }
                                                }
                                            }

                                            if (eventIdsWithMammogramTest.Contains(medicareResultEditModel.EventId))
                                            {
                                                // Update the mammogram result
                                                var testResultRepository = new MammogramTestRepository();
                                                var mammogramTestResult  = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                var mamoTest             = ((Core.Medical.Domain.MammogramTestResult)mammogramTestResult);
                                                if (mamoTest != null && mamoTest.Finding != null && mamoTest.TestNotPerformed == null && mamoTest.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.MammogramReading = mamoTest.Finding.Label;
                                                }
                                            }
                                            if (eventIdsWithAwvSpiro.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new AwvSpiroTestRepository();
                                                var awvSpiroTestResult   = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvSpiroTestResult != null && awvSpiroTestResult.TestNotPerformed == null && awvSpiroTestResult.UnableScreenReason == null)
                                                {
                                                    if (awvSpiroTestResult.ResultStatus != null)
                                                    {
                                                        medicareResultEditModel.AwvSpiroStateNumber = (int)awvSpiroTestResult.ResultStatus.StateNumber;
                                                    }
                                                    var spirotest = ((Core.Medical.Domain.AwvSpiroTestResult)awvSpiroTestResult);
                                                    if (spirotest.Finding != null)
                                                    {
                                                        medicareResultEditModel.AwvSpiroFindingLabel = spirotest.Finding.Label;
                                                    }
                                                    if (spirotest.Obstructive != null)
                                                    {
                                                        medicareResultEditModel.AwvSpiroObstructiveLabel = spirotest.Obstructive.Label.ToString();
                                                    }
                                                }
                                            }
                                            //if (eventIdsWithMonoFilament.Contains(medicareResultEditModel.EventId))
                                            //{
                                            //    var testResultRepository = new MonofilamentTestRepository();
                                            //    var monoTestResult = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId);
                                            //    if (monoTestResult != null && monoTestResult.ResultStatus != null)
                                            //    {
                                            //        medicareResultEditModel.MonoFilamentStateNumber = (int)monoTestResult.ResultStatus.StateNumber;
                                            //    }
                                            //}
                                            if (eventIdsWithEchocardiogram.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new AwvEchocardiogramTestRepository();
                                                var awvEchoTestResult    = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvEchoTestResult != null && awvEchoTestResult.TestNotPerformed == null && awvEchoTestResult.UnableScreenReason == null)
                                                {
                                                    try
                                                    {
                                                        if (awvEchoTestResult != null && awvEchoTestResult.ResultStatus != null)
                                                        {
                                                            medicareResultEditModel.AwvEchoStateNumber = (int)awvEchoTestResult.ResultStatus.StateNumber;
                                                        }
                                                        var echocartest = ((Core.Medical.Domain.AwvEchocardiogramTestResult)awvEchoTestResult);

                                                        medicareResultEditModel.AwvEchoFindingLabel   = echocartest.EstimatedEjactionFraction != null ? echocartest.EstimatedEjactionFraction.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading = new MedicareResultEditModel.EchocardiogramReadings();

                                                        if (echocartest.EstimatedEjactionFraction != null)
                                                        {
                                                            medicareResultEditModel.EchocardiogramReading.EstimatedEjactionFractionMin = echocartest.EstimatedEjactionFraction.MinValue;
                                                            medicareResultEditModel.EchocardiogramReading.EstimatedEjactionFractionMax = echocartest.EstimatedEjactionFraction.MaxValue;
                                                        }
                                                        //Aortic
                                                        medicareResultEditModel.EchocardiogramReading.Aortic = echocartest.Aortic != null && echocartest.Aortic.Reading;
                                                        if (echocartest.AorticMorphology != null)
                                                        {
                                                            foreach (var standardFinding in echocartest.AorticMorphology)
                                                            {
                                                                if (standardFinding.Label == "Stenosis")
                                                                {
                                                                    medicareResultEditModel.EchocardiogramReading.AorticStenosis = true;
                                                                }
                                                            }
                                                        }
                                                        var aorticRegurgitation = echocartest.AorticRegurgitation != null ? echocartest.AorticRegurgitation.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading.AorticRegurgitation = aorticRegurgitation != null ? (aorticRegurgitation == "Mod" ? "Moderate" : aorticRegurgitation) : null;

                                                        //Mitral
                                                        medicareResultEditModel.EchocardiogramReading.Mitral = echocartest.Mitral != null && echocartest.Mitral.Reading;
                                                        if (echocartest.MitralMorphology != null)
                                                        {
                                                            foreach (var standardFinding in echocartest.MitralMorphology)
                                                            {
                                                                if (standardFinding.Label == "Stenosis")
                                                                {
                                                                    medicareResultEditModel.EchocardiogramReading.MitralStenosis = true;
                                                                }
                                                                if (standardFinding.Label == "Mitral Prolapse")
                                                                {
                                                                    medicareResultEditModel.EchocardiogramReading.MitralProlapse = true;
                                                                }
                                                            }
                                                        }
                                                        var mitralRegurgitation = echocartest.MitralRegurgitation != null ? echocartest.MitralRegurgitation.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading.MitralRegurgitation = mitralRegurgitation != null ? (mitralRegurgitation == "Mod" ? "Moderate" : mitralRegurgitation) : null;

                                                        //Pulmonic
                                                        medicareResultEditModel.EchocardiogramReading.Pulmonic = echocartest.Pulmonic != null && echocartest.Pulmonic.Reading;
                                                        var pulmonicRegurgitation = echocartest.PulmonicRegurgitation != null ? echocartest.PulmonicRegurgitation.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading.PulmonicRegurgitation = pulmonicRegurgitation != null ? (pulmonicRegurgitation == "Mod" ? "Moderate" : pulmonicRegurgitation) : null;


                                                        //Tricuspid
                                                        medicareResultEditModel.EchocardiogramReading.Tricuspid     = echocartest.Tricuspid != null && echocartest.Tricuspid.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.HighOrGreater = echocartest.MorphologyTricuspidHighOrGreater != null && echocartest.MorphologyTricuspidHighOrGreater.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.TricuspidPap  = echocartest.TricuspidPap != null ? echocartest.TricuspidPap.Reading : null;
                                                        var tricuspidRegurgitation = echocartest.TricuspidRegurgitation != null ? echocartest.TricuspidRegurgitation.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading.TricuspidRegurgitation = tricuspidRegurgitation != null ? (tricuspidRegurgitation == "Mod" ? "Moderate" : tricuspidRegurgitation) : null;

                                                        //DiastolicDysfunction
                                                        medicareResultEditModel.EchocardiogramReading.DiastolicDysfunction        = echocartest.DiastolicDysfunction != null && echocartest.DiastolicDysfunction.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.DistolicDysfunctionFinding  = echocartest.DistolicDysfunctionFinding != null ? echocartest.DistolicDysfunctionFinding.Label : null;
                                                        medicareResultEditModel.EchocardiogramReading.DiastolicDysfunctionEeRatio = echocartest.DiastolicDysfunctionEeRatio != null ? echocartest.DiastolicDysfunctionEeRatio.Reading : null;

                                                        medicareResultEditModel.EchocardiogramReading.AorticRoot             = echocartest.AorticRoot != null && echocartest.AorticRoot.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.Sclerotic              = echocartest.Sclerotic != null && echocartest.Sclerotic.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.Atherosclerosis        = echocartest.Atherosclerosis != null && echocartest.Atherosclerosis.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.VentricularHypertrophy = echocartest.VentricularHypertrophy != null && echocartest.VentricularHypertrophy.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.Arrythmia              = echocartest.Arrythmia != null && echocartest.Arrythmia.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.AFib     = echocartest.AFib != null && echocartest.AFib.Reading;
                                                        medicareResultEditModel.EchocardiogramReading.AFlutter = echocartest.AFlutter != null && echocartest.AFlutter.Reading;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        _logger.Error(" error EchocardiogramReading   Customer : " + medicareResultEditModel.CustomerId + " Message: " + ex.Message + "\n stack Trace: " + ex.StackTrace);
                                                    }
                                                }
                                            }
                                            if (eventIdsWithUrineMicroalbumin.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new UrineMicroalbuminTestRepository();
                                                var awvUrinTestResult    = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvUrinTestResult != null && awvUrinTestResult.ResultStatus != null && awvUrinTestResult.TestNotPerformed == null && awvUrinTestResult.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AwvUrinStateNumber = (int)awvUrinTestResult.ResultStatus.StateNumber;
                                                    var urintest = ((Core.Medical.Domain.UrineMicroalbuminTestResult)awvUrinTestResult);
                                                    if (urintest != null && urintest.Finding != null)
                                                    {
                                                        medicareResultEditModel.AwvUrinFindingLabel = urintest.Finding.Label;
                                                    }
                                                }
                                            }


                                            if (eventIdsWithAwvLipid.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new AwvLipidTestRepository();
                                                var awvLipidTestResult   = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvLipidTestResult != null && awvLipidTestResult.ResultStatus != null && awvLipidTestResult.TestNotPerformed == null &&
                                                    awvLipidTestResult.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AwvLipidStateNumber = (int)awvLipidTestResult.ResultStatus.StateNumber;
                                                    var awvLipid = ((Core.Medical.Domain.AwvLipidTestResult)awvLipidTestResult);
                                                    if (awvLipid != null)
                                                    {
                                                        medicareResultEditModel.LipidReading = new MedicareResultEditModel.Lipid();
                                                        if (awvLipid.TotalCholestrol != null &&
                                                            awvLipid.TotalCholestrol.Finding != null)
                                                        {
                                                            medicareResultEditModel.AwvLipidTotalCholestrol = awvLipid.TotalCholestrol.Reading;
                                                            medicareResultEditModel.LipidReading.Tc         = awvLipid.TotalCholestrol.Reading;
                                                        }
                                                        if (awvLipid.HDL != null && awvLipid.HDL.Finding != null)
                                                        {
                                                            medicareResultEditModel.LipidReading.Hdl = awvLipid.HDL.Reading;
                                                        }
                                                        if (awvLipid.LDL != null && awvLipid.LDL.Finding != null)
                                                        {
                                                            medicareResultEditModel.LipidReading.Ldl = awvLipid.LDL.Reading;
                                                        }
                                                        if (awvLipid.TriGlycerides != null && awvLipid.TriGlycerides.Finding != null)
                                                        {
                                                            medicareResultEditModel.LipidReading.Trig = awvLipid.TriGlycerides.Reading;
                                                        }
                                                    }
                                                }
                                            }
                                            if (eventIdsWithDiabeticRetinopathy.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new DiabeticRetinopathyTestRepository();
                                                var awvDrsTestResult     = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvDrsTestResult != null && awvDrsTestResult.ResultStatus != null && awvDrsTestResult.TestNotPerformed == null && awvDrsTestResult.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AwvDrsStateNumber = (int)awvDrsTestResult.ResultStatus.StateNumber;
                                                }
                                            }
                                            if (eventIdsWithAwvEkg.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new AwvEkgTestRepository();
                                                var awvEkgTestResult     = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvEkgTestResult != null && awvEkgTestResult.ResultStatus != null && awvEkgTestResult.TestNotPerformed == null && awvEkgTestResult.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AwvEkgStateNumber = (int)awvEkgTestResult.ResultStatus.StateNumber;
                                                }
                                            }
                                            if (eventIdsWithAwvHba1C.Contains(medicareResultEditModel.EventId))
                                            {
                                                var testResultRepository = new AwvHemaglobinTestRepository();
                                                var awvHba1CTestResult   = testResultRepository.GetTestResults(medicareResultEditModel.CustomerId, medicareResultEditModel.EventId, isNewResultFlow);
                                                if (awvHba1CTestResult != null && awvHba1CTestResult.ResultStatus != null && awvHba1CTestResult.TestNotPerformed == null && awvHba1CTestResult.UnableScreenReason == null)
                                                {
                                                    medicareResultEditModel.AwvHbA1CStateNumber = (int)awvHba1CTestResult.ResultStatus.StateNumber;
                                                }
                                            }
                                        }
                                        _logger.Info("Medicare Customer Sync Starting  for tag: " + tag.Alias + " Page : " + (i + 1));

                                        var phyids = currentList.Where(x => x.PhysicianOruId > 0).Select(x => x.PhysicianOruId).ToArray();
                                        var names  = _organizationRoleUserRepository.GetNameIdPairofUsers(phyids);
                                        if (names.Any())
                                        {
                                            foreach (var medicareResultEditModel in currentList.Where(x => x.PhysicianOruId > 0))
                                            {
                                                var n = names.FirstOrDefault(x => x.FirstValue == medicareResultEditModel.PhysicianOruId);
                                                if (n != null)
                                                {
                                                    medicareResultEditModel.PhysicianName = n.SecondValue;
                                                }
                                            }
                                        }

                                        var model = new MedicareResultListmodel {
                                            EhrResultEditmodels = currentList.ToList()
                                        };

                                        var result = _medicareApiService.PostAnonymous <bool>(_settings.MedicareApiUrl + MedicareApiUrl.UpdateCustomerResult, model);
                                        if (result)
                                        {
                                            _logger.Info("Medicare Customer Sync for tag: " + tag.Alias + " Page : " + (i + 1));
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        _logger.Error(" error occur Medicare Customer Sync for tag: " + tag.Alias + " Customer : " + (i + 1) + " Message: " + exception.Message + "\n stack Trace: " + exception.StackTrace);
                                    }
                                }
                            }

                            var kynCustomerIds = _kyaLabValuesRepository.GetRecentKynLabValuesForMedicareSync(exportFromTime, tag.Alias).ToArray();
                            if (kynCustomerIds.Any())
                            {
                                const int pageSize   = 25;
                                var       totalPages = Math.Ceiling((double)(kynCustomerIds.Count()) / pageSize);
                                for (var i = 0; i < totalPages; i++)
                                {
                                    var currentList = kynCustomerIds.Skip(i * pageSize).Take(pageSize).ToArray();
                                    try
                                    {
                                        _logger.Info("Medicare Customer Sync Starting  for tag: " + tag.Alias + " Page : " + (i + 1));

                                        var model = new MedicareKynResultListmodel()
                                        {
                                            EhrResultEditmodels = currentList.ToList()
                                        };
                                        var result = _medicareApiService.PostAnonymous <bool>(_settings.MedicareApiUrl + MedicareApiUrl.UpdateCustomerKynResult, model);
                                        if (result)
                                        {
                                            _logger.Info("Medicare Customer Sync for tag: " + tag.Alias + " Page : " + (i + 1));
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        _logger.Error(" error occur Medicare Customer Sync for tag: " + tag.Alias + " Customer : " + (i + 1) + " Message: " + exception.Message + "\n stack Trace: " + exception.StackTrace);
                                    }
                                }
                            }
                        }


                        _customSettingManager.SerializeandSave(path, new CustomSettings {
                            LastTransactionDate = newLastTransactionDate
                        });
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Error("Error occurred for SyncCustomerResultPollingAgent Message: " + exception.Message + "\n stack Trace: " + exception.StackTrace);
            }
        }
Esempio n. 4
0
        private LabsInboundViewModel SetLabResults(LabsInboundViewModel model, long customerId, long eventId, long testId, bool isNewResultFlow, bool getLeftReadings = false)
        {
            var isTestPurchased = false;
            ITestResultRepository testResultRepository;

            if (testId == (long)LabInboundTestType.Echo)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvEcho);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvEchocardiogramTestRepository();
                    var awvEchoTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvEchoTestResult != null && (awvEchoTestResult.TestNotPerformed == null || awvEchoTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvEchoTestResult as AwvEchocardiogramTestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.A1C)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvHBA1C);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvHemaglobinTestRepository();
                    var awvHemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvHemaglobinTestResult != null && (awvHemaglobinTestResult.TestNotPerformed == null || awvHemaglobinTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvHemaglobinTestResult as AwvHemaglobinTestResult;
                        if (result != null && result.Hba1c != null)
                        {
                            model.LabResult = result.Hba1c.Reading;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.Ekg)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvEkg);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvEkgTestRepository();
                    var awvEkgTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvEkgTestResult != null && (awvEkgTestResult.TestNotPerformed == null || awvEkgTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvEkgTestResult as AwvEkgTestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            //FL Blue asked us to Leave the Test with blank result field

            /*else if (testId == (long)LabInboundTestType.DiabeticRetinopathy)
             * {
             *  isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.DiabeticRetinopathy);
             *  if (isTestPurchased)
             *  {
             *      testResultRepository = new DiabeticRetinopathyTestRepository();
             *      var diabeticRetinopathyTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
             *      if (diabeticRetinopathyTestResult != null && (diabeticRetinopathyTestResult.TestNotPerformed == null || diabeticRetinopathyTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
             *      {
             *          var result = diabeticRetinopathyTestResult as DiabeticRetinopathyTestResult;
             *          if (result != null && result.Finding != null)
             *              model.LabResult = result.Finding.Label;
             *      }
             *  }
             * }*/

            else if (testId == (long)LabInboundTestType.UrineMicroalbumin)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.UrineMicroalbumin);
                if (isTestPurchased)
                {
                    testResultRepository = new UrineMicroalbuminTestRepository();
                    var urineMicroalbuminTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (urineMicroalbuminTestResult != null && (urineMicroalbuminTestResult.TestNotPerformed == null || urineMicroalbuminTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = urineMicroalbuminTestResult as UrineMicroalbuminTestResult;
                        if (result != null && result.MicroalbuminValue != null)
                        {
                            model.LabResult = result.MicroalbuminValue.Reading;
                        }
                        else
                        {
                            model.LabResult = KitDistributedString;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.AwvAbi)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvABI);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvAbiTestRepository();
                    var awvAbiTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvAbiTestResult != null && (awvAbiTestResult.TestNotPerformed == null || awvAbiTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvAbiTestResult as AwvAbiTestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.ScreeningMammographyDigital)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Mammogram);
                if (isTestPurchased)
                {
                    testResultRepository = new MammogramTestRepository();
                    var mammogramTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (mammogramTestResult != null && (mammogramTestResult.TestNotPerformed == null || mammogramTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = mammogramTestResult as MammogramTestResult;
                        if (result != null && result.Finding != null && !string.IsNullOrWhiteSpace(result.Finding.Label))
                        {
                            model.LabResult = "BIRAD-" + result.Finding.Label.Substring(0, 1);
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.AwvSpirometry)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvSpiro);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvSpiroTestRepository();
                    var awvSpiroTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvSpiroTestResult != null && (awvSpiroTestResult.TestNotPerformed == null || awvSpiroTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvSpiroTestResult as AwvSpiroTestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.BloodPressure)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Hypertension);
                if (isTestPurchased)
                {
                    testResultRepository = new HypertensionTestRepository();
                    var hyperTenstionTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (hyperTenstionTestResult != null && (hyperTenstionTestResult.TestNotPerformed == null || hyperTenstionTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var basicBiometric = _basicBiometricRepository.Get(eventId, customerId);
                        if (basicBiometric != null)
                        {
                            model.LabResult = (basicBiometric.SystolicPressure.HasValue ? basicBiometric.SystolicPressure.Value.ToString() : "0") + "/" + (basicBiometric.DiastolicPressure.HasValue ? basicBiometric.DiastolicPressure.Value.ToString() : "0");
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.AwvAaa)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvAAA);
                if (isTestPurchased)
                {
                    testResultRepository = new AwvAaaTestRepository();
                    var awvAaaTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (awvAaaTestResult != null && (awvAaaTestResult.TestNotPerformed == null || awvAaaTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = awvAaaTestResult as AwvAaaTestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.Ifobt)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.IFOBT);
                if (isTestPurchased)
                {
                    testResultRepository = new IFOBTTestRepository();
                    var ifobtTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (ifobtTestResult != null && (ifobtTestResult.TestNotPerformed == null || ifobtTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = ifobtTestResult as IFOBTTestResult;
                        if (result != null && result.Finding != null && !string.IsNullOrWhiteSpace(result.Finding.Label) && (result.Finding.Label.ToLower() == PositiveString.ToLower() ||
                                                                                                                             result.Finding.Label.ToLower() == NegativeString.ToLower()))
                        {
                            model.LabResult = result.Finding.Label;
                        }
                        else
                        {
                            model.LabResult = KitDistributedString;
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.Lead)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Lead);
                if (isTestPurchased)
                {
                    testResultRepository = new LeadTestRepository();
                    var leadTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (leadTestResult != null && (leadTestResult.TestNotPerformed == null || leadTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = leadTestResult as LeadTestResult;
                        if (result != null)
                        {
                            var readings      = testResultRepository.GetAllReadings((int)TestType.Lead);
                            var readingLabels = new List <string>();
                            if (getLeftReadings)
                            {
                                model.LabType = EnumExtension.GetDescription(LabInboundTestType.Lead) + " L";
                                if (result.LeftResultReadings != null)
                                {
                                    var leftResultReadings = result.LeftResultReadings;

                                    if (leftResultReadings.NoVisualPlaque != null && leftResultReadings.NoVisualPlaque.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.LeftNoVisualPlaque);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (leftResultReadings.VisuallyDemonstratedPlaque != null && leftResultReadings.VisuallyDemonstratedPlaque.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.LeftVisuallyDemonstratedPlaque);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (leftResultReadings.ModerateStenosis != null && leftResultReadings.ModerateStenosis.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.LeftModerateStenosis);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (leftResultReadings.PossibleOcclusion != null && leftResultReadings.PossibleOcclusion.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.LeftPossibleOcclusion);
                                        readingLabels.Add(reading.LableText);
                                    }
                                }
                            }
                            else
                            {
                                model.LabType = EnumExtension.GetDescription(LabInboundTestType.Lead) + " R";
                                if (result.RightResultReadings != null)
                                {
                                    var rightResultReading = result.RightResultReadings;

                                    if (rightResultReading.NoVisualPlaque != null && rightResultReading.NoVisualPlaque.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.RightNoVisualPlaque);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (rightResultReading.VisuallyDemonstratedPlaque != null && rightResultReading.VisuallyDemonstratedPlaque.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.RightVisuallyDemonstratedPlaque);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (rightResultReading.ModerateStenosis != null && rightResultReading.ModerateStenosis.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.RightModerateStenosis);
                                        readingLabels.Add(reading.LableText);
                                    }

                                    if (rightResultReading.PossibleOcclusion != null && rightResultReading.PossibleOcclusion.Reading != null)
                                    {
                                        var reading = readings.First(x => x.Label == ReadingLabels.RightPossibleOcclusion);
                                        readingLabels.Add(reading.LableText);
                                    }
                                }
                            }

                            model.LabResult = string.Join(", ", readingLabels);
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.Monofilament)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Monofilament);
                if (isTestPurchased)
                {
                    testResultRepository = new MonofilamentTestRepository();
                    var monofilamentTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (monofilamentTestResult != null && (monofilamentTestResult.TestNotPerformed == null || monofilamentTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = monofilamentTestResult as MonofilamentTestResult;
                        if (result != null)
                        {
                            var readings = testResultRepository.GetAllReadings((int)TestType.Monofilament);
                            if (getLeftReadings)
                            {
                                model.LabType = EnumExtension.GetDescription(LabInboundTestType.Monofilament) + " L";
                                if (result.LeftPositive != null)
                                {
                                    var reading = readings.First(x => x.Label == ReadingLabels.MonofilamentLeftFootSensationIntact);
                                    model.LabResult = reading.LableText;
                                }
                                else if (result.LeftNegative != null)
                                {
                                    var reading = readings.First(x => x.Label == ReadingLabels.MonofilamentLeftFootSensationNotIntact);
                                    model.LabResult = reading.LableText;
                                }
                            }
                            else
                            {
                                model.LabType = EnumExtension.GetDescription(LabInboundTestType.Monofilament) + " R";
                                if (result.RightPositive != null)
                                {
                                    var reading = readings.First(x => x.Label == ReadingLabels.MonofilamentRightFootSensationIntact);
                                    model.LabResult = reading.LableText;
                                }
                                else if (result.RightNegative != null)
                                {
                                    var reading = readings.First(x => x.Label == ReadingLabels.MonofilamentRightFootSensationNotIntact);
                                    model.LabResult = reading.LableText;
                                }
                            }
                        }
                    }
                }
            }

            else if (testId == (long)LabInboundTestType.QuantaFloAbi)
            {
                isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.QuantaFloABI);
                if (isTestPurchased)
                {
                    testResultRepository = new QuantaFloABITestRepository();
                    var quantaFloAbiTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                    if (quantaFloAbiTestResult != null && (quantaFloAbiTestResult.TestNotPerformed == null || quantaFloAbiTestResult.TestNotPerformed.TestNotPerformedReasonId <= 0))
                    {
                        var result = quantaFloAbiTestResult as QuantaFloABITestResult;
                        if (result != null && result.Finding != null)
                        {
                            model.LabResult = result.Finding.Label;
                        }
                    }
                }
            }

            return(model);
        }