public PcpResultExportModel SetIfobtlobinData(PcpResultExportModel model, IFOBTTestResult testResult, bool useBlankValue = false)
        {
            if (testResult.Finding != null)
            {
                model.IfobtFinding = testResult.Finding.Label;
            }

            model.IfobtSerialKey = GetResultReading(testResult.SerialKey);

            model.IfobtUnabletoScreen = 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.IfobtCritical = PcpResultExportHelper.YesString;
            }
            else if (!useBlankValue)
            {
                model.IfobtCritical = PcpResultExportHelper.NoString;
            }

            if (testResult.PhysicianInterpretation != null)
            {
                model.IfobtPhysicianNotes = testResult.PhysicianInterpretation.Remarks;
            }

            return(model);
        }
Пример #2
0
        public override TestResult CreateActualTestResult(CustomerEventScreeningTestsEntity customerEventScreeningTestEntity)
        {
            var customerEventReadingEntities = customerEventScreeningTestEntity.CustomerEventReading.ToList();

            var testResult = new IFOBTTestResult(customerEventScreeningTestEntity.CustomerEventScreeningTestId);

            testResult.SerialKey = CreateResultReadingforInputValues((int)ReadingLabels.IFOBTSerialKey, customerEventReadingEntities);

            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.Any())
            {
                var testResultService = new TestResultService();
                var standardFindings  = testResultService.GetAllStandardFindings <int?>((int)TestType.IFOBT);

                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.TechnicallyLimitedbutReadable = CreateResultReading((int)ReadingLabels.TechnicallyLimitedbutReadable, customerEventReadingEntities);
            testResult.RepeatStudy = CreateResultReading((int)ReadingLabels.RepeatStudy, customerEventReadingEntities);

            return(testResult);
        }
