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); } }
public IEnumerable <TestResult> Parse(DataRow dr) { SaveBasicBiometric(dr); var asiTestResult = (ASITestResult)_asiTestRepository.GetTestResults(_customerId, _eventId, _isNewResultFlow); if (asiTestResult == null && _testResultService.IsTestPurchasedByCustomer(_eventId, _customerId, (long)TestType.ASI)) { asiTestResult = new ASITestResult(); } if (asiTestResult == null) { return(null); } var pressureReadings = GetBpValues(dr); if (pressureReadings == null) { return(null); } var testResults = new List <TestResult>(); asiTestResult.PressureReadings = SynchronizeBpValues(pressureReadings, asiTestResult.PressureReadings); testResults.Add(asiTestResult); return(testResults); }
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 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 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 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); } 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); } 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 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 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); }
private void SaveTestResults(KynHealthAssessmentEditModel model, long uploadedby) { TestResultRepository testResultRepository; var customerId = model.CustomerId; var eventId = model.EventId; var isNewResultFlow = _eventRepository.IsEventHasNewResultFlow(eventId); var service = new Service.TestResultService(); var eventCustomerResultId = SaveEventCustomerResult(eventId, customerId, uploadedby); //basic biometric var eventCustomer = _eventCustomerRepository.Get(eventId, customerId); var basicBiometric = _basicBiometricRepository.Get(eventId, customerId); basicBiometric = _kynHealthAssessmentFactory.GetBasicTestResultBiometricDomain(model, basicBiometric, uploadedby); if (basicBiometric != null) { basicBiometric.Id = eventCustomer.Id; ((IRepository <BasicBiometric>)_basicBiometricRepository).Save(basicBiometric); } long[] kynTestIds = { (long)TestType.Kyn, (long)TestType.HKYN, (long)TestType.MyBioCheckAssessment }; var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, kynTestIds); //Kyn Test Result var isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Kyn); var isKynPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.HKYN); var isMyBioCheckPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment); if (isPurchased) { var kynTest = eventTests.First(x => x.TestId == (int)TestType.Kyn).Test; SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.Kyn, kynTest.IsRecordable, isNewResultFlow); } else if (isKynPurchased) { var hKynTest = eventTests.First(x => x.TestId == (int)TestType.HKYN).Test; SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.HKYN, hKynTest.IsRecordable, isNewResultFlow); } else if (isMyBioCheckPurchased) { var mybioCheckAssessment = eventTests.First(x => x.TestId == (int)TestType.MyBioCheckAssessment).Test; SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.MyBioCheckAssessment, mybioCheckAssessment.IsRecordable, isNewResultFlow); } //lipidTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Lipid); if (isPurchased) { testResultRepository = new LipidTestRepository(ReadingSource.Manual); var lipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); lipidTestresult = _kynHealthAssessmentFactory.GetLipidTestResultDomain(model, lipidTestresult as LipidTestResult, uploadedby, isNewResultFlow); if (lipidTestresult != null) { testResultRepository.SaveTestResults(lipidTestresult, customerId, eventId, uploadedby); } } //AwvLipidTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvLipid); if (isPurchased) { testResultRepository = new AwvLipidTestRepository(ReadingSource.Manual); var awvLipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); awvLipidTestresult = _kynHealthAssessmentFactory.GetAwvLipidTestResultDomain(model, awvLipidTestresult as AwvLipidTestResult, uploadedby, isNewResultFlow); if (awvLipidTestresult != null) { testResultRepository.SaveTestResults(awvLipidTestresult, customerId, eventId, uploadedby); } } //AwvGlucoseTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvGlucose); if (isPurchased) { testResultRepository = new AwvGlucoseTestRepository(ReadingSource.Manual); var awvGlucoseTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); awvGlucoseTestresult = _kynHealthAssessmentFactory.GetAwvGlucoseTestResultDomain(model, awvGlucoseTestresult as AwvGlucoseTestResult, uploadedby, isNewResultFlow); if (awvGlucoseTestresult != null) { testResultRepository.SaveTestResults(awvGlucoseTestresult, customerId, eventId, uploadedby); } } //AwvLipidTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Cholesterol); if (isPurchased) { testResultRepository = new CholesterolTestRepository(ReadingSource.Manual); var cholesterolTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); cholesterolTestresult = _kynHealthAssessmentFactory.GetCholesterolTestResultDomain(model, cholesterolTestresult as CholesterolTestResult, uploadedby, isNewResultFlow); if (cholesterolTestresult != null) { testResultRepository.SaveTestResults(cholesterolTestresult, customerId, eventId, uploadedby); } } //AwvGlucoseTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Diabetes); if (isPurchased) { testResultRepository = new DiabetesTestRepository(ReadingSource.Manual); var diabetesTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); diabetesTestresult = _kynHealthAssessmentFactory.GetDiabetesTestResultDomain(model, diabetesTestresult as DiabetesTestResult, uploadedby, isNewResultFlow); if (diabetesTestresult != null) { testResultRepository.SaveTestResults(diabetesTestresult, customerId, eventId, uploadedby); } } //Hypertension Test Result isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Hypertension); if (isPurchased) { testResultRepository = new HypertensionTestRepository(ReadingSource.Manual); var hypertensionTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); hypertensionTestresult = _kynHealthAssessmentFactory.GetHypertensionTestResultDomain(model, hypertensionTestresult as HypertensionTestResult, uploadedby, isNewResultFlow); if (hypertensionTestresult != null) { testResultRepository.SaveTestResults(hypertensionTestresult, customerId, eventId, uploadedby); } } isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.A1C); if (isPurchased) { testResultRepository = new HemaglobinTestRepository(ReadingSource.Manual); var hemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); hemaglobinTestResult = _kynHealthAssessmentFactory.GetHemaglobinA1CTestResultDomain(model, hemaglobinTestResult as HemaglobinA1CTestResult, uploadedby, isNewResultFlow); if (hemaglobinTestResult != null) { testResultRepository.SaveTestResults(hemaglobinTestResult, customerId, eventId, uploadedby); } } isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvHBA1C); if (isPurchased) { testResultRepository = new AwvHemaglobinTestRepository(ReadingSource.Manual); var awvHemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); awvHemaglobinTestResult = _kynHealthAssessmentFactory.GetAwvHemaglobinTestResultDomain(model, awvHemaglobinTestResult as AwvHemaglobinTestResult, uploadedby, isNewResultFlow); if (awvHemaglobinTestResult != null) { testResultRepository.SaveTestResults(awvHemaglobinTestResult, customerId, eventId, uploadedby); } } //MyBioCheckTestresult isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment); if (isPurchased) { testResultRepository = new MyBioAssessmentTestRepository(ReadingSource.Manual); var myBioAssessmentTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow); myBioAssessmentTestResult = _kynHealthAssessmentFactory.GetMyBioCheckAssessmentTestResultDomain(model, myBioAssessmentTestResult as MyBioAssessmentTestResult, uploadedby, isNewResultFlow); if (myBioAssessmentTestResult != null) { testResultRepository.SaveTestResults(myBioAssessmentTestResult, customerId, eventId, uploadedby); } } }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_microalbuminResultOutputPath); if (string.IsNullOrEmpty(directoryPath) && string.IsNullOrEmpty(directoryPath)) { return(null); } List <string> pdfFiles = null; if (!string.IsNullOrEmpty(directoryPath)) { pdfFiles = GetPdfFiles(directoryPath); } var eventList = DirectoryOperationsHelper.GetDirectories(directoryPath); if (eventList != null && eventList.Any()) { _logger.Info("Number of Events : " + eventList.Count()); foreach (var events in eventList) { long customerId = 0; long eventId = 0; string errorMessage = string.Empty; if (!long.TryParse(events, out eventId)) { _logger.Info("Event Id not found : " + events); continue; } List <string> pdfResults = null; var eventFolder = Path.Combine(directoryPath, events); if (!string.IsNullOrEmpty(eventFolder)) { pdfResults = GetPdfFiles(eventFolder); if (pdfResults != null && pdfResults.Any()) { _logger.Info("Number of Files to Parse : " + pdfFiles.Count() + " Event Id is :" + events); foreach (var filePath in pdfResults) { var fileNameWithExtention = Path.GetFileName(filePath); if (!string.IsNullOrEmpty(fileNameWithExtention)) { fileNameWithExtention = fileNameWithExtention.ToLower(); } var fileName = Path.GetFileNameWithoutExtension(filePath); if (!string.IsNullOrEmpty(fileName)) { fileName = fileName.ToLower(); } _logger.Info("=============== Parsing Started for file: " + fileName + " ================="); TestType testTypeId; string testName = ""; try { var temp = fileName.Split('_'); var memberIdString = temp[0]; testName = Convert.ToString(temp[1]); testTypeId = ((TestType)Enum.Parse(typeof(TestType), testName)); IEnumerable <long> customerIds = _customerRepository.GetCustomerIdByInsuranceId(memberIdString); if (!customerIds.IsNullOrEmpty()) { errorMessage = "Invalid member Id: " + memberIdString + " File Path" + filePath; _logger.Info(errorMessage); continue; } var eventCustomers = _eventCustomerRepository.GetbyEventId(eventId); eventCustomers = eventCustomers.Where(x => customerIds.Contains(x.CustomerId) && x.AppointmentId.HasValue); if (eventCustomers.IsNullOrEmpty()) { errorMessage = "customer has not been booked for event with member Id: " + memberIdString + " EventId : " + eventId; _logger.Info(errorMessage); continue; } if (eventCustomers.Count() > 1) { errorMessage = "more than one customer has been booked for event with member Id: " + memberIdString + " EventId : " + eventId; _logger.Info(errorMessage); continue; } customerId = eventCustomers.First().CustomerId; } catch (Exception) { errorMessage = "File name is not in correct format. "; _logger.Error(errorMessage); continue; } var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)testTypeId); if (!isTestPurchased) { errorMessage = string.Format("Customer Id :" + customerId + " Test: " + testName + " not purchased "); _logger.Info(errorMessage); continue; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, testTypeId); MovedParsedFile(filePath, eventId); //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 = " System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace; _logger.Error(errorMessage); // _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.DiabeticRetinopathy, customerId, MedicalEquipmentTag.Vatica, false); } } } } } } return(eventCustomerAggregates); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); _resultArchiveLogs = new List <ResultArchiveLog>(); var folderPath = GetFolderPathfor(_geDirectoryPath); if (!string.IsNullOrEmpty(folderPath)) { ExtractDicomFiles(folderPath); foreach (var filePath in Directory.GetFiles(folderPath)) { if (!Path.GetExtension(filePath).ToLower().Contains("xls")) { continue; } var fileName = Path.GetFileName(filePath); DataSet dataset = null; try { dataset = _excelReader.ReadfromExcelintoDataset(filePath); } catch { try { dataset = ParseCsvintoDatatable(filePath); } catch { _logger.Error("\nNot Able to parse File : " + filePath); } } if (dataset == null || dataset.Tables.Count < 1) { continue; } var dataTable = dataset.Tables[0]; if (!CheckifDatatableContainsRequiredColumns(dataTable)) { _logger.Info("\nColumns to Identify CustomerId and Test Type are missing in File: " + fileName); continue; } if (dataTable.Rows.Count < 1) { _logger.Info("\nNo Rows found in the File : " + fileName); continue; } long customerId; TestType testType; GetCustomerIdandTestTypeFromDataTable(dataTable, out customerId, out testType); if (customerId < 1) { _logger.Info("\nNo Valid Customer Id found in File : " + fileName); continue; } if ((int)testType < 1) { _logger.Info("\nNo Test Identifier found in File : " + fileName); continue; } try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)testType); if (!isTestPurchasedByCustomer) { _logger.Info(testType + " is not availed by CustomerId[" + customerId + "].\n"); continue; } } catch (Exception ex) { _logger.Error(testType + " is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace); continue; } GetTestResultsforgivenCustomer(customerId, folderPath, testType, dataTable, eventCustomerAggregates); } AddTestResultsfortheCustomerMissingReadingFile(folderPath, eventCustomerAggregates); } 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); } }
private bool ParseValidationCheck(string fileName, string filePath, out long eventId, out long customerId, out TestType testTypeId) { EventCustomer eventCustomer = null; string errorMessage = string.Empty; string testName = string.Empty; eventId = 0; customerId = 0; testTypeId = 0; try { var temp = fileName.Split('_'); if (temp.Length < 3) { _loggerForClient.Info("Incorrect format Name formate for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } var customerIdString = temp[0]; var eventIdString = temp[1]; testName = Convert.ToString(temp[2]); if (!long.TryParse(eventIdString, out eventId)) { _loggerForClient.Info("Incorrect format of Event Id : " + eventIdString + " for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } if (eventId <= 0) { _loggerForClient.Info("Incorrect Event Id : " + customerIdString + " for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } string labParseLogger = "LabParseLogger_" + eventIdString; _labParseEventLogger = _logManager.GetLogger(labParseLogger); if (!Enum.TryParse(testName, true, out testTypeId)) { errorMessage = "Test Name incorrect :" + testName + " for pdf filename (" + fileName + ")."; _labParseEventLogger.Error(errorMessage); _loggerForClient.Info("Test Name incorrect :" + testName + " for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } if (!long.TryParse(customerIdString, out customerId)) { _labParseEventLogger.Info("Incorrect format of Customer Id : " + customerIdString + " for pdf filename (" + fileName + ")."); _loggerForClient.Info("Incorrect format of Customer Id : " + customerIdString + " for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } if (customerId <= 0) { _labParseEventLogger.Info("Incorrect Customer Id : " + customerIdString + " for pdf filename (" + fileName + ")."); _loggerForClient.Info("Incorrect Customer Id : " + customerIdString + " for pdf filename (" + fileName + ")."); MovedParsedFile(filePath); return(false); } eventCustomer = _eventCustomerRepository.Get(eventId, customerId); if (eventCustomer == null) { var message = "customer : " + customerId + " has not been " + eventId + " booked appointment for pdf filename (" + fileName + ")."; _labParseEventLogger.Info(message); _loggerForClient.Info(message); MovedParsedFile(filePath); return(false); } if (eventCustomer.AppointmentId.HasValue == false) { errorMessage = "customer appointment has been canceled Customer Id: " + customerId + ", EventId : " + eventId + " for pdf filename (" + fileName + ")."; _labParseEventLogger.Info(errorMessage); _loggerForClient.Info(errorMessage); MovedParsedFile(filePath); return(false); } if (eventCustomer.NoShow == true) { errorMessage = "customer has been marked as No Show Customer Id: " + customerId + ", EventId : " + eventId + " for pdf filename (" + fileName + ")."; _labParseEventLogger.Info(errorMessage); _loggerForClient.Info(errorMessage); MovedParsedFile(filePath); return(false); } if (eventCustomer.LeftWithoutScreeningReasonId.HasValue) { errorMessage = "customer has been marked as Left without screening Id: " + customerId + ", EventId : " + eventId + " for pdf filename (" + fileName + ")."; _labParseEventLogger.Info(errorMessage); _loggerForClient.Info(errorMessage); MovedParsedFile(filePath); return(false); } } catch (Exception ex) { errorMessage = "PDF File name (" + fileName + ") is incorrect format. Exception is :" + ex.Message; _labParseEventLogger.Error(errorMessage); _loggerForClient.Info("PDF File name: " + fileName + " is incorrect format."); MovedParsedFile(filePath); return(false); } var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventCustomer.Id, (long)testTypeId); if (!isTestPurchased) { errorMessage = string.Format("Customer Id :" + customerId + " Test: " + testName + " not purchased for event Id :" + eventId + " and pdf filename (" + fileName + ")"); _labParseEventLogger.Info(errorMessage); _loggerForClient.Info("Customer Id :" + customerId + " is not purchased test (" + testName + ") for event Id: " + eventId + " and pdf filename (" + fileName + ")"); MovedParsedFile(filePath); return(false); } return(true); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); _resultArchiveLogs = new List <ResultArchiveLog>(); var filePath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(filePath)) { return(null); } var dtBloodworks = ParseCsvintoDatatable(filePath); var isColumnsForLipidValid = BloodworksLipidParser.IsDatatableConversionfromCsvValid(dtBloodworks); if (!dtBloodworks.Columns.Contains(ColumnforCustomerId) || !isColumnsForLipidValid) { _logger.Error("Bloodworks File provided is an Invalid File!"); return(null); } foreach (DataRow dr in dtBloodworks.Rows) { long customerId = 0; if (dr[ColumnforCustomerId] != null && dr[ColumnforCustomerId] != DBNull.Value && !string.IsNullOrEmpty(dr[ColumnforCustomerId].ToString())) { long.TryParse(dr[ColumnforCustomerId].ToString(), out customerId); } if (customerId < 1) { _logger.Error("Customer Id not found in the row number " + (dtBloodworks.Rows.IndexOf(dr) + 1)); continue; } _logger.Info("\n\n ===================> Lipid Parsing for CustomerId : " + customerId + "\n"); try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Lipid); if (!isTestPurchasedByCustomer) { _logger.Info("Lipid is not availed by CustomerId[" + customerId + "].\n"); } else { var testResult = _lipidParser.Parse(dr); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_lipidParser.ErrorSummary, TestType.Lipid, customerId); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); AddResultArchiveLog(ex.Message, TestType.Lipid, customerId, false); } _logger.Info("\n\n ===================> Blood Pressure Parsing for CustomerId : " + customerId + "\n"); try { _bloodPressureSynchronizer = new BloodPressureSynchronizer(_logger, customerId, _eventId, _updatedBy, _isNewResultFlow); var testResults = _bloodPressureSynchronizer.Parse(dr); if (testResults != null) { foreach (var testResult in testResults) { AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_bloodPressureSynchronizer.ErrorSummary, testResult is ASITestResult ? TestType.ASI : TestType.PAD, customerId); } } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); } _logger.Info("\n\n ===================> Hba1c Parsing for CustomerId : " + customerId + "\n"); try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.A1C); if (!isTestPurchasedByCustomer) { _logger.Info("Hba1c is not availed by CustomerId[" + customerId + "]. \n"); } else { var testResult = _hba1CParser.Parse(dr); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_hba1CParser.ErrorSummary, TestType.A1C, customerId); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); AddResultArchiveLog(ex.Message, TestType.A1C, customerId, false); } try { _logger.Info("\n\n ===================> Section for Not Recordable, but Performed Tests - for CustomerId : " + customerId + "\n"); AddTestResultListforOtherRecordables(ColumnforTshPerformed, customerId, TestType.Thyroid, dr, eventCustomerAggregates); AddTestResultListforOtherRecordables(ColumnforPsaPerformed, customerId, TestType.Psa, dr, eventCustomerAggregates); AddTestResultListforOtherRecordables(ColumnforCrpPerformed, customerId, TestType.Crp, dr, eventCustomerAggregates); AddTestResultListforOtherRecordables(ColumnforColorectalPerformed, customerId, TestType.Colorectal, dr, eventCustomerAggregates); AddTestResultListforOtherRecordables(ColumnforKynPerformed, customerId, TestType.Kyn, dr, eventCustomerAggregates); var testResult = GetTestResultforRecordables(customerId, ColumnforEchoNotPerformed, ColumnforEchoNotes, dr, TestType.Echocardiogram); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); testResult = GetTestResultforRecordables(customerId, ColumnforAaaNotPerformed, ColumnforAaaNotes, dr, TestType.AAA); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); testResult = GetTestResultforRecordables(customerId, ColumnforAsiNotPerformed, ColumnforAsiNotes, dr, TestType.ASI); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); testResult = GetTestResultforRecordables(customerId, ColumnforEkgNotPerformed, ColumnforEkgNotes, dr, TestType.EKG); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); testResult = GetTestResultforRecordables(customerId, ColumnforPadNotPerformed, ColumnforPadNotes, dr, TestType.PAD); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); testResult = GetTestResultforRecordables(customerId, ColumnforStrokeNotPerformed, ColumnforStrokeNotes, dr, TestType.Stroke); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); } } 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() { try { DataTable dataTable = null; if (ReadDataFromNewLab) { dataTable = GetDatatableFromCsv(); } else { dataTable = GetDatatableFromExcel(); } if (dataTable == null) { return(null); } foreach (DataRow dr in dataTable.Rows) { long customerId = 0; long eventId = 0; var log = CreateBloodTestResultLog(dr); if (!IsValidEventIdCustomerId(dr, log, ref eventId, ref customerId)) { BloodTestResultParserLogs.Add(log); continue; } bool isMenBloodPanelPurchased = false; bool isWomenBloodPanelPurchased = false; //Men Blood Panel try { _logger.Info(string.Format("Started parsing Men's Blood Panel for CustomerId {0} EventId {1}", customerId, eventId)); isMenBloodPanelPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MenBloodPanel); if (isMenBloodPanelPurchased) { ParseDataForMenBloodPanel(dr, log, customerId, eventId); } else { var message = string.Format("Men's Blood Panel is not availed by Customer Id {0} - EventId {1}", customerId, eventId); _logger.Info(message); } } catch (Exception ex) { var message = "Some exception while parsing Data for Men's Blood Panel. Message: " + ex.Message; AppendTestResultLog(log, message, false); _logger.Error(message + "\t Stack Trace " + ex.StackTrace); } try { _logger.Info(string.Format("Started parsing Women's Blood Panel for CustomerId {0} EventId {1}", customerId, eventId)); isWomenBloodPanelPurchased = _testResultService.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.WomenBloodPanel); if (isWomenBloodPanelPurchased) { ParseDataForWomenBloodPanel(dr, log, customerId, eventId); } else { var message = string.Format("Women's Blood Panel is not availed by Customer Id {0} - EventId {1}", customerId, eventId); _logger.Info(message); } } catch (Exception ex) { var message = "Some exception while parsing Data for Women's Blood Panel. Message: " + ex.Message; AppendTestResultLog(log, message, false); _logger.Error(message + "\t Stack Trace " + ex.StackTrace); } if (!isWomenBloodPanelPurchased) { //TSH try { _logger.Info(string.Format("Started parsing TSH for CustomerId {0} EventId {1}", customerId, eventId)); ParseDataForThyroid(dr, log, customerId, eventId); } catch (Exception ex) { var message = "Some exception while parsing Data for TSH. Message: " + ex.Message; AppendTestResultLog(log, message, false); _logger.Error(message + "\t Stack Trace " + ex.StackTrace); } } if (!isMenBloodPanelPurchased) { //PSA try { _logger.Info(string.Format("Started parsing PSA for CustomerId {0} EventId {1}", customerId, eventId)); ParseDataForPsa(dr, log, customerId, eventId); } catch (Exception ex) { var messsage = "Some exception while parsing Data for PSA. Message: " + ex.Message; _logger.Error(messsage + "\t strack trace : " + ex.StackTrace); AppendTestResultLog(log, messsage, false); } } if (!isMenBloodPanelPurchased && !isWomenBloodPanelPurchased) { //CRP try { _logger.Info(string.Format("Started parsing CRP for CustomerId {0} EventId {1}", customerId, eventId)); ParseDataForCrp(dr, log, customerId, eventId); } catch (Exception ex) { var messsage = "Some exception while parsing Data for CRP. Message: " + ex.Message; _logger.Error(messsage + "\t strack trace : " + ex.StackTrace); AppendTestResultLog(log, messsage, false); } } if (!isMenBloodPanelPurchased) { //Testosterone try { _logger.Info(string.Format("Started parsing Testosterone for CustomerId {0} EventId {1}", customerId, eventId)); ParseDataForTestosterone(dr, log, customerId, eventId); } catch (Exception ex) { var messsage = "Some exception while parsing Data for Testosterone. Message: " + ex.Message; _logger.Error(messsage + "\t strack trace : " + ex.StackTrace); AppendTestResultLog(log, messsage, false); } } if (!isWomenBloodPanelPurchased) { //VitaminD try { _logger.Info(string.Format("Started parsing VitaminD for CustomerId {0} EventId {1}", customerId, eventId)); ParseDataForVitaminD(dr, log, customerId, eventId); } catch (Exception ex) { var message = "Some exception while parsing Data for VitaminD. Message: " + ex.Message; AppendTestResultLog(log, message, false); _logger.Error(message + "\t Stack Trace " + ex.StackTrace); } } BloodTestResultParserLogs.Add(log); } } catch (Exception ex) { _logger.Error("Some error occured while parsing blood test(s). Message:" + ex.Message + "\n" + ex.StackTrace, ex); } return(_eventCustomerScreeningAggregates); }
private void ParseCsv(string csvFilePath, List <EventCustomerScreeningAggregate> eventCustomerAggregates) { var dtCardiovision = ParseCsvintoDatatable(csvFilePath); var isColumnsForPadValid = CardiovisionPadParser.IsDatatableConversionfromCsvValid(dtCardiovision); var isColumnsForAsiValid = CardiovisionAsiParser.IsDatatableConversionfromCsvValid(dtCardiovision); var isColumnsForAwvAbiValid = CardiovisionAwvAbiParser.IsDatatableConversionfromCsvValid(dtCardiovision); if (!dtCardiovision.Columns.Contains(ColumnforCustomerId) || (!isColumnsForAsiValid && !isColumnsForPadValid && !isColumnsForAwvAbiValid)) { _logger.Error("Cardiovision File provided is an Invalid File!"); return; } foreach (DataRow dr in dtCardiovision.Rows) { long customerId = 0; if (dr[ColumnforCustomerId] != null && dr[ColumnforCustomerId] != DBNull.Value && !string.IsNullOrEmpty(dr[ColumnforCustomerId].ToString())) { long.TryParse(dr[ColumnforCustomerId].ToString(), out customerId); } if (customerId < 1) { _logger.Error("Customer Id not found in the row number " + (dtCardiovision.Rows.IndexOf(dr) + 1)); continue; } if (isColumnsForPadValid || isColumnsForAwvAbiValid) { _logger.Info("\n\n ===================> PAD Parsing for CustomerId : " + customerId + "\n"); var isPadTestPurchasedByCustomer = false; try { isPadTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.PAD); var isAwvAbiTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvABI); if (!isPadTestPurchasedByCustomer && !isAwvAbiTestPurchasedByCustomer) { _logger.Info("PAD is not availed by CustomerId[" + customerId + "]. \n"); } else if (isPadTestPurchasedByCustomer) { var testResult = _padParser.Parse(dr); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_padParser.ErrorSummary, TestType.PAD, customerId); } else if (isAwvAbiTestPurchasedByCustomer) { var testResult = _awvAbiParser.Parse(dr); AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_awvAbiParser.ErrorSummary, TestType.AwvABI, customerId); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); AddResultArchiveLog(ex.Message, (isPadTestPurchasedByCustomer ? TestType.PAD : TestType.AwvABI), customerId, false); } } _bloodPressureSynchronizer = new BloodPressureSynchronizer(_logger, customerId, _eventId, 0, _isNewResultFlow); if (isColumnsForAsiValid) { _logger.Info("\n\n ===================> ASI Parsing for CustomerId : " + customerId + "\n"); try { bool isTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.ASI); if (!isTestPurchasedByCustomer) { _logger.Info("ASI is not availed by CustomerId[" + customerId + "]. \n"); } else { var testResult = _asiParser.Parse(dr); var pressureReadings = _bloodPressureSynchronizer.GetReadingsinDb(); if (testResult != null && pressureReadings != null && testResult is ASITestResult) { var asiTestResult = (testResult as ASITestResult); if (asiTestResult.PressureReadings == null) { asiTestResult.PressureReadings = pressureReadings; } } AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, customerId, testResult); AddResultArchiveLog(_asiParser.ErrorSummary, TestType.ASI, customerId); } } catch (Exception ex) { _logger.Error("System Failure! Error: " + ex.Message + "\n\t" + ex.StackTrace); AddResultArchiveLog(ex.Message, TestType.ASI, customerId, false); } } } }
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); }