public PcpResultExportModel SetDiabeticRetinopathyData(PcpResultExportModel model, DiabeticRetinopathyTestResult testResult, bool useBlankValue = false)
        {
            //model.DiabeticRetinopathyLevel = GetOutputFromStandaredFinding(testResult.DiabeticRetinopathyLevel);
            //model.DiabeticRetinopathyMacularEdemaLevel = GetOutputFromStandaredFinding(testResult.MacularEdemaLevel);

            //model.DiabeticRetinopathyHasSuspectedVeinOcclusion = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedVeinOcclusion, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedWetAmd = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedWetAmd, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedDryAmd = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedDryAmd, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedHtnRetinopathy = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedHtnRetinopathy, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedEpiretinalMembrane = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedEpiretinalMembrane, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedMacularHole = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedMacularHole, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedCataract = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedCataract, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedOtherDisease = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedOtherDisease, useBlankValue);
            //model.DiabeticRetinopathyHasSuspectedGlaucoma = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.SuspectedGlaucoma, useBlankValue);

            //model.DiabeticRetinopathyTechnicallyLimitedButReadable = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.TechnicallyLimitedbutReadable, useBlankValue);
            //model.DiabeticRetinopathyRepeatStudyUnreadable = PcpResultExportHelper.GetOutputFromBoolTypeResultReading(testResult.RepeatStudy, useBlankValue);

            //model.DiabeticRetinopathyUnabletoScreen = 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.DiabeticRetinopathyCritical = PcpResultExportHelper.YesString;
            //else if(!useBlankValue)
            //    model.DiabeticRetinopathyCritical = PcpResultExportHelper.NoString;

            //if (testResult.PhysicianInterpretation != null)
            //    model.DiabeticRetinopathyPhysicianNotes = testResult.PhysicianInterpretation.Remarks;

            return(model);
        }
        public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList();

            var testResult = new DiabeticRetinopathyTestResult(customerEventScreeningTestEntity.CustomerEventScreeningTestId);

            testResult.SuspectedVeinOcclusion      = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedVeinOcclusion, customerEventReadingEntities);
            testResult.SuspectedWetAmd             = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedWetAmd, customerEventReadingEntities);
            testResult.SuspectedHtnRetinopathy     = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedHtnRetinopathy, customerEventReadingEntities);
            testResult.SuspectedEpiretinalMembrane = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedEpiretinalMembrane, customerEventReadingEntities);
            testResult.SuspectedMacularHole        = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedMacularHole, customerEventReadingEntities);
            testResult.SuspectedCataract           = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedCataract, customerEventReadingEntities);
            testResult.SuspectedOtherDisease       = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedOtherDisease, customerEventReadingEntities);
            testResult.SuspectedGlaucoma           = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedGlaucoma, customerEventReadingEntities);
            testResult.SuspectedDryAmd             = CreateResultReading((int)ReadingLabels.DiabeticRetinopathySuspectedDryAmd, customerEventReadingEntities);

            testResult.DiabeticRetinopathyHighestLevelOfSpecificity = CreateResultReading((int)ReadingLabels.DiabeticRetinopathyHighestLevelOfSpecificity, customerEventReadingEntities);
            testResult.MacularEdemaHighestLevelOfSpecificity        = CreateResultReading((int)ReadingLabels.MacularEdemaHighestLevelOfSpecificity, customerEventReadingEntities);

            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.DiabeticRetinopathy);
                var diabeticRetinopathyLevelFindings = testResultService.GetAllStandardFindings <int?>((int)TestType.DiabeticRetinopathy, (int)ReadingLabels.DiabeticRetinopathyHighestLevelOfSpecificity);
                var macularEdemLevel = testResultService.GetAllStandardFindings <int?>((int)TestType.DiabeticRetinopathy, (int)ReadingLabels.MacularEdemaHighestLevelOfSpecificity);

                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;
                    }

                    finding = CreateFindingObject(customerEventTestStandardFindingEntity, diabeticRetinopathyLevelFindings, standardFindingTestReadingEntity, (int?)ReadingLabels.DiabeticRetinopathyHighestLevelOfSpecificity);
                    if (finding != null)
                    {
                        testResult.DiabeticRetinopathyLevel = finding; return;
                    }

                    finding = CreateFindingObject(customerEventTestStandardFindingEntity, macularEdemLevel, standardFindingTestReadingEntity, (int?)ReadingLabels.MacularEdemaHighestLevelOfSpecificity);
                    if (finding != null)
                    {
                        testResult.MacularEdemaLevel = finding; return;
                    }
                });
            }

            if (customerEventScreeningTestEntity.TestMedia != null && customerEventScreeningTestEntity.TestMedia.Count > 0)
            {
                var fileEntityCollection = customerEventScreeningTestEntity.FileCollectionViaTestMedia.ToList();
                var testMediaEntity      = customerEventScreeningTestEntity.TestMedia.FirstOrDefault();

                testResult.ResultImage = new ResultMedia(testMediaEntity.MediaId)
                {
                    File          = GetFileObjectfromEntity(testMediaEntity.FileId, fileEntityCollection),
                    Thumbnail     = testMediaEntity.ThumbnailFileId != null ? new File(testMediaEntity.ThumbnailFileId.Value) : null,
                    ReadingSource = testMediaEntity.IsManual ? ReadingSource.Manual : ReadingSource.Automatic
                };
            }


            testResult.TechnicallyLimitedbutReadable = CreateResultReading((int)ReadingLabels.TechnicallyLimitedbutReadable, customerEventReadingEntities);
            testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities);

            return(testResult);
        }
