private void ParseDataforKyn(long customerId, string filePath) { var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Kyn); if (isTestPurchased) { _logger.Info(string.Format("Found Customer : [{0}]", customerId)); _resultParserHelper.AddResultArchiveLog("", TestType.Kyn, customerId, MedicalEquipmentTag.KynDataProcessor, true); } else { _logger.Info(string.Format("KYN is not availed by Customer : [{0}]", customerId)); File.Delete(filePath); } }
private void ParseDataForCrp(DataRow dr, BloodTestResultParserLog log, long customerId, long eventId) { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Crp); var isEmpty = IsDataRowItemEmpty(dr[ColumnCrp]); string message; if (isEmpty && !isTestPurchasedByCustomer) { _logger.Info(string.Format("For Customer Id {0} - EventId {1}, no data for CRP", customerId, eventId)); return; } if (isEmpty) { message = string.Format("For Customer Id {0} - EventId {1}, no data for CRP", customerId, eventId); _logger.Info(message); AppendTestResultLog(log, message, false); } else if (!isTestPurchasedByCustomer) { message = string.Format("CRP is not availed by CustomerId {0} - EventId {1}", customerId, eventId); AppendTestResultLog(log, message, false); _logger.Info(message); } else { var testResult = new CrpTestResult { LCRP = new ResultReading <string>(ReadingLabels.LCRP) { ReadingSource = ReadingSource.Automatic, Reading = dr[ColumnCrp].ToString() } }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(_eventCustomerScreeningAggregates, eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog("", TestType.Crp, customerId, MedicalEquipmentTag.Bloodworks); } }
private void ParseDataForHypertension(long customerId, BasicBiometric basicBiometric) { var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Hypertension); try { if (isTestPurchased) { var testResult = new HypertensionTestResult { Systolic = new ResultReading <int?> { Reading = basicBiometric.SystolicPressure }, Diastolic = new ResultReading <int?> { Reading = basicBiometric.DiastolicPressure }, RightArmBpMeasurement = new ResultReading <bool> { Reading = basicBiometric.IsRightArmBpMeasurement }, BloodPressureElevated = new ResultReading <bool> { Reading = basicBiometric.SystolicPressure >= 140 || basicBiometric.DiastolicPressure >= 90 } }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(_eventCustomerScreeningAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(_bloodworkAppLipidParser.ErrorSummary, TestType.Hypertension, customerId, MedicalEquipmentTag.Bloodworks, true); } else { _logger.Info(string.Format("Hypertension is not availed by Customer : [{0}]", customerId)); } } catch (Exception exception) { _logger.Error(string.Format("Some error occured while parsing data of Hypertension Test for customerId {0} and event Id {1} \nMessage:{2} \nStack Trace: {3}", customerId, _eventId, exception.Message, exception.StackTrace)); } }
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); }
private void ParseforFilePath(string filePath, List <EventCustomerScreeningAggregate> eventCustomerAggregates) { if (!string.IsNullOrEmpty(filePath)) { long customerId = 0; var headerType = GetHeaderTypeFromFile(filePath, out customerId).ToLower(); var reportKind = ""; if (headerType.Contains(ReportKindAaa)) { reportKind = ReportKindAaa; } else if (headerType.Contains(ReportKindStroke)) { reportKind = ReportKindStroke; } else if (headerType.Contains(ReportKindEcho)) { reportKind = ReportKindEcho; } else if (headerType.Contains(ReportKindThyroid)) { reportKind = ReportKindThyroid; } else if (headerType.Contains(ReportKindImt)) { reportKind = ReportKindImt; } else if (headerType.Contains(ReportKindLead)) { reportKind = ReportKindLead; } if (!string.IsNullOrEmpty(headerType) && customerId > 0) { var mediaFilePath = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId); switch (reportKind) { case ReportKindAaa: bool isPpAaaPurchased = false; bool isHcpAaaPurchased = false; bool isAwvAaaPurchased = false; try { _logger.Info("\n\n ===================> AAA Parsing for CustomerId : " + customerId + "\n"); bool isAaaPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AAA); isPpAaaPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.PPAAA); isHcpAaaPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.HCPAAA); isAwvAaaPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvAAA); if (!isAaaPurchased && !isPpAaaPurchased && !isHcpAaaPurchased && !isAwvAaaPurchased) { _logger.Info("AAA is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } ITestParser aaaParser = null; if (isPpAaaPurchased) { aaaParser = new BioSoundPpAaaParser(filePath, mediaFilePath.PhysicalPath, _logger); var ppAaaTestResult = aaaParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, ppAaaTestResult); _resultParserHelper.AddResultArchiveLog(aaaParser.ErrorSummary, TestType.PPAAA, customerId, MedicalEquipmentTag.BioSound); } else if (isHcpAaaPurchased) { aaaParser = new BioSoundHcpAaaParser(filePath, mediaFilePath.PhysicalPath, _logger); var hcpAaaTestResult = aaaParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, hcpAaaTestResult); _resultParserHelper.AddResultArchiveLog(aaaParser.ErrorSummary, TestType.HCPAAA, customerId, MedicalEquipmentTag.BioSound); } else if (isAwvAaaPurchased) { aaaParser = new BioSoundAwvAaaParser(filePath, mediaFilePath.PhysicalPath, _logger, _eventId, customerId); var awvAaaTestResult = aaaParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, awvAaaTestResult); _resultParserHelper.AddResultArchiveLog(aaaParser.ErrorSummary, TestType.AwvAAA, customerId, MedicalEquipmentTag.BioSound); } if (isAaaPurchased) { if (_aaaParserToUse.ToLower().Equals("biosoundaaaparser")) { aaaParser = new BioSoundAaaParser(filePath, mediaFilePath.PhysicalPath, _logger); } else { aaaParser = new BioSoundAaaParser2(filePath, mediaFilePath.PhysicalPath, _logger); } var aaaTestResult = aaaParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, aaaTestResult); _resultParserHelper.AddResultArchiveLog(aaaParser.ErrorSummary, TestType.AAA, customerId, MedicalEquipmentTag.BioSound); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, (isPpAaaPurchased ? TestType.PPAAA : (isHcpAaaPurchased ? TestType.HCPAAA : (isAwvAaaPurchased ? TestType.AwvAAA : TestType.AAA))) , customerId, MedicalEquipmentTag.BioSound, false); } break; case ReportKindEcho: var testEchoType = TestType.Echocardiogram; try { _logger.Info("\n\n ===================> Echo Parsing for CustomerId : " + customerId + "\n"); var isEchoPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Echocardiogram); var isPpEchoPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.PPEcho); var isHcpEchoPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.HCPEcho); var isAwvEchoPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEcho); if (!isEchoPurchasedByCustomer && !isPpEchoPurchasedByCustomer && !isHcpEchoPurchasedByCustomer && !isAwvEchoPurchasedByCustomer) { _logger.Info("Echocardiogram is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } if (isPpEchoPurchasedByCustomer) { testEchoType = TestType.PPEcho; } else if (isHcpEchoPurchasedByCustomer) { testEchoType = TestType.HCPEcho; } else if (isAwvEchoPurchasedByCustomer) { testEchoType = TestType.AwvEcho; } ITestParser echoParser = new BioSoundEchoParser(filePath, mediaFilePath.PhysicalPath, _logger, testEchoType); var echoTestResult = echoParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, echoTestResult); _resultParserHelper.AddResultArchiveLog(echoParser.ErrorSummary, testEchoType, customerId, MedicalEquipmentTag.BioSound); } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, testEchoType, customerId, MedicalEquipmentTag.BioSound, false); } break; case ReportKindStroke: bool isHcpCarotidPurchased = false; bool isAwvCarotidPurchased = false; try { _logger.Info("\n\n ===================> Stroke Parsing for CustomerId : " + customerId + "\n"); bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Stroke); isHcpCarotidPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.HCPCarotid); isAwvCarotidPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvCarotid); if (!isTestPurchasedByCustomer && !isHcpCarotidPurchased && !isAwvCarotidPurchased) { _logger.Info("Stroke is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } if (isHcpCarotidPurchased) { ITestParser hcpCarotidParser = new BioSoundHcpCarotidParser(filePath, mediaFilePath.PhysicalPath, _logger); var hcpCarotidTestResult = hcpCarotidParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, hcpCarotidTestResult); _resultParserHelper.AddResultArchiveLog(hcpCarotidParser.ErrorSummary, TestType.HCPCarotid, customerId, MedicalEquipmentTag.BioSound); } else if (isAwvCarotidPurchased) { ITestParser awvCarotidParser = new BioSoundAwvCarotidParser(filePath, mediaFilePath.PhysicalPath, _logger); var hcpCarotidTestResult = awvCarotidParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, hcpCarotidTestResult); _resultParserHelper.AddResultArchiveLog(awvCarotidParser.ErrorSummary, TestType.AwvCarotid, customerId, MedicalEquipmentTag.BioSound); } else { ITestParser strokeParser = new BioSoundStrokeParser(filePath, mediaFilePath.PhysicalPath, _logger); var strokeTestResult = strokeParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, strokeTestResult); _resultParserHelper.AddResultArchiveLog(strokeParser.ErrorSummary, TestType.Stroke, customerId, MedicalEquipmentTag.BioSound); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, isHcpCarotidPurchased ? TestType.HCPCarotid : (isAwvCarotidPurchased ? TestType.AwvCarotid : TestType.Stroke), customerId, MedicalEquipmentTag.BioSound, false); } break; case ReportKindLead: try { _logger.Info("\n\n ===================> Lead Parsing for CustomerId : " + customerId + "\n"); bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Lead); if (!isTestPurchasedByCustomer) { _logger.Info("Lead is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } ITestParser leadParser = new BioSoundLeadParser(filePath, mediaFilePath.PhysicalPath, _logger); var leadTestResult = leadParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, leadTestResult); _resultParserHelper.AddResultArchiveLog(leadParser.ErrorSummary, TestType.Lead, customerId, MedicalEquipmentTag.BioSound); } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.Lead, customerId, MedicalEquipmentTag.BioSound, false); } break; case ReportKindThyroid: try { _logger.Info("\n\n ===================> Thyroid Parsing for CustomerId : " + customerId + "\n"); bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Thyroid); if (!isTestPurchasedByCustomer) { _logger.Info("Thyroid is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } ITestParser thyroidParser = new BioSoundThyroidParser(filePath, mediaFilePath.PhysicalPath, _logger); var thyroidTestResult = thyroidParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, thyroidTestResult); _resultParserHelper.AddResultArchiveLog(thyroidParser.ErrorSummary, TestType.Thyroid, customerId, MedicalEquipmentTag.BioSound); } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.Thyroid, customerId, MedicalEquipmentTag.BioSound, false); } break; case ReportKindImt: try { _logger.Info("\n\n ===================> IMT Parsing for CustomerId : " + customerId + "\n"); bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.IMT); if (!isTestPurchasedByCustomer) { _logger.Info("IMT is not availed by CustomerId[" + customerId + "]. But is recorded for. Not parsing the record. \n"); break; } ITestParser imtParser = new BioSoundImtParser(filePath, mediaFilePath.PhysicalPath, _logger); var imtTestResult = imtParser.Parse(); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, imtTestResult); _resultParserHelper.AddResultArchiveLog(imtParser.ErrorSummary, TestType.IMT, customerId, MedicalEquipmentTag.BioSound); } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + " \n\t " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.IMT, customerId, MedicalEquipmentTag.BioSound, false); } break; } } } }
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 IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } var testType = TestType.QuantaFloABI; foreach (var filePath in Directory.GetFiles(directoryPath)) { long customerId = 0; if (string.IsNullOrEmpty(filePath) || !Path.GetExtension(filePath).ToLower().Contains("pdf")) { _logger.Info("file path empty or not contain pdf"); continue; } var fileName = Path.GetFileName(filePath); try { if (fileName.Split('_').Length > 2) { long.TryParse(fileName.Split('_')[2], out customerId); } } catch (Exception exception) { _logger.Error(string.Format("some Error occured while extracting customerId from file Path {0} exception : {1} \n stacktrace: {2}", filePath, exception.Message, exception.StackTrace)); continue; } if (customerId <= 0) { _logger.Error(string.Format("customerId not found in file Path {0}", filePath)); continue; } try { bool isQuantaFloAbiPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)testType); if (!isQuantaFloAbiPurchased) { _logger.Info("QuantaFlo ABI is not availed by CustomerId[" + customerId + "].\n"); continue; } var foldertoSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, foldertoSaveImage, testType.ToString()); if (resultMedia != null) { var mediaFilePath = foldertoSaveImage + Path.GetFileNameWithoutExtension(resultMedia.File.Path) + ".pdf"; File.Copy(filePath, mediaFilePath); } var testResult = new QuantaFloABITestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.QuantaFlo); _logger.Info(string.Concat("\nParsing succeeded for QuantaFlo-ABI for Customer Id: ", customerId, "\n")); } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, testType, customerId, MedicalEquipmentTag.QuantaFlo, false); } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } var pdfFiles = DirectoryOperationsHelper.GetFiles(directoryPath, "*.pdf"); //GetPdfFiles(directoryPath); if (pdfFiles != null && pdfFiles.Any()) { _logger.Info("Number of Files to Parse : " + pdfFiles.Count()); foreach (var filePath in pdfFiles) { var fileName = Path.GetFileName(filePath); long customerId = 0; string errorMessage = string.Empty; _logger.Info("=============== Parsing Started for file: " + fileName + " ================="); var pdfText = GetTextFromPdf(filePath); if (string.IsNullOrWhiteSpace(pdfText)) { continue; } var lstText = pdfText.Replace("\r", "").Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); var customerIdString = lstText.Where(x => x.Contains("Patient ID:")).FirstOrDefault(); if (string.IsNullOrWhiteSpace(customerIdString) || !long.TryParse(customerIdString.Replace("Patient ID:", "").Trim(), out customerId)) { errorMessage = "DPN: CustomerId could be blank or not an numeric value in Pdf file @" + filePath + " and text is: " + customerIdString; _logger.Info(errorMessage); continue; } var eventCustomer = _eventCustomerRepository.Get(_eventId, customerId); if (eventCustomer == null) { errorMessage = "DPN: Customer: " + customerId + " is not registered on Event Id :" + _eventId + " for file path: " + filePath; _logger.Info(errorMessage); continue; } var isTestPurchased = _eventCustomerRepository.IsTestPurchasedByEventIdCustomerId(_eventId, customerId, (long)TestType.DPN); if (!isTestPurchased) { errorMessage = "DPN: Test not purchased for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } var resultState = _eventCustomerResultRepository.GetByCustomerIdAndEventId(customerId, _eventId); if (resultState != null && _isNewResultFlow && resultState.ResultState >= (int)NewTestResultStateNumber.PostAuditNew) { errorMessage = "DPN (New Result Flow): Pdf can not parsed because current result state is " + NewTestResultStateNumber.PostAuditNew.ToString() + " for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } if (resultState != null && !_isNewResultFlow && resultState.ResultState >= (int)TestResultStateNumber.PostAudit) { errorMessage = "DPN (Old Result Flow): Pdf can not parsed because current result state is " + TestResultStateNumber.PostAudit.ToString() + " for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, TestType.DPN); if (resultMedia != null) { resultMedia.ReadingSource = ReadingSource.Automatic; TestResult testResult = new DpnTestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.DPN, customerId, MedicalEquipmentTag.Vatica); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { errorMessage = "DPN: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace; _logger.Error(errorMessage); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.DPN, customerId, MedicalEquipmentTag.Vatica, false); } _logger.Info("=============== Parsing Ended for file: " + fileName + " ================="); } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var testType = TestType.FocAttestation; var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } var pdfFiles = Directory.GetFiles(directoryPath, "*.pdf"); if (pdfFiles.IsNullOrEmpty()) { _logger.Info("file path empty or not contain pdf"); return(eventCustomerAggregates); } foreach (var filePath in pdfFiles) { long customerId = 0; try { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); long.TryParse(fileNameWithoutExtension, out customerId); if (customerId <= 0) { _logger.Error(string.Format("customerId not found in file Path {0}", filePath)); continue; } } catch (Exception exception) { _logger.Error(string.Format("some Error occured while extracting customerId from file Path {0} exception : {1} \n stacktrace: {2}", filePath, exception.Message, exception.StackTrace)); continue; } try { bool isFOCAttestationPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)testType); if (!isFOCAttestationPurchased) { _logger.Info("FOC Attestation is not availed by CustomerId[" + customerId + "].\n"); continue; } var foldertoSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, foldertoSaveImage, testType.ToString()); if (resultMedia != null) { resultMedia.ReadingSource = ReadingSource.Automatic; var testResult = new FocAttestationTestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.FocAttestation); _logger.Info(string.Concat("\nParsing succeeded for FOC Attestation for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, testType, customerId, MedicalEquipmentTag.FocAttestation, false); } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } var filePathsForXml = Directory.GetFiles(directoryPath, "*.xml").OrderBy(m => m).ToArray(); var filePathsForJpg = Directory.GetFiles(directoryPath, "*.jpg").OrderBy(m => m).ToArray(); //var fileNameArray = filePathsForXml.Select(Path.GetFileNameWithoutExtension).ToList(); //.AddRange(filePathsForJpg.Select(Path.GetFileNameWithoutExtension)); if (filePathsForXml.Count() > 0) { foreach (var xmlFilePath in filePathsForXml) { var fileName = Path.GetFileName(xmlFilePath); long customerId = GetCustomerId(fileName); if (customerId < 1) { _logger.Info("CustomerId not found on XML file " + xmlFilePath); continue; } try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG); if (!isTestPurchasedByCustomer) { _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 { var imageFilePath = filePathsForJpg.Where( f => Path.GetFileNameWithoutExtension(f) == Path.GetFileNameWithoutExtension(xmlFilePath)). FirstOrDefault(); if (string.IsNullOrEmpty(imageFilePath)) { imageFilePath = filePathsForJpg.Where(f => f.Contains(customerId.ToString())).FirstOrDefault(); if (!string.IsNullOrEmpty(imageFilePath)) { filePathsForJpg = filePathsForJpg.Where(f => f != imageFilePath).Select(f => f).ToArray(); } } var testResult = new EKGTestResult(); string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = string.IsNullOrEmpty(imageFilePath) ? null : _mediaHelper.GetfromImageFile(new FileInfo(imageFilePath), TestType.EKG.ToString(), folderToSaveImage, _settings.HideEkgSection); var resultData = GetDatafromXml(xmlFilePath, testResult); if (!resultData && resultMedia == null) { _logger.Info(string.Concat("\nNo Data found for Id: ", customerId, "\n")); continue; } testResult.ResultImage = resultMedia; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.EKG, customerId, MedicalEquipmentTag.Schiller); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.EKG, customerId, MedicalEquipmentTag.Schiller, false); } } } if (filePathsForJpg.Count() > 0) { foreach (var jpgFilePath in filePathsForJpg) { var imageFilePath = filePathsForXml.Where(f => Path.GetFileNameWithoutExtension(f) == Path.GetFileNameWithoutExtension(jpgFilePath)).FirstOrDefault(); if (!string.IsNullOrEmpty(imageFilePath)) { continue; } var fileName = Path.GetFileName(jpgFilePath); long customerId = GetCustomerId(fileName); if (customerId < 1) { _logger.Info("CustomerId not found on XML file " + filePathsForJpg); continue; } try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG); if (!isTestPurchasedByCustomer) { _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 { EKGTestResult ekgTestResult; var testResult = _testResultRepository.GetTestResults(customerId, _eventId, _isNewResultFlow); if (testResult == null) { ekgTestResult = new EKGTestResult(); } else { ekgTestResult = (EKGTestResult)testResult; } string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = _mediaHelper.GetfromImageFile(new FileInfo(jpgFilePath), TestType.EKG.ToString(), folderToSaveImage, _settings.HideEkgSection); if (resultMedia == null) { _logger.Info(string.Concat("\nNo Data found for Id: ", customerId, "\n")); continue; } ekgTestResult.ResultImage = resultMedia; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, ekgTestResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.EKG, customerId, MedicalEquipmentTag.Schiller); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.EKG, customerId, MedicalEquipmentTag.Schiller, false); } } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var mediaLocation = _mediaRepository.GetEawvHraResultMediaLocation(); var mediaArchiveLocation = _mediaRepository.GetEawvHraResultArchiveMediaLocation(); try { var xmlFilePaths = Directory.GetFiles(mediaLocation.PhysicalPath, "*.xml"); foreach (var xmlfile in xmlFilePaths) { _logger.Info("reading xml File: " + xmlfile); HraResultTags eawvHraResult = null; try { eawvHraResult = _eawvHraSerializer.Deserialize(xmlfile); } catch (Exception ex) { _logger.Error("Some error occurred while reading xml. Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); File.Move(xmlfile, Path.Combine(mediaArchiveLocation.PhysicalPath, Path.GetFileName(xmlfile))); } if (eawvHraResult == null) { _logger.Info("Some error occurred while reading xml."); File.Move(xmlfile, Path.Combine(mediaArchiveLocation.PhysicalPath, Path.GetFileName(xmlfile))); } if (eawvHraResult.Events.IsNullOrEmpty()) { _logger.Info("No Event Data found for Tag: " + eawvHraResult.Name); File.Move(xmlfile, Path.Combine(mediaArchiveLocation.PhysicalPath, Path.GetFileName(xmlfile))); continue; } var eventid = eawvHraResult.Events.First().EventId; var account = _corporateAccountRepository.GetbyEventId(eventid); if (account == null) { _logger.Info("No Corporate Account For Event Id: " + eventid); File.Move(xmlfile, Path.Combine(mediaArchiveLocation.PhysicalPath, Path.GetFileName(xmlfile))); continue; } _logger.Info("Running for corporate Account " + account.Tag); var theEvent = _eventRepository.GetById(eventid); QuestionnaireType questionnaireType = QuestionnaireType.None; if (account != null && account.IsHealthPlan && theEvent != null) { questionnaireType = _accountHraChatQuestionnaireHistoryServices.QuestionnaireTypeByAccountIdandEventDate(account.Id, theEvent.EventDate); } if (questionnaireType != QuestionnaireType.HraQuestionnaire) { _logger.Info("HRA Questionnaire is not started"); continue; } var eawvTestNotPurchsed = new HraResultTags { Name = eawvHraResult.Name, Events = new List <HraResultEvent>() }; foreach (var hraResultEvent in eawvHraResult.Events) { var eventCustomers = _eventCustomerRepository.GetbyEventId(hraResultEvent.EventId); if (eventCustomers.IsNullOrEmpty()) { _logger.Info("No Event Cusotmer found"); continue; } var customeridNotToParse = eventCustomers.Where(x => x.NoShow || x.LeftWithoutScreeningReasonId.HasValue).Select(x => x.CustomerId); var snapshotFolderPath = Path.Combine(mediaLocation.PhysicalPath, eawvHraResult.Name, hraResultEvent.EventId.ToString(), HraFolderSnapshot); var preventionFolderPlan = Path.Combine(mediaLocation.PhysicalPath, eawvHraResult.Name, hraResultEvent.EventId.ToString(), HraFolderPreventionPlan); var resultReportFolderPath = Path.Combine(mediaLocation.PhysicalPath, eawvHraResult.Name, hraResultEvent.EventId.ToString(), HraFolderResultReport); var snapShotCustomerIds = (hraResultEvent.Snapshot != null && !hraResultEvent.Snapshot.CustomerId.IsNullOrEmpty()) ? hraResultEvent.Snapshot.CustomerId.Where(c => !customeridNotToParse.Contains(c)).Select(c => c).Distinct() : new List <long>(); var preventionPlanCustomerIds = (hraResultEvent.PreventionPlan != null && !hraResultEvent.PreventionPlan.CustomerId.IsNullOrEmpty()) ? hraResultEvent.PreventionPlan.CustomerId.Where(c => !customeridNotToParse.Contains(c)).Select(c => c).Distinct() : new List <long>(); var resultReportCustomerIds = (hraResultEvent.ResultReport != null && !hraResultEvent.ResultReport.CustomerId.IsNullOrEmpty()) ? hraResultEvent.ResultReport.CustomerId.Where(c => !customeridNotToParse.Contains(c)).Select(c => c).Distinct() : new List <long>(); _logger.Info(string.Format("============================Reading Snapshot for Tag:{0} EventId {1}=================================", eawvHraResult.Name, hraResultEvent.EventId)); _logger.Info(string.Format("snapshot folder Path: {0}", snapshotFolderPath)); var customerTestNotPurchased = new List <long>(); if (Directory.Exists(snapshotFolderPath)) { _logger.Info("Count: " + snapShotCustomerIds.Count()); foreach (var customerId in snapShotCustomerIds) { var snapShotFilePath = Path.Combine(snapshotFolderPath, customerId + ".pdf"); if (!File.Exists(snapShotFilePath)) { _logger.Info("SnapShot File does not exist at following location: " + snapShotFilePath); continue; } _logger.Info("SnapShot File exists at location: " + snapShotFilePath); var isEAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(hraResultEvent.EventId, customerId, (long)TestType.eAWV); if (!isEAwvTestPurchasedByCustomer) { customerTestNotPurchased.Add(customerId); _logger.Info("EAWV : EAWV tests is not availed by CustomerId [" + customerId + "].\n"); continue; } try { var mediaFiles = new List <ResultMedia>(); string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, hraResultEvent.EventId).PhysicalPath; _logger.Info("Get Snapshot Media"); var snapShotResultMedia = GetMediaFromPdfFile(snapShotFilePath, folderToSavePdf, TestType.eAWV, AwvFileTypes.SnapShot); if (snapShotResultMedia != null) { _logger.Info("Inside SpanShot Result Media"); snapShotResultMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(snapShotResultMedia); if (preventionPlanCustomerIds.Any(c => c == customerId)) { var preventionPlanFile = Path.Combine(preventionFolderPlan, customerId + ".pdf"); if (File.Exists(preventionPlanFile)) { var preventionPlanMedia = GetMediaFromPdfFile(preventionPlanFile, folderToSavePdf, TestType.eAWV, AwvFileTypes.PreventionPlan); if (preventionFolderPlan != null) { preventionPlanMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(preventionPlanMedia); preventionPlanCustomerIds = preventionPlanCustomerIds.Where(c => c != customerId).ToList(); } } else { _logger.Info( "Prevention Plan File does not exist at following location: " + preventionPlanFile); } } if (resultReportCustomerIds.Any(c => c == customerId)) { var resultReportFile = Path.Combine(resultReportFolderPath, customerId + ".pdf"); if (File.Exists(resultReportFile)) { var resultExportMedia = GetMediaFromPdfFile(resultReportFile, folderToSavePdf, TestType.eAWV, AwvFileTypes.ResultExport); if (resultExportMedia != null) { resultExportMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(resultExportMedia); resultReportCustomerIds = resultReportCustomerIds.Where(c => c != customerId).ToList(); } } else { _logger.Info( "Result Report File does not exist at following location: " + resultReportFile); } } var testResult = new EAwvTestResult { ResultImages = mediaFiles }; _logger.Info("Inside SnapShot for adding Customer Aggregate"); _resultParserHelper.AddTestResulttoEventCustomerAggregate( eventCustomerAggregates, hraResultEvent.EventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } else { _logger.Info("SpanShot Result Media Not Found"); } } catch (Exception ex) { _logger.Error("EAwv HRA: System Failure! Message: " + ex.Message + "\n\t Stack Trace: " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } } } else { _logger.Info("Snapshot Directory does not exit for EventId " + hraResultEvent.EventId); _logger.Info("Snapshot Directory Path " + hraResultEvent.EventId); } _logger.Info(string.Format("============================Reading Prevention Plan for Tag:{0} EventId {1}=================================", eawvHraResult.Name, hraResultEvent.EventId)); _logger.Info(string.Format("Prevention Plan folder Path: {0}", preventionFolderPlan)); if (Directory.Exists(preventionFolderPlan)) { foreach (var customerId in preventionPlanCustomerIds) { var preventionFilePath = Path.Combine(preventionFolderPlan, customerId + ".pdf"); if (!File.Exists(preventionFilePath)) { _logger.Info("Prevention Plan File does not exist at following location: " + preventionFilePath); continue; } var isEAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(hraResultEvent.EventId, customerId, (long)TestType.eAWV); if (!isEAwvTestPurchasedByCustomer) { customerTestNotPurchased.Add(customerId); _logger.Info("EAWV : EAWV tests is not availed by CustomerId [" + customerId + "].\n"); continue; } try { var mediaFiles = new List <ResultMedia>(); string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, hraResultEvent.EventId).PhysicalPath; var preventionPlanResultMedia = GetMediaFromPdfFile(preventionFilePath, folderToSavePdf, TestType.eAWV, AwvFileTypes.PreventionPlan); if (preventionPlanResultMedia != null) { preventionPlanResultMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(preventionPlanResultMedia); if (resultReportCustomerIds.Any(c => c == customerId)) { var resultReportFile = Path.Combine(resultReportFolderPath, customerId + ".pdf"); if (File.Exists(resultReportFile)) { var resultExportaMedia = GetMediaFromPdfFile(resultReportFile, folderToSavePdf, TestType.eAWV, AwvFileTypes.ResultExport); if (resultExportaMedia != null) { resultExportaMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(resultExportaMedia); resultReportCustomerIds = resultReportCustomerIds.Where(c => c != customerId).ToList(); } } else { _logger.Info("Result Report File does not exist at following location: " + resultReportFile); } } var testResult = new EAwvTestResult { ResultImages = mediaFiles }; _logger.Info("Inside PreventionPLan for adding Customer Aggregate"); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, hraResultEvent.EventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } } catch (Exception ex) { _logger.Error("EAwv HRA: System Failure! Message: " + ex.Message + "\n\t Stack Trace: " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } } } else { _logger.Info("Prevention Plan Directory does not exit for EventId " + hraResultEvent.EventId); _logger.Info("Prevention Plan Directory Path " + hraResultEvent.EventId); } _logger.Info(string.Format("============================Reading Result Report for Tag:{0} EventId {1}=================================", eawvHraResult.Name, hraResultEvent.EventId)); _logger.Info(string.Format("Result Report folder Path: {0}", resultReportFolderPath)); if (Directory.Exists(resultReportFolderPath)) { foreach (var customerId in resultReportCustomerIds) { var resultReportFilePath = Path.Combine(resultReportFolderPath, customerId + ".pdf"); if (!File.Exists(resultReportFilePath)) { _logger.Info("Result Report File does not exist at following location: " + resultReportFilePath); continue; } var isEAwvTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(hraResultEvent.EventId, customerId, (long)TestType.eAWV); if (!isEAwvTestPurchasedByCustomer) { customerTestNotPurchased.Add(customerId); _logger.Info("EAWV : EAWV tests is not availed by CustomerId [" + customerId + "].\n"); continue; } try { var mediaFiles = new List <ResultMedia>(); string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, hraResultEvent.EventId).PhysicalPath; var resultExportMedia = GetMediaFromPdfFile(resultReportFilePath, folderToSavePdf, TestType.eAWV, AwvFileTypes.ResultExport); if (resultExportMedia != null) { resultExportMedia.ReadingSource = ReadingSource.Automatic; mediaFiles.Add(resultExportMedia); var testResult = new EAwvTestResult { ResultImages = mediaFiles }; _logger.Info("Inside Result Report for adding Customer Aggregate"); _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, hraResultEvent.EventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } } catch (Exception ex) { _logger.Error("EAwv HRA: System Failure! Message: " + ex.Message + "\n\t Stack Trace: " + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.eAWV, customerId, MedicalEquipmentTag.HRA); } } } else { _logger.Info("Result Report Directory does not exit for EventId " + hraResultEvent.EventId); _logger.Info("Result Report Directory Path " + hraResultEvent.EventId); } if (!customerTestNotPurchased.IsNullOrEmpty()) { eawvTestNotPurchsed.Events.Add(new HraResultEvent { EventId = hraResultEvent.EventId, PreventionPlan = new HraResultPreventionPlan { CustomerId = customerTestNotPurchased.ToList() }, Snapshot = new HraResultSnapshot { CustomerId = customerTestNotPurchased.ToList() }, ResultReport = new HraResultReport() { CustomerId = customerTestNotPurchased.ToList() } }); } } if (!eawvTestNotPurchsed.Events.IsNullOrEmpty()) { _eawvHraSerializer.SerializeandSave(Path.Combine(mediaLocation.PhysicalPath, "customerNotPurchaseTest_" + DateTime.Now.ToFileTime() + ".xml"), eawvTestNotPurchsed); } try { var archiveFileName = Path.Combine(mediaArchiveLocation.PhysicalPath, Path.GetFileName(xmlfile)); if (File.Exists(archiveFileName)) { File.Delete(archiveFileName); } File.Move(xmlfile, archiveFileName); } catch (Exception ex) { _logger.Error("Error while moving XML File in Archive folder"); _logger.Info(string.Format("Message: {0}", ex.Message)); _logger.Info(string.Format("stackTrace: {0}", ex.StackTrace)); } } } catch (Exception ex) { _logger.Error("Some Error occurred while parsing Eawv Result"); _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } _logger.Info("EAWVParser eventCustomerAggregates count " + eventCustomerAggregates.Count); return(eventCustomerAggregates); }
private void GetDataImportedtoSystem(long customerId, IEnumerable <string> allImageFiles, IEnumerable <string> allXmlFiles) { bool strokeFound = false; bool aaaFound = false; var aaaPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AAA); var strokePurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Stroke); var mediaLocation = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var aaaTestResult = new AAATestResult { ResultImages = new List <ResultMedia>() }; var strokeTestResult = new StrokeTestResult { ResultImages = new List <ResultMedia>() }; foreach (var imageFile in allImageFiles) { var fileName = Path.GetFileNameWithoutExtension(imageFile); string imageType = string.Empty; string xmlFile = ""; if (allXmlFiles.Count() == 0) { if (strokePurchased) { imageType = StrokeImageIdentifier; } else if (aaaPurchased) { imageType = AaaImageIdentifier; } } else { var startIndex = fileName.IndexOf("["); var endIndex = fileName.IndexOf("]"); if (startIndex < 0 || endIndex < 0) { continue; } var identifier = fileName.Substring(startIndex + 1, endIndex - (startIndex + 1)).ToLower(); xmlFile = allXmlFiles.Where(f => Path.GetFileNameWithoutExtension(f).ToLower().Contains(identifier)).SingleOrDefault(); if (string.IsNullOrEmpty(xmlFile)) { continue; } imageType = GetImageTypefromXmlFile(xmlFile); } if (string.IsNullOrEmpty(imageType)) { continue; } imageType = imageType.ToLower(); if (imageType == AaaImageIdentifier) { aaaFound = true; if (!aaaPurchased) { continue; } var resultMedia = _mediaHelper.GetfromImageFile(new FileInfo(imageFile), "Aaa", mediaLocation); aaaTestResult.ResultImages.Add(resultMedia); } else if (imageType == StrokeImageIdentifier) { strokeFound = true; if (!strokePurchased) { continue; } var resultMedia = _mediaHelper.GetfromImageFile(new FileInfo(imageFile), "Stroke", mediaLocation); strokeTestResult.ResultImages.Add(resultMedia); } else { _logger.Info(string.Format("Invalid Image Identifier = [{0}] from XML = [{1}].", imageType, xmlFile)); } } if (!aaaPurchased && aaaFound) { _logger.Info(string.Format("AAA not purchased by Customer [{0}], but files are found.", customerId)); } else if (aaaPurchased && aaaFound) { _resultParserHelper.AddTestResulttoEventCustomerAggregate(_eventCustomerScreeningAggregates, _eventId, customerId, aaaTestResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.AAA, customerId, MedicalEquipmentTag.UltrasoundTransducer); } else if (aaaPurchased) { _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.AAA, customerId, MedicalEquipmentTag.UltrasoundTransducer, false); } if (!strokePurchased && strokeFound) { _logger.Info(string.Format("Stroke not purchased by Customer [{0}], but files are found.", customerId)); } else if (strokePurchased && strokeFound) { _resultParserHelper.AddTestResulttoEventCustomerAggregate(_eventCustomerScreeningAggregates, _eventId, customerId, strokeTestResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.Stroke, customerId, MedicalEquipmentTag.UltrasoundTransducer); } else if (strokePurchased) { _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.Stroke, customerId, MedicalEquipmentTag.UltrasoundTransducer, false); } }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var pdfResults = DirectoryOperationsHelper.GetFiles(_labReportOutputPath, "*.pdf"); var rawTxtFile = DirectoryOperationsHelper.GetFiles(_labReportOutputPath, "*.txt"); DataTable dtRawDataTable = new DataTable(); if (rawTxtFile != null && rawTxtFile.Count() > 0) { _loggerForClient.Info("Total " + rawTxtFile.Count() + " Text File found."); foreach (var file in rawTxtFile) { string txtFilename = new FileInfo(file).Name; try { dtRawDataTable = GetRecordsFromTextFile(file, txtFilename, dtRawDataTable); } catch (Exception ex) { _loggerForClient.Info("File name :" + txtFilename + " is blank. Exception :" + ex.Message); MovedParsedFile(file); } } if (dtRawDataTable != null) { _loggerForClient.Info("Total " + dtRawDataTable.Rows.Count() + " records found from all text file "); } } else { _loggerForClient.Info("There is not any text file availble"); } var standardFinding = _standardFindingRepository.GetAllStandardFindings <decimal?>((int)TestType.IFOBT); if (pdfResults != null && pdfResults.Any()) { _loggerForClient.Info("Number of Files to be Parse : " + pdfResults.Count()); foreach (var filePath in pdfResults) { string errorMessage = string.Empty; long customerId = 0; long eventId = 0; TestType testTypeId; var fileName = Path.GetFileNameWithoutExtension(filePath); var extension = Path.GetExtension(filePath); if (extension != ".pdf") { errorMessage = "file with pdf extension supported only"; _loggerForClient.Error(errorMessage); MovedParsedFile(filePath); continue; } _loggerForClient.Info("=============== Parsing Started for file: " + fileName + " ================="); _loggerForClient.Info("Parsing Started for File: " + fileName); if (!ParseValidationCheck(fileName, filePath, out eventId, out customerId, out testTypeId)) { continue; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, testTypeId); MovedParsedFile(filePath); if (resultMedia != null && testTypeId == TestType.IFOBT) { var finding = new StandardFinding <int>(); finding = GetIFOBTFinding(dtRawDataTable, eventId, customerId, testTypeId, fileName, standardFinding); resultMedia.ReadingSource = ReadingSource.Automatic; TestResult testResult = new IFOBTTestResult { ResultImage = resultMedia, Finding = finding }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.IFOBT, customerId, MedicalEquipmentTag.LabReportParser); _labParseEventLogger.Info(string.Concat("\nPDF Filename(" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", TestType.IFOBT, "\n")); _loggerForClient.Info(string.Concat("\nPDF Filename (" + fileName + "): parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " ,TestType :", TestType.IFOBT, "\n")); } else if (resultMedia != null && testTypeId == TestType.UrineMicroalbumin) { ResultReading <string> microAlbuminValue = new ResultReading <string>(); microAlbuminValue = GetUrineMicroAlbuminValue(dtRawDataTable, eventId, customerId, testTypeId, fileName); resultMedia.ReadingSource = ReadingSource.Automatic; TestResult testResult = new UrineMicroalbuminTestResult { ResultImage = resultMedia, MicroalbuminValue = microAlbuminValue }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.UrineMicroalbumin, customerId, MedicalEquipmentTag.LabReportParser); _labParseEventLogger.Info(string.Concat("\nFilename(" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", TestType.UrineMicroalbumin, "\n")); _loggerForClient.Info(string.Concat("\nFilename (" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " ,TestType :", TestType.UrineMicroalbumin, "\n")); } else { var message = string.Concat("\nFilename(" + fileName + "): Test(" + testTypeId + ") is an invalid test for parsing for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", testTypeId, "\n"); _labParseEventLogger.Info(message); _loggerForClient.Info(message); } } catch (Exception ex) { errorMessage = " System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace; _labParseEventLogger.Error(errorMessage); _loggerForClient.Error("Parsing failed for filename :" + fileName + ".Please contact to Administrator."); MovedParsedFile(filePath); _resultParserHelper.AddResultArchiveLog(ex.Message, testTypeId, customerId, MedicalEquipmentTag.LabReportParser, false); } } } if (dtRawDataTable != null && dtRawDataTable.Columns.Count() > 0 && dtRawDataTable.Rows.Count > 0) { var rows = dtRawDataTable.Select("IsParse=false"); if (rows != null && rows.Any()) { dtRawDataTable = rows.CopyToDataTable(); if (dtRawDataTable.Rows.Count > 0) { eventCustomerAggregates = SaveResultWithoutMedia(eventCustomerAggregates, dtRawDataTable, standardFinding); } } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath) && string.IsNullOrEmpty(directoryPath)) { return(null); } List <string> pdfFiles = null; if (!string.IsNullOrEmpty(directoryPath)) { pdfFiles = GetPdfFiles(directoryPath); } if (pdfFiles != null && pdfFiles.Any()) { _logger.Info("Number of Files to Parse : " + pdfFiles.Count()); foreach (var filePath in pdfFiles) { var fileNameWithExtention = Path.GetFileName(filePath); if (!string.IsNullOrEmpty(fileNameWithExtention)) { fileNameWithExtention = fileNameWithExtention.ToLower(); } var fileName = Path.GetFileNameWithoutExtension(filePath); if (!string.IsNullOrEmpty(fileName)) { fileName = fileName.ToLower(); } long customerId = 0; long eventId = 0; string errorMessage = string.Empty; _logger.Info("=============== Parsing Started for file: " + fileName + " ================="); try { var temp = fileName.Substring(fileName.IndexOf("_mrn_") + 5); var customerIdString = temp.Substring(0, temp.IndexOf("_")); if (!long.TryParse(customerIdString, out customerId)) { errorMessage = "Diabetic Retinopathy: CustomerId not found on Pdf file" + filePath; _logger.Info(errorMessage); SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage); continue; } } catch (Exception) { errorMessage = "File name is not in correct formate. "; _logger.Error(errorMessage); SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage); continue; } try { eventId = _eventCustomerRepository.GetEventIdAttendedByCustomerForTest(customerId, (long)TestType.DiabeticRetinopathy, _settings.DiabeticRetinopathyNoOfDaysToCheckForEvent); if (eventId <= 0) { errorMessage = string.Format("Diabetic Retinopathy: No Event attended by customer {0} in last {1} days.", customerId, _settings.DiabeticRetinopathyNoOfDaysToCheckForEvent); _logger.Info(errorMessage); SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage); continue; } } catch (Exception ex) { errorMessage = "Diabetic Retinopathy: CustomerId [" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace; _logger.Info(errorMessage); SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage); continue; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, TestType.DiabeticRetinopathy); if (resultMedia != null) { TestResult testResult = new DiabeticRetinopathyTestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.DiabeticRetinopathy, customerId, MedicalEquipmentTag.Vatica); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { errorMessage = "Diabetic Retinopathy: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace; _logger.Error(errorMessage); SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.DiabeticRetinopathy, customerId, MedicalEquipmentTag.Vatica, false); } _logger.Info("=============== Parsing Ended for file: " + fileName + " ================="); } } return(eventCustomerAggregates); }
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); }
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)) { if (Path.GetExtension(filePath).ToLower().Contains("pdf")) { var fileName = Path.GetFileName(filePath); var 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; } try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.PulmonaryFunction); if (!isTestPurchasedByCustomer) { _logger.Info("Pulmonary is not availed by CustomerId[" + customerId + "].\n"); continue; } } catch (Exception ex) { _logger.Info("Pulmonary is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } try { string folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = _mediaHelper.GetMediaFromPdfFile(filePath, folderToSaveImage, TestType.PulmonaryFunction.ToString()); if (resultMedia != null) { var testResult = new PulmonaryFunctionTestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.EKG, customerId, MedicalEquipmentTag.PulmonaryMachine); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.EKG, customerId, MedicalEquipmentTag.PulmonaryMachine, 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 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); }