예제 #1
0
        private List <Observation> AwvHba1cObservations(Customer customer, Event theEventData)
        {
            ITestResultRepository testResultRepository = new AwvGlucoseTestRepository();
            var isNewResultFlow = theEventData.EventDate >= _settings.ResultFlowChangeDate;

            var testResult = (AwvGlucoseTestResult)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.Glucose != null)
                {
                    var reading = testResult.Glucose != null ? testResult.Glucose.Reading != null?testResult.Glucose.Reading.ToString() : "" : "";

                    var refRang = string.Empty;
                    if (testResult.Glucose.Finding != null)
                    {
                        refRang = testResult.Glucose.Finding.Label;
                    }

                    var urinalysis = new Observation
                    {
                        Id         = ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvGlucose).SecondValue,
                        TemplateId = new[] { ClinicalDocumentHelper.ClinicalRoots.First(cr => cr.FirstValue == ClinicalRootType.AwvGlucose).SecondValue },
                        Code       = ClinicalDocumentHelper.LoincCodes.First(x => x.FirstValue == LoincCode.AwvGlucose).SecondValue,
                        Reference  = " <referenceRange><observationRange><text>" + refRang + "</text></observationRange></referenceRange>",
                        StatusCode = new StatusCode {
                            Code = "completed"
                        },
                        ObservationValue = new ObservationValue {
                            Value = reading, Unit = "mg/dl"
                        }
                    };

                    observation.Add(urinalysis);
                }
            }
            return(observation);
        }
        private void SaveTestResults(KynHealthAssessmentEditModel model, long uploadedby)
        {
            TestResultRepository testResultRepository;
            var customerId = model.CustomerId;
            var eventId    = model.EventId;

            var isNewResultFlow = _eventRepository.IsEventHasNewResultFlow(eventId);

            var service = new Service.TestResultService();

            var eventCustomerResultId = SaveEventCustomerResult(eventId, customerId, uploadedby);

            //basic biometric
            var eventCustomer  = _eventCustomerRepository.Get(eventId, customerId);
            var basicBiometric = _basicBiometricRepository.Get(eventId, customerId);

            basicBiometric = _kynHealthAssessmentFactory.GetBasicTestResultBiometricDomain(model, basicBiometric, uploadedby);

            if (basicBiometric != null)
            {
                basicBiometric.Id = eventCustomer.Id;
                ((IRepository <BasicBiometric>)_basicBiometricRepository).Save(basicBiometric);
            }
            long[] kynTestIds = { (long)TestType.Kyn, (long)TestType.HKYN, (long)TestType.MyBioCheckAssessment };
            var    eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, kynTestIds);
            //Kyn Test Result
            var isPurchased           = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Kyn);
            var isKynPurchased        = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.HKYN);
            var isMyBioCheckPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment);

            if (isPurchased)
            {
                var kynTest = eventTests.First(x => x.TestId == (int)TestType.Kyn).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.Kyn, kynTest.IsRecordable, isNewResultFlow);
            }
            else if (isKynPurchased)
            {
                var hKynTest = eventTests.First(x => x.TestId == (int)TestType.HKYN).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.HKYN, hKynTest.IsRecordable, isNewResultFlow);
            }
            else if (isMyBioCheckPurchased)
            {
                var mybioCheckAssessment = eventTests.First(x => x.TestId == (int)TestType.MyBioCheckAssessment).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.MyBioCheckAssessment, mybioCheckAssessment.IsRecordable, isNewResultFlow);
            }

            //lipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Lipid);

            if (isPurchased)
            {
                testResultRepository = new LipidTestRepository(ReadingSource.Manual);
                var lipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                lipidTestresult = _kynHealthAssessmentFactory.GetLipidTestResultDomain(model, lipidTestresult as LipidTestResult, uploadedby, isNewResultFlow);
                if (lipidTestresult != null)
                {
                    testResultRepository.SaveTestResults(lipidTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvLipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvLipid);

            if (isPurchased)
            {
                testResultRepository = new AwvLipidTestRepository(ReadingSource.Manual);
                var awvLipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvLipidTestresult = _kynHealthAssessmentFactory.GetAwvLipidTestResultDomain(model, awvLipidTestresult as AwvLipidTestResult, uploadedby, isNewResultFlow);
                if (awvLipidTestresult != null)
                {
                    testResultRepository.SaveTestResults(awvLipidTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvGlucoseTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvGlucose);

            if (isPurchased)
            {
                testResultRepository = new AwvGlucoseTestRepository(ReadingSource.Manual);
                var awvGlucoseTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvGlucoseTestresult = _kynHealthAssessmentFactory.GetAwvGlucoseTestResultDomain(model, awvGlucoseTestresult as AwvGlucoseTestResult, uploadedby, isNewResultFlow);
                if (awvGlucoseTestresult != null)
                {
                    testResultRepository.SaveTestResults(awvGlucoseTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvLipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Cholesterol);

            if (isPurchased)
            {
                testResultRepository = new CholesterolTestRepository(ReadingSource.Manual);
                var cholesterolTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                cholesterolTestresult = _kynHealthAssessmentFactory.GetCholesterolTestResultDomain(model, cholesterolTestresult as CholesterolTestResult, uploadedby, isNewResultFlow);
                if (cholesterolTestresult != null)
                {
                    testResultRepository.SaveTestResults(cholesterolTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvGlucoseTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Diabetes);

            if (isPurchased)
            {
                testResultRepository = new DiabetesTestRepository(ReadingSource.Manual);
                var diabetesTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                diabetesTestresult = _kynHealthAssessmentFactory.GetDiabetesTestResultDomain(model, diabetesTestresult as DiabetesTestResult, uploadedby, isNewResultFlow);
                if (diabetesTestresult != null)
                {
                    testResultRepository.SaveTestResults(diabetesTestresult, customerId, eventId, uploadedby);
                }
            }

            //Hypertension Test Result
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Hypertension);
            if (isPurchased)
            {
                testResultRepository = new HypertensionTestRepository(ReadingSource.Manual);
                var hypertensionTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                hypertensionTestresult = _kynHealthAssessmentFactory.GetHypertensionTestResultDomain(model, hypertensionTestresult as HypertensionTestResult, uploadedby, isNewResultFlow);
                if (hypertensionTestresult != null)
                {
                    testResultRepository.SaveTestResults(hypertensionTestresult, customerId, eventId, uploadedby);
                }
            }

            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.A1C);
            if (isPurchased)
            {
                testResultRepository = new HemaglobinTestRepository(ReadingSource.Manual);
                var hemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                hemaglobinTestResult = _kynHealthAssessmentFactory.GetHemaglobinA1CTestResultDomain(model, hemaglobinTestResult as HemaglobinA1CTestResult, uploadedby, isNewResultFlow);
                if (hemaglobinTestResult != null)
                {
                    testResultRepository.SaveTestResults(hemaglobinTestResult, customerId, eventId, uploadedby);
                }
            }

            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvHBA1C);
            if (isPurchased)
            {
                testResultRepository = new AwvHemaglobinTestRepository(ReadingSource.Manual);
                var awvHemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvHemaglobinTestResult = _kynHealthAssessmentFactory.GetAwvHemaglobinTestResultDomain(model, awvHemaglobinTestResult as AwvHemaglobinTestResult, uploadedby, isNewResultFlow);

                if (awvHemaglobinTestResult != null)
                {
                    testResultRepository.SaveTestResults(awvHemaglobinTestResult, customerId, eventId, uploadedby);
                }
            }

            //MyBioCheckTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment);

            if (isPurchased)
            {
                testResultRepository = new MyBioAssessmentTestRepository(ReadingSource.Manual);
                var myBioAssessmentTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                myBioAssessmentTestResult = _kynHealthAssessmentFactory.GetMyBioCheckAssessmentTestResultDomain(model, myBioAssessmentTestResult as MyBioAssessmentTestResult, uploadedby, isNewResultFlow);
                if (myBioAssessmentTestResult != null)
                {
                    testResultRepository.SaveTestResults(myBioAssessmentTestResult, customerId, eventId, uploadedby);
                }
            }
        }