private bool GetDatafromXml(string filePath, EKGTestResult testResult) { XDocument xDoc = null; try { xDoc = XDocument.Load(filePath); } catch { _logger.Error(string.Format("Exception while loading XML Doc for {0}", filePath)); return(false); } if (testResult == null) { testResult = new EKGTestResult(); } testResult.VentRate = GetIntObject(GetDatafromXmlNode(xDoc, StringForHeartRate), ReadingLabels.VentRate); testResult.PRInterval = GetDecimalObject(GetDatafromXmlNode(xDoc, StringForPrInterval), ReadingLabels.PRInterval); testResult.QRSDuration = GetDecimalObject(GetDatafromXmlNode(xDoc, StringForQrsDuration), ReadingLabels.QRSDuration); testResult.QTInterval = GetDecimalObject(GetDatafromXmlNode(xDoc, StringForQtInterval), ReadingLabels.QTInterval); testResult.QTcInterval = GetDecimalObject(GetDatafromXmlNode(xDoc, StringForQtcInterval), ReadingLabels.QTcInterval); if (testResult.VentRate == null && testResult.PRInterval == null && testResult.QRSDuration == null && testResult.QTInterval == null && testResult.QTcInterval == null) { return(false); } return(true); }
public override TestResult GetTestResults(long customerId, long eventId, bool isNewResultFlow) { List <CustomerEventScreeningTestsEntity> customerEventScreeningTests = GetTestResultsByTestId(customerId, eventId, (int)TestType.EKG); var testResult = _testResultFactory.CreateTestResults(customerEventScreeningTests).SingleOrDefault(); if (testResult == null) { return(null); } EKGTestResult ekgTestResult = (EKGTestResult)testResult; if (ekgTestResult.ResultImage != null) { GetFileDataforResultmedia(ekgTestResult.ResultImage); } testResult.IsNewResultFlow = isNewResultFlow; return(testResult); }
public void SaveEKGTestResults() { var testResult = new EKGTestResult { PRInterval = new ResultReading <decimal?>(4) { Reading = 11, ReadingSource = ReadingSource.Automatic }, RRInterval = new ResultReading <int?>(8) { Reading = 21, ReadingSource = ReadingSource.Automatic }, VentRate = new ResultReading <int?>(9) { Reading = 31, ReadingSource = ReadingSource.Automatic }, QRSDuration = new ResultReading <decimal?>(5) { Reading = 41, ReadingSource = ReadingSource.Automatic }, QTInterval = new ResultReading <decimal?>(7) { Reading = 51, ReadingSource = ReadingSource.Automatic }, QTDispersion = new ResultReading <int?>(6) { Reading = 61, ReadingSource = ReadingSource.Automatic }, DataRecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = new OrganizationRoleUser { UserId = 1058, RoleId = 8, OrganizationId = 1 }, DataRecorderModifier = new OrganizationRoleUser { UserId = 1058, RoleId = 8, OrganizationId = 1 }, DateCreated = DateTime.Now, DateModified = DateTime.Now }, Finding = new StandardFinding <int?>(1) { Description = "", Label = "NORMAL", MaxValue = null, MinValue = null }, ResultStatus = new TestResultState { SelfPresent = true, StateNumber = (int)TestResultStateNumber.ManualEntry, Status = TestResultStatus.Incomplete } }; Assert.IsTrue(_testResultRepository.SaveTestResults(testResult, CUSTOMER_ID, EVENT_ID, TECHNICIAN_ID)); }
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 void CopyOverEkgGraph(long eventId, long customerId, string saveFilePath, EKGTestResult testResult) { if (testResult == null || testResult.ResultImage == null) { return; } var destinationDirectory = Path.GetDirectoryName(saveFilePath); var supportDestDirectoryPath = destinationDirectory + @"\" + StringforMediaDirectory; if (!Directory.Exists(supportDestDirectoryPath)) { Directory.CreateDirectory(supportDestDirectoryPath); } string input = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath + testResult.ResultImage.File.Path; using (Image img = Image.FromFile(input)) { //rotate the picture by 90 degrees and re-save the picture as a Jpeg img.RotateFlip(RotateFlipType.Rotate270FlipNone); img.Save(supportDestDirectoryPath + "\\" + testResult.ResultImage.File.Path, System.Drawing.Imaging.ImageFormat.Jpeg); } }
public 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 override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity) { var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList(); var testResult = new EKGTestResult(customerEventScreeningTestEntity.CustomerEventScreeningTestId); if (customerEventScreeningTestEntity.TestMedia != null && customerEventScreeningTestEntity.TestMedia.Count > 0) { var fileEntityCollection = customerEventScreeningTestEntity.FileCollectionViaTestMedia.ToList(); var testMediaEntity = customerEventScreeningTestEntity.TestMedia.FirstOrDefault(); testResult.ResultImage = new ResultMedia(testMediaEntity.MediaId); testResult.ResultImage.File = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection); testResult.ResultImage.Thumbnail = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null; if (testMediaEntity.IsManual) { testResult.ResultImage.ReadingSource = ReadingSource.Manual; } else { testResult.ResultImage.ReadingSource = ReadingSource.Automatic; } } var customerEventTestStandardFindingEntities = customerEventScreeningTestEntity.CustomerEventTestStandardFinding.ToList(); var testResultService = new TestResultService(); var standardFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.EKG); var bundleBranchFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.EKG, (int)ReadingLabels.BundleBranchBlock); var infarctionFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.EKG, (int)ReadingLabels.InfarctionPattern); var standardFindingTestReadingEntities = customerEventScreeningTestEntity. StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.ToList(); customerEventTestStandardFindingEntities.ForEach(customerEventTestStandardFindingEntity => { var standardFindingTestReadingEntity = standardFindingTestReadingEntities.Find(entity => entity.StandardFindingTestReadingId == customerEventTestStandardFindingEntity.StandardFindingTestReadingId); if (standardFindingTestReadingEntity == null) { return; } var standardFindingEntity = standardFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault(); if (standardFindingEntity != null) { testResult.Finding = new StandardFinding <int?>(standardFindingEntity.Id) { CustomerEventStandardFindingId = customerEventTestStandardFindingEntity. CustomerEventTestStandardFindingId, Label = standardFindingEntity.Label, MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue), MinValue = Convert.ToInt32(standardFindingEntity.MinValue) }; return; } standardFindingEntity = bundleBranchFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault(); if (standardFindingEntity != null) { var finding = new StandardFinding <int>(standardFindingEntity.Id) { CustomerEventStandardFindingId = customerEventTestStandardFindingEntity. CustomerEventTestStandardFindingId, Label = standardFindingEntity.Label, MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue), MinValue = Convert.ToInt32(standardFindingEntity.MinValue) }; if (testResult.BundleBranchBlockFinding == null) { testResult.BundleBranchBlockFinding = new List <StandardFinding <int> >(); } testResult.BundleBranchBlockFinding.Add(finding); return; } standardFindingEntity = infarctionFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault(); if (standardFindingEntity != null) { var finding = new StandardFinding <int>(standardFindingEntity.Id) { CustomerEventStandardFindingId = customerEventTestStandardFindingEntity. CustomerEventTestStandardFindingId, Label = standardFindingEntity.Label, MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue), MinValue = Convert.ToInt32(standardFindingEntity.MinValue) }; if (testResult.InfarctionPatternFinding == null) { testResult.InfarctionPatternFinding = new List <StandardFinding <int> >(); } testResult.InfarctionPatternFinding.Add(finding); return; } }); testResult.PRInterval = CreateResultReadingforNullableDecimal((int)ReadingLabels.PRInterval, customerEventReadingEntities); testResult.QRSDuration = CreateResultReadingforNullableDecimal((int)ReadingLabels.QRSDuration, customerEventReadingEntities); testResult.QTcInterval = CreateResultReadingforNullableDecimal((int)ReadingLabels.QTcInterval, customerEventReadingEntities); testResult.PRTAxis = new PRTAxis(); testResult.PRTAxis.PFront = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisPFront, customerEventReadingEntities); testResult.PRTAxis.QRSFront = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisQRSFront, customerEventReadingEntities); testResult.PRTAxis.TFront = CreateResultReadingforNullableInt((int)ReadingLabels.PRTAxisTFront, customerEventReadingEntities); testResult.QTDispersion = CreateResultReadingforNullableInt((int)ReadingLabels.QTDispersion, customerEventReadingEntities); testResult.QTInterval = CreateResultReadingforNullableDecimal((int)ReadingLabels.QTInterval, customerEventReadingEntities); testResult.RRInterval = CreateResultReadingforNullableInt((int)ReadingLabels.RRInterval, customerEventReadingEntities); testResult.VentRate = CreateResultReadingforNullableInt((int)ReadingLabels.VentRate, customerEventReadingEntities); testResult.SinusRythm = CreateResultReading((int)ReadingLabels.SinusRythm, customerEventReadingEntities); testResult.SinusArrythmia = CreateResultReading((int)ReadingLabels.SinusArrythmia, customerEventReadingEntities); testResult.SinusBradycardia = CreateResultReading((int)ReadingLabels.SinusBradycardia, customerEventReadingEntities); testResult.Mild = CreateResultReading((int)ReadingLabels.Mild, customerEventReadingEntities); testResult.Marked = CreateResultReading((int)ReadingLabels.Marked, customerEventReadingEntities); testResult.SinusTachycardia = CreateResultReading((int)ReadingLabels.SinusTachycardia, customerEventReadingEntities); testResult.AtrialFibrillation = CreateResultReading((int)ReadingLabels.AtrialFibrillation, customerEventReadingEntities); testResult.AtrialFlutter = CreateResultReading((int)ReadingLabels.AtrialFlutter, customerEventReadingEntities); testResult.SVT = CreateResultReading((int)ReadingLabels.SVT, customerEventReadingEntities); testResult.PACs = CreateResultReading((int)ReadingLabels.PACs, customerEventReadingEntities); testResult.PVCs = CreateResultReading((int)ReadingLabels.PVCs, customerEventReadingEntities); testResult.QRSWidening = CreateResultReading((int)ReadingLabels.QRSWidening, customerEventReadingEntities); testResult.LeftAxis = CreateResultReading((int)ReadingLabels.LeftAxis, customerEventReadingEntities); testResult.RightAxis = CreateResultReading((int)ReadingLabels.RightAxis, customerEventReadingEntities); testResult.AbnormalAxis = CreateResultReading((int)ReadingLabels.AbnormalAxis, customerEventReadingEntities); testResult.Left = CreateResultReading((int)ReadingLabels.Left, customerEventReadingEntities); testResult.Right = CreateResultReading((int)ReadingLabels.Right, customerEventReadingEntities); testResult.HeartBlock = CreateResultReading((int)ReadingLabels.HeartBlock, customerEventReadingEntities); testResult.TypeI = CreateResultReading((int)ReadingLabels.TypeI, customerEventReadingEntities); testResult.TypeII = CreateResultReading((int)ReadingLabels.TypeII, customerEventReadingEntities); testResult.FirstDegreeBlock = CreateResultReading((int)ReadingLabels.FirstDegreeBlock, customerEventReadingEntities); testResult.SecondDegreeBlock = CreateResultReading((int)ReadingLabels.SecondDegreeBlock, customerEventReadingEntities); testResult.ThirdDegreeCompleteHeartBlock = CreateResultReading((int)ReadingLabels.ThirdDegreeCompleteHeartBlock, customerEventReadingEntities); testResult.Artifact = CreateResultReading((int)ReadingLabels.Artifact, customerEventReadingEntities); testResult.BundleBranchBlock = CreateResultReading((int)ReadingLabels.BundleBranchBlock, customerEventReadingEntities); testResult.LeftAnteriorFasicularBlock = CreateResultReading((int)ReadingLabels.LeftAnteriorFasicularBlock, customerEventReadingEntities); testResult.VentricularHypertrophy = CreateResultReading((int)ReadingLabels.VentricularHypertrophy, customerEventReadingEntities); testResult.LeftVentricularHypertrophy = CreateResultReading((int)ReadingLabels.LeftVHypertrophy, customerEventReadingEntities); testResult.RightVentricularHypertrophy = CreateResultReading((int)ReadingLabels.RightVHypertrophy, customerEventReadingEntities); testResult.ProlongedQTInterval = CreateResultReading((int)ReadingLabels.ProlongedQTInterval, customerEventReadingEntities); testResult.IschemicSTTChanges = CreateResultReading((int)ReadingLabels.IschemicSTTChanges, customerEventReadingEntities); testResult.NonSpecificSTTChanges = CreateResultReading((int)ReadingLabels.NonSpecificSTTChanges, customerEventReadingEntities); testResult.PoorRWaveProgression = CreateResultReading((int)ReadingLabels.PoorRWaveProgression, customerEventReadingEntities); testResult.InfarctionPattern = CreateResultReading((int)ReadingLabels.InfarctionPattern, customerEventReadingEntities); testResult.AtypicalQWaveLead = CreateResultReading((int)ReadingLabels.AtypicalQWaveLead, customerEventReadingEntities); testResult.AtrialEnlargement = CreateResultReading((int)ReadingLabels.AtrialEnlargement, customerEventReadingEntities); testResult.LeftAtrialEnlargement = CreateResultReading((int)ReadingLabels.LeftAtrialEnlargment, customerEventReadingEntities); testResult.RightAtrialEnlargement = CreateResultReading((int)ReadingLabels.RightAtrialEnlargment, customerEventReadingEntities); testResult.RepolarizationVariant = CreateResultReading((int)ReadingLabels.RepolarizationVariant, customerEventReadingEntities); testResult.PacerRythm = CreateResultReading((int)ReadingLabels.PacerRythm, customerEventReadingEntities); testResult.SupraventricularArrythmia = CreateResultReading((int)ReadingLabels.SupraventricularArrythmia, customerEventReadingEntities); testResult.ReversedLeads = CreateResultReading((int)ReadingLabels.ReversedLeads, customerEventReadingEntities); testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities); testResult.ComparetoEkg = CreateResultReading((int)ReadingLabels.ComparetoEkg, customerEventReadingEntities); testResult.LowVoltage = CreateResultReading((int)ReadingLabels.LowVoltage, customerEventReadingEntities); testResult.LimbLeads = CreateResultReading((int)ReadingLabels.LimbLeads, customerEventReadingEntities); testResult.PrecordialLeads = CreateResultReading((int)ReadingLabels.PrecordialLeads, customerEventReadingEntities); return(testResult); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } foreach (var filePath in 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); }