Beispiel #1
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);
        }