Exemplo n.º 3
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

            if (string.IsNullOrEmpty(directoryPath) && string.IsNullOrEmpty(directoryPath))
            {
                return(null);
            }


            List <string> pdfFiles = null;

            if (!string.IsNullOrEmpty(directoryPath))
            {
                pdfFiles = GetPdfFiles(directoryPath);
            }

            if (pdfFiles != null && pdfFiles.Any())
            {
                _logger.Info("Number of Files to Parse : " + pdfFiles.Count());

                foreach (var filePath in pdfFiles)
                {
                    var fileNameWithExtention = Path.GetFileName(filePath);
                    if (!string.IsNullOrEmpty(fileNameWithExtention))
                    {
                        fileNameWithExtention = fileNameWithExtention.ToLower();
                    }

                    var fileName = Path.GetFileNameWithoutExtension(filePath);
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        fileName = fileName.ToLower();
                    }

                    long   customerId   = 0;
                    long   eventId      = 0;
                    string errorMessage = string.Empty;

                    _logger.Info("=============== Parsing Started for file: " + fileName + " =================");

                    try
                    {
                        var temp             = fileName.Substring(fileName.IndexOf("_mrn_") + 5);
                        var customerIdString = temp.Substring(0, temp.IndexOf("_"));

                        if (!long.TryParse(customerIdString, out customerId))
                        {
                            errorMessage = "Diabetic Retinopathy: CustomerId not found on Pdf file" + filePath;
                            _logger.Info(errorMessage);
                            SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage);
                            continue;
                        }
                    }
                    catch (Exception)
                    {
                        errorMessage = "File name is not in correct formate. ";
                        _logger.Error(errorMessage);
                        SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage);
                        continue;
                    }


                    try
                    {
                        eventId = _eventCustomerRepository.GetEventIdAttendedByCustomerForTest(customerId, (long)TestType.DiabeticRetinopathy, _settings.DiabeticRetinopathyNoOfDaysToCheckForEvent);
                        if (eventId <= 0)
                        {
                            errorMessage = string.Format("Diabetic Retinopathy: No Event attended by customer {0} in last {1} days.", customerId, _settings.DiabeticRetinopathyNoOfDaysToCheckForEvent);
                            _logger.Info(errorMessage);
                            SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage);
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMessage = "Diabetic Retinopathy:  CustomerId [" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace;
                        _logger.Info(errorMessage);
                        SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage);

                        continue;
                    }

                    try
                    {
                        string folderToSavePdf = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath;
                        var    resultMedia     = GetMediaFromPdfFile(filePath, folderToSavePdf, TestType.DiabeticRetinopathy);

                        if (resultMedia != null)
                        {
                            TestResult testResult = new DiabeticRetinopathyTestResult {
                                ResultImage = resultMedia
                            };

                            _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult);
                            _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.DiabeticRetinopathy, customerId, MedicalEquipmentTag.Vatica);

                            _logger.Info(string.Concat("\nParsing succeeded for Customer Id: ", customerId, "\n"));
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMessage = "Diabetic Retinopathy: System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace;
                        _logger.Error(errorMessage);
                        SaveDiabeticRetinopathyParserlog(fileNameWithExtention, customerId, eventId, errorMessage);
                        _resultParserHelper.AddResultArchiveLog(ex.Message, TestType.DiabeticRetinopathy, customerId, MedicalEquipmentTag.Vatica, false);
                    }


                    _logger.Info("=============== Parsing Ended for file: " + fileName + " =================");
                }
            }

            return(eventCustomerAggregates);
        }