Пример #3
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var       eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();
            var       pdfResults     = DirectoryOperationsHelper.GetFiles(_labReportOutputPath, "*.pdf");
            var       rawTxtFile     = DirectoryOperationsHelper.GetFiles(_labReportOutputPath, "*.txt");
            DataTable dtRawDataTable = new DataTable();

            if (rawTxtFile != null && rawTxtFile.Count() > 0)
            {
                _loggerForClient.Info("Total " + rawTxtFile.Count() + " Text File found.");
                foreach (var file in rawTxtFile)
                {
                    string txtFilename = new FileInfo(file).Name;
                    try
                    {
                        dtRawDataTable = GetRecordsFromTextFile(file, txtFilename, dtRawDataTable);
                    }
                    catch (Exception ex)
                    {
                        _loggerForClient.Info("File name :" + txtFilename + " is blank. Exception :" + ex.Message);
                        MovedParsedFile(file);
                    }
                }

                if (dtRawDataTable != null)
                {
                    _loggerForClient.Info("Total " + dtRawDataTable.Rows.Count() + " records found from all text file ");
                }
            }
            else
            {
                _loggerForClient.Info("There is not any text file availble");
            }

            var standardFinding = _standardFindingRepository.GetAllStandardFindings <decimal?>((int)TestType.IFOBT);

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

                foreach (var filePath in pdfResults)
                {
                    string   errorMessage = string.Empty;
                    long     customerId   = 0;
                    long     eventId      = 0;
                    TestType testTypeId;

                    var fileName  = Path.GetFileNameWithoutExtension(filePath);
                    var extension = Path.GetExtension(filePath);

                    if (extension != ".pdf")
                    {
                        errorMessage = "file with pdf extension supported only";
                        _loggerForClient.Error(errorMessage);
                        MovedParsedFile(filePath);
                        continue;
                    }

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

                    if (!ParseValidationCheck(fileName, filePath, out eventId, out customerId, out testTypeId))
                    {
                        continue;
                    }

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

                        if (resultMedia != null && testTypeId == TestType.IFOBT)
                        {
                            var finding = new StandardFinding <int>();
                            finding = GetIFOBTFinding(dtRawDataTable, eventId, customerId, testTypeId, fileName, standardFinding);
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            TestResult testResult = new IFOBTTestResult {
                                ResultImage = resultMedia, Finding = finding
                            };
                            _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult);
                            _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.IFOBT, customerId, MedicalEquipmentTag.LabReportParser);

                            _labParseEventLogger.Info(string.Concat("\nPDF Filename(" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", TestType.IFOBT, "\n"));
                            _loggerForClient.Info(string.Concat("\nPDF Filename (" + fileName + "): parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " ,TestType :", TestType.IFOBT, "\n"));
                        }
                        else if (resultMedia != null && testTypeId == TestType.UrineMicroalbumin)
                        {
                            ResultReading <string> microAlbuminValue = new ResultReading <string>();
                            microAlbuminValue         = GetUrineMicroAlbuminValue(dtRawDataTable, eventId, customerId, testTypeId, fileName);
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            TestResult testResult = new UrineMicroalbuminTestResult {
                                ResultImage = resultMedia, MicroalbuminValue = microAlbuminValue
                            };
                            _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult);
                            _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.UrineMicroalbumin, customerId, MedicalEquipmentTag.LabReportParser);

                            _labParseEventLogger.Info(string.Concat("\nFilename(" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", TestType.UrineMicroalbumin, "\n"));
                            _loggerForClient.Info(string.Concat("\nFilename (" + fileName + "): Parsing successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " ,TestType :", TestType.UrineMicroalbumin, "\n"));
                        }
                        else
                        {
                            var message = string.Concat("\nFilename(" + fileName + "): Test(" + testTypeId + ") is an invalid test for parsing for Customer Id: ", customerId, " ,Event Id: ", eventId, " TestType :", testTypeId, "\n");
                            _labParseEventLogger.Info(message);
                            _loggerForClient.Info(message);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMessage = " System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace;
                        _labParseEventLogger.Error(errorMessage);
                        _loggerForClient.Error("Parsing failed for filename :" + fileName + ".Please contact to Administrator.");

                        MovedParsedFile(filePath);
                        _resultParserHelper.AddResultArchiveLog(ex.Message, testTypeId, customerId, MedicalEquipmentTag.LabReportParser, false);
                    }
                }
            }
            if (dtRawDataTable != null && dtRawDataTable.Columns.Count() > 0 && dtRawDataTable.Rows.Count > 0)
            {
                var rows = dtRawDataTable.Select("IsParse=false");
                if (rows != null && rows.Any())
                {
                    dtRawDataTable = rows.CopyToDataTable();

                    if (dtRawDataTable.Rows.Count > 0)
                    {
                        eventCustomerAggregates = SaveResultWithoutMedia(eventCustomerAggregates, dtRawDataTable, standardFinding);
                    }
                }
            }
            return(eventCustomerAggregates);
        }
Пример #4
0
        private List <EventCustomerScreeningAggregate> SaveResultWithoutMedia(List <EventCustomerScreeningAggregate> eventCustomerAggregates, DataTable dtRawDataTable, List <StandardFinding <decimal?> > standardFinding)
        {
            try
            {
                foreach (DataRow dr in dtRawDataTable.Rows)
                {
                    long     intFinding     = 0;
                    long     customerId     = 0;
                    long     eventId        = 0;
                    string   summaryFinding = string.Empty;
                    string   txtFileName    = string.Empty;
                    TestType testTypeId;
                    StandardFinding <int> finding = new StandardFinding <int>();
                    if (!ValidateDataTable(dr, out txtFileName, out eventId, out customerId, out testTypeId, out summaryFinding))
                    {
                        continue;
                    }
                    if (testTypeId == TestType.UrineMicroalbumin)
                    {
                        ResultReading <string> microAlbuminValue = new ResultReading <string>()
                        {
                            Label            = ReadingLabels.MicroalbuminValue,
                            Reading          = summaryFinding,
                            RecorderMetaData = new DataRecorderMetaData(UploadedBy, DateTime.Now, null),
                            ReadingSource    = ReadingSource.Automatic
                        };

                        TestResult testResult = new UrineMicroalbuminTestResult {
                            MicroalbuminValue = microAlbuminValue
                        };
                        _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult);
                        _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.UrineMicroalbumin, customerId, MedicalEquipmentTag.LabReportParser);
                    }
                    else if (testTypeId == TestType.IFOBT)
                    {
                        summaryFinding = summaryFinding.ToLower();
                        var query = standardFinding.Where(x => x.Label.ToLower() == summaryFinding).Select(x => x.Id);
                        if (query != null && query.Count() > 0)
                        {
                            intFinding = query.First();
                        }
                        if (intFinding == 0)
                        {
                            _labParseEventLogger.Info("file(" + txtFileName + "): Test result format is not correct for Customer Id :" + customerId + ",EventId :" + eventId + " and Test: " + testTypeId);
                            _loggerForClient.Info("file(" + txtFileName + "): Test result format is not correct for Customer Id :" + customerId + ",EventId :" + eventId + " and Test: " + testTypeId);
                            continue;
                        }
                        finding = new StandardFinding <int>(Convert.ToInt32(intFinding));

                        TestResult testResult = new IFOBTTestResult {
                            Finding = finding
                        };
                        _resultParserHelper.AddTestResulttoEventCustomerAggregate(eventCustomerAggregates, eventId, customerId, testResult);
                        _resultParserHelper.AddResultArchiveLog(string.Empty, TestType.IFOBT, customerId, MedicalEquipmentTag.LabReportParser);
                    }
                    else
                    {
                        var message = "file(" + txtFileName + "): Test(" + testTypeId + ") is an invalid test for parsing for Customer Id :" + customerId + ",EventId :" + eventId;
                        _labParseEventLogger.Info(message);
                        _loggerForClient.Info(message);
                        continue;
                    }

                    _labParseEventLogger.Info(string.Concat("file(" + txtFileName + "): Result saved successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " and Test :", testTypeId, "\n"));
                    _loggerForClient.Info(string.Concat("file(" + txtFileName + "): Result saved successfully for Customer Id: ", customerId, " ,Event Id: ", eventId, " and Test :", testTypeId, "\n"));
                }
            }
            catch (Exception ex)
            {
                _labParseEventLogger.Info("\nText File: Issue on data saving. Exception: " + ex.Message + "  \n");
                _loggerForClient.Info("\nText File: Issue on data saving.Please contact to Administrator \n");
            }
            return(eventCustomerAggregates);
        }