public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity) { var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList(); var testResult = new SpiroTestResult(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.Spiro); 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; } }); } if (customerEventScreeningTestEntity.TestMedia != null && customerEventScreeningTestEntity.TestMedia.Count > 0) { var fileEntityCollection = customerEventScreeningTestEntity.FileCollectionViaTestMedia.ToList(); var testMediaEntity = customerEventScreeningTestEntity.TestMedia.FirstOrDefault(); testResult.ResultImage = new ResultMedia(testMediaEntity.MediaId) { File = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection), Thumbnail = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null, ReadingSource = testMediaEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic }; } testResult.TechnicallyLimitedbutReadable = CreateResultReading((int)ReadingLabels.TechnicallyLimitedbutReadable, customerEventReadingEntities); testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities); testResult.PoorEffort = CreateResultReading((int)ReadingLabels.PoorEffort, customerEventReadingEntities); testResult.Restrictive = CreateResultReading((int)ReadingLabels.Restrictive, customerEventReadingEntities); testResult.Obstructive = CreateResultReading((int)ReadingLabels.Obstructive, customerEventReadingEntities); return(testResult); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } foreach (var filePath in Directory.GetFiles(directoryPath)) { _isSpiroFile = false; // IsEkgIppeFile = false; if (Path.GetExtension(filePath).ToLower().Contains("pdf")) { var fileName = Path.GetFileName(filePath); if (fileName.ToLower().StartsWith(SpiroFilePrefix.ToLower())) { _isSpiroFile = true; } //if (fileName.ToLower().StartsWith(EkgIppeFilePreFix.ToLower())) // IsEkgIppeFile = true; var customerIdString = ""; if (_isSpiroFile) { var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1); customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_")); } //else if (IsEkgIppeFile) //{ // if (fileName.ToLower().StartsWith(EkgIppeFilePreFix.ToLower())) // { // var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1); // customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_")); // } // else // customerIdString = fileName.Substring(0, fileName.IndexOf("_")); //} else { if (fileName.ToLower().StartsWith(EkgFilePrefix.ToLower())) { var tempFileName = fileName.Substring(fileName.IndexOf("_") + 1); customerIdString = tempFileName.Substring(0, tempFileName.IndexOf("_")); } else { customerIdString = fileName.Substring(0, fileName.IndexOf("_")); } } long customerId = 0; if (!long.TryParse(customerIdString, out customerId)) { _logger.Info("CustomerId not found on Pdf file" + filePath); continue; } bool isSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro); bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro); bool isEkgTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG); bool isAwvEkgTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkg); bool isAwvEkgIppeTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkgIPPE); try { if (_isSpiroFile) { if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer) { _logger.Info("Spiro is not availed by CustomerId[" + customerId + "].\n"); continue; } } else { if (!isEkgTestPurchasedByCustomer && !isAwvEkgTestPurchasedByCustomer && !isAwvEkgIppeTestPurchasedByCustomer) { _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "].\n"); continue; } } } catch (Exception ex) { if (_isSpiroFile) { _logger.Info("Spiro is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); } else { _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); } continue; } try { TestType testType; TestResult testResult = null; if (_isSpiroFile) { testType = TestType.Spiro; if (isAwvSpiroTestPurchasedByCustomer) { testType = TestType.AwvSpiro; } string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString(), false); if (resultMedia != null) { if (isAwvSpiroTestPurchasedByCustomer) { testResult = new AwvSpiroTestResult { ResultImage = resultMedia }; } else if (isSpiroTestPurchasedByCustomer) { testResult = new SpiroTestResult { ResultImage = resultMedia }; } _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.Schiller); _logger.Info(string.Concat("\nParsing succeeded for Spiro for Customer Id: ", customerId, "\n")); } } else { testType = TestType.EKG; if (isAwvEkgIppeTestPurchasedByCustomer) //&& IsEkgIppeFile { testType = TestType.AwvEkgIPPE; } else if (isAwvEkgTestPurchasedByCustomer) { testType = TestType.AwvEkg; } string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString()); if (resultMedia != null) { switch (testType) { case TestType.EKG: testResult = new EKGTestResult { ResultImage = resultMedia }; break; case TestType.AwvEkg: testResult = new AwvEkgTestResult { ResultImage = resultMedia }; break; case TestType.AwvEkgIPPE: testResult = new AwvEkgIppeTestResult { ResultImage = resultMedia }; break; } _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.Schiller); _logger.Info(string.Concat("\nParsing succeeded for EKG for Customer Id: ", customerId, "\n")); } } } catch (Exception ex) { if (_isSpiroFile) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvSpiroTestPurchasedByCustomer ? TestType.AwvSpiro : TestType.Spiro, customerId, MedicalEquipmentTag.Schiller, false); } else { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvEkgIppeTestPurchasedByCustomer ? TestType.AwvEkgIPPE : isAwvEkgTestPurchasedByCustomer ? TestType.AwvEkg : TestType.EKG, customerId, MedicalEquipmentTag.Schiller, false); } } } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } foreach (var filePath in DirectoryOperationsHelper.GetFiles(directoryPath)) { if (Path.GetExtension(filePath).ToLower().Contains("pdf")) { _logger.Info("Parsing file : " + filePath); var customerIdString = ""; var fileName = Path.GetFileName(filePath); try { customerIdString = fileName.Split('_')[2]; } catch { customerIdString = fileName; } // var customerIdString = fileName.IndexOf("_") > 0 ? fileName.Substring(0, fileName.IndexOf("_")) : fileName; long customerId; if (!long.TryParse(customerIdString, out customerId)) { _logger.Info("Customer ID not found on Pdf file : " + filePath); continue; } bool isSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro); bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro); try { if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer) { _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "].\n"); continue; } } catch (Exception ex) { _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } try { TestResult testResult = null; var testType = TestType.Spiro; if (isAwvSpiroTestPurchasedByCustomer) { testType = TestType.AwvSpiro; } var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString()); resultMedia.ReadingSource = ReadingSource.Automatic; if (resultMedia != null) { switch (testType) { case TestType.Spiro: testResult = new SpiroTestResult { ResultImage = resultMedia }; break; case TestType.AwvSpiro: testResult = new AwvSpiroTestResult { ResultImage = resultMedia }; break; } _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.CardioCard); _logger.Info(string.Concat("\nParsing succeeded for SPIRO/AWVSPIRO for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isSpiroTestPurchasedByCustomer ? TestType.Spiro : TestType.AwvSpiro, customerId, MedicalEquipmentTag.CardioCard, false); } } } return(eventCustomerAggregates); }
public void CopyOverSpiroGraph(long eventId, long customerId, string saveFilePath, SpiroTestResult testResult) { if (testResult == null || testResult.ResultImage == null) { return; } var destinationDirectory = Path.GetDirectoryName(saveFilePath); var supportDestDirectoryPath = destinationDirectory + @"\" + StringforMediaDirectory; if (!Directory.Exists(supportDestDirectoryPath)) { Directory.CreateDirectory(supportDestDirectoryPath); } string input = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath + testResult.ResultImage.File.Path; using (Image img = Image.FromFile(input)) { //rotate the picture by 90 degrees and re-save the picture as a Jpeg //img.RotateFlip(RotateFlipType.Rotate270FlipNone); img.Save(supportDestDirectoryPath + "\\" + testResult.ResultImage.File.Path, System.Drawing.Imaging.ImageFormat.Jpeg); } }
public PhysicianPartnerResultExportModel SetSpiroData(PhysicianPartnerResultExportModel model, SpiroTestResult testResult) { if (testResult.Finding != null) { model.SpiroResult = testResult.Finding.Label; } model.SpiroPoorEffort = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.PoorEffort); model.SpiroRestrictive = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Restrictive); model.SpiroObstructive = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.Obstructive); model.SpiroTechnicallyLimitedButReadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable); model.SpiroRepeatStudyUnreadable = PhysicianPartnerResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudy); model.SpiroUnabletoScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString; if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical)) { model.SpiroCritical = PhysicianPartnerResultExportHelper.YesString; } else { model.SpiroCritical = PhysicianPartnerResultExportHelper.NoString; } if (testResult.PhysicianInterpretation != null) { model.SpiroPhysicianNotes = testResult.PhysicianInterpretation.Remarks; } return(model); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } foreach (var filePath in DirectoryOperationsHelper.GetFiles(directoryPath)) { if (Path.GetExtension(filePath).ToLower().Contains("pdf")) { _logger.Info("Parsing file : " + filePath); var fileName = Path.GetFileName(filePath); bool isSpiro = false; var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); isSpiro = fileNameWithoutExtension.ToLower().EndsWith(SpiroFilePrefix); var searchPattern = fileName.Substring(0, GetIndexOfNthOccurence(fileName, '_', 5)) + "*" + (isSpiro ? "_spiro.pdf" : "_ecg.pdf"); var versionedFiles = DirectoryOperationsHelper.GetFiles(directoryPath, searchPattern).Select(Path.GetFileName);; var latestVersion = versionedFiles.OrderByDescending(x => x).First(); if (Path.GetFileName(filePath) != latestVersion) { _logger.Info("A more recent version of this file is present : " + latestVersion); continue; } var customerIdString = fileName.IndexOf("_") > 0 ? fileName.Substring(0, fileName.IndexOf("_")) : fileName; long customerId; if (!long.TryParse(customerIdString, out customerId)) { _logger.Info("Customer ID not found on Pdf file : " + filePath); continue; } if (!isSpiro) { bool isEkgTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG); bool isAwvEkgTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkg); bool isAwvEkgIppeTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkgIPPE); try { if (!isEkgTestPurchasedByCustomer && !isAwvEkgTestPurchasedByCustomer && !isAwvEkgIppeTestPurchasedByCustomer) { _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "].\n"); continue; } } catch (Exception ex) { _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } try { TestResult testResult = null; var testType = TestType.EKG; if (isAwvEkgIppeTestPurchasedByCustomer) //&& IsEkgIppeFile { testType = TestType.AwvEkgIPPE; } else if (isAwvEkgTestPurchasedByCustomer) { testType = TestType.AwvEkg; } var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString()); resultMedia.ReadingSource = ReadingSource.Automatic; if (resultMedia != null) { switch (testType) { case TestType.EKG: testResult = new EKGTestResult { ResultImage = resultMedia }; break; case TestType.AwvEkg: testResult = new AwvEkgTestResult { ResultImage = resultMedia }; break; case TestType.AwvEkgIPPE: testResult = new AwvEkgIppeTestResult { ResultImage = resultMedia }; break; } _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.CardioCard); _logger.Info(string.Concat("\nParsing succeeded for EKG for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvEkgIppeTestPurchasedByCustomer ? TestType.AwvEkgIPPE : isAwvEkgTestPurchasedByCustomer ? TestType.AwvEkg : TestType.EKG, customerId, MedicalEquipmentTag.CardioCard, false); } } else if (isSpiro) { bool isSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro); bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro); try { if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer) { _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "].\n"); continue; } } catch (Exception ex) { _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } try { TestResult testResult = null; var testType = TestType.Spiro; if (isAwvSpiroTestPurchasedByCustomer) { testType = TestType.AwvSpiro; } var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString(), false); resultMedia.ReadingSource = ReadingSource.Automatic; if (resultMedia != null) { switch (testType) { case TestType.Spiro: testResult = new SpiroTestResult { ResultImage = resultMedia }; break; case TestType.AwvSpiro: testResult = new AwvSpiroTestResult { ResultImage = resultMedia }; break; } _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.CardioCard); _logger.Info(string.Concat("\nParsing succeeded for SPIRO/AWVSPIRO for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isSpiroTestPurchasedByCustomer ? TestType.Spiro : TestType.AwvSpiro, customerId, MedicalEquipmentTag.CardioCard, false); } } } } return(eventCustomerAggregates); }