public bool UpdateFraminghamValue(long customerEventScreeningTestId, decimal framinghamValue) { var testReadingId = GetListOfTestReadingAndReadingId((int)TestType.Diabetes).Find(testReadingReadingPair => (testReadingReadingPair. FirstValue == (int) ReadingLabels. FraminghamRisk)).SecondValue; var customerEventReadingEntity = new CustomerEventReadingEntity { Value = framinghamValue.ToString(), TestReadingId = testReadingId, CustomerEventScreeningTestId = customerEventScreeningTestId }; using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter()) { IRelationPredicateBucket bucket = new RelationPredicateBucket(CustomerEventReadingFields.TestReadingId == testReadingId); bucket.PredicateExpression.AddWithAnd(CustomerEventReadingFields.CustomerEventScreeningTestId == customerEventScreeningTestId); if (myAdapter.UpdateEntitiesDirectly(customerEventReadingEntity, bucket) == 0) { throw new PersistenceFailureException(); } return(true); } }
private CompoundResultReading <decimal?> CreateTestReadingforaDecimalValue(CustomerEventReadingEntity testReadingEntity, int readingId, List <StandardFindingTestReadingEntity> standardFindingTestReadingEntities, decimal?value) { StandardFindingTestReadingEntity standardFindingTestReading = null; if (testReadingEntity.StandardFindingTestReadingId != null) { standardFindingTestReading = standardFindingTestReadingEntities.Find(standardFindingTestReadingEntity => (standardFindingTestReadingEntity.ReadingId == readingId) && (testReadingEntity.StandardFindingTestReadingId == standardFindingTestReadingEntity.StandardFindingTestReadingId) ); } var testReading = new CompoundResultReading <decimal?>(testReadingEntity.CustomerEventReadingId) { Label = (ReadingLabels)readingId, Reading = value, ReadingSource = testReadingEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic, RecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = new OrganizationRoleUser(testReadingEntity.CreatedByOrgRoleUserId), DateCreated = testReadingEntity.CreatedOn, DataRecorderModifier = testReadingEntity.UpdatedByOrgRoleUserId.HasValue ? new OrganizationRoleUser(testReadingEntity.UpdatedByOrgRoleUserId.Value) : null, DateModified = testReadingEntity.UpdatedOn } }; decimal testReadingValue = 0; var allFindings = new TestResultService().GetAllStandardFindings <decimal?>((int)TestType.Hemoglobin, readingId); if (testReadingEntity.Value != null && decimal.TryParse(testReadingEntity.Value, out testReadingValue)) { var findings = (new TestResultService()).GetMultipleCalculatedStandardFinding(decimal.Round(testReadingValue, 1), (int)TestType.Hemoglobin, readingId); var finding = findings.FirstOrDefault(); if (findings.Count() == 1) { testReading.Finding = new StandardFinding <decimal?>(Convert.ToInt64(testReadingEntity.StandardFindingTestReadingId == null ? finding : standardFindingTestReading.StandardFindingId)); } else if (findings.Count() > 1) { var avFindings = allFindings.FindAll(f => f.Label.ToLower().IndexOf(_toCheckFor) == 0); finding = findings.FirstOrDefault(f => avFindings.Select(av => av.Id).Contains(f)); testReading.Finding = new StandardFinding <decimal?>(Convert.ToInt64(testReadingEntity.StandardFindingTestReadingId == null ? finding : standardFindingTestReading.StandardFindingId)); } } else if (testReadingEntity.StandardFindingTestReadingId != null) { testReading.Finding = new StandardFinding <decimal?>(standardFindingTestReading.StandardFindingId); } if (testReading.Finding != null) { testReading.Finding = allFindings.Find(standardFinding => standardFinding.Id == testReading.Finding.Id); } return(testReading); }
private IEnumerable <CustomerEventReadingEntity> GetSmokerDiabeticReading(long customerId, IEnumerable <CustomerEventReadingEntity> eventReadingEntities) { var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); using (var myAdapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(myAdapter); var smokerDiabeticData = from healthInformation in linqMetaData.CustomerHealthInfo where healthInformation.CustomerId == customerId select new { Id = healthInformation.CustomerHealthQuestionId, Value = healthInformation.HealthQuestionAnswer }; smokerDiabeticData = smokerDiabeticData.Where( smokerDiabetic => smokerDiabetic.Id == SmokerId || smokerDiabetic.Id == DiabeticId); var smokerData = customerEventReadingEntities.Where( customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.Smoker). SingleOrDefault(); var diabeticData = customerEventReadingEntities.Where( customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.Diabetes). SingleOrDefault(); foreach (var data in smokerDiabeticData) { var customerEventReadingEntity = new CustomerEventReadingEntity() { CustomerEventReadingId = data.Id == SmokerId ? smokerData != null ? smokerData.CustomerEventReadingId : 0 : diabeticData != null ? diabeticData.CustomerEventReadingId : 0, Value = data.Value == "Yes" ? true.ToString() : false.ToString(), TestReading = new TestReadingEntity { ReadingId = data.Id == SmokerId ? (int)ReadingLabels.Smoker : (int) ReadingLabels.Diabetes } }; customerEventReadingEntities.Add(customerEventReadingEntity); } } return(customerEventReadingEntities); }
public bool UpdateFraminghamValue(long customerEventScreeningTestId, decimal framinghamValue) { var testReadingId = GetListOfTestReadingAndReadingId((int)TestType.FraminghamRisk).Find(testReadingReadingPair => (testReadingReadingPair. FirstValue == (int) ReadingLabels. FraminghamRisk)). SecondValue; var customerEventReadingEntity = new CustomerEventReadingEntity { Value = framinghamValue.ToString(), TestReadingId = testReadingId, CustomerEventScreeningTestId = customerEventScreeningTestId }; using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(myAdapter); var framinghamCustomerReading = linqMetaData.CustomerEventReading.Where(customerEventReading => customerEventReading.CustomerEventScreeningTestId == customerEventScreeningTestId && customerEventReading.TestReadingId == testReadingId).SingleOrDefault(); if (framinghamCustomerReading != null && framinghamCustomerReading.CustomerEventReadingId > 0) { IRelationPredicateBucket bucket = new RelationPredicateBucket(CustomerEventReadingFields.TestReadingId == testReadingId); bucket.PredicateExpression.AddWithAnd(CustomerEventReadingFields.CustomerEventScreeningTestId == customerEventScreeningTestId); if (myAdapter.UpdateEntitiesDirectly(customerEventReadingEntity, bucket) == 0) { throw new PersistenceFailureException(); } } else { if (!myAdapter.SaveEntity(customerEventReadingEntity)) { throw new PersistenceFailureException(); } } return(true); } }
private static CompoundResultReading <decimal?> CreateTestReadingforaDecimalValue(CustomerEventReadingEntity testReadingEntity, int readingId, List <StandardFindingTestReadingEntity> standardFindingTestReadingEntities, decimal?value) { StandardFindingTestReadingEntity standardFindingTestReading = null; if (testReadingEntity.StandardFindingTestReadingId != null) { standardFindingTestReading = standardFindingTestReadingEntities.Find(standardFindingTestReadingEntity => (standardFindingTestReadingEntity.ReadingId == readingId) && (testReadingEntity.StandardFindingTestReadingId == standardFindingTestReadingEntity.StandardFindingTestReadingId)); } var testReading = new CompoundResultReading <decimal?>(testReadingEntity.CustomerEventReadingId) { Label = (ReadingLabels)readingId, Reading = value, ReadingSource = testReadingEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic, RecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = new OrganizationRoleUser(testReadingEntity.CreatedByOrgRoleUserId), DateCreated = testReadingEntity.CreatedOn, DataRecorderModifier = testReadingEntity.UpdatedByOrgRoleUserId.HasValue ? new OrganizationRoleUser(testReadingEntity.UpdatedByOrgRoleUserId.Value) : null, DateModified = testReadingEntity.UpdatedOn } }; if (value != null) { testReading.Finding = new StandardFinding <decimal?>(Convert.ToInt64(testReadingEntity.StandardFindingTestReadingId == null ? (new TestResultService()).GetCalculatedStandardFinding(decimal.Round(value.Value, 1), (int)TestType.Cholesterol, readingId) : standardFindingTestReading.StandardFindingId)); } else if (testReadingEntity.StandardFindingTestReadingId != null) { testReading.Finding = new StandardFinding <decimal?>(standardFindingTestReading.StandardFindingId); } if (testReading.Finding != null) { testReading.Finding = new TestResultService().GetAllStandardFindings <decimal?>((int)TestType.Cholesterol, readingId).Find(standardFinding => standardFinding.Id == testReading.Finding.Id); } return(testReading); }
public override CustomerEventScreeningTestsEntity CreateActualTestResultEntity(TestResult testResult, List <OrderedPair <int, int> > testReadingReadingPairs) { var cholesterolTestResult = testResult as CholesterolTestResult; var customerEventScreeningTestsEntity = new CustomerEventScreeningTestsEntity(testResult.Id) { TestId = (int)TestType.Cholesterol }; var resultIntpretations = new List <long>(); var pathwayRecomendations = new List <long>(); var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); if (cholesterolTestResult != null) { CustomerEventReadingEntity customerEventTestReadingEntity = null; if (cholesterolTestResult.TotalCholesterol != null) { customerEventTestReadingEntity = CreateEventReadingEntity(cholesterolTestResult.TotalCholesterol, (int)ReadingLabels.TotalCholestrol, testReadingReadingPairs); int tCholestrol = 0; long findingId = 0; if (cholesterolTestResult.TotalCholesterol.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (int.TryParse(cholesterolTestResult.TotalCholesterol.Reading, out tCholestrol) == false) { findingId = cholesterolTestResult.TotalCholesterol.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TotalCholestrol, cholesterolTestResult.TotalCholesterol.Finding.Id); } else { findingId = (new TestResultService()).GetCalculatedStandardFinding(Convert.ToInt32(cholesterolTestResult.TotalCholesterol.Reading), (int)TestType.Cholesterol, (int)ReadingLabels.TotalCholestrol); if (cholesterolTestResult.TotalCholesterol.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { findingId = cholesterolTestResult.TotalCholesterol.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TotalCholestrol, cholesterolTestResult.TotalCholesterol.Finding.Id); } } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TotalCholestrol, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (cholesterolTestResult.HDL != null) { customerEventTestReadingEntity = CreateEventReadingEntity(cholesterolTestResult.HDL, (int)ReadingLabels.HDL, testReadingReadingPairs); int hdl = 0; long findingId = 0; if (cholesterolTestResult.HDL.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (int.TryParse(cholesterolTestResult.HDL.Reading, out hdl) == false) { findingId = cholesterolTestResult.HDL.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.HDL, cholesterolTestResult.HDL.Finding.Id); } else { var allFindings = new TestResultService().GetAllStandardFindings <int>((int)TestType.Cholesterol, (int)ReadingLabels.HDL); var findings = (new TestResultService()).GetMultipleCalculatedStandardFinding(Convert.ToInt32(cholesterolTestResult.HDL.Reading), (int)TestType.Cholesterol, (int)ReadingLabels.HDL); var avFindings = allFindings.FindAll(f => f.Label.ToLower().IndexOf(_toCheckFor) == 0); findingId = findings.FirstOrDefault(f => avFindings.Select(av => av.Id).Contains(f)); if (cholesterolTestResult.HDL.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.HDL, cholesterolTestResult.HDL.Finding.Id); findingId = cholesterolTestResult.HDL.Finding.Id; } } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.HDL, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (cholesterolTestResult.LDL != null) { customerEventTestReadingEntity = CreateEventReadingEntity(cholesterolTestResult.LDL, (int)ReadingLabels.LDL, testReadingReadingPairs); long findingId = 0; if (cholesterolTestResult.LDL.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (cholesterolTestResult.LDL.Reading != null) { findingId = ((new TestResultService()).GetCalculatedStandardFinding(cholesterolTestResult.LDL.Reading, (int)TestType.Cholesterol, (int)ReadingLabels.LDL)); customerEventTestReadingEntity.StandardFindingTestReadingId = (cholesterolTestResult.LDL.Finding.Id == findingId ? null : (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.LDL, cholesterolTestResult.LDL.Finding.Id)); findingId = cholesterolTestResult.LDL.Finding.Id != findingId ? cholesterolTestResult.LDL.Finding.Id : findingId; } else if (cholesterolTestResult.LDL.Finding != null) { findingId = cholesterolTestResult.LDL.Finding.Id; if (customerEventTestReadingEntity == null) { customerEventTestReadingEntity = CreateEventReadingEntitywithNullReading(cholesterolTestResult.LDL, (int)ReadingLabels.LDL, testReadingReadingPairs); } customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.LDL, cholesterolTestResult.LDL.Finding.Id); } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.LDL, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (cholesterolTestResult.TriGlycerides != null) { customerEventTestReadingEntity = CreateEventReadingEntity(cholesterolTestResult.TriGlycerides, (int)ReadingLabels.TriGlycerides, testReadingReadingPairs); int triglycerides = 0; long findingId = 0; if (cholesterolTestResult.TriGlycerides.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (int.TryParse(cholesterolTestResult.TriGlycerides.Reading, out triglycerides) == false) { findingId = cholesterolTestResult.TriGlycerides.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TriGlycerides, cholesterolTestResult.TriGlycerides.Finding.Id); } else { findingId = (new TestResultService()).GetCalculatedStandardFinding(Convert.ToInt32(cholesterolTestResult.TriGlycerides.Reading), (int)TestType.Cholesterol, (int)ReadingLabels.TriGlycerides); if (cholesterolTestResult.TriGlycerides.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TriGlycerides, cholesterolTestResult.TriGlycerides.Finding.Id); findingId = cholesterolTestResult.TriGlycerides.Finding.Id; } } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TriGlycerides, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (cholesterolTestResult.TCHDLRatio != null) { customerEventTestReadingEntity = CreateEventReadingEntity(cholesterolTestResult.TCHDLRatio, (int)ReadingLabels.TCHDLRatio, testReadingReadingPairs); long findingId = 0; if (cholesterolTestResult.TCHDLRatio.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (cholesterolTestResult.TCHDLRatio.Reading != null) { findingId = ((new TestResultService()).GetCalculatedStandardFinding(cholesterolTestResult.TCHDLRatio.Reading, (int)TestType.Cholesterol, (int)ReadingLabels.TCHDLRatio)); customerEventTestReadingEntity.StandardFindingTestReadingId = (cholesterolTestResult.TCHDLRatio.Finding.Id == findingId ? null : (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TCHDLRatio, cholesterolTestResult.TCHDLRatio.Finding.Id)); findingId = findingId != cholesterolTestResult.TCHDLRatio.Finding.Id ? cholesterolTestResult.TCHDLRatio.Finding.Id : findingId; } else if (cholesterolTestResult.TCHDLRatio.Finding != null) { if (customerEventTestReadingEntity == null) { customerEventTestReadingEntity = CreateEventReadingEntitywithNullReading(cholesterolTestResult.TCHDLRatio, (int)ReadingLabels.TCHDLRatio, testReadingReadingPairs); } findingId = cholesterolTestResult.TCHDLRatio.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TCHDLRatio, cholesterolTestResult.TCHDLRatio.Finding.Id); } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Cholesterol, (int)ReadingLabels.TCHDLRatio, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (testResult.ResultStatus.StateNumber == (int)TestResultStateNumber.Evaluated || testResult.ResultStatus.StateNumber == (int)NewTestResultStateNumber.Evaluated) { if (resultIntpretations.Count > 0) { testResult.ResultInterpretation = ResultInterpretation.Normal.GetMax(resultIntpretations); } if (pathwayRecomendations.Count > 0) { testResult.PathwayRecommendation = PathwayRecommendation.None.GetMax(pathwayRecomendations); } } } customerEventScreeningTestsEntity.CustomerEventReading.AddRange(customerEventReadingEntities); return(customerEventScreeningTestsEntity); }
private IEnumerable <CustomerEventReadingEntity> GetSystolicDiastolicReading(long eventCustomerResultId) { var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); using (var myAdapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(myAdapter); var listPadPair = GetListOfTestReadingAndReadingId((int)TestType.PAD); var listAsiPair = GetListOfTestReadingAndReadingId((int)TestType.ASI); var selectedPadPair = listPadPair.FindAll(padPair => padPair.FirstValue == (int)ReadingLabels.SystolicRight || padPair.FirstValue == (int)ReadingLabels.DiastolicRight); var selectedAsiPair = listAsiPair.FindAll(asiPair => asiPair.FirstValue == (int)ReadingLabels.SystolicRight || asiPair.FirstValue == (int)ReadingLabels.DiastolicRight); string systolicVal, diastolicVal; systolicVal = diastolicVal = string.Empty; var recordForSystolicDiastolic = linqMetaData.CustomerEventScreeningTests.Where(customerEventScreeningTest => customerEventScreeningTest.EventCustomerResultId == eventCustomerResultId && (customerEventScreeningTest.TestId == (long)TestType.PAD || customerEventScreeningTest.TestId == (long)TestType.ASI)).ToList(); if (recordForSystolicDiastolic == null || recordForSystolicDiastolic.Count < 1) { return(customerEventReadingEntities); } recordForSystolicDiastolic.ForEach(record => { if (record.TestId == (long)TestType.PAD) { var customerEventReadings = linqMetaData.CustomerEventReading.Where(eventReading => eventReading.CustomerEventScreeningTestId == record.CustomerEventScreeningTestId).ToList(); if (string.IsNullOrEmpty(systolicVal)) { var systolicReadingFromPad = customerEventReadings.Find(eventReading => selectedPadPair.Where(padpair => padpair.FirstValue == (int)ReadingLabels.SystolicRight).SingleOrDefault().SecondValue == eventReading.TestReadingId); if (systolicReadingFromPad != null) { systolicVal = systolicReadingFromPad.Value; } } if (string.IsNullOrEmpty(diastolicVal)) { var diastolicReadingFromPad = customerEventReadings.Find(eventReading => selectedPadPair.Where(padpair => padpair.FirstValue == (int)ReadingLabels.DiastolicRight).SingleOrDefault().SecondValue == eventReading.TestReadingId); if (diastolicReadingFromPad != null) { diastolicVal = diastolicReadingFromPad.Value; } } } else if (record.TestId == (long)TestType.ASI) { var customerEventReadings = linqMetaData.CustomerEventReading.Where(eventReading => eventReading.CustomerEventScreeningTestId == record.CustomerEventScreeningTestId).ToList(); if (string.IsNullOrEmpty(systolicVal)) { var systolicReadingFromAsi = customerEventReadings.Find(eventReading => selectedAsiPair.Where(asiPair => asiPair.FirstValue == (int)ReadingLabels.SystolicRight).SingleOrDefault().SecondValue == eventReading.TestReadingId); if (systolicReadingFromAsi != null) { systolicVal = systolicReadingFromAsi.Value; } } if (string.IsNullOrEmpty(diastolicVal)) { var diastolicReadingFromAsi = customerEventReadings.Find(eventReading => selectedAsiPair.Where(asiPair => asiPair.FirstValue == (int)ReadingLabels.DiastolicRight).SingleOrDefault().SecondValue == eventReading.TestReadingId); if (diastolicReadingFromAsi != null) { diastolicVal = diastolicReadingFromAsi.Value; } } } }); if (!string.IsNullOrEmpty(diastolicVal)) { var customerEventReadingEntity = new CustomerEventReadingEntity(0) { Value = diastolicVal, TestReading = new TestReadingEntity { ReadingId = (int)ReadingLabels.DiastolicRight } }; customerEventReadingEntities.Add(customerEventReadingEntity); } if (!string.IsNullOrEmpty(systolicVal)) { var customerEventReadingEntity = new CustomerEventReadingEntity(0) { Value = systolicVal, TestReading = new TestReadingEntity { ReadingId = (int)ReadingLabels.SystolicRight } }; customerEventReadingEntities.Add(customerEventReadingEntity); } } return(customerEventReadingEntities); }
public override CustomerEventScreeningTestsEntity CreateActualTestResultEntity(TestResult testResult, List <OrderedPair <int, int> > testReadingReadingPairs) { var diabetesTestResult = testResult as DiabetesTestResult; var customerEventScreeningTestsEntity = new CustomerEventScreeningTestsEntity(testResult.Id) { TestId = (int)TestType.Diabetes }; var resultIntpretations = new List <long>(); var pathwayRecomendations = new List <long>(); var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); if (diabetesTestResult != null) { CustomerEventReadingEntity customerEventTestReadingEntity = null; if (diabetesTestResult.Glucose != null) { customerEventTestReadingEntity = CreateEventReadingEntity(diabetesTestResult.Glucose, (int)ReadingLabels.Glucose, testReadingReadingPairs); long findingId = 0; if (diabetesTestResult.Glucose.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (diabetesTestResult.Glucose.Reading == null) { if (customerEventTestReadingEntity == null) { customerEventTestReadingEntity = CreateEventReadingEntitywithNullReading(diabetesTestResult.Glucose, (int)ReadingLabels.Glucose, testReadingReadingPairs); } customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Diabetes, (int)ReadingLabels.Glucose, diabetesTestResult.Glucose.Finding.Id); findingId = diabetesTestResult.Glucose.Finding.Id; } else { findingId = (new TestResultService()).GetCalculatedStandardFinding(Convert.ToInt32(diabetesTestResult.Glucose.Reading), (int)TestType.Diabetes, (int)ReadingLabels.Glucose); if (diabetesTestResult.Glucose.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Diabetes, (int)ReadingLabels.Glucose, diabetesTestResult.Glucose.Finding.Id); findingId = diabetesTestResult.Glucose.Finding.Id; } } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Diabetes, (int)ReadingLabels.Glucose, findingId); if (finding.ResultInterpretation != null) { resultIntpretations.Add(finding.ResultInterpretation.Value); } if (finding.PathwayRecommendation != null) { pathwayRecomendations.Add(finding.PathwayRecommendation.Value); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (testResult.ResultStatus.StateNumber == (int)TestResultStateNumber.Evaluated || testResult.ResultStatus.StateNumber == (int)NewTestResultStateNumber.Evaluated) { if (resultIntpretations.Count > 0) { testResult.ResultInterpretation = ResultInterpretation.Normal.GetMax(resultIntpretations); } if (pathwayRecomendations.Count > 0) { testResult.PathwayRecommendation = PathwayRecommendation.None.GetMax(pathwayRecomendations); } } } customerEventScreeningTestsEntity.CustomerEventReading.AddRange(customerEventReadingEntities); return(customerEventScreeningTestsEntity); }
public override CustomerEventScreeningTestsEntity CreateActualTestResultEntity(TestResult testResult, List <OrderedPair <int, int> > testReadingReadingPairs) { var hemoglobinTestResult = testResult as HemoglobinTestResult; var customerEventScreeningTestsEntity = new CustomerEventScreeningTestsEntity(testResult.Id) { TestId = (int)TestType.Hemoglobin }; var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); if (hemoglobinTestResult != null) { CustomerEventReadingEntity customerEventTestReadingEntity = null; if (hemoglobinTestResult.Hemoglobin != null) { customerEventTestReadingEntity = CreateEventReadingEntity(hemoglobinTestResult.Hemoglobin, (int)ReadingLabels.Hemoglobin, testReadingReadingPairs); long findingId = 0; if (hemoglobinTestResult.Hemoglobin.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (hemoglobinTestResult.Hemoglobin.Reading == null) { if (customerEventTestReadingEntity == null) { customerEventTestReadingEntity = CreateEventReadingEntitywithNullReading(hemoglobinTestResult.Hemoglobin, (int)ReadingLabels.Hemoglobin, testReadingReadingPairs); } findingId = hemoglobinTestResult.Hemoglobin.Finding.Id; customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Hemoglobin, (int)ReadingLabels.Hemoglobin, hemoglobinTestResult.Hemoglobin.Finding.Id); } else { var allFindings = new TestResultService().GetAllStandardFindings <int>((int)TestType.Hemoglobin, (int)ReadingLabels.Hemoglobin); var reading = hemoglobinTestResult.Hemoglobin.Reading != null?decimal.Round(hemoglobinTestResult.Hemoglobin.Reading.Value, 1) : (decimal?)null; var findings = (new TestResultService()).GetMultipleCalculatedStandardFinding(reading, (int)TestType.Hemoglobin, (int)ReadingLabels.Hemoglobin); var avFindings = allFindings.FindAll(f => f.Label.ToLower().IndexOf(_toCheckFor) == 0); findingId = findings.FirstOrDefault(f => avFindings.Select(av => av.Id).Contains(f)); if (hemoglobinTestResult.Hemoglobin.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.Hemoglobin, (int)ReadingLabels.Hemoglobin, hemoglobinTestResult.Hemoglobin.Finding.Id); findingId = hemoglobinTestResult.Hemoglobin.Finding.Id; } } if (findingId > 0) { var finding = GetSelectedStandardFinding((int)TestType.Hemoglobin, (int)ReadingLabels.Hemoglobin, findingId); if (testResult.ResultStatus.StateNumber == (int)TestResultStateNumber.Evaluated || testResult.ResultStatus.StateNumber == (int)NewTestResultStateNumber.Evaluated) { testResult.ResultInterpretation = finding.ResultInterpretation; testResult.PathwayRecommendation = finding.PathwayRecommendation; } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (hemoglobinTestResult.TechnicallyLimitedbutReadable != null) { var customerEventReadingEntity = CreateEventReadingEntity(hemoglobinTestResult.TechnicallyLimitedbutReadable, (int)ReadingLabels.TechnicallyLimitedbutReadable, testReadingReadingPairs); if (customerEventReadingEntity != null) { customerEventReadingEntities.Add(customerEventReadingEntity); } } if (hemoglobinTestResult.RepeatStudy != null) { var customerEventReadingEntity = CreateEventReadingEntity(hemoglobinTestResult.RepeatStudy, (int)ReadingLabels.RepeatStudy, testReadingReadingPairs); if (customerEventReadingEntity != null) { customerEventReadingEntities.Add(customerEventReadingEntity); } } if (customerEventReadingEntities.Count > 0) { customerEventScreeningTestsEntity.CustomerEventReading.AddRange(customerEventReadingEntities); } } return(customerEventScreeningTestsEntity); }
public override CustomerEventScreeningTestsEntity CreateActualTestResultEntity(TestResult testResult, List <OrderedPair <int, int> > testReadingReadingPairs) { var awvBoneMassTestResult = testResult as AwvBoneMassTestResult; var customerEventScreeningTestsEntity = new CustomerEventScreeningTestsEntity(testResult.Id) { TestId = (int)TestType.AwvBoneMass }; var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); CustomerEventReadingEntity customerEventReading = null; testResult.ResultInterpretation = null; // TODO : This code should be moved to a Coordinator/Service. if (awvBoneMassTestResult.EstimatedTScore != null && awvBoneMassTestResult.EstimatedTScore.Finding != null) { customerEventReading = CreateEventReadingEntity(awvBoneMassTestResult.EstimatedTScore, (int)ReadingLabels.EstimatedTScore, testReadingReadingPairs) ?? new CustomerEventReadingEntity(awvBoneMassTestResult.EstimatedTScore.Id) { IsManual = true, CreatedByOrgRoleUserId = awvBoneMassTestResult.EstimatedTScore.RecorderMetaData.DataRecorderCreator.Id, CreatedOn = awvBoneMassTestResult.EstimatedTScore.RecorderMetaData.DateCreated, UpdatedByOrgRoleUserId = awvBoneMassTestResult.EstimatedTScore.RecorderMetaData.DataRecorderModifier != null ? (long?)awvBoneMassTestResult.EstimatedTScore.RecorderMetaData.DataRecorderModifier.Id : null, UpdatedOn = awvBoneMassTestResult.EstimatedTScore.RecorderMetaData.DateModified, TestReadingId = testReadingReadingPairs.Find(testReadingpair => testReadingpair.FirstValue == (int)ReadingLabels.EstimatedTScore).SecondValue }; if (awvBoneMassTestResult.EstimatedTScore.Reading == null) { customerEventReading.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.AwvBoneMass, (int)ReadingLabels.EstimatedTScore, awvBoneMassTestResult.EstimatedTScore.Finding.Id); } else { int findingId = (new TestResultService()).GetCalculatedStandardFinding(awvBoneMassTestResult.EstimatedTScore.Reading, (int)TestType.AwvBoneMass, (int)ReadingLabels.EstimatedTScore); if (awvBoneMassTestResult.EstimatedTScore.Finding.Id == findingId) { customerEventReading.StandardFindingTestReadingId = null; } else { customerEventReading.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding((int)TestType.AwvBoneMass, (int)ReadingLabels.EstimatedTScore, awvBoneMassTestResult.EstimatedTScore.Finding.Id); } } if (awvBoneMassTestResult.EstimatedTScore.Finding.Id > 0) { var finding = GetSelectedStandardFinding((int)TestType.AwvBoneMass, (int)ReadingLabels.EstimatedTScore, awvBoneMassTestResult.EstimatedTScore.Finding.Id); if (testResult.ResultStatus.StateNumber == (int)TestResultStateNumber.Evaluated || testResult.ResultStatus.StateNumber == (int)NewTestResultStateNumber.Evaluated) { testResult.ResultInterpretation = finding.ResultInterpretation; testResult.PathwayRecommendation = finding.PathwayRecommendation; } } } if (customerEventReading != null) { customerEventReadingEntities.Add(customerEventReading); } if (customerEventReadingEntities.Count > 0) { customerEventScreeningTestsEntity.CustomerEventReading.AddRange(customerEventReadingEntities); } return(customerEventScreeningTestsEntity); }
public override CustomerEventScreeningTestsEntity CreateActualTestResultEntity(TestResult testResult, List <OrderedPair <int, int> > testReadingReadingPairs) { var liverTestResult = testResult as LiverTestResult; var customerEventScreeningTestsEntity = new CustomerEventScreeningTestsEntity(testResult.Id) { TestId = (int)TestType.Liver }; var customerEventReadingEntities = new List <CustomerEventReadingEntity>(); if (liverTestResult != null) { CustomerEventReadingEntity customerEventTestReadingEntity = null; if (liverTestResult.ALT != null) { customerEventTestReadingEntity = new CustomerEventReadingEntity() { TestReadingId = testReadingReadingPairs.Find(testReadingReadingPair => (testReadingReadingPair. FirstValue == (int) ReadingLabels.ALT)) .SecondValue, CustomerEventReadingId = Convert.ToInt32(liverTestResult.ALT.Id), Value = liverTestResult.ALT.Reading != null?liverTestResult.ALT.Reading.ToString() : null, IsManual = (liverTestResult.ALT.ReadingSource == ReadingSource.Manual ? true : false), CreatedByOrgRoleUserId = testResult.DataRecorderMetaData.DataRecorderCreator.Id, CreatedOn = testResult.DataRecorderMetaData.DateCreated }; if (liverTestResult.ALT.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (liverTestResult.ALT.Reading == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding ((int)TestType.Liver, (int)ReadingLabels.ALT, liverTestResult.ALT.Finding.Id); } else { int findingId = (new TestResultService()).GetCalculatedStandardFinding(Convert.ToInt32(liverTestResult.ALT.Reading), (int)TestType.Liver, (int)ReadingLabels.ALT); if (liverTestResult.ALT.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding ((int)TestType.Liver, (int)ReadingLabels.ALT, liverTestResult.ALT.Finding.Id); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } if (liverTestResult.AST != null) { customerEventTestReadingEntity = new CustomerEventReadingEntity() { TestReadingId = testReadingReadingPairs.Find(testReadingReadingPair => (testReadingReadingPair. FirstValue == (int) ReadingLabels.AST)) .SecondValue, CustomerEventReadingId = Convert.ToInt32(liverTestResult.AST.Id), Value = liverTestResult.AST.Reading != null?liverTestResult.AST.Reading.ToString() : null, IsManual = (liverTestResult.AST.ReadingSource == ReadingSource.Manual ? true : false), CreatedByOrgRoleUserId = testResult.DataRecorderMetaData.DataRecorderCreator.Id, CreatedOn = testResult.DataRecorderMetaData.DateCreated }; if (liverTestResult.AST.Finding == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else if (liverTestResult.AST.Reading == null) { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding ((int)TestType.Liver, (int)ReadingLabels.AST, liverTestResult.AST.Finding.Id); } else { int findingId = (new TestResultService()).GetCalculatedStandardFinding(Convert.ToInt32(liverTestResult.AST.Reading), (int)TestType.Liver, (int)ReadingLabels.AST); if (liverTestResult.AST.Finding.Id == findingId) { customerEventTestReadingEntity.StandardFindingTestReadingId = null; } else { customerEventTestReadingEntity.StandardFindingTestReadingId = (int?)new TestResultService().GetStandardFindingTestReadingIdForStandardFinding ((int)TestType.Liver, (int)ReadingLabels.AST, liverTestResult.AST.Finding.Id); } } customerEventReadingEntities.Add(customerEventTestReadingEntity); } } customerEventScreeningTestsEntity.CustomerEventReading.AddRange(customerEventReadingEntities); return(customerEventScreeningTestsEntity); }