public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity) { var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList(); var testResult = new MedicareTestResult(customerEventScreeningTestEntity.CustomerEventScreeningTestId); var customerEventTestStandardFindingEntities = customerEventScreeningTestEntity.CustomerEventTestStandardFinding.ToList(); var standardFindingTestReadingEntities = customerEventScreeningTestEntity.StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.ToList(); if (customerEventTestStandardFindingEntities.Count() > 0) { var testResultService = new TestResultService(); var standardFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.Medicare); customerEventTestStandardFindingEntities.ForEach(customerEventTestStandardFindingEntity => { var standardFindingTestReadingEntity = standardFindingTestReadingEntities.Find(entity => entity.StandardFindingTestReadingId == customerEventTestStandardFindingEntity.StandardFindingTestReadingId); if (standardFindingTestReadingEntity == null) { return; } var finding = CreateFindingObject(customerEventTestStandardFindingEntity, standardFindings, standardFindingTestReadingEntity, null); if (finding != null) { testResult.Finding = finding; return; } }); } var testMediaCollection = customerEventScreeningTestEntity.TestMedia.ToList(); var fileEntityCollection = customerEventScreeningTestEntity.FileCollectionViaTestMedia.ToList(); if (testMediaCollection.Count > 0) { var resultMedia = new List <ResultMedia>(); testMediaCollection.ForEach(testMedia => resultMedia.Add(new ResultMedia(testMedia.MediaId) { File = GetFileObjectfromEntity(testMedia.FileId, fileEntityCollection), Thumbnail = testMedia.ThumbnailFileId != null ? new File(testMedia.ThumbnailFileId.Value) : null, ReadingSource = testMedia.IsManual ? ReadingSource.Manual : ReadingSource.Automatic })); testResult.ResultImages = resultMedia; } testResult.TechnicallyLimitedbutReadable = CreateResultReading((int)ReadingLabels.TechnicallyLimitedbutReadable, customerEventReadingEntities); testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities); return(testResult); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPreventionPlanPath = GetFolderPathfor(_resultOutputPreventionPlanPath); var directorySnapShotPath = GetFolderPathfor(_resultOutputSanpShotPath); if (string.IsNullOrEmpty(directoryPreventionPlanPath) && string.IsNullOrEmpty(directorySnapShotPath)) { return(null); } List <string> snapShotFiles = null; List <string> preventionPlanFiles = null; if (!string.IsNullOrEmpty(directorySnapShotPath)) { snapShotFiles = GetPdfFiles(directorySnapShotPath); } if (!string.IsNullOrEmpty(directoryPreventionPlanPath)) { preventionPlanFiles = GetPdfFiles(directoryPreventionPlanPath); } if (snapShotFiles != null && snapShotFiles.Any()) { foreach (var filePath in snapShotFiles) { var customerIdString = Path.GetFileNameWithoutExtension(filePath); long customerId = 0; if (!long.TryParse(customerIdString, out customerId)) { _logger.Info("AWV Snap Shot: CustomerId not found on Pdf file" + filePath); continue; } bool isAwvTestPurchasedByCustomer = false; bool isMedicareTestPurchasedByCustomer = false; try { isAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AWV); if (!isAwvTestPurchasedByCustomer) { isMedicareTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Medicare); if (!isMedicareTestPurchasedByCustomer) { bool isAwvSubsequentTestPurchadedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSubsequent); if (!isAwvSubsequentTestPurchadedByCustomer) { _logger.Info("AWV Snap Shot: None of AWV tests is availed by CustomerId[" + customerId + "].\n"); continue; } } } } catch (Exception ex) { _logger.Info("AWV Snap Shot: None of the AWV tests is availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } TestType testType; if (isAwvTestPurchasedByCustomer) { testType = TestType.AWV; } else if (isMedicareTestPurchasedByCustomer) { testType = TestType.Medicare; } else { testType = TestType.AwvSubsequent; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var snapShotResultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, testType, AwvFileTypes.SnapShot); var mediaFiles = new List <ResultMedia>(); if (snapShotResultMedia != null) { mediaFiles.Add(snapShotResultMedia); if (preventionPlanFiles != null && preventionPlanFiles.Any()) { var preventionPlanFile = preventionPlanFiles.Where(ppf => Path.GetFileNameWithoutExtension(ppf) == customerIdString).Select(ppf => ppf).SingleOrDefault(); if (!string.IsNullOrEmpty(preventionPlanFile)) { var preventionPlanrResultMedia = GetMediaFromPdfFile(preventionPlanFile, folderToSavePdf, testType, AwvFileTypes.PreventionPlan); mediaFiles.Add(preventionPlanrResultMedia); preventionPlanFiles.Remove(preventionPlanFile); } } TestResult testResult = null; if (testType == TestType.AWV) { testResult = new AwvTestResult { ResultImages = mediaFiles } } ; else if (testType == TestType.Medicare) { testResult = new MedicareTestResult { ResultImages = mediaFiles } } ; else if (testType == TestType.AwvSubsequent) { testResult = new AwvSubsequentTestResult { ResultImages = mediaFiles } } ; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.AWVPP); _logger.Info(string.Concat("\n AWV Snap Shot.Parsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("AWV Snap Shot: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, testType, customerId, MedicalEquipmentTag.AWVPP, false); } } } //Prevention Plan Files if (preventionPlanFiles != null && preventionPlanFiles.Any()) { foreach (var filePath in preventionPlanFiles) { var customerIdString = Path.GetFileNameWithoutExtension(filePath); long customerId = 0; if (!long.TryParse(customerIdString, out customerId)) { _logger.Info("AWV Prevention Plan: CustomerId not found on Pdf file" + filePath); continue; } bool isAwvTestPurchasedByCustomer = false; bool isMedicareTestPurchasedByCustomer = false; bool isAwvSubsequentTestPurchadedByCustomer = false; try { isAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AWV); if (!isAwvTestPurchasedByCustomer) { isMedicareTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Medicare); if (!isMedicareTestPurchasedByCustomer) { isAwvSubsequentTestPurchadedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSubsequent); if (!isAwvSubsequentTestPurchadedByCustomer) { var isEAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.eAWV); if (!isEAwvTestPurchasedByCustomer) { _logger.Info("AWV Prevention Plan: None of AWV tests is availed by CustomerId[" + customerId + "].\n"); continue; } } } } } catch (Exception ex) { _logger.Info("AWV Prevention Plan: None of the AWV tests is availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } TestType testType; if (isAwvTestPurchasedByCustomer) { testType = TestType.AWV; } else if (isMedicareTestPurchasedByCustomer) { testType = TestType.Medicare; } else if (isAwvSubsequentTestPurchadedByCustomer) { testType = TestType.AwvSubsequent; } else { testType = TestType.eAWV; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var preventionPlanrResultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, testType, AwvFileTypes.PreventionPlan); var mediaFiles = new List <ResultMedia>(); if (preventionPlanrResultMedia != null) { mediaFiles.Add(preventionPlanrResultMedia); TestResult testResult = null; if (testType == TestType.AWV) { testResult = new AwvTestResult { ResultImages = mediaFiles } } ; else if (testType == TestType.Medicare) { testResult = new MedicareTestResult { ResultImages = mediaFiles } } ; else if (testType == TestType.AwvSubsequent) { testResult = new AwvSubsequentTestResult { ResultImages = mediaFiles } } ; else if (testType == TestType.eAWV) { testResult = new EAwvTestResult { ResultImages = mediaFiles } } ; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.AWVPP); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("AWV Prevention Plan: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, testType, customerId, MedicalEquipmentTag.AWVPP, false); } } } return(eventCustomerAggregates); }