Пример #1
0
        public void LoadFloChecAbiTestResults(HtmlDocument doc, FloChecABITestResult testResult, bool removeLongDescription, IEnumerable <CustomerScreeningEvaluatinPhysicianViewModel> physicians, IEnumerable <EventPhysicianTest> eventPhysicianTests,
                                              List <OrderedPair <long, string> > technicianIdNamePairs, bool loadImages, bool showUnreadableTest, IEnumerable <PhysicianEvaluation> eventCustomerPhysicianEvaluations, CustomerSkipReview customerSkipReview)
        {
            var incidentalFindings = _incidentalFindingRepository.GetAllIncidentalFinding((int)TestType.FloChecABI);

            if (testResult != null)
            {
                var selectedNode = doc.DocumentNode.SelectSingleNode("//div[@id='FloChecAbi-rpp-section']");
                if (selectedNode != null && (testResult.UnableScreenReason == null || testResult.UnableScreenReason.Count == 0) && (testResult.TestNotPerformed == null || testResult.TestNotPerformed.TestNotPerformedReasonId <= 0) &&
                    (showUnreadableTest || testResult.RepeatStudy == null || testResult.RepeatStudy.Reading == false))
                {
                    selectedNode.SetAttributeValue("style", "display:block;");
                }


                _resultPdfHelper.SetPhysicianSignature(doc, "FloChecAbi-primaryEvalPhysicianSign", "FloChecAbi-overreadEvalPhysicianSign", physicians, eventPhysicianTests, eventCustomerPhysicianEvaluations, customerSkipReview);

                var     readings = new TestResultRepository().GetAllReadings((int)TestType.FloChecABI);
                decimal?leftAbi  = null;
                decimal?rightAbi = null;

                foreach (var resultReading in readings)
                {
                    switch (resultReading.Label)
                    {
                    case ReadingLabels.LeftABI:
                        if (testResult.LeftResultReadings != null)
                        {
                            _resultPdfHelper.SetInputBox(doc, "FloChecAbitxtLeftFootdABI", testResult.LeftResultReadings.ABI);

                            if (testResult.LeftResultReadings.ABI != null && testResult.LeftResultReadings.ABI.Reading.HasValue)
                            {
                                leftAbi = testResult.LeftResultReadings.ABI.Reading;
                            }
                        }
                        break;

                    case ReadingLabels.LeftHandBFI:
                        if (testResult.LeftResultReadings != null)
                        {
                            _resultPdfHelper.SetInputBox(doc, "FloChecAbitxtLeftHandBFI", testResult.LeftResultReadings.BFI);
                        }
                        break;

                    case ReadingLabels.RightABI:
                        if (testResult.RightResultReadings != null)
                        {
                            _resultPdfHelper.SetInputBox(doc, "FloChecAbitxtRightFootdABI", testResult.RightResultReadings.ABI);

                            if (testResult.RightResultReadings.ABI != null && testResult.RightResultReadings.ABI.Reading.HasValue)
                            {
                                rightAbi = testResult.RightResultReadings.ABI.Reading;
                            }
                        }
                        break;

                    case ReadingLabels.RightHandBFI:
                        if (testResult.RightResultReadings != null)
                        {
                            _resultPdfHelper.SetInputBox(doc, "FloChecAbitxtRightHandBFI", testResult.RightResultReadings.BFI);
                        }
                        break;

                    case ReadingLabels.RepeatStudy:
                        _resultPdfHelper.SetCheckBox(doc, "RepeatStudyFloChecAbiInputCheck", testResult.RepeatStudy);
                        break;
                    }
                }

                long leftFindingId = 0;
                if (leftAbi != null)
                {
                    leftFindingId = _testResultService.GetCalculatedStandardFinding(leftAbi.Value, (int)TestType.FloChecABI, null);
                }

                long rightFindingId = 0;
                if (rightAbi != null)
                {
                    rightFindingId = _testResultService.GetCalculatedStandardFinding(rightAbi.Value, (int)TestType.FloChecABI, null);
                }

                var standardFindingList = _standardFindingRepository.GetAllStandardFindings <decimal>((int)TestType.FloChecABI);

                long findingId = 0;

                if (leftFindingId == rightFindingId)
                {
                    findingId = leftFindingId;
                }
                else if (leftFindingId > 0 && rightFindingId > 0)
                {
                    var lf = standardFindingList.Single(f => f.Id == leftFindingId);
                    var rf = standardFindingList.Single(f => f.Id == rightFindingId);

                    findingId = lf.WorstCaseOrder > rf.WorstCaseOrder ? lf.Id : rf.Id;
                }
                else
                {
                    findingId = leftFindingId > rightFindingId ? leftFindingId : rightFindingId;
                }

                LoadFloChecAbiFindings(doc, testResult.Finding, standardFindingList, findingId, true, (testResult.UnableScreenReason != null && testResult.UnableScreenReason.Count > 0 ? testResult.UnableScreenReason.First() : null));
                _resultPdfHelper.SetTechnician(doc, testResult, "techFloChecAbi", "technotesFloChecAbi", technicianIdNamePairs);
                _resultPdfHelper.SetIncidentalFindings(doc, incidentalFindings, testResult.IncidentalFindings, "FloChecAbiIncidentalFinding");
                _resultPdfHelper.SetPhysicianRemarks(doc, testResult, "followUpFloChecAbi", "criticalFloChecAbi", "physicianRemarksFloChecAbi");
                _resultPdfHelper.SetUnableToScreenReasons(doc, TestType.FloChecABI, "FloChecAbiUnableToScreen", testResult.UnableScreenReason);

                if (testResult.IncidentalFindings != null && testResult.IncidentalFindings.Any())
                {
                    selectedNode = doc.DocumentNode.SelectSingleNode("//p[@id='incidentalfinding-description-FloChecAbi']");
                    if (selectedNode != null)
                    {
                        selectedNode.SetAttributeValue("style", "display:block;");
                    }
                }

                if (testResult.ResultImage != null && (testResult.UnableScreenReason == null || testResult.UnableScreenReason.Count == 0) && (showUnreadableTest || testResult.RepeatStudy == null || testResult.RepeatStudy.Reading == false))
                {
                    _resultPdfHelper.LoadTestMedia(doc, new[] { testResult.ResultImage }, "testmedia-FloChecAbi", loadImages);
                }

                selectedNode = doc.DocumentNode.SelectSingleNode("//div[@id='FloChecAbi-longdescription-div']");
                if (selectedNode != null)
                {
                    selectedNode.SetAttributeValue("style", removeLongDescription ? "display:none" : "display:block");
                }
            }
            else
            {
                LoadFloChecAbiFindings(doc, null, null, 0, false);
                _resultPdfHelper.SetUnableToScreenReasons(doc, TestType.FloChecABI, "FloChecAbiUnableToScreen", null);
                _resultPdfHelper.SetIncidentalFindings(doc, incidentalFindings, null, "FloChecAbiIncidentalFinding");
            }
        }
Пример #2
0
        public void CopyOverFloChecAbiPdf(long eventId, long customerId, string saveFilePath, FloChecABITestResult 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))
            {
                img.Save(supportDestDirectoryPath + "\\" + testResult.ResultImage.File.Path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
        public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestsEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestsEntity.CustomerEventReading.ToList();

            var testResult = new FloChecABITestResult(customerEventScreeningTestsEntity.CustomerEventScreeningTestId)
            {
                LeftResultReadings  = new FloChecABIReadings(),
                RightResultReadings = new FloChecABIReadings(),
                PencilDopplerUsed   = this.CreateResultReading((int)ReadingLabels.PencilDopplerUsed, customerEventReadingEntities),

                RepeatStudy = this.CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities)
            };


            testResult.RightResultReadings.ABI = CreateResultReadingforNullableDecimal((int)ReadingLabels.RightABI, customerEventReadingEntities);
            testResult.LeftResultReadings.ABI  = CreateResultReadingforNullableDecimal((int)ReadingLabels.LeftABI, customerEventReadingEntities);

            testResult.RightResultReadings.BFI = CreateResultReadingforNullableDecimal((int)ReadingLabels.RightHandBFI, customerEventReadingEntities);
            testResult.LeftResultReadings.BFI  = CreateResultReadingforNullableDecimal((int)ReadingLabels.LeftHandBFI, customerEventReadingEntities);

            if (customerEventScreeningTestsEntity.TestMedia != null && customerEventScreeningTestsEntity.TestMedia.Count > 0)
            {
                var fileEntityCollection = customerEventScreeningTestsEntity.FileCollectionViaTestMedia.ToList();
                var testMediaEntity      = customerEventScreeningTestsEntity.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 standardFindings         = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI);
            var standardFindingsLeftAbi  = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI, (int)ReadingLabels.LeftABI);
            var standardFindingsRightAbi = new TestResultService().GetAllStandardFindings <decimal>((int)TestType.FloChecABI, (int)ReadingLabels.RightABI);

            var testResultService = new TestResultService();

            StandardFinding <decimal> leftResultFinding, rightResultFinding;

            leftResultFinding = rightResultFinding = null;

            if (standardFindings == null || standardFindings.Count < 1)
            {
                standardFindings = standardFindingsLeftAbi;
            }

            int findingId = 0;

            if (testResult.LeftResultReadings.ABI != null)
            {
                findingId         = testResultService.GetCalculatedStandardFinding(testResult.LeftResultReadings.ABI.Reading, (int)TestType.FloChecABI, standardFindingsLeftAbi != null && standardFindingsLeftAbi.Count() > 0 ? (int?)ReadingLabels.LeftABI : null);
                leftResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }

            if (testResult.RightResultReadings.ABI != null)
            {
                findingId          = testResultService.GetCalculatedStandardFinding(testResult.RightResultReadings.ABI.Reading, (int)TestType.FloChecABI, standardFindingsRightAbi != null && standardFindingsRightAbi.Count() > 0 ? (int?)ReadingLabels.RightABI : null);
                rightResultFinding = standardFindings.Where(f => f.Id == findingId).SingleOrDefault();
            }
            if (standardFindingsLeftAbi == null || standardFindingsLeftAbi.Count() < 1)
            {
                var customerEventTestStandardFindingEntity = customerEventScreeningTestsEntity.CustomerEventTestStandardFinding.FirstOrDefault();

                if (customerEventTestStandardFindingEntity != null)
                {
                    var standardFindingTestReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventTestStandardFinding.LastOrDefault();

                    var standardFindingEntity = standardFindings.ToList().FindAll(standardFinding => standardFinding.Id == standardFindingTestReadingEntity.StandardFindingId).FirstOrDefault();

                    if (standardFindingEntity != null)
                    {
                        testResult.Finding = new StandardFinding <decimal>(standardFindingEntity.Id)
                        {
                            CustomerEventStandardFindingId = customerEventTestStandardFindingEntity.CustomerEventTestStandardFindingId,
                            Label    = standardFindingEntity.Label,
                            MaxValue = Convert.ToInt32(standardFindingEntity.MaxValue),
                            MinValue = Convert.ToInt32(standardFindingEntity.MinValue)
                        };
                    }
                }
                else
                {
                    testResult.Finding = GetFindingToConsider(leftResultFinding, rightResultFinding);

                    if (testResult.Finding != null)
                    {
                        var standardFinding = standardFindings.Find(finding => finding.Id == testResult.Finding.Id);
                        if (standardFinding != null)
                        {
                            testResult.Finding = standardFinding;
                        }
                    }
                }
            }
            else
            {
                var testReadingLAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.LeftABI).SingleOrDefault();
                var testReadingRAbiReading = customerEventReadingEntities.Where(customerEventReading => customerEventReading.TestReading.ReadingId == (int)ReadingLabels.RightABI).SingleOrDefault();

                if (testReadingLAbiReading != null && testReadingLAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.FloChecABI && stdFindingTestReading.ReadingId == (int)ReadingLabels.LeftABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.LeftResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (leftResultFinding != null)
                {
                    testResult.LeftResultReadings.Finding = leftResultFinding;
                }

                if (testResult.LeftResultReadings.Finding != null)
                {
                    testResult.LeftResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.LeftResultReadings.Finding.Id).SingleOrDefault();
                }

                //-----------------------------------------------------------------------------------
                if (testReadingRAbiReading != null && testReadingRAbiReading.StandardFindingTestReadingId != null)
                {
                    var standardFindingReadingEntity = customerEventScreeningTestsEntity.StandardFindingTestReadingCollectionViaCustomerEventReading.ToList().Find(stdFindingTestReading =>
                                                                                                                                                                   stdFindingTestReading.TestId == (int)TestType.FloChecABI && stdFindingTestReading.ReadingId == (int)ReadingLabels.RightABI);

                    if (standardFindingReadingEntity != null)
                    {
                        testResult.RightResultReadings.Finding = new StandardFinding <decimal>(standardFindingReadingEntity.StandardFindingId);
                    }
                }
                else if (rightResultFinding != null)
                {
                    testResult.RightResultReadings.Finding = rightResultFinding;
                }

                if (testResult.RightResultReadings.Finding != null)
                {
                    testResult.RightResultReadings.Finding = standardFindings.Where(sf => sf.Id == testResult.RightResultReadings.Finding.Id).SingleOrDefault();
                }
            }

            return(testResult);
        }
Пример #4
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

            if (string.IsNullOrEmpty(directoryPath))
            {
                return(null);
            }
            var testType = TestType.FloChecABI;

            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 isFloChecAbiPurchased = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)testType);

                    if (!isFloChecAbiPurchased)
                    {
                        _logger.Info("FloChec 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 FloChecABITestResult {
                        ResultImage = resultMedia
                    };

                    _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, _eventId, customerId, testResult);
                    _resultParserHelper.AddResultArchiveLog(string.Empty, testType, customerId, MedicalEquipmentTag.FloChec);

                    _logger.Info(string.Concat("\nParsing succeeded for FloChec  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.FloChec, false);
                }
            }

            return(eventCustomerAggregates);
        }