public PcpResultExportModel SetDpnData(PcpResultExportModel model, DpnTestResult testResult, bool useBlankValue = false) { if (testResult.Finding != null) { model.DpnResult = testResult.Finding.Label; } model.DpnAmplitude = testResult.Amplitude != null ? testResult.Amplitude.Reading != null?testResult.Amplitude.Reading.ToString() : "" : ""; model.DpnConductionVelocity = testResult.ConductionVelocity != null ? testResult.ConductionVelocity.Reading != null?testResult.ConductionVelocity.Reading.ToString() : "" : ""; model.DpnRightLeg = PcpResultExportHelper.GetOutputFromNullableBoolTypeResultReading(testResult.RightLeg, useBlankValue); model.DpnLeftLeg = PcpResultExportHelper.GetOutputFromNullableBoolTypeResultReading(testResult.LeftLeg, useBlankValue); model.DpnUnabletoScreen = testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? PcpResultExportHelper.YesString : (useBlankValue ? "" : PcpResultExportHelper.NoString); if ((testResult.ResultStatus != null && testResult.ResultStatus.SelfPresent) || (testResult.PhysicianInterpretation != null && testResult.PhysicianInterpretation.IsCritical)) { model.DpnCritical = PcpResultExportHelper.YesString; } else if (!useBlankValue) { model.DpnCritical = PcpResultExportHelper.NoString; } return(model); }
public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity) { var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList(); var testResult = new DpnTestResult(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) { File = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection), Thumbnail = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null, ReadingSource = testMediaEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic }; } var customerEventTestStandardFindingEntities = customerEventScreeningTestEntity.CustomerEventTestStandardFinding.ToList(); var standardFindingTestReadingEntities = customerEventScreeningTestEntity.StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.ToList(); if (customerEventTestStandardFindingEntities.Count() > 0) { var testResultService = new TestResultService(); var standardFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.DPN); customerEventTestStandardFindingEntities.ForEach(customerEventTestStandardFindingEntity => { var standardFindingTestReadingEntity = standardFindingTestReadingEntities.Find(entity => entity.StandardFindingTestReadingId == customerEventTestStandardFindingEntity.StandardFindingTestReadingId); if (standardFindingTestReadingEntity == null) { return; } var finding = CreateFindingObject(customerEventTestStandardFindingEntity, standardFindings, standardFindingTestReadingEntity, null); if (finding != null) { testResult.Finding = finding; return; } }); } testResult.Amplitude = CreateResultReadingforNullableDecimal((int)ReadingLabels.DpnAmplitude, customerEventReadingEntities); testResult.ConductionVelocity = CreateResultReadingforNullableDecimal((int)ReadingLabels.DpnConductionVelocity, customerEventReadingEntities); testResult.RightLeg = CreateResultReadingforNullableBool((int)ReadingLabels.DpnRightLeg, customerEventReadingEntities); testResult.LeftLeg = CreateResultReadingforNullableBool((int)ReadingLabels.DpnLeftLeg, customerEventReadingEntities); testResult.TechnicallyLimitedbutReadable = CreateResultReading((int)ReadingLabels.TechnicallyLimitedbutReadable, customerEventReadingEntities); testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities); return(testResult); }
public IEnumerable <EventCustomerScreeningAggregate> Parse() { var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>(); var directoryPath = GetFolderPathfor(_resultOutputPath); if (string.IsNullOrEmpty(directoryPath)) { return(null); } var pdfFiles = DirectoryOperationsHelper.GetFiles(directoryPath, "*.pdf"); //GetPdfFiles(directoryPath); if (pdfFiles != null && pdfFiles.Any()) { _logger.Info("Number of Files to Parse : " + pdfFiles.Count()); foreach (var filePath in pdfFiles) { var fileName = Path.GetFileName(filePath); long customerId = 0; string errorMessage = string.Empty; _logger.Info("=============== Parsing Started for file: " + fileName + " ================="); var pdfText = GetTextFromPdf(filePath); if (string.IsNullOrWhiteSpace(pdfText)) { continue; } var lstText = pdfText.Replace("\r", "").Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); var customerIdString = lstText.Where(x => x.Contains("Patient ID:")).FirstOrDefault(); if (string.IsNullOrWhiteSpace(customerIdString) || !long.TryParse(customerIdString.Replace("Patient ID:", "").Trim(), out customerId)) { errorMessage = "DPN: CustomerId could be blank or not an numeric value in Pdf file @" + filePath + " and text is: " + customerIdString; _logger.Info(errorMessage); continue; } var eventCustomer = _eventCustomerRepository.Get(_eventId, customerId); if (eventCustomer == null) { errorMessage = "DPN: Customer: " + customerId + " is not registered on Event Id :" + _eventId + " for file path: " + filePath; _logger.Info(errorMessage); continue; } var isTestPurchased = _eventCustomerRepository.IsTestPurchasedByEventIdCustomerId(_eventId, customerId, (long)TestType.DPN); if (!isTestPurchased) { errorMessage = "DPN: Test not purchased for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } var resultState = _eventCustomerResultRepository.GetByCustomerIdAndEventId(customerId, _eventId); if (resultState != null && _isNewResultFlow && resultState.ResultState >= (int)NewTestResultStateNumber.PostAuditNew) { errorMessage = "DPN (New Result Flow): Pdf can not parsed because current result state is " + NewTestResultStateNumber.PostAuditNew.ToString() + " for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } if (resultState != null && !_isNewResultFlow && resultState.ResultState >= (int)TestResultStateNumber.PostAudit) { errorMessage = "DPN (Old Result Flow): Pdf can not parsed because current result state is " + TestResultStateNumber.PostAudit.ToString() + " for Customer Id :" + customerId + " Event Id :" + _eventId + " and file path: " + filePath; _logger.Info(errorMessage); continue; } try { string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath; var resultMedia = GetMediaFromPdfFile(filePath, folderToSavePdf, TestType.DPN); if (resultMedia != null) { resultMedia.ReadingSource = ReadingSource.Automatic; TestResult testResult = new DpnTestResult { ResultImage = resultMedia }; _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult); _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.DPN, customerId, MedicalEquipmentTag.Vatica); _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n")); } } catch (Exception ex) { errorMessage = "DPN: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace; _logger.Error(errorMessage); _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.DPN, customerId, MedicalEquipmentTag.Vatica, false); } _logger.Info("=============== Parsing Ended for file: " + fileName + " ================="); } } return(eventCustomerAggregates); }