private void DeleteUnUsedFolder(string filePath, string fileName)
 {
     try
     {
         var enddate       = DateTime.Today.AddDays(-7);
         var existingFiles = new List <string>();
         for (var date = DateTime.Today; enddate < date; date = date.AddDays(-1))
         {
             string filename = fileName + date.ToString("yyyyMMdd") + ".txt";
             existingFiles.Add(filename);
         }
         var files = DirectoryOperationsHelper.GetFiles(filePath, fileName + "*.txt");
         foreach (string file in files)
         {
             if (existingFiles.Any(x => file.EndsWith(x)))
             {
                 continue;
             }
             DirectoryOperationsHelper.DeleteFileIfExist(file);
         }
     }
     catch (Exception ex)
     {
         _logger.Error("While creating CSV File : " + ex.Message + "\n\t" + ex.StackTrace + "\n\n");
     }
 }
示例#2
0
        private void ParseFileFromBPShare(IEnumerable <long> customerIds, string sourceDirectory, string destinationDirectory)
        {
            try
            {
                var filesFocAttestation = DirectoryOperationsHelper.GetFiles(sourceDirectory, "*.pdf");
                foreach (var customerId in customerIds)
                {
                    _logger.Info("Proccessed for Customer Id " + customerId);
                    var focAttestationFile = string.Empty;
                    var destinationFile    = string.Empty;

                    var attestationfile = filesFocAttestation.FirstOrDefault(fsd => !string.IsNullOrEmpty(fsd) && Path.GetFileNameWithoutExtension(fsd).ToLower().Trim() == customerId.ToString());

                    if (attestationfile.IsNullOrEmpty())
                    {
                        _logger.Info("File not found for customer Id " + customerId);
                        continue;
                    }
                    destinationFile = Path.Combine(destinationDirectory, customerId + ".pdf");
                    _logger.Info("File Moving for customer Id " + customerId + " Source file name :" + attestationfile + ", destination file name : " + destinationFile);

                    DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);

                    DirectoryOperationsHelper.Move(attestationfile, destinationFile);
                    _logger.Info("File Moved for customer Id " + customerId + " Source file name :" + attestationfile + ", destination file name : " + destinationFile);
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("Error on Copy File From BPShare Message: " + exception.Message + "\n stack trace: " + exception.StackTrace));
            }
        }
示例#3
0
        public void Parse()
        {
            try
            {
                _loggerForClient = _logManager.GetLogger("LabReportClientLogger_" + DateTime.Now.ToString("yyyyMMdd"));
                _loggerForClient.Info("\n\n\n=== Lab Report Parsing - " + Directory.GetParent(_labReportTestResultPath).Name + "\\" + (new DirectoryInfo(_labReportTestResultPath)).Name + " ============\n");

                var timeOfDay = DateTime.Now;

                if (_isDevEnvironment || timeOfDay.TimeOfDay > new TimeSpan(3, 0, 0))
                {
                    if (!DirectoryOperationsHelper.IsDirectoryExist(_labReportTestResultPath))
                    {
                        _loggerForClient.Info("Lab Report Parsing - Folder does not exist at location" + _labReportTestResultPath);
                        return;
                    }
                    if (!DirectoryOperationsHelper.GetFiles(_labReportTestResultPath).Any())
                    {
                        _loggerForClient.Info("Lab Report Parsing - There is not any File available for Parsing " + _labReportTestResultPath);
                        return;
                    }

                    var fileList = DirectoryOperationsHelper.GetFiles(_labReportTestResultPath);

                    if (fileList != null && fileList.Any())
                    {
                        _loggerForClient.Info("Number of Events : " + fileList.Count());

                        var labReportParser       = new LabReportParser(_labReportTestResultPath, _labReportArchivedTestResultPath, _loggerForClient, _settings, _eventCustomerRepository, _logManager);
                        var customerScreeningData = labReportParser.Parse();
                        _loggerForClient.Info("----------------------------");
                        Save(customerScreeningData, UploadedBy);
                    }
                }

                //DirectoryOperationsHelper.CreateDirectoryIfNotExist(_labParseClientLoggerPath);
                //var sourcePath = _mediaRepository.GetLogFolderLocation().PhysicalPath;
                //sourcePath = Path.Combine(sourcePath, folderName);
                //var clientLoggerFiles = DirectoryOperationsHelper.GetFiles(sourcePath, "LabReportClientLogger_" + DateTime.Now.ToString("ddMMyyyy_") + "*.txt");
                //if (clientLoggerFiles.Count() > 0)
                //{
                //    foreach (var clientLogger in clientLoggerFiles)
                //    {
                //        string fileName = new FileInfo(clientLogger).Name;
                //        var sourceFile = Path.Combine(sourcePath, fileName);
                //        var destinationFile = Path.Combine(_labParseClientLoggerPath, fileName);
                //        DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);
                //        DirectoryOperationsHelper.Copy(sourceFile, destinationFile);
                //    }

                //}
            }
            catch (Exception ex)
            {
                _loggerForClient.Error("Lab Report parsing: " + ex.Message + "\n" + ex.StackTrace, ex);
            }
        }
示例#4
0
        private void MoveFileToArchive(string sourceFolder, string destinationFolder)
        {
            _logger.Info("Moving directory to archive folder.");
            var directories = DirectoryOperationsHelper.GetDirectories(sourceFolder);

            if (directories == null || !directories.Any())
            {
                _logger.Info("No directory found to move into archive.");
                return;
            }

            directories = directories.Where(x => !x.Contains(DateTime.Today.Year.ToString())).ToArray();

            if (directories.Any())
            {
                foreach (var dir in directories)
                {
                    var files = DirectoryOperationsHelper.GetFiles(dir, "*.pdf");
                    if (!files.Any())
                    {
                        _logger.Info("No files found in Directory: " + dir + "to move into archive.");
                        continue;
                    }

                    _logger.Info(string.Format("{0} files found in directory: {1}.", files.Count(), dir));

                    var folderName = Path.GetFileName(dir.TrimEnd(Path.DirectorySeparatorChar));

                    var destinationPath = Path.Combine(destinationFolder, folderName);
                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationPath);

                    foreach (var file in files)
                    {
                        if (DirectoryOperationsHelper.IsFileExist(file))
                        {
                            var fileName            = Path.GetFileName(file);
                            var destinationFileName = Path.Combine(destinationPath, fileName);
                            try
                            {
                                DirectoryOperationsHelper.DeleteFileIfExist(destinationFileName);
                                DirectoryOperationsHelper.Move(file, destinationFileName);
                                _logger.Info(string.Format("{0} file moved into {1} from directory: {2}.", fileName, destinationPath, dir));
                            }
                            catch (Exception ex)
                            {
                                _logger.Error(string.Format("Exception occurred while moving file {0} to {1}. \nException Message: {2}\n\tStackTrace:{3}", file, destinationFileName, ex.Message, ex.StackTrace));
                            }
                        }
                    }

                    DirectoryOperationsHelper.DeleteDirectory(dir);
                }
            }
        }
        public void PollForHourlyReport()
        {
            try
            {
                var timeOfDay = DateTime.Now;
                _logger.Info(string.Format("Time of Date {0}", timeOfDay));

                if (timeOfDay.TimeOfDay > new TimeSpan(_settings.HourlyAppointmentBookedStartTime, 0, 0))
                {
                    timeOfDay = timeOfDay.AddMinutes(10);
                    var filter = new HourlyAppointmentsBookedListModelFilter
                    {
                        FromDate = timeOfDay.Date,
                        ToDate   = DateTime.Now,
                        ShowCustomersWithAppointment = true
                    };
                    if (DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.HourlyAppointmentBookedDownloadPath))
                    {
                        try
                        {
                            var files = DirectoryOperationsHelper.GetFiles(_settings.HourlyAppointmentBookedDownloadPath, string.Format("HourlyAppointmentBookedReport_{0}*.csv", timeOfDay.ToString("yyyyMMdd")));
                            foreach (var file in files)
                            {
                                DirectoryOperationsHelper.DeleteFileIfExist(file);
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("some error occurred while deleting Hourly Report");
                            _logger.Error(string.Format("Message: {0}", ex.Message));
                            _logger.Error(string.Format("Stack Trace: {0}", ex.StackTrace));
                        }


                        var hourlyReport = Path.Combine(_settings.HourlyAppointmentBookedDownloadPath, string.Format("HourlyAppointmentBookedReport_{0}.csv", timeOfDay.ToString("yyyyMMddHHmm")));
                        HourlyAppointmentsBooked(filter, hourlyReport);

                        var notificationModel = _emailNotificationModelsFactory.GetHourlyAppointmentBookedReportNotificationViewModel("AppointmentBookedReport", hourlyReport);
                        _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.HourlyNotificationAppointmentBookedReport, EmailTemplateAlias.HourlyNotificationAppointmentBookedReport, notificationModel, 0, 1, "Hourly Appointment Booked Report");
                    }
                }
                else
                {
                    _logger.Info(string.Format("Hourly AppointmentBooked Report Service can not be Run as it is restricted Time {0}", timeOfDay));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("some error occurred while generating Hourly Report");
                _logger.Error(string.Format("Message: {0}", ex.Message));
                _logger.Error(string.Format("Stack Trace: {0}", ex.StackTrace));
            }
        }
        private void DeleteIffileExist(string destinationPath, int year)
        {
            var files = DirectoryOperationsHelper.GetFiles(destinationPath, "*.csv");

            foreach (var file in files)
            {
                if (!string.IsNullOrEmpty(file) && file.Contains("PCPReport_") && file.Contains("_" + year))
                {
                    if (DirectoryOperationsHelper.IsFileExist(file))
                    {
                        File.Delete(file);
                    }
                }
            }
        }
        private void ParseFilesForCustomer(string dirPath, long eventId)
        {
            var eventlogger = _logManager.GetLogger("HkynParsing_" + eventId);

            eventlogger.Info("started Parsing for EventId: " + eventId);

            var evnentCustomers = _eventCustomerResultRepository.GetByEventId(eventId);

            foreach (var eventCustomer in evnentCustomers)
            {
                try
                {
                    var files = DirectoryOperationsHelper.GetFiles(dirPath, eventCustomer.CustomerId + "*.pdf");

                    if (files.IsNullOrEmpty())
                    {
                        eventlogger.Info("No file found for CustomerId: " + eventCustomer.CustomerId);
                        continue;
                    }

                    var mediaLocation = _mediaRepository.GetKynIntegrationOutputDataLocation(eventId, eventCustomer.CustomerId);

                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(mediaLocation.PhysicalPath);

                    var fileName = KynFileTypes.GetFileName(TestType.HKYN, KynFileTypes.ParticipantSummaryReport);

                    var destinationFilePath = Path.Combine(mediaLocation.PhysicalPath, fileName);
                    var sourceFile          = files.First();

                    eventlogger.Info("Source File: " + sourceFile);
                    eventlogger.Info("destinationFilePath: " + destinationFilePath);

                    DirectoryOperationsHelper.DeleteFileIfExist(destinationFilePath);

                    DirectoryOperationsHelper.Move(sourceFile, destinationFilePath);
                }
                catch (Exception ex)
                {
                    _logger.Error("Some error occurred while parsing for Event id " + eventId + " CustomerId: " + eventCustomer.CustomerId);
                    _logger.Error("Message: " + ex.Message);
                    _logger.Error("Stack Trace: " + ex.StackTrace);
                }
            }

            eventlogger.Info("completed Parsing  for EventId: " + eventId);
        }
示例#8
0
        private static string GetFolderPathfor(string toFindinFolder)
        {
            // Need to provide a better pattern
            if (DirectoryOperationsHelper.GetFiles(toFindinFolder).Any(file => Path.GetExtension(file).ToLower().IndexOf("pdf") > 0))
            {
                return(toFindinFolder);
            }

            foreach (string directory in DirectoryOperationsHelper.GetDirectories(toFindinFolder))
            {
                var path = GetFolderPathfor(directory);
                if (!string.IsNullOrEmpty(path))
                {
                    return(path);
                }
            }

            return(string.Empty);
        }
示例#9
0
        private void CopyFileToClientLocation(string folderPath)
        {
            _logger.Info("Source Path CopyFileToClientLocation : " + folderPath);

            if (DirectoryOperationsHelper.IsDirectoryExist(_clientLocationFolder))
            {
                _logger.Info("Destination Location Exists: " + _clientLocationFolder);

                if (DirectoryOperationsHelper.IsDirectoryExist(folderPath))
                {
                    _logger.Info("Source Path Exists: " + folderPath);

                    var crossfilePath = DirectoryOperationsHelper.GetFiles(folderPath);
                    if (!crossfilePath.IsNullOrEmpty())
                    {
                        _logger.Info("Number of Crosswalk Found:" + crossfilePath);

                        foreach (var filePath in crossfilePath)
                        {
                            var fileName = Path.GetFileName(filePath);
                            if (string.IsNullOrWhiteSpace(fileName))
                            {
                                continue;
                            }

                            var destinationFileName = Path.Combine(_clientLocationFolder, fileName);
                            DirectoryOperationsHelper.Copy(filePath, destinationFileName);
                            _logger.Info("Source: " + filePath);
                            _logger.Info("Destination: " + destinationFileName);
                        }
                    }
                    else
                    {
                        _logger.Info("No Crosswalk Found");
                    }
                }
            }
            else
            {
                _logger.Info("Destination Path not exist : " + _clientLocationFolder);
            }
        }
        private void AttachAttestationForm(string sourcePath, string searchPattern, string destinationFolder, string destinationFileName = "")
        {
            if (DirectoryOperationsHelper.IsDirectoryExist(sourcePath))
            {
                var files = DirectoryOperationsHelper.GetFiles(sourcePath, "*" + searchPattern + ".pdf");
                if (files != null && files.Any())
                {
                    foreach (var file in files)
                    {
                        var destinationFile = Path.Combine(destinationFolder, !string.IsNullOrEmpty(destinationFileName) ? destinationFileName + ".pdf" : Path.GetFileNameWithoutExtension(file) + ".pdf");
                        if (DirectoryOperationsHelper.IsFileExist(destinationFile))
                        {
                            DirectoryOperationsHelper.Delete(destinationFile);
                        }

                        DirectoryOperationsHelper.Copy(file, destinationFile);
                    }
                }
                else
                {
                    _logger.Info(string.Format("No file Found in folder : {0} for search pattern : {1}", sourcePath, searchPattern));
                }
            }
        }
        public void PollForParsePatientDataFromAces()
        {
            try
            {
                _logger.Info("Entering Parse Patient Data From Aces Polling Agent @:" + DateTime.Now);

                var sftpFileLocation = _settings.ParsePatientDataSftpPath;
                var mediaLocation    = _mediaRepository.GetParsePatientDataMediaFileLocation();

                var archiveFolder = Path.Combine(mediaLocation.PhysicalPath, "Archive", DateTime.Today.ToString("yyyyMMdd"));
                var failedFolder  = Path.Combine(mediaLocation.PhysicalPath, "Failed", DateTime.Today.ToString("yyyyMMdd"));

                var getFilesFromSftp = DirectoryOperationsHelper.GetFiles(sftpFileLocation, "TCPA_AcesID_HipID*.txt");

                if (getFilesFromSftp.IsNullOrEmpty())
                {
                    _logger.Info("No files found for parsing.");
                    return;
                }

                DirectoryOperationsHelper.CreateDirectoryIfNotExist(archiveFolder);

                foreach (var file in getFilesFromSftp)
                {
                    var fileName = Path.GetFileName(file);
                    MoveFile(file, Path.Combine(mediaLocation.PhysicalPath, fileName));
                }

                var filesToParse = DirectoryOperationsHelper.GetFiles(mediaLocation.PhysicalPath, "*.txt");
                _logger.Info("Number of files to Parse:" + filesToParse.Count());
                const int pageSize = 100;

                foreach (var file in filesToParse)
                {
                    try
                    {
                        var fileName   = Path.GetFileName(file);
                        var sourceFile = Path.Combine(mediaLocation.PhysicalPath, fileName);

                        var patientData   = _pipeDelimitedReportHelper.Read(sourceFile);
                        var recordsInFile = patientData.Rows.Count;
                        if (recordsInFile == 0)
                        {
                            _logger.Info("No record found in " + fileName);
                            MoveFile(sourceFile, Path.Combine(archiveFolder, fileName));
                            continue;
                        }
                        _logger.Info("Parsing file: " + fileName);
                        _logger.Info("Total number of records to file: " + recordsInFile);
                        var failedRecords     = new List <PatientParsedDataViewModel>();
                        var parsedPatientData = ParsePatientData(patientData.AsEnumerable(), failedRecords);
                        if (parsedPatientData.Any())
                        {
                            var pageNumber   = 1;
                            int totalRecords = parsedPatientData.Count();

                            var totalPages = (totalRecords / pageSize) + (totalRecords % pageSize != 0 ? 1 : 0);
                            do
                            {
                                var pagedCustomers    = parsedPatientData.Skip(pageSize * (pageNumber - 1)).Take(pageSize);
                                var parsedCustomerIds = pagedCustomers.Select(x => x.CustomerId).ToArray();
                                var customerIds       = _customerRepository.CheckCustomerExists(parsedCustomerIds).ToArray();
                                if (parsedCustomerIds.Count() != customerIds.Count())
                                {
                                    var customerIdNotExist = parsedCustomerIds.Except(customerIds);
                                    var failedCustomers    = pagedCustomers.Where(x => customerIdNotExist.Contains(x.CustomerId));
                                    failedCustomers.ForEach(x => x.Error = "HIPID does not exist.");
                                    failedRecords.AddRange(failedCustomers);
                                    pagedCustomers = pagedCustomers.Where(x => customerIds.Contains(x.CustomerId));
                                }

                                var customerIdsAlreadyHaveAcesId = _customerRepository.CheckCustomerAlreadyHaveAcesId(customerIds);
                                if (customerIdsAlreadyHaveAcesId.Count() != 0)
                                {
                                    var customersAlreadyHaveAcesId = pagedCustomers.Where(x => customerIdsAlreadyHaveAcesId.Contains(x.CustomerId));
                                    customersAlreadyHaveAcesId.ForEach(x => x.Error = "Patient already have ACESID.");
                                    failedRecords.AddRange(customersAlreadyHaveAcesId);
                                    pagedCustomers = pagedCustomers.Where(x => !customerIdsAlreadyHaveAcesId.Contains(x.CustomerId));
                                }

                                var acesIdAlreadyAssignedToCustomers = _customerRepository.CheckAcesIdAlreadyAssignedToCustomer(pagedCustomers.Select(x => x.AcesId.ToLower()).ToArray());
                                if (acesIdAlreadyAssignedToCustomers.Count() != 0)
                                {
                                    var acesIdAlreadyAssignedCustomers = pagedCustomers.Where(x => acesIdAlreadyAssignedToCustomers.Contains(x.AcesId));
                                    acesIdAlreadyAssignedCustomers.ForEach(x => x.Error = "ACESID already assigned to a patient.");
                                    failedRecords.AddRange(acesIdAlreadyAssignedCustomers);
                                    pagedCustomers = pagedCustomers.Where(x => !acesIdAlreadyAssignedToCustomers.Contains(x.AcesId.ToLower()));
                                }
                                _logger.Info(string.Format("Number of customer to parse: {0} in page: {1}", pagedCustomers.Count(), pageNumber));
                                foreach (var customer in pagedCustomers)
                                {
                                    try
                                    {
                                        _logger.Info("Parsing data for CustomerId: " + customer.CustomerId);
                                        var customerEligibility      = _customerEligibilityRepository.GetByCustomerIdAndYear(customer.CustomerId, DateTime.Today.Year);
                                        var customerProfileHistoryId = _customerProfileHistoryRepository.CreateCustomerHistory(customer.CustomerId, orgRoleId, customerEligibility);
                                        _eventCustomerRepository.UpdateCustomerProfileIdByCustomerId(customer.CustomerId, customerProfileHistoryId);
                                        _customerRepository.UpdateAcesId(customer.CustomerId, customer.AcesId);
                                    }
                                    catch (Exception ex)
                                    {
                                        failedRecords.Add(new PatientParsedDataViewModel()
                                        {
                                            AcesId = customer.AcesId, CustomerId = customer.CustomerId, Error = "Some error occurred while updating."
                                        });
                                        _logger.Error(string.Format("Error occurred while updating record for CustomerId: {0}.\nMessage: {1}\n\tStackTrace: {2}", customer.CustomerId, ex.Message, ex.StackTrace));
                                    }
                                }

                                pageNumber++;
                            }while (totalPages >= pageNumber);
                        }
                        CreateFailedPatientFile(fileName, failedFolder, failedRecords);
                        MoveFile(sourceFile, Path.Combine(archiveFolder, fileName));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Error occurred while processing the {0}.\nMessage: {1}\n\tStackTrace: {2}", file, ex.Message, ex.StackTrace));
                        var fileName = Path.GetFileName(file);
                        MoveFile(file, Path.Combine(archiveFolder, fileName));
                    }
                }
                _logger.Info("File parsing completed @ " + DateTime.Now);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Exception occurred during execution of servcie. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace));
                return;
            }
        }
示例#12
0
        public void Parse()
        {
            try
            {
                _logger.Info("Running Loinc Lab Data");

                if (!DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.LoincLabDataPath))
                {
                    _logger.Info(string.Format("Folder could not be created. Please check path: {0} ", _settings.LoincLabDataPath));
                    return;
                }

                var loincMediaLocation = _mediaRepository.GetLoincMediaLocation();
                var archiveLocation    = _mediaRepository.GetLoincArchiveMediaLocation();

                var loincLabfiles = DirectoryOperationsHelper.GetFiles(_settings.LoincLabDataPath, "*.csv");
                if (loincLabfiles.IsNullOrEmpty())
                {
                    _logger.Info(string.Format("No csv file found at following location {0}", _settings.LoincLabDataPath));
                }
                else
                {
                    UploadLoincFiles(loincLabfiles, loincMediaLocation.PhysicalPath, (long)OutboundUploadType.LoincLabData);
                }

                var uploadedFiles = _outboundUploadRepository.GetAllUploadedFilesByType((long)OutboundUploadType.LoincLabData);
                if (uploadedFiles.IsNullOrEmpty())
                {
                    _logger.Info("No new files uploaded for Loinc Lab Data.");
                    return;
                }

                foreach (var uploadedFile in uploadedFiles)
                {
                    try
                    {
                        var file = GetFile(uploadedFile.FileId);

                        if (!System.IO.File.Exists(loincMediaLocation.PhysicalPath + file.Path))
                        {
                            _logger.Info("File not found : " + loincMediaLocation.PhysicalPath + file.Path);
                            continue;
                        }

                        uploadedFile.StatusId       = (long)OutboundUploadStatus.Parsing;
                        uploadedFile.ParseStartTime = DateTime.Now;
                        _outboundUploadRepository.Save(uploadedFile);

                        _logger.Info("Importing File : " + file.Path);

                        var loincLabData = _csvReader.ReadWithTextQualifierLargeData(loincMediaLocation.PhysicalPath + file.Path);

                        var csvStringBuilder = new StringBuilder();
                        csvStringBuilder.Append(LogHeader + Environment.NewLine);

                        long totalRows = 0, successRows = 0;

                        foreach (var dataTable in loincLabData)
                        {
                            if (dataTable.Rows.Count == 0)
                            {
                                _logger.Info("No records found for file : " + loincMediaLocation.PhysicalPath + file.Path);
                                continue;
                            }
                            foreach (DataRow row in dataTable.Rows)
                            {
                                totalRows++;
                                LoincLabDataEditModel model = null;

                                model = GetLoincLabData(row);

                                var errorRow = model.MemberId + "," + model.Gmpi + "," + model.Loinc + "," + model.LoincDescription + "," + model.ResultValue + "," + model.ResultUnits + "," + model.RefRange + "," + model.DoS;

                                try
                                {
                                    if (model != null && !model.IsEmpty())
                                    {
                                        var domain = new LoincLabData
                                        {
                                            MemberId         = model.MemberId,
                                            Gmpi             = model.Gmpi,
                                            Loinc            = model.Loinc,
                                            LoincDescription = model.LoincDescription,
                                            ResultValue      = model.ResultValue,
                                            ResultUnits      = model.ResultUnits,
                                            RefRange         = model.RefRange,
                                            DateOfService    = GetRowDateValue(model.DoS),
                                            Year             = DateTime.Today.Year,
                                            DateCreated      = DateTime.Now,
                                            UploadId         = uploadedFile.Id,
                                        };

                                        _loincLabDataRepository.Save(domain);
                                    }

                                    successRows++;
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(string.Format("Some Error Occurred Message: {0} \n stack Trace: {1}", ex.Message, ex.StackTrace));
                                    csvStringBuilder.Append(errorRow + "," + ex.Message + Environment.NewLine);
                                }
                            }
                        }

                        if (successRows < totalRows)
                        {
                            var logFileName = file.Path + "_Log.csv";

                            var logFile = SaveLogFile(_settings.LoincLabDataPath + logFileName, csvStringBuilder);
                            uploadedFile.LogFileId = logFile.Id;
                        }

                        uploadedFile.SuccessUploadCount = successRows;
                        uploadedFile.FailedUploadCount  = totalRows - successRows;
                        uploadedFile.ParseEndTime       = DateTime.Now;
                        uploadedFile.StatusId           = successRows > 0 ? (long)OutboundUploadStatus.Parsed : (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);

                        if (successRows > 1)
                        {
                            System.IO.File.Move(loincMediaLocation.PhysicalPath + file.Path, archiveLocation.PhysicalPath + file.Path);
                            ((IFileRepository)_fileRepository).MarkasArchived(file.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        uploadedFile.StatusId = (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);
                        _logger.Error(string.Format("while Parsing File"));
                        _logger.Error("Ex Message" + ex.Message);
                        _logger.Error("Ex Stack Trace " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while Parsing Loinc Lab Data Files.");
                _logger.Error(ex);
            }
        }
示例#13
0
        public void PollForBiomassEvents()
        {
            try
            {
                if (_stopTrailService)
                {
                    _logger.Info("Trail service has been stopped");
                    return;
                }
                var timeOfDay = DateTime.Now;
                if (_isDevEnvironment || timeOfDay.TimeOfDay > new TimeSpan(3, 0, 0))
                {
                    _logger.Info("Initialising xml generation.....");
                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(_bioCheckAssessmentFailedListPath);
                    var files = DirectoryOperationsHelper.GetFiles(_bioCheckAssessmentFailedListPath, "failedCustomerRecord*.xml");
                    if (files.IsNullOrEmpty())
                    {
                        _logger.Info("No Failed Customer XML found");
                        return;
                    }

                    foreach (var file in files)
                    {
                        try
                        {
                            var failedCustomerRecords = _bioCheckAssessmentFailedListXmlSerializer.Deserialize(file);

                            if (failedCustomerRecords == null || failedCustomerRecords.EventCustomers.IsNullOrEmpty())
                            {
                                _logger.Info("no record found in failedRecord XML in File: " + file);
                                continue;
                            }

                            var customerIds = failedCustomerRecords.EventCustomers.Select(x => x.CustomerId);
                            var eventid     = failedCustomerRecords.EventCustomers.First().EventId;
                            var eventData   = _eventRepository.GetById(eventid);

                            DirectoryOperationsHelper.DeleteFileIfExist(file);

                            int totalrecords;
                            var logger         = _logManager.GetLogger("FailedBioCheckJson" + eventData.Id);
                            var eventCustomers = _eventCustomerRepository.GetMyBioCheckEventCustomers(1, 400, new MyBioCheckCustomerModelFilter {
                                EventId = eventData.Id
                            }, out totalrecords);

                            if (eventCustomers == null || !eventCustomers.Any())
                            {
                                logger.Info(string.Format("No event customers found for Event Id {0} EventDate {1}", eventData.Id, eventData.EventDate));
                                return;
                            }

                            eventCustomers = eventCustomers.Where(x => customerIds.Contains(x.CustomerId));
                            _myBioCheckAssessmentJsonHelper.GenerateJsonforEventCustomers(eventData, eventCustomers, logger);
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("Some Error Occurred While generating Failed Customer BioCheck Assessment Message: " + ex.Message + " Stack Trace: " + ex.StackTrace);
                        }
                    }
                }
                else
                {
                    _logger.Info(string.Format("Generate MyBioCheck Polling can not be called as time of day is {0}", timeOfDay.TimeOfDay));
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("Some Error Occurred. Message: {0} , StackTrace {1}", exception.Message, exception.StackTrace));
            }
        }
示例#14
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);
        }
示例#15
0
        public void PollForCallParsing()
        {
            try
            {
                _logger.Info("Entering In GMS Dialer Parsing ");
                var timeOfDay = DateTime.Now;
                if (_isDevEnvironment || (timeOfDay.TimeOfDay < new TimeSpan(1, 0, 0)) || (timeOfDay.TimeOfDay > new TimeSpan(2, 0, 0)))
                {
                    //Check for file
                    _logger.Info("Getting files");

                    var sourceLocation = _settings.GmsDialerFilePath;
                    var dialerFiles    = DirectoryOperationsHelper.GetFiles(sourceLocation, "*.csv");
                    if (dialerFiles.IsNullOrEmpty())
                    {
                        _logger.Info("No dialer file found at " + sourceLocation);
                        return;
                    }

                    //move file to media location
                    var mediaLocation       = _mediaRepository.GetGMSDialerMediaFileLocation();
                    var archiveMediaLoation = _mediaRepository.GetGMSDialerArchiveMediaLocation();
                    foreach (var dialerFile in dialerFiles)
                    {
                        var fileInfo = new FileInfo(dialerFile);

                        DirectoryOperationsHelper.Move(dialerFile, mediaLocation.PhysicalPath + fileInfo.Name);
                    }

                    long orgRoleUserId = 1;

                    var gmsUser = _userLoginRepository.GetByUserName(_settings.GmsUserName);
                    if (gmsUser != null)
                    {
                        var organizationRoleUser = _organizationRoleUserRepository.GetOrganizationRoleUsermodel(gmsUser.Id, (long)Roles.CallCenterRep);
                        if (organizationRoleUser != null)
                        {
                            orgRoleUserId = organizationRoleUser.OrganizationRoleUserId;
                        }
                    }

                    //parse file
                    var files = DirectoryOperationsHelper.GetFiles(mediaLocation.PhysicalPath, "*.csv");
                    foreach (var file in files)
                    {
                        try
                        {
                            var fileInfo = new FileInfo(file);

                            var callTable = _csvReader.ReadWithTextQualifier(file);
                            if (callTable.Rows.Count == 0)
                            {
                                _logger.Info(string.Format("No data for file FileName:{0}.", file));
                                return;
                            }

                            var missingColumnNames = _gmsCallParserHelper.CheckForColumns(callTable.Rows[0]);
                            if (!string.IsNullOrEmpty(missingColumnNames))
                            {
                                _logger.Info(string.Format("Invalid file FileName:{0}. Missing headers: {1}", file, missingColumnNames));
                                return;
                            }

                            foreach (DataRow row in callTable.Rows)
                            {
                                var model = _gmsCallParserHelper.GetGmsDialerCallModel(row);
                                try
                                {
                                    _callUploadService.SaveGmsDialerCall(model, orgRoleUserId, _logger);
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(string.Format("Error for Customer Id: {0} in file: {1}. Message: {2}. \n Stack Trace{3}", model.CustomerId, fileInfo.Name, ex.Message, ex.StackTrace));
                                }
                            }

                            //move to archive location
                            DirectoryOperationsHelper.Move(file, archiveMediaLoation.PhysicalPath + fileInfo.Name);
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Error for file {0}. Message: {1} \n Stack Trace : {2}", file, ex.Message, ex.StackTrace));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("GMSDialerParsing Exception Message: " + ex.Message + "\n Stack Trace:" + ex.StackTrace);
            }
        }
        public void PollForPdfDownload()
        {
            try
            {
                if (_accountIds.IsNullOrEmpty())
                {
                    return;
                }
                var corporateAccounts = _corporateAccountRepository.GetByIds(_accountIds);

                foreach (var corporateAccount in corporateAccounts)
                {
                    try
                    {
                        _logger.Info(string.Format("Generating for accountId {0} and account tag {1}. ", corporateAccount.Id, corporateAccount.Tag));

                        var destinationFolderPdf  = string.Format(_destinationFolderPdfSetting, corporateAccount.FolderName);
                        var customSettingFilePath = string.Format(_customSettingFile, corporateAccount.Tag);
                        var customSettings        = _customSettingManager.Deserialize(customSettingFilePath);

                        var exportToTime   = DateTime.Now.AddHours(-1);
                        var exportFromTime = customSettings.LastTransactionDate ?? _cutOfDate;

                        DateTime?stopSendingPdftoHealthPlanDate = null;
                        if (corporateAccount.IsHealthPlan)
                        {
                            stopSendingPdftoHealthPlanDate = _stopSendingPdftoHealthPlanDate;
                        }
                        _logger.Info("exportToTime: " + exportToTime.ToString("MM/dd/yyyy"));
                        _logger.Info("exportFromTime: " + exportFromTime.ToString("MM/dd/yyyy"));

                        var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsToFax((int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, exportToTime, exportFromTime, corporateAccount.Id, corporateAccount.Tag, true, stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate);

                        var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray();

                        if (eventCustomerResults == null || !customerResults.Any())
                        {
                            _logger.Info(string.Format("No event customer result list for {0} Result Pdf Download.", corporateAccount.Tag));
                            continue;
                        }

                        if (_optumAccountIds.Contains(corporateAccount.Id))
                        {
                            try
                            {
                                DirectoryOperationsHelper.DeleteDirectory(destinationFolderPdf, true);
                            }
                            catch (Exception ex)
                            {
                                _logger.Error("Some error occurred while deleting directory at path: " + destinationFolderPdf);
                                _logger.Error("Message: " + ex.Message);
                                _logger.Error("Stack Trace: " + ex.StackTrace);
                            }
                        }

                        _logger.Info(string.Format("Found {0} customers for {1} Result Pdf Download. ", eventCustomerResults.Count(), corporateAccount.Tag));

                        var pcpResultReport = _mediaRepository.GetPdfFileNameForPcpResultReport();

                        var healthPlanResultReport = _mediaRepository.GetPdfFileNameForHealthPlanResultReport();

                        var resultPostedToPlanFileName = Path.Combine(_resultPostedToPlanPath, string.Format("ResultPostedto_{0}.xml", corporateAccount.Tag));
                        var resultPosted = _resultPdfPostedSerializer.Deserialize(resultPostedToPlanFileName);
                        resultPosted = resultPosted == null || resultPosted.Customer.IsNullOrEmpty() ? new ResultPdfPostedXml {
                            Customer = new List <CustomerInfo>()
                        } : resultPosted;

                        _logger.Info(string.Format("Result Pdf file Transfer started for {0} ", corporateAccount.Tag));

                        var customersWithNoMrn    = new List <long>();
                        var newCustomersWithNoMrn = new List <long>();

                        foreach (var ecr in customerResults)
                        {
                            var sourceUrl = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + healthPlanResultReport;

                            if (!File.Exists(sourceUrl))
                            {
                                sourceUrl = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + pcpResultReport;
                            }

                            if (File.Exists(sourceUrl))
                            {
                                try
                                {
                                    SetReusltPdfNameing(ecr, corporateAccount, destinationFolderPdf, sourceUrl, resultPosted, newCustomersWithNoMrn);
                                }
                                catch (Exception exception)
                                {
                                    _logger.Error(string.Format("some error occured for the customerId {0}, {1},\n Messagen {2} \n Stack Trace {3}", ecr.CustomerId, ecr.EventId, exception.Message, exception.StackTrace));
                                }
                            }
                            else
                            {
                                _logger.Info(string.Format("File not generated or removed for the customerId {0}, {1}", ecr.CustomerId, ecr.EventId));
                            }
                        }

                        if (corporateAccount.Id == _settings.OptumNvAccountId || corporateAccount.Id == _settings.OptumNvMedicareAccountId)
                        {
                            _logger.Info("Sending Old Files to SFTP");

                            PostCustomerWithNoMrn(corporateAccount, destinationFolderPdf, resultPosted, customersWithNoMrn);

                            _logger.Info("Sending Old Files to SFTP Completed");

                            if (!customersWithNoMrn.IsNullOrEmpty())
                            {
                                newCustomersWithNoMrn.AddRange(customersWithNoMrn);
                            }

                            newCustomersWithNoMrn = newCustomersWithNoMrn.Distinct().ToList();

                            SaveCustomersWithNoMrn(corporateAccount, newCustomersWithNoMrn);
                        }

                        customSettings.LastTransactionDate = exportToTime;
                        _customSettingManager.SerializeandSave(customSettingFilePath, customSettings);

                        if (resultPosted != null && !resultPosted.Customer.IsNullOrEmpty())
                        {
                            _logger.Info("Result posted Log for " + corporateAccount.Tag);
                            resultPosted = _resultPdfFileHelper.CorrectMissingRecords(resultPosted);

                            var pdfLogfile = string.Format(_settings.PdfLogFilePath, corporateAccount.FolderName);
                            pdfLogfile = Path.Combine(pdfLogfile, "Download");

                            try
                            {
                                DirectoryOperationsHelper.CreateDirectoryIfNotExist(pdfLogfile);
                                if (DirectoryOperationsHelper.IsDirectoryExist(pdfLogfile))
                                {
                                    var filesTobedeleted = DirectoryOperationsHelper.GetFiles(pdfLogfile, "*" + corporateAccount.Tag + "_PdfLogFile*");
                                    foreach (var logFile in filesTobedeleted)
                                    {
                                        DirectoryOperationsHelper.DeleteFileIfExist(logFile);
                                    }
                                }

                                var resultPostedCustomers = resultPosted.Customer.Where(x => x.EventDate.HasValue && x.EventDate.Value.Year >= _cutOfDate.Year);
                                _resultPdfFileHelper.CreateCsvForFileShared(resultPostedCustomers, pdfLogfile, corporateAccount.Tag + "_PdfLogFile");
                            }
                            catch (Exception ex)
                            {
                                _logger.Error("some error occurred");
                                _logger.Error("exception: " + ex.Message);
                                _logger.Error("stack trace: " + ex.StackTrace);
                            }

                            _logger.Info("Result posted Log Completed for " + corporateAccount.Tag);
                        }

                        _resultPdfPostedSerializer.SerializeandSave(resultPostedToPlanFileName, resultPosted);

                        _logger.Info(string.Format("Result Pdf file Transfer completed for {0} ", corporateAccount.Tag));
                        _logger.Info("");
                        _logger.Info("");
                        _logger.Info("================================================================================");
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("some error occured for AccountId: {0} and account tag: {1} Exception Message: \n{2}, \n stack Trace: \n\t {3} ", corporateAccount.Id, corporateAccount.Tag, ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("some error occured Exception Message: \n{0}, \n stack Trace: \n\t {1} ", exception.Message, exception.StackTrace));
            }
        }
示例#17
0
        private void PatientWithGapTag(DateTime exportToTime, DateTime exportFromTime, CorporateAccount corporateAccount, DateTime?eventDateFromConsider, DateTime?eventDateToConsider)
        {
            try
            {
                var destinationFolderPdfPath = string.Format(_destinationFolderResultPdfPath, corporateAccount.FolderName);
                destinationFolderPdfPath = destinationFolderPdfPath + "\\Q-ResultPdf";

                PostResultPdfOnSftp(exportToTime, exportFromTime, corporateAccount, destinationFolderPdfPath, true, _bcbsMiGapPatinetTags);

                if (DirectoryOperationsHelper.IsDirectoryExist(destinationFolderPdfPath) && DirectoryOperationsHelper.GetFiles(destinationFolderPdfPath).Any())
                {
                    var destinationSftp = string.Format(_destinationFolderResultReportPath, corporateAccount.FolderName);

                    if (!DirectoryOperationsHelper.IsDirectoryExist(destinationSftp))
                    {
                        DirectoryOperationsHelper.CreateDirectory(destinationSftp);
                    }

                    var destinationfile = destinationSftp + @"\Q_MOBILE_ResultPdf_" + DateTime.Today.ToString("yyyyMMdd") + ".zip";

                    _zipHelper.CreateZipFiles(destinationFolderPdfPath, destinationfile, true);
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("some error occurred for the \n Message {0} \n Stack Trace {1}", exception.Message, exception.StackTrace));
            }
        }
示例#18
0
        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);
        }
示例#19
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

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

            foreach (var filePath in DirectoryOperationsHelper.GetFiles(directoryPath))
            {
                if (Path.GetExtension(filePath).ToLower().Contains("pdf"))
                {
                    _logger.Info("Parsing file : " + filePath);
                    var  fileName = Path.GetFileName(filePath);
                    bool isSpiro  = false;
                    var  fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                    isSpiro = fileNameWithoutExtension.ToLower().EndsWith(SpiroFilePrefix);


                    var searchPattern = fileName.Substring(0, GetIndexOfNthOccurence(fileName, '_', 5)) + "*" + (isSpiro ? "_spiro.pdf" : "_ecg.pdf");

                    var versionedFiles = DirectoryOperationsHelper.GetFiles(directoryPath, searchPattern).Select(Path.GetFileName);;

                    var latestVersion = versionedFiles.OrderByDescending(x => x).First();

                    if (Path.GetFileName(filePath) != latestVersion)
                    {
                        _logger.Info("A more recent version of this file is present : " + latestVersion);
                        continue;
                    }

                    var customerIdString = fileName.IndexOf("_") > 0 ? fileName.Substring(0, fileName.IndexOf("_")) : fileName;

                    long customerId;

                    if (!long.TryParse(customerIdString, out customerId))
                    {
                        _logger.Info("Customer ID not found on Pdf file : " + filePath);
                        continue;
                    }

                    if (!isSpiro)
                    {
                        bool isEkgTestPurchasedByCustomer        = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.EKG);
                        bool isAwvEkgTestPurchasedByCustomer     = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkg);
                        bool isAwvEkgIppeTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvEkgIPPE);

                        try
                        {
                            if (!isEkgTestPurchasedByCustomer && !isAwvEkgTestPurchasedByCustomer && !isAwvEkgIppeTestPurchasedByCustomer)
                            {
                                _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("EKG/ECG is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                            continue;
                        }

                        try
                        {
                            TestResult testResult = null;
                            var        testType   = TestType.EKG;

                            if (isAwvEkgIppeTestPurchasedByCustomer) //&& IsEkgIppeFile
                            {
                                testType = TestType.AwvEkgIPPE;
                            }
                            else if (isAwvEkgTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvEkg;
                            }

                            var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString());
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            if (resultMedia != null)
                            {
                                switch (testType)
                                {
                                case TestType.EKG:
                                    testResult = new EKGTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkg:
                                    testResult = new AwvEkgTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvEkgIPPE:
                                    testResult = new AwvEkgIppeTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;
                                }

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

                                _logger.Info(string.Concat("\nParsing succeeded for EKG  for Customer Id: ", customerId, "\n"));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isAwvEkgIppeTestPurchasedByCustomer ? TestType.AwvEkgIPPE : isAwvEkgTestPurchasedByCustomer ? TestType.AwvEkg : TestType.EKG, customerId, MedicalEquipmentTag.CardioCard, false);
                        }
                    }
                    else if (isSpiro)
                    {
                        bool isSpiroTestPurchasedByCustomer    = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro);
                        bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro);

                        try
                        {
                            if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer)
                            {
                                _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "].\n");
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                            continue;
                        }

                        try
                        {
                            TestResult testResult = null;
                            var        testType   = TestType.Spiro;

                            if (isAwvSpiroTestPurchasedByCustomer)
                            {
                                testType = TestType.AwvSpiro;
                            }

                            var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                            var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString(), false);
                            resultMedia.ReadingSource = ReadingSource.Automatic;

                            if (resultMedia != null)
                            {
                                switch (testType)
                                {
                                case TestType.Spiro:
                                    testResult = new SpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;

                                case TestType.AwvSpiro:
                                    testResult = new AwvSpiroTestResult
                                    {
                                        ResultImage = resultMedia
                                    };
                                    break;
                                }

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

                                _logger.Info(string.Concat("\nParsing succeeded for SPIRO/AWVSPIRO  for Customer Id: ", customerId, "\n"));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                            _resultParserHelper.AddResultArchiveLog(ex.Message, isSpiroTestPurchasedByCustomer ? TestType.Spiro : TestType.AwvSpiro, customerId, MedicalEquipmentTag.CardioCard, false);
                        }
                    }
                }
            }
            return(eventCustomerAggregates);
        }
示例#20
0
        public IEnumerable <EventCustomerScreeningAggregate> Parse()
        {
            var eventCustomerAggregates = new List <EventCustomerScreeningAggregate>();

            var directoryPath = GetFolderPathfor(_resultOutputPath);

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

            foreach (var filePath in DirectoryOperationsHelper.GetFiles(directoryPath))
            {
                if (Path.GetExtension(filePath).ToLower().Contains("pdf"))
                {
                    _logger.Info("Parsing file : " + filePath);
                    var customerIdString = "";
                    var fileName         = Path.GetFileName(filePath);
                    try
                    {
                        customerIdString = fileName.Split('_')[2];
                    }
                    catch
                    {
                        customerIdString = fileName;
                    }

                    // var customerIdString = fileName.IndexOf("_") > 0 ? fileName.Substring(0, fileName.IndexOf("_")) : fileName;

                    long customerId;

                    if (!long.TryParse(customerIdString, out customerId))
                    {
                        _logger.Info("Customer ID not found on Pdf file : " + filePath);
                        continue;
                    }

                    bool isSpiroTestPurchasedByCustomer    = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.Spiro);
                    bool isAwvSpiroTestPurchasedByCustomer = _testResultService.IsTestPurchasedByCustomer(_eventId, customerId, (long)TestType.AwvSpiro);

                    try
                    {
                        if (!isSpiroTestPurchasedByCustomer && !isAwvSpiroTestPurchasedByCustomer)
                        {
                            _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "].\n");
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Info("SPIRO/AWVSPIRO is not availed by CustomerId[" + customerId + "]. Exception Caused.\n Message: " + ex.Message + ".\t Stack Trace:" + ex.StackTrace);
                        continue;
                    }

                    try
                    {
                        TestResult testResult = null;
                        var        testType   = TestType.Spiro;

                        if (isAwvSpiroTestPurchasedByCustomer)
                        {
                            testType = TestType.AwvSpiro;
                        }

                        var folderToSaveImage = _mediaRepository.GetResultMediaFileLocation(customerId, _eventId).PhysicalPath;

                        var resultMedia = GetMediaFromPdfFile(filePath, folderToSaveImage, testType.ToString());
                        resultMedia.ReadingSource = ReadingSource.Automatic;

                        if (resultMedia != null)
                        {
                            switch (testType)
                            {
                            case TestType.Spiro:
                                testResult = new SpiroTestResult
                                {
                                    ResultImage = resultMedia
                                };
                                break;

                            case TestType.AwvSpiro:
                                testResult = new AwvSpiroTestResult
                                {
                                    ResultImage = resultMedia
                                };
                                break;
                            }

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

                            _logger.Info(string.Concat("\nParsing succeeded for SPIRO/AWVSPIRO  for Customer Id: ", customerId, "\n"));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("System Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                        _resultParserHelper.AddResultArchiveLog(ex.Message, isSpiroTestPurchasedByCustomer ? TestType.Spiro : TestType.AwvSpiro, customerId, MedicalEquipmentTag.CardioCard, false);
                    }
                }
            }
            return(eventCustomerAggregates);
        }
示例#21
0
        public void PollForUpdate()
        {
            var files = DirectoryOperationsHelper.GetFiles(_settings.MediaLocation + "\\PreAppprovedTest", "*PreAppprovedTest*.csv");

            var createdBy = _organizationRoleUserRepository.GetOrganizationRoleUser(1);

            foreach (var file in files)
            {
                _logger.Info("Parsing file : " + file);

                DataTable table = _csvReader.ReadWithTextQualifier(file);

                if (table.Rows.Count <= 0)
                {
                    _logger.Info("No records found.");
                    continue;
                }

                foreach (DataRow row in table.Rows)
                {
                    var clientId = GetRowValue(row, "Client_Id");
                    //var contractNumber = GetRowValue(row, "Contract_Number");
                    var preApprovedTests = GetPreApprovedTests(row, "Pre-approved tests");

                    if (string.IsNullOrEmpty(clientId))                  // || string.IsNullOrEmpty(contractNumber)
                    {
                        _logger.Info("Skipping row : Client Id blank."); //or Contract Number
                        continue;
                    }

                    var chaseOutbound = _chaseOutboundRepository.GetByClientId(clientId);

                    if (chaseOutbound == null)
                    {
                        _logger.Info(string.Format("Chase data not found for Client Id : {0}", clientId));
                        continue;
                    }

                    if (preApprovedTests != null && preApprovedTests.Any())
                    {
                        var pairs = TestType.A1C.GetNameValuePairs();
                        var preApprovedTestExists = pairs.Where(x => preApprovedTests.Contains(x.SecondValue.ToLower())).Select(x => x.SecondValue.ToLower());

                        var testNotExist = string.Empty;

                        if (preApprovedTestExists != null && preApprovedTestExists.Any() && (preApprovedTestExists.Count() != preApprovedTests.Count()))
                        {
                            var testNotExistInSystem = preApprovedTests.Where(x => !preApprovedTestExists.Contains(x.ToLower())).Select(x => x).ToArray();

                            testNotExist = string.Join(",", testNotExistInSystem);
                        }
                        else if (preApprovedTestExists == null || !preApprovedTestExists.Any())
                        {
                            testNotExist = string.Join(",", preApprovedTests);
                        }

                        if (!string.IsNullOrEmpty(testNotExist))
                        {
                            _logger.Info(testNotExist + " test alias name does not exist in HIP");
                            continue;
                        }

                        var preApprovedTestIds = pairs.Where(x => preApprovedTests.Contains(x.SecondValue.ToLower())).Select(x => (long)x.FirstValue);
                        if (preApprovedTestIds != null && preApprovedTestIds.Any())
                        {
                            _preApprovedTestRepository.SavePreApprovedTests(chaseOutbound.CustomerId, preApprovedTestIds, createdBy.Id);

                            _logger.Info(string.Format("Pre-approved tests updated for Client Id : {0}", clientId));
                        }
                    }
                }

                _logger.Info("Parsed file : " + file);
            }
        }
示例#22
0
        public void PollForPdfDownload()
        {
            try
            {
                if (_accountIds.IsNullOrEmpty())
                {
                    return;
                }
                var corporateAccounts = _corporateAccountRepository.GetByIds(_accountIds);

                foreach (var corporateAccount in corporateAccounts)
                {
                    try
                    {
                        _logger.Info(string.Format("Generating for accountId {0} and account tag {1}. ", corporateAccount.Id, corporateAccount.Tag));

                        var destinationFolderPdf  = string.Format(_destinationFolderPdfSetting, corporateAccount.FolderName);
                        var customSettingFilePath = string.Format(_customSettingFile, corporateAccount.Tag);
                        var customSettings        = _customSettingManager.Deserialize(customSettingFilePath);

                        var exportToTime   = DateTime.Now.AddHours(-1);
                        var exportFromTime = customSettings.LastTransactionDate ?? _cutOfDate;

                        bool     inclcludeCustomTag = false;
                        string[] CustomTags         = null;
                        var      considerEventDate  = true;

                        DateTime?eventCutOfDate = _settings.PPEventCutOfDate;

                        if (corporateAccount.Id == _settings.HealthNowAccountId)
                        {
                            CustomTags         = _settings.HealthNowCustomTags;
                            inclcludeCustomTag = true;
                        }
                        if (corporateAccount.Id == _settings.ExcellusAccountId)
                        {
                            CustomTags         = _settings.ExcellusCustomTags;
                            inclcludeCustomTag = true;
                        }

                        if (corporateAccount.Id == _settings.PPAccountId)
                        {
                            considerEventDate = true;
                        }

                        DateTime?stopSendingPdftoHealthPlanDate = null;
                        if (corporateAccount.IsHealthPlan)
                        {
                            stopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate;
                        }

                        var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsToFax((int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, exportToTime, exportFromTime,
                                                                                                               corporateAccount.Id, corporateAccount.Tag, true, CustomTags, inclcludeCustomTag, considerEventDate, eventCutOfDate
                                                                                                               , stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate);

                        var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray();
                        customerResults = customerResults ?? new EventCustomerResult[] { };

                        var resultNotPostedFileName       = string.Format("ResultNotPostedto_{0}.xml", corporateAccount.Tag);
                        var resultNotPostedToPlanFileName = Path.Combine(_settings.ResultNotPostedToPlanPath, resultNotPostedFileName);

                        var resultNotPosted = _resultPdfNotPostedSerializer.Deserialize(resultNotPostedToPlanFileName);
                        resultNotPosted = resultNotPosted == null || resultNotPosted.EventCustomer.IsNullOrEmpty() ? new ResultPdfNotPosted {
                            EventCustomer = new List <EventCustomerInfo>()
                        } : resultNotPosted;

                        if (resultNotPosted.EventCustomer.Count > 0)
                        {
                            var eventCustomerIds = resultNotPosted.EventCustomer.Select(x => x.EventCustomerId);

                            if (!customerResults.IsNullOrEmpty())
                            {
                                var freshCustomerEventCustomerIds = customerResults.Select(x => x.Id);
                                eventCustomerIds = (from q in eventCustomerIds where !freshCustomerEventCustomerIds.Contains(q) select q).ToList();
                            }


                            int totalRecords = eventCustomerIds.Count();
                            int pageNumber   = 0;
                            int pagesize     = 100;

                            while (true)
                            {
                                if (totalRecords < 1)
                                {
                                    break;
                                }

                                var totalItems  = pageNumber * pagesize;
                                var customerIds = eventCustomerIds.Skip(totalItems).Take(pagesize);
                                var resultNotPostedEventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsByIdsAndResultState(customerIds, (int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false);

                                if (!resultNotPostedEventCustomerResults.IsNullOrEmpty())
                                {
                                    var resultReports = resultNotPostedEventCustomerResults.ToArray();

                                    if (customerResults.IsNullOrEmpty())
                                    {
                                        customerResults = resultReports.ToArray();
                                    }
                                    else
                                    {
                                        customerResults = customerResults.Concat(resultReports).ToArray();
                                    }
                                }
                                pageNumber++;

                                if (totalItems >= totalRecords)
                                {
                                    break;
                                }
                            }
                        }

                        resultNotPosted.EventCustomer = !resultNotPosted.EventCustomer.IsNullOrEmpty() ? new List <EventCustomerInfo>() : resultNotPosted.EventCustomer;

                        if (eventCustomerResults == null || !customerResults.Any())
                        {
                            _logger.Info(string.Format("No event customer result list for {0} Result Pdf Download.", corporateAccount.Tag));
                            continue;
                        }

                        _logger.Info(string.Format("Found {0} customers for {1} Result Pdf Download. ", eventCustomerResults.Count(), corporateAccount.Tag));

                        var pcpResultReport = _mediaRepository.GetPdfFileNameForPcpResultReport();

                        var healthPlanResultReport = _mediaRepository.GetPdfFileNameForHealthPlanResultReport();

                        var resultPostedToPlanFileName = Path.Combine(_resultPostedToPlanPath, string.Format("ResultPostedto_{0}.xml", corporateAccount.Tag));
                        var resultPosted = _resultPdfPostedSerializer.Deserialize(resultPostedToPlanFileName);

                        resultPosted = resultPosted == null || resultPosted.Customer.IsNullOrEmpty() ? new ResultPdfPostedXml {
                            Customer = new List <CustomerInfo>()
                        } : resultPosted;
                        var resultPostedCustomer = new List <CustomerInfo>();

                        var healthPlanDownloadPath = Path.Combine(string.Format(_settings.HealthPlanDownloadPath, corporateAccount.FolderName), string.Format("ResultPDFs_{0}", DateTime.Now.ToString("yyyyMMdd")));

                        foreach (var ecr in customerResults)
                        {
                            var sourceUrl = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + healthPlanResultReport;

                            if (!DirectoryOperationsHelper.IsFileExist(sourceUrl))
                            {
                                sourceUrl = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + pcpResultReport;
                            }

                            if (DirectoryOperationsHelper.IsFileExist(sourceUrl))
                            {
                                try
                                {
                                    string fileName = ecr.CustomerId.ToString();

                                    var eventDirectoryPdf = Path.Combine(destinationFolderPdf, ecr.EventId.ToString());
                                    var customer          = _customerRepository.GetCustomer(ecr.CustomerId);
                                    var theEvent          = _eventRepository.GetById(ecr.EventId);

                                    if (corporateAccount.Id == _martinsPointExclusiveAccountId)
                                    {
                                        fileName = "Exclusive_" + customer.InsuranceId;
                                    }
                                    else if (corporateAccount.Id == _settings.ExcellusAccountId)
                                    {
                                        fileName = customer.InsuranceId;
                                    }
                                    else if (corporateAccount.Id == _settings.HealthNowAccountId)
                                    {
                                        fileName          = customer.InsuranceId;
                                        eventDirectoryPdf = healthPlanDownloadPath;
                                    }
                                    else if (corporateAccount.Id == _settings.AppleCareAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = string.Format("{0}_{1}", customer.InsuranceId, theEvent.EventDate.ToString("yyyyMMdd"));
                                        }
                                        else
                                        {
                                            fileName = string.Format("NoMember_{0}_{1}", customer.CustomerId, theEvent.EventDate.ToString("yyyyMMdd"));
                                        }

                                        fileName = _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, fileName, (long)ResultFormatType.PDF);
                                    }
                                    else if (corporateAccount.Id == _settings.MedMutualAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = string.Format("{0}_{1}", customer.InsuranceId, theEvent.EventDate.ToString("yyyyMMdd"));
                                        }
                                        else
                                        {
                                            fileName = string.Format("NoMember_{0}_{1}", customer.CustomerId, theEvent.EventDate.ToString("yyyyMMdd"));
                                        }

                                        eventDirectoryPdf = healthPlanDownloadPath;

                                        fileName = _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, fileName, (long)ResultFormatType.PDF);
                                    }
                                    else if (corporateAccount.Id == _settings.ConnecticareAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = customer.InsuranceId + "_" + customer.Name.LastName + "_" + customer.Name.FirstName + " " + customer.Name.MiddleName
                                                       + theEvent.EventDate.ToString("yyyy-MM-dd") + "_HF_COMM";
                                        }

                                        else
                                        {
                                            fileName = customer.Name.LastName + "_" + customer.Name.FirstName + " " + customer.Name.MiddleName
                                                       + theEvent.EventDate.ToString("yyyy-MM-dd") + "_HF_COMM";
                                        }

                                        eventDirectoryPdf = string.Format(_settings.HealthPlanDownloadPath, corporateAccount.FolderName);
                                    }
                                    else if (corporateAccount.Id == _settings.ConnecticareMaAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = customer.InsuranceId + "_" + customer.Name.LastName + "_" + customer.Name.FirstName + " " + customer.Name.MiddleName
                                                       + theEvent.EventDate.ToString("yyyy-MM-dd") + "_HF_MCR";
                                        }

                                        else
                                        {
                                            fileName = customer.Name.LastName + "_" + customer.Name.FirstName + " " + customer.Name.MiddleName
                                                       + theEvent.EventDate.ToString("yyyy-MM-dd") + "_HF_MCR";
                                        }

                                        eventDirectoryPdf = string.Format(_settings.HealthPlanDownloadPath, corporateAccount.FolderName);
                                    }
                                    else if (corporateAccount.Id == _settings.BcbsAlAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = customer.CustomerId + "_" + customer.Name.FirstName + " " + customer.Name.LastName + "_" + customer.InsuranceId;
                                        }
                                        else
                                        {
                                            fileName = customer.CustomerId + "_" + customer.Name.FirstName + " " + customer.Name.LastName;
                                        }

                                        eventDirectoryPdf = destinationFolderPdf + "\\" + ecr.EventId + "_" + DateTime.Today.ToString("MM-dd-yyyy");
                                    }
                                    else if (corporateAccount.Id == _settings.FloridaBlueFepAccountId)
                                    {
                                        if (!string.IsNullOrEmpty(customer.InsuranceId))
                                        {
                                            fileName = string.Format("GWC_CW_{0}", customer.InsuranceId);
                                        }

                                        else
                                        {
                                            fileName = string.Format("GWC_CW_NoMemberId_{0}", customer.CustomerId);
                                        }

                                        eventDirectoryPdf = Path.Combine(string.Format(_settings.HealthPlanDownloadPath, corporateAccount.FolderName), "PDFs");
                                    }
                                    else if (corporateAccount.Id == _settings.PPAccountId)
                                    {
                                        fileName          = theEvent.Id + "_" + customer.CustomerId;
                                        eventDirectoryPdf = string.Format(_settings.HealthPlanDownloadPath, corporateAccount.FolderName);
                                    }
                                    else if (corporateAccount.Id == _settings.NammAccountId)
                                    {
                                        fileName          = theEvent.Id + "_" + customer.CustomerId;
                                        eventDirectoryPdf = string.Format(_settings.HealthPlanExportRootPath, corporateAccount.FolderName);
                                    }

                                    if (corporateAccount.MarkPennedBack && ecr.IsPennedBack)
                                    {
                                        fileName += "_" + corporateAccount.PennedBackText;
                                    }

                                    if (corporateAccount.ResultFormatTypeId == (long)ResultFormatType.Both || corporateAccount.ResultFormatTypeId == (long)ResultFormatType.PDF)
                                    {
                                        var destinationFileName = _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, fileName, (long)ResultFormatType.PDF);
                                        var pdfFileName         = destinationFileName + ".pdf";
                                        var pdfResultFile       = Path.Combine(eventDirectoryPdf, pdfFileName);
                                        _resultPdfDownloadHelper.ExportResultInPdfFormat(pdfFileName, sourceUrl, eventDirectoryPdf);

                                        var isFilePosted = true;

                                        if (DirectoryOperationsHelper.IsFileExist(pdfResultFile))
                                        {
                                            var pgpFilePath = _pgpFileEncryptionHelper.EncryptFile(corporateAccount, pdfResultFile);

                                            if (_settings.SendReportToHcpNv && _settings.HcpNvAccountId == corporateAccount.Id)
                                            {
                                                isFilePosted = ExportResultOnHcpNvSftp(ecr.CustomerId + ".pdf", sourceUrl, ecr.EventId);
                                            }

                                            if (_settings.BcbsAlAccountId == corporateAccount.Id)
                                            {
                                                var sftpSettings = _sftpCridentialManager.Deserialize(_settings.SftpResouceFilePath + corporateAccount.Tag + ".xml");

                                                isFilePosted = ExportFileOnClientSftp(pdfResultFile, _settings.BcbsAlSftpDownloadPath + "Individual Member Results (PDFs)\\" + ecr.EventId + "_" + DateTime.Today.ToString("MM-dd-yyyy"), sftpSettings);
                                            }

                                            if (corporateAccount.Id == _settings.FloridaBlueFepAccountId)
                                            {
                                                var destinationSftpPath = _settings.FloridaBlueSftpPath + "\\" + corporateAccount.FolderName + "\\Download\\PDfs";
                                                isFilePosted = UploadSingleFile(pdfResultFile, destinationSftpPath, _settings.FloridaBlueSftpHost, _settings.FloridaBlueSftpUserName, _settings.FloridaBlueSftpPassword);
                                            }

                                            if (isFilePosted)
                                            {
                                                resultPostedCustomer.Add(_resultPdfFileHelper.GetCustomerInfo(theEvent, Path.GetFileName(pgpFilePath), (long)ResultFormatType.PDF, customer, ecr.Id));
                                            }
                                            else
                                            {
                                                resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                                {
                                                    EventCustomerId = ecr.Id,
                                                    EventId         = ecr.EventId,
                                                    CustomerId      = ecr.CustomerId,
                                                    Error           = "File Not posted on Client SFTP."
                                                });
                                            }

                                            _logger.Info("destination: " + pdfResultFile);
                                            _logger.Info("Source: " + sourceUrl);
                                        }
                                        else
                                        {
                                            resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                            {
                                                EventCustomerId = ecr.Id,
                                                EventId         = ecr.EventId,
                                                CustomerId      = ecr.CustomerId,
                                                Error           = "file not Moved on HIP SFTP."
                                            });
                                        }
                                    }

                                    if (corporateAccount.ResultFormatTypeId == (long)ResultFormatType.Both || corporateAccount.ResultFormatTypeId == (long)ResultFormatType.TIF)
                                    {
                                        var destinationFileName = _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, fileName, (long)ResultFormatType.TIF);
                                        var tipResultFile       = Path.Combine(eventDirectoryPdf, destinationFileName + ".tif");
                                        _resultPdfDownloadHelper.ExportResultInTiffFormat(destinationFileName + ".tif", sourceUrl, eventDirectoryPdf);

                                        var isFilePosted = true;
                                        var pgpFilePath  = _pgpFileEncryptionHelper.EncryptFile(corporateAccount, tipResultFile);

                                        if (DirectoryOperationsHelper.IsFileExist(tipResultFile))
                                        {
                                            if (_settings.SendReportToHcpNv && _settings.HcpNvAccountId == corporateAccount.Id)
                                            {
                                                isFilePosted = ExportResultOnHcpNvSftp(ecr.CustomerId + ".tif", sourceUrl, ecr.EventId, false);
                                            }

                                            if (_settings.BcbsAlAccountId == corporateAccount.Id)
                                            {
                                                var sftpSettings = _sftpCridentialManager.Deserialize(_settings.SftpResouceFilePath + corporateAccount.Tag + ".xml");
                                                isFilePosted = ExportFileOnClientSftp(tipResultFile, _settings.BcbsAlSftpDownloadPath + "Individual Member Results (PDFs)\\" + ecr.EventId + "_" + DateTime.Today.ToString("MM-dd-yyyy"), sftpSettings);
                                            }
                                            if (isFilePosted)
                                            {
                                                resultPostedCustomer.Add(_resultPdfFileHelper.GetCustomerInfo(theEvent, Path.GetFileName(pgpFilePath), (long)ResultFormatType.TIF, customer, ecr.Id));
                                            }
                                            else
                                            {
                                                resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                                {
                                                    EventCustomerId = ecr.Id,
                                                    EventId         = ecr.EventId,
                                                    CustomerId      = ecr.CustomerId,
                                                    Error           = "File Not posted on Client SFTP."
                                                });
                                            }

                                            _logger.Info("destination: " + tipResultFile);
                                            _logger.Info("Source: " + sourceUrl);
                                        }
                                        else
                                        {
                                            resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                            {
                                                EventCustomerId = ecr.Id,
                                                EventId         = ecr.EventId,
                                                CustomerId      = ecr.CustomerId,
                                                Error           = "file not Moved on HIP SFTP."
                                            });
                                        }
                                    }
                                }
                                catch (Exception exception)
                                {
                                    resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                    {
                                        EventCustomerId = ecr.Id,
                                        EventId         = ecr.EventId,
                                        CustomerId      = ecr.CustomerId,
                                        Error           = "file not Moved on HIP SFTP."
                                    });

                                    _logger.Error(string.Format("some error occurred for the customerId {0}, {1},\n Message {2} \n Stack Trace {3}", ecr.CustomerId, ecr.EventId, exception.Message, exception.StackTrace));
                                }
                            }
                            else
                            {
                                _logger.Info(string.Format("File not generated or removed for the customerId {0}, {1}", ecr.CustomerId, ecr.EventId));

                                resultNotPosted.EventCustomer.Add(new EventCustomerInfo
                                {
                                    EventCustomerId = ecr.Id,
                                    EventId         = ecr.EventId,
                                    CustomerId      = ecr.CustomerId,
                                    Error           = "File not generated or removed."
                                });
                            }
                        }

                        if (corporateAccount.Id == _settings.HealthNowAccountId || corporateAccount.Id == _settings.MedMutualAccountId)
                        {
                            if (DirectoryOperationsHelper.IsDirectoryExist(healthPlanDownloadPath) &&
                                DirectoryOperationsHelper.GetFiles(healthPlanDownloadPath).Any())
                            {
                                var isZipFileCreated = false;
                                try
                                {
                                    _zipHelper.CreateZipFiles(healthPlanDownloadPath);
                                    isZipFileCreated = true;
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(string.Format("some error occurred while creating zip file for AccountId: {0} and account tag: {1} Exception Message: \n{2}, \n stack Trace: \n\t {3} ",
                                                                corporateAccount.Id, corporateAccount.Tag, ex.Message, ex.StackTrace));
                                }

                                if (isZipFileCreated)
                                {
                                    resultPosted.Customer.AddRange(resultPostedCustomer);
                                }
                                else
                                {
                                    resultNotPosted.EventCustomer.AddRange(
                                        resultPostedCustomer.Select(x => new EventCustomerInfo
                                    {
                                        EventCustomerId = x.EventCustomerId,
                                        CustomerId      = x.CustomerId,
                                        EventId         = x.EventId,
                                        Error           = "Error occurred while creating zip file."
                                    }));
                                }
                            }

                            DirectoryOperationsHelper.DeleteDirectory(healthPlanDownloadPath, true);
                        }
                        else
                        {
                            resultPosted.Customer.AddRange(resultPostedCustomer);
                        }

                        customSettings.LastTransactionDate = exportToTime;
                        _customSettingManager.SerializeandSave(customSettingFilePath, customSettings);

                        CorrectandSaveResultPosted(resultPosted, corporateAccount);
                        _resultPdfNotPostedSerializer.SerializeandSave(resultNotPostedToPlanFileName, resultNotPosted);

                        if (resultNotPosted.EventCustomer.Count > 0)
                        {
                            _resultPdfEmailNotificationHelper.SendEmailNotificationForFileNotPosted(corporateAccount.Tag, resultNotPosted.EventCustomer.Count, _logger);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("some error occurred for AccountId: {0} and account tag: {1} Exception Message: \n{2}, \n stack Trace: \n\t {3} ", corporateAccount.Id, corporateAccount.Tag, ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("some error occurred Exception Message: \n{0}, \n stack Trace: \n\t {1} ", exception.Message, exception.StackTrace));
            }
        }
示例#23
0
        private void GenerateCrosswalkInboundReport(CrosswalkInboundFilter filter)
        {
            var account = _corporateAccountRepository.GetById(filter.AccountId);

            filter.Tag = account.Tag;

            if (account.IsHealthPlan)
            {
                filter.StopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate;
            }

            var model = _crosswalkInboundReportService.GetCrosswalkInboundReportList(filter, _logger);

            if (model != null)
            {
                var folder = string.Format(_settings.FloridaBlueInboundReportPath, account.FolderName, DateTime.Now.ToString("yyyy-MM-dd"));
                if (!Directory.Exists(folder))
                {
                    DirectoryOperationsHelper.CreateDirectory(folder);
                }
                var fileName    = _pipeDelimitedReportHelper.GetReportName(ReportType.CrosswalkInbound) + ".txt";
                var zipFileName = _pipeDelimitedReportHelper.GetReportName(ReportType.CrosswalkZip);

                if (model.Collection != null && model.Collection.Any())
                {
                    _logger.Info("generating File");
                    var tempMediaLocation = _mediaRepository.GetTempMediaFileLocation().PhysicalPath + zipFileName + "\\";
                    if (!Directory.Exists(tempMediaLocation))
                    {
                        DirectoryOperationsHelper.CreateDirectory(tempMediaLocation);
                    }

                    var resultPostedToPlanFileName = Path.Combine(_resultPostedToPlanPath, string.Format("ResultPostedto_{0}.xml", account.Tag));
                    var resultPosted = _resultPdfPostedSerializer.Deserialize(resultPostedToPlanFileName);
                    resultPosted = resultPosted == null || resultPosted.Customer.IsNullOrEmpty() ? new ResultPdfPostedXml {
                        Customer = new List <CustomerInfo>()
                    } : resultPosted;

                    foreach (var crosswalkViewModel in model.Collection)
                    {
                        var hafResultPdfLocation = _mediaRepository.GetPremiumVersionResultPdfLocation(crosswalkViewModel.EventId, crosswalkViewModel.CustomerId);
                        var hafResultPdfFileName = _mediaRepository.GetPdfFileNameForHealthPlanResultReport();
                        var pcpResultPdfFileName = _mediaRepository.GetPdfFileNameForPcpResultReport();

                        _logger.Info(" Event Id: " + crosswalkViewModel.EventId + " Customer Id: " + crosswalkViewModel.CustomerId);

                        if (DirectoryOperationsHelper.IsFileExist(tempMediaLocation + crosswalkViewModel.FileName))
                        {
                            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(tempMediaLocation + crosswalkViewModel.FileName);
                            var files = DirectoryOperationsHelper.GetFiles(tempMediaLocation, fileNameWithoutExtension + "*.pdf");
                            crosswalkViewModel.FileName = fileNameWithoutExtension + "_" + files.Count() + ".pdf";
                        }

                        if (File.Exists(hafResultPdfLocation.PhysicalPath + hafResultPdfFileName))
                        {
                            var destinationFileName = GetFileName(resultPosted.Customer, crosswalkViewModel.EventId, crosswalkViewModel.CustomerId, Path.GetFileNameWithoutExtension(crosswalkViewModel.FileName), (long)ResultFormatType.PDF);
                            crosswalkViewModel.FileName = destinationFileName + ".pdf";

                            _logger.Info("Copying File.. filePath from : " + hafResultPdfLocation.PhysicalPath + hafResultPdfFileName);
                            _logger.Info("Copying File.. filePath To : " + tempMediaLocation + crosswalkViewModel.FileName);

                            DirectoryOperationsHelper.Copy(hafResultPdfLocation.PhysicalPath + hafResultPdfFileName, tempMediaLocation + crosswalkViewModel.FileName);

                            resultPosted.Customer.Add(GetCustomerInfo(crosswalkViewModel));
                        }
                        else if (File.Exists(hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName))
                        {
                            var destinationFileName = GetFileName(resultPosted.Customer, crosswalkViewModel.EventId, crosswalkViewModel.CustomerId, Path.GetFileNameWithoutExtension(crosswalkViewModel.FileName), (long)ResultFormatType.PDF);
                            crosswalkViewModel.FileName = destinationFileName + ".pdf";

                            _logger.Info("Copying File.. filePath from : " + hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName);
                            _logger.Info("Copying File.. filePath To : " + tempMediaLocation + crosswalkViewModel.FileName);

                            DirectoryOperationsHelper.Copy(hafResultPdfLocation.PhysicalPath + pcpResultPdfFileName, tempMediaLocation + crosswalkViewModel.FileName);

                            resultPosted.Customer.Add(GetCustomerInfo(crosswalkViewModel));
                        }
                        else
                        {
                            _logger.Info("file not found");
                        }
                    }

                    _resultPdfPostedSerializer.SerializeandSave(resultPostedToPlanFileName, resultPosted);

                    _pipeDelimitedReportHelper.Write(model.Collection, folder, fileName);
                    DirectoryOperationsHelper.Copy(folder + "\\" + fileName, tempMediaLocation + fileName);

                    _logger.Info("generating Zip ");
                    _zipHelper.CreateZipFiles(tempMediaLocation, folder + "\\" + zipFileName + ".zip");

                    if (_sendReportToSftp)
                    {
                        try
                        {
                            _logger.Info("Sending zip to SFTP.");

                            var destinationPath = _destinationSftpPath + "\\" + account.FolderName + "\\Download\\Reports";
                            SendFilesToSftp(Path.Combine(folder, zipFileName + ".zip"), destinationPath, zipFileName + ".zip");

                            _logger.Info("Zip sent to SFTP.");
                        }
                        catch (Exception ex)
                        {
                            _logger.Info("Error sending zip to SFTP.");
                            _logger.Error("Message : " + ex.Message);
                            _logger.Error("Stack Trace : " + ex.StackTrace);
                        }
                    }

                    _logger.Info("Deleting temp folder: " + tempMediaLocation);
                    DirectoryOperationsHelper.DeleteDirectory(tempMediaLocation, true);

                    _logger.Info("Deleting text file: " + folder + "\\" + fileName);
                    DirectoryOperationsHelper.Delete(folder + "\\" + fileName);
                }
                else
                {
                    _logger.Info("No Data found for account Id: " + filter.AccountId);
                }
            }
            else
            {
                _logger.Info("No record found for " + account.Tag);
            }
        }
        private void ParseAppleCareAttestationForm(IEnumerable <Customer> customers, MediaLocation unlockedParseLocation, CorporateAccount account)
        {
            var appleCareLocation    = string.Format(_settings.AppleCareAttestationFormsPath, account.FolderName);
            var appleCareSharedFiles = DirectoryOperationsHelper.GetFiles(appleCareLocation, "*.pdf");

            if (appleCareSharedFiles.Length < 1)
            {
                _logger.Info("No attestation file found");
                return;
            }
            appleCareSharedFiles = appleCareSharedFiles.Select(x => x.ToLower()).ToArray();

            foreach (var customer in customers)
            {
                if (!customer.DateOfBirth.HasValue)
                {
                    _logger.Info("customer do not have DoB to match");
                    continue;
                }

                if (string.IsNullOrWhiteSpace(customer.Mrn))
                {
                    _logger.Info("customer do not have Mrn to match");
                    continue;
                }

                _logger.Info("looking for Files: first Name: " + customer.Name.FirstName + " Last Name: " + customer.Name.LastName + " DoB: " + customer.DateOfBirth.Value.ToString("MMddyyyy") + " Mrn: " + customer.Name.FirstName);

                var files = appleCareSharedFiles.Select(x => x.Trim().ToLower());

                files = files.Where(x =>
                                    x.Contains(customer.Name.FirstName.ToLower()) &&
                                    x.Contains(customer.Name.LastName.ToLower()) &&
                                    x.Contains(customer.DateOfBirth.Value.ToString("MMddyyyy")) &&
                                    x.Contains(customer.Mrn.ToLower())
                                    ).ToArray();

                if (files.IsNullOrEmpty())
                {
                    _logger.Info("no files found with matching first name, last name, DoB and MRN");
                    continue;
                }

                _logger.Info("found: " + files.Count() + " Files");

                try
                {
                    var sourceFileName = files.FirstOrDefault();
                    if (files.Count() > 1)
                    {
                        sourceFileName = MergeAttestationFils(files);
                    }

                    DownloadAttestationForm(sourceFileName, unlockedParseLocation.PhysicalPath, customer.CustomerId + ".pdf");
                }
                catch (Exception ex)
                {
                    _logger.Error("Message: " + ex.Message);
                    _logger.Error("Stack Trace: " + ex.StackTrace);
                }
            }
        }
示例#25
0
        public void PollForMemberUploadbyAces()
        {
            try
            {
                if (_stopMemberUploadbyAces)
                {
                    _logger.Info("Customer Eligibility Upload Polling Agent stopped @:" + DateTime.Now);
                    return;
                }

                _logger.Info("Entering Member Upload by Aces Polling Agent @" + DateTime.Now);

                if (!DirectoryOperationsHelper.IsDirectoryExist(_memberUploadbyAcesSourceFolderPath))
                {
                    _logger.Info("Source folder not availble.");
                    return;
                }
                var files = DirectoryOperationsHelper.GetFiles(_memberUploadbyAcesSourceFolderPath, "*.txt");

                if (files.IsNullOrEmpty())
                {
                    _logger.Info("Files not availble in Source Folder.");
                    return;
                }

                var intakeFiles = files.Where(x => x.ToLower().Contains("outtake") && !x.ToLower().Contains("eligibility")).ToList();

                if (intakeFiles.IsNullOrEmpty())
                {
                    _logger.Info("Files not availble in Source Folder after outtake filter.");
                    return;
                }

                var mediaLocation = _mediaRepository.GetMemberUploadbyAcesFolderLocation();

                MoveFileMediaLocation(intakeFiles, mediaLocation);

                var todaysFiles = DirectoryOperationsHelper.GetFiles(Path.Combine(mediaLocation.PhysicalPath, DateTime.Today.ToString("yyyyMMdd")));

                if (todaysFiles.IsNullOrEmpty())
                {
                    _logger.Info("Files not availble in Source Folder.");
                    return;
                }

                var corporateAccount = _corporateAccountRepository.GetAllCorporateAccountAcestoHipInTake();
                if (corporateAccount.IsNullOrEmpty())
                {
                    _logger.Info("Account not found for Aces to Hip upload.");
                    return;
                }

                var languages = _languageRepository.GetAll();
                var labs      = _labRepository.GetAll();

                var sendMail = false;
                foreach (var account in corporateAccount)
                {
                    _logger.Info("Parsing start for Account Tag :" + account.Tag);

                    var acesToHipIntakeShortName = account.AcesToHipIntakeShortName;

                    if (string.IsNullOrWhiteSpace(acesToHipIntakeShortName))
                    {
                        _logger.Info("AcesToHipIntake ShortName is blank for Account Tag :" + account.Tag);
                        continue;
                    }

                    acesToHipIntakeShortName = acesToHipIntakeShortName.ToLower() + "_";
                    var filesAcesToHipIntakeShortName = todaysFiles.Where(x => x.ToLower().Contains(acesToHipIntakeShortName) && x.ToLower().Contains("outtake") && !x.ToLower().Contains("eligibility"));

                    if (filesAcesToHipIntakeShortName.IsNullOrEmpty())
                    {
                        _logger.Info("Files not available for Short name : " + acesToHipIntakeShortName + " and Account Tag :" + account.Tag);
                        continue;
                    }

                    var customerList = new List <long>();

                    foreach (var file in filesAcesToHipIntakeShortName)
                    {
                        var filewithoutExtension = Path.GetFileNameWithoutExtension(file);
                        var acesClientShortName  = filewithoutExtension.Split('_')[0];
                        if (acesClientShortName.ToLower() != account.AcesToHipIntakeShortName.ToLower())
                        {
                            _logger.Info("File Short name : " + acesClientShortName + " and Account Short name :" + account.AcesToHipIntakeShortName.ToLower() + " not matched.");
                            continue;
                        }

                        if (ParseMemberUploadbyAces(file, account, customerList, languages, labs))
                        {
                            if (!sendMail)
                            {
                                sendMail = true;
                            }
                        }
                    }

                    if (customerList.IsNullOrEmpty())
                    {
                        _logger.Info("PatientReportWithnoCustomTag Report not generated because new Customer not found for short name : " + acesToHipIntakeShortName + " and Account Tag :" + account.Tag);
                        continue;
                    }

                    PatientReportWithnoCustomTag(customerList.ToArray(), account.Tag);
                }
                if (sendMail)
                {
                    var listWithoutCustomTagsModel = _emailNotificationModelsFactory.GetListWithoutCustomTagsViewModel(_memberUploadbyAcesSourceFolderPath, Path.Combine(_memberUploadbyAcesSourceFolderPath, "Failed")
                                                                                                                       , Path.Combine(_memberUploadbyAcesSourceFolderPath, "AdjustOrder"));
                    _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.ListWithoutCustomTags, EmailTemplateAlias.ListWithoutCustomTags, listWithoutCustomTagsModel, 0, 1, "MemberUploadbyAcesPollingAgent");
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Exception occurred during execution of servcie. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace));
                return;
            }
        }
示例#26
0
        public void Parse()
        {
            try
            {
                _logger.Info("Running Loinc Crosswalk");

                if (!DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.LoincCrosswalkPath))
                {
                    _logger.Info(string.Format("Folder could not be created. Please check path: {0} ", _settings.LoincCrosswalkPath));
                    return;
                }

                var loincMediaLocation = _mediaRepository.GetLoincMediaLocation();
                var archiveLocation    = _mediaRepository.GetLoincArchiveMediaLocation();

                var loincCrosswalkfiles = DirectoryOperationsHelper.GetFiles(_settings.LoincCrosswalkPath, "*.csv");
                if (loincCrosswalkfiles.IsNullOrEmpty())
                {
                    _logger.Info(string.Format("No csv file found at following location {0}", _settings.LoincCrosswalkPath));
                }
                else
                {
                    UploadLoincFiles(loincCrosswalkfiles, loincMediaLocation.PhysicalPath, (long)OutboundUploadType.LoincCrosswalk);
                }

                var uploadedFiles = _outboundUploadRepository.GetAllUploadedFilesByType((long)OutboundUploadType.LoincCrosswalk);
                if (uploadedFiles.IsNullOrEmpty())
                {
                    _logger.Info("No new files uploaded for Loinc Crosswalk.");
                    return;
                }

                foreach (var uploadedFile in uploadedFiles)
                {
                    try
                    {
                        var file = GetFile(uploadedFile.FileId);

                        if (!System.IO.File.Exists(loincMediaLocation.PhysicalPath + file.Path))
                        {
                            _logger.Info("File not found : " + loincMediaLocation.PhysicalPath + file.Path);
                            continue;
                        }

                        uploadedFile.StatusId       = (long)OutboundUploadStatus.Parsing;
                        uploadedFile.ParseStartTime = DateTime.Now;
                        _outboundUploadRepository.Save(uploadedFile);

                        _logger.Info("Importing File : " + file.Path);

                        var dataTable = _csvReader.CsvToDataTable(loincMediaLocation.PhysicalPath + file.Path, true, ",");

                        var csvStringBuilder = new StringBuilder();
                        csvStringBuilder.Append(LogHeader + Environment.NewLine);

                        long totalRows = 0, successRows = 0;

                        if (dataTable.Rows.Count == 0)
                        {
                            _logger.Info("No records found for file : " + loincMediaLocation.PhysicalPath + file.Path);
                            continue;
                        }
                        foreach (DataRow row in dataTable.Rows)
                        {
                            totalRows++;
                            var model    = GetLoincCrosswalk(row);
                            var errorRow = model.LoincNumber + "," + model.Component + "," + model.System + "," + model.MethodType + "," + model.VersionLastChanged + "," + model.DefinitionDescription + "," + model.Formula + model.Species
                                           + model.ExampleAnswers + "," + model.SurveyQuestionText + "," + model.SurveyQuestionSource + "," + model.UnitsRequired + "," + model.SubmittedUnits + "," + model.CdiscCommonTests + "," + model.Hl7FieldSubfieldId
                                           + model.ExternalCopyrightNotice + model.ExampleUnits + model.LongCommonName;

                            try
                            {
                                if (!model.IsEmpty())
                                {
                                    model.Year        = DateTime.Today.Year;
                                    model.DateCreated = DateTime.Now;
                                    model.UploadId    = uploadedFile.Id;
                                }
                                _loincCrosswalkRepository.Save(model);
                                successRows++;
                            }
                            catch (Exception ex)
                            {
                                _logger.Error(string.Format("Some Error Occurred Message: {0} \n stack Trace: {1}", ex.Message, ex.StackTrace));
                                csvStringBuilder.Append(errorRow + "," + ex.Message + Environment.NewLine);
                            }
                        }

                        if (successRows < totalRows)
                        {
                            var logFileName = file.Path + "_Log.csv";

                            var logFile = SaveLogFile(_settings.LoincCrosswalkPath + logFileName, csvStringBuilder);
                            uploadedFile.LogFileId = logFile.Id;
                        }

                        uploadedFile.SuccessUploadCount = successRows;
                        uploadedFile.FailedUploadCount  = totalRows - successRows;
                        uploadedFile.ParseEndTime       = DateTime.Now;
                        uploadedFile.StatusId           = successRows > 0 ? (long)OutboundUploadStatus.Parsed : (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);

                        if (successRows > 1)
                        {
                            System.IO.File.Move(loincMediaLocation.PhysicalPath + file.Path, archiveLocation.PhysicalPath + file.Path);
                            ((IFileRepository)_fileRepository).MarkasArchived(file.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        uploadedFile.StatusId = (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);
                        _logger.Error(string.Format("while Parsing File"));
                        _logger.Error("Ex Message" + ex.Message);
                        _logger.Error("Ex Stack Trace " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while Parsing Loinc Crosswalk Files.");
                _logger.Error(ex);
            }
        }
示例#27
0
        public void GenerateHafAssessment(long eventId)
        {
            try
            {
                var eventLogger = _logManager.GetLogger("HealthAssessmentFormGenerator_" + eventId);
                eventLogger.Info("Generating HAF for Event Id: " + eventId);
                _pdfGenerator.PaperSize = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.PaperSize);

                try
                {
                    var eventCustomers = _eventCustomerRepository.GetbyEventId(eventId);

                    if (eventCustomers != null && eventCustomers.Any())
                    {
                        eventCustomers = eventCustomers.Where(ec => ec.AppointmentId.HasValue).ToArray();

                        if (eventCustomers != null && eventCustomers.Any())
                        {
                            eventLogger.Info("found EventCustomers Count: " + eventCustomers.Count());

                            var mediaLocation = _mediaRepository.GetMedicalHistoryMediaLocation(eventId);

                            DirectoryOperationsHelper.CreateDirectoryIfNotExist(mediaLocation.PhysicalPath);

                            DirectoryOperationsHelper.DeleteFiles(mediaLocation.PhysicalPath);
                            var eventData = _eventRepository.GetById(eventId);
                            var account   = _corporateAccountRepository.GetbyEventId(eventId);

                            var corporateSurveyPdf = "";
                            if (account != null && account.CaptureSurvey)
                            {
                                if (account.SurveyPdfFileId > 0)
                                {
                                    var surveyPdf = _fileRepository.GetById(account.SurveyPdfFileId);
                                    if (surveyPdf != null)
                                    {
                                        corporateSurveyPdf = _mediaRepository.GetCorporateSurveyPdfFolderLocation().PhysicalPath + surveyPdf.Path;
                                    }
                                }
                            }

                            var corporateCheckListPdf = "";
                            if (account != null && account.PrintCheckList && account.CheckListFileId > 0 && eventData.EventDate >= _settings.ChecklistChangeDate)
                            {
                                var checkListFilePdf = _fileRepository.GetById(account.CheckListFileId);
                                if (checkListFilePdf != null)
                                {
                                    corporateCheckListPdf = _mediaRepository.GetCorporateCheckListPdfFolderLocation().PhysicalPath + checkListFilePdf.Path;
                                }
                            }

                            var filesFocAttestation    = new[] { "" };
                            var mediaLocFocAttestation = _mediaRepository.GetUnlockEventsParseLocation(eventId);

                            if (account != null && account.Id == _settings.HcpNvAccountId)
                            {
                                if (DirectoryOperationsHelper.IsDirectoryExist(mediaLocFocAttestation.PhysicalPath))
                                {
                                    filesFocAttestation = Directory.GetFiles(mediaLocFocAttestation.PhysicalPath, "*.*");
                                    filesFocAttestation = filesFocAttestation.Where(fsd => !string.IsNullOrEmpty(fsd)).ToArray();
                                }
                            }
                            else
                            {
                                if (DirectoryOperationsHelper.IsDirectoryExist(mediaLocFocAttestation.PhysicalPath))
                                {
                                    filesFocAttestation = Directory.GetFiles(mediaLocFocAttestation.PhysicalPath, "*.pdf");
                                    filesFocAttestation = filesFocAttestation.Where(fsd => !string.IsNullOrEmpty(fsd)).ToArray();
                                }
                            }

                            var tempMediaLocation = _mediaRepository.GetTempMediaFileLocation();
                            var customers         = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray());

                            int index = 0;
                            foreach (var eventCustomer in eventCustomers)
                            {
                                eventLogger.Info(string.Format("Generating HAF for Event Id: {0} and Customer Id : {1} ", eventId, eventCustomer.CustomerId));
                                string url                = _settings.HealthAssessmentFormUrl + string.Format("?eventId={0}&customerId={1}&LoadLayout=false&showKynEditModel=true&bulkPrint=true&removeChache={2}", eventCustomer.EventId, eventCustomer.CustomerId, Guid.NewGuid());
                                var    customer           = customers.First(c => c.CustomerId == eventCustomer.CustomerId);
                                var    focAttestationFile = string.Empty;

                                if (account != null)
                                {
                                    var questFile = Path.Combine(_mediaRepository.GetQuestUploadMediaFileLocation().PhysicalPath, account.Tag + "_Quest.pdf");

                                    if (account.Id == _settings.WellmedAccountId || account.Id == _settings.WellmedTxAccountId)
                                    {
                                        var memberId = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId.ToLower().Trim();
                                        focAttestationFile = filesFocAttestation.FirstOrDefault(fsd => !string.IsNullOrEmpty(fsd) && Path.GetFileNameWithoutExtension(fsd).ToLower().Trim() == memberId);
                                        eventLogger.Info(string.Format("focAttestationFile : {0}", focAttestationFile));

                                        var _files = new List <string>();

                                        if (!string.IsNullOrEmpty(focAttestationFile) && DirectoryOperationsHelper.IsFileExist(focAttestationFile))
                                        {
                                            eventLogger.Info(string.Format("focAttestationFile : First if {0}", focAttestationFile));
                                            _files.Add(focAttestationFile);
                                        }

                                        if (DirectoryOperationsHelper.IsFileExist(questFile))
                                        {
                                            eventLogger.Info(string.Format("focAttestationFile : 2nd if {0}", questFile));
                                            _files.Add(questFile);
                                        }

                                        if (!_files.IsNullOrEmpty())
                                        {
                                            if (_files.Count() > 1)
                                            {
                                                eventLogger.Info(string.Format("focAttestationFile : File Count {0}", _files.Count()));
                                                focAttestationFile = GetFocAttestationFileMerge(_files, focAttestationFile, eventLogger);
                                            }
                                            else
                                            {
                                                eventLogger.Info(string.Format("focAttestationFile : File[0] {0}", _files[0]));
                                                focAttestationFile = _files[0];
                                                eventLogger.Info(string.Format("focAttestationFile : Last {0}", focAttestationFile));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        focAttestationFile = GetFocAttestationFileForMht(filesFocAttestation, customer.CustomerId.ToString(), eventLogger);
                                    }
                                    //else if (account.Id == _settings.MolinaAccountId)
                                    //{
                                    //    var hicn = string.IsNullOrEmpty(customer.Hicn) ? "" : customer.Hicn.ToLower().Trim();
                                    //    focAttestationFile = filesFocAttestation.FirstOrDefault(fsd => !string.IsNullOrEmpty(fsd) && Path.GetFileNameWithoutExtension(fsd).ToLower().Trim() == hicn);
                                    //}
                                    //else if (account.Id == _settings.HcpNvAccountId)
                                    //{

                                    //}
                                    //else if (_settings.MonarchAccountIds.Contains(account.Id))
                                    //{
                                    //    var gmpi = string.IsNullOrEmpty(customer.AdditionalField4) ? "" : customer.AdditionalField4.ToLower().Trim();

                                    //    if (!string.IsNullOrEmpty(gmpi))
                                    //    {
                                    //        focAttestationFile = GetFocAttestationFile(filesFocAttestation, "_" + gmpi.ToLower(), focAttestationFile, eventLogger);
                                    //    }
                                    //}
                                    //else if (account.Id == _settings.AppleCareAccountId)
                                    //{
                                    //    focAttestationFile = GetFocAttestationFile(filesFocAttestation, customer.CustomerId.ToString(), focAttestationFile, eventLogger);
                                    //}
                                    //else if (account.Id == _settings.NammAccountId)
                                    //{
                                    //    focAttestationFile = GetFocAttestationFile(filesFocAttestation, customer.CustomerId.ToString(), focAttestationFile, eventLogger);
                                    //}
                                }

                                var focAttestationFilePath = string.Empty;
                                eventLogger.Info("focAttestationFile: " + focAttestationFile);

                                if (!string.IsNullOrEmpty(focAttestationFile))
                                {
                                    focAttestationFilePath = focAttestationFile;
                                }

                                var annualComprehensiveExamPdf  = string.Empty;
                                var memberInformationProfilePdf = string.Empty;

                                if (!string.IsNullOrEmpty(customer.Hicn))
                                {
                                    var fileNamePattern = customer.Hicn + (customer.Name != null ? "_" + customer.Name.LastName + "_" + customer.Name.FirstName : "");
                                    if (account != null && account.PrintAceForm)
                                    {
                                        try
                                        {
                                            var mediaLocationForAce = _mediaRepository.GetAceMipLocation(account.FolderName, fileNamePattern, "ACE");
                                            var aceFiles            = DirectoryOperationsHelper.GetFiles(mediaLocationForAce.PhysicalPath, fileNamePattern + "*_ACE.pdf");
                                            if (aceFiles.Any())
                                            {
                                                annualComprehensiveExamPdf = _pdfGenerator.ExtractPdfPagesFromEnd(aceFiles.First(), tempMediaLocation.PhysicalPath + "Ripped_" + customer.Hicn + "_ACE.pdf", NumberOfPagesToExtractFromAcePdf);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            eventLogger.Error(string.Format("Unable to attach ACE form to the bulk HAF for CustomerID : {0}\nMessage : {1}", customer.CustomerId, ex.Message));
                                        }
                                    }

                                    if (account != null && account.PrintMipForm)
                                    {
                                        try
                                        {
                                            var mediaLocationForMip = _mediaRepository.GetAceMipLocation(account.FolderName, fileNamePattern, "MIP");
                                            var mipFiles            = DirectoryOperationsHelper.GetFiles(mediaLocationForMip.PhysicalPath, fileNamePattern + "*_MIP.pdf");
                                            if (mipFiles.Any())
                                            {
                                                memberInformationProfilePdf = mipFiles.First();
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            eventLogger.Error(string.Format("Unable to attach MIP to the bulk HAF for CustomerID : {0}\nMessage : {1}", customer.CustomerId, ex.Message));
                                        }
                                    }
                                }
                                var consentHeaderWithChecklistpdf = string.Empty;

                                if (!string.IsNullOrWhiteSpace(corporateCheckListPdf) && DirectoryOperationsHelper.IsFileExist(corporateCheckListPdf))
                                {
                                    var    tempPath         = _mediaRepository.GetTempMediaFileLocation();
                                    var    consentHeader    = Path.Combine(tempPath.PhysicalPath, Guid.NewGuid() + ".pdf");
                                    string consentHeaderUrl = _settings.ConsentHeaderFormUrl + string.Format("?eventId={0}&customerId={1}&removeChache={2}", eventCustomer.EventId, eventCustomer.CustomerId, Guid.NewGuid());
                                    _pdfGenerator.GeneratePdf(consentHeaderUrl, consentHeader);

                                    consentHeaderWithChecklistpdf = Path.Combine(tempPath.PhysicalPath, Guid.NewGuid() + ".pdf");
                                    var consentHeaderWithChecklistpdfArray = new string[] { consentHeader, corporateCheckListPdf };
                                    _pdfGenerator.Merge(consentHeaderWithChecklistpdf, consentHeaderWithChecklistpdfArray);
                                }


                                _pdfGenerator.GeneratePdfForHaf(url, mediaLocation.PhysicalPath + (++index).ToString("000.") + eventCustomer.CustomerId + ".pdf", corporateSurveyPdf, "", focAttestationFilePath, consentHeaderWithChecklistpdf,
                                                                annualComprehensiveExamPdf, memberInformationProfilePdf);
                            }

                            eventLogger.Info("Merging HAF for Event Id: " + eventId);
                            _pdfGenerator.GetPdffilesfromLocationandMergeintoOne(mediaLocation.PhysicalPath, mediaLocation.PhysicalPath + "Event_" + eventId + ".pdf");
                            _eventRepository.SetGenrateHealthAssesmentFormStatus(eventId, false, (long)GenerateHealthAssesmentFormStatus.Completed);

                            index = 0;

                            foreach (var eventCustomer in eventCustomers)
                            {
                                DirectoryOperationsHelper.Delete(mediaLocation.PhysicalPath + (++index).ToString("000.") + eventCustomer.CustomerId + ".pdf");
                            }
                        }
                        else
                        {
                            eventLogger.Info("No customer found with appointment attached with this event. Merging HAF for Event Id: " + eventId);
                            _eventRepository.SetGenrateHealthAssesmentFormStatus(eventId, false, (long)GenerateHealthAssesmentFormStatus.Completed);
                        }
                    }
                    else
                    {
                        eventLogger.Info("No customer found attached with this event. Merging HAF for Event Id: " + eventId);
                        _eventRepository.SetGenrateHealthAssesmentFormStatus(eventId, false, (long)GenerateHealthAssesmentFormStatus.Completed);
                    }
                }
                catch (Exception ex)
                {
                    _eventRepository.SetGenrateHealthAssesmentFormStatus(eventId, true, (long)GenerateHealthAssesmentFormStatus.Pending);
                    eventLogger.Error("\n" + ex.Message + "\n\t Stack Trace: " + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                _eventRepository.SetGenrateHealthAssesmentFormStatus(eventId, true, (long)GenerateHealthAssesmentFormStatus.Pending);
                _logger.Error("\n" + ex.Message + "\n\t Stack Trace: " + ex.StackTrace);
            }
        }
        public void PollForParsing()
        {
            try
            {
                var timeOfDay = DateTime.Now;

                if (_isDevEnvironment || timeOfDay.TimeOfDay > new TimeSpan(4, 0, 0))
                {
                    _logger.Info("Service started...");
                    var directoryInfo = DirectoryOperationsHelper.GetDirectories(_hkynParsePdfPath);

                    if (directoryInfo.IsNullOrEmpty())
                    {
                        _logger.Info("No Directory found for Parsing");
                        return;
                    }

                    foreach (var dirPath in directoryInfo)
                    {
                        try
                        {
                            var dirInfo = DirectoryOperationsHelper.GetDirectoryInfo(dirPath);
                            if (dirInfo != null)
                            {
                                var files = DirectoryOperationsHelper.GetFiles(dirPath, "*.Pdf");


                                long eventid = 0;
                                long.TryParse(dirInfo.Name, out eventid);

                                if (eventid > 0)
                                {
                                    var eventData = _eventRepository.GetById(eventid);

                                    if (files.IsNullOrEmpty())
                                    {
                                        _logger.Info("No file found inside " + dirInfo.Name);
                                        if (eventData.EventDate > DateTime.Today.AddDays(-DeleteEmptyFolderAfter))
                                        {
                                            DirectoryOperationsHelper.DeleteDirectory(dirPath, true);
                                        }
                                        continue;
                                    }

                                    ParseFilesForCustomer(dirPath, eventid);
                                }
                                else
                                {
                                    _logger.Info("folder does not contain valid Name: " + dirInfo.Name);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("Some error occurred for Dir Path: " + dirPath);
                            _logger.Error("Message: " + ex.Message);
                            _logger.Error("Stack Trace: " + ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Some error occurred while parsing");
                _logger.Error("Message: " + ex.Message);
                _logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }
示例#29
0
        public void PollForCustomerEligibilityUpload()
        {
            try
            {
                if (_settings.StopCustomerEligibilityUpload)
                {
                    _logger.Info("Customer Eligibility Upload Polling Agent stopped @:" + DateTime.Now);
                    return;
                }

                _logger.Info("Entering Customer Eligibility Upload Polling Agent @:" + DateTime.Now);

                var sftpFileLocation = _settings.CustomerEligibilityUploadSftpPath;
                var mediaLocation    = _mediaRepository.GetCustomerEligibilityUploadFolderLocation();

                var archiveFolder = Path.Combine(mediaLocation.PhysicalPath, "Archive", DateTime.Today.ToString("yyyyMMdd"));
                var failedFolder  = Path.Combine(mediaLocation.PhysicalPath, "Failed", DateTime.Today.ToString("yyyyMMdd"));

                var getFilesFromSftp = DirectoryOperationsHelper.GetFiles(sftpFileLocation, "*.txt").Where(x => x.ToLower().Contains("outtake") && x.ToLower().Contains("eligibility"));

                if (getFilesFromSftp.IsNullOrEmpty())
                {
                    _logger.Info("No files found for parsing.");
                    return;
                }

                DirectoryOperationsHelper.CreateDirectoryIfNotExist(archiveFolder);
                DirectoryOperationsHelper.CreateDirectoryIfNotExist(failedFolder);

                var timeStamp = DateTime.Now.ToString("yyyyMMddhhmmss");

                foreach (var file in getFilesFromSftp)
                {
                    var fileName = Path.GetFileNameWithoutExtension(file);
                    MoveFile(file, Path.Combine(mediaLocation.PhysicalPath, fileName + "_" + timeStamp + ".txt"));
                }

                var filesToParse = DirectoryOperationsHelper.GetFiles(mediaLocation.PhysicalPath, "*.txt");
                _logger.Info("Number of files to Parse:" + filesToParse.Count());

                foreach (var file in filesToParse)
                {
                    var fileName = Path.GetFileName(file);
                    try
                    {
                        var patientData = _pipeDelimitedReportHelper.ReadWithTextQualifier(file);

                        var columns            = patientData.Columns.Cast <DataColumn>().Select(x => x.ColumnName.ToLower()).ToArray();
                        var missingColumnNames = _corporateUploadHelper.CheckAllCustomerEligibilityUploadColumnExist(columns);

                        if (!string.IsNullOrEmpty(missingColumnNames))
                        {
                            _logger.Info("Column Name(" + missingColumnNames + ") missing in file(" + fileName + ")");
                            MoveFile(file, Path.Combine(failedFolder, fileName));
                            continue;
                        }

                        var recordsInFile = patientData.Rows.Count;
                        if (recordsInFile == 0)
                        {
                            _logger.Info("No record found in " + fileName);
                            MoveFile(file, Path.Combine(archiveFolder, fileName));
                            continue;
                        }
                        _logger.Info("Parsing file: " + fileName);
                        _logger.Info("Total number of records in file: " + recordsInFile);

                        var failedRecords = new List <CustomerEligibilityUploadViewModel>();

                        var parseEligibilityData = ParseEligibilityData(patientData.AsEnumerable(), failedRecords);

                        if (parseEligibilityData.Any())
                        {
                            foreach (var customerEligibility in parseEligibilityData)
                            {
                                try
                                {
                                    _logger.Info("Getting customer for AcesId: " + customerEligibility.AcesId);
                                    List <Customer> customers   = null;
                                    var             errorMesage = string.Empty;

                                    if (!string.IsNullOrWhiteSpace((customerEligibility.AcesId)) || !string.IsNullOrWhiteSpace(customerEligibility.MemberId))
                                    {
                                        if (!string.IsNullOrWhiteSpace(customerEligibility.AcesId))
                                        {
                                            customers = _customerRepository.GetCustomersByAcesId(customerEligibility.AcesId);

                                            if (customers.IsNullOrEmpty())
                                            {
                                                errorMesage = "Customer not found for AcesId: " + customerEligibility.AcesId;
                                                _logger.Info(errorMesage);
                                            }
                                        }
                                        else
                                        {
                                            errorMesage = "AcesId not provided for Member Id: " + customerEligibility.MemberId;
                                            _logger.Info(errorMesage);
                                        }

                                        if (customers.IsNullOrEmpty())
                                        {
                                            if (!string.IsNullOrWhiteSpace(customerEligibility.MemberId))
                                            {
                                                customers = _customerRepository.GetCustomersByMemberId(customerEligibility.MemberId);

                                                if (customers.IsNullOrEmpty())
                                                {
                                                    errorMesage = errorMesage + ", " + "Customer not found for Member ID: " + customerEligibility.MemberId;
                                                    _logger.Info(errorMesage);
                                                }
                                            }
                                            else
                                            {
                                                errorMesage = errorMesage + " , " + "Member Id not provided for AcesId: " + customerEligibility.AcesId;
                                                _logger.Info(errorMesage);
                                            }
                                        }

                                        if (customers.IsNullOrEmpty())
                                        {
                                            customerEligibility.Error = errorMesage;
                                            failedRecords.Add(customerEligibility);

                                            _logger.Info("Record not parsed:  " + errorMesage);
                                            continue;
                                        }

                                        bool?eligibility = null;

                                        if (customerEligibility.Eligibility.ToLower() == CustomerEligibilityYes.ToLower())
                                        {
                                            eligibility = true;
                                        }

                                        else if (customerEligibility.Eligibility.ToLower() == CustomerEligibilityNo.ToLower())
                                        {
                                            eligibility = false;
                                        }

                                        int eligibilityYear = Convert.ToInt32(customerEligibility.EligibilityYear);

                                        foreach (var customer in customers)
                                        {
                                            _customerEligibilityService.Save(customer.CustomerId, eligibilityYear, eligibility, OrgRoleId, _logger);
                                            _logger.Info("Customer Eligibility inserted successfully for CustomerID: " + customer.CustomerId);
                                        }
                                    }
                                    else
                                    {
                                        errorMesage = "Aces Id or Member Id not provided ";
                                        customerEligibility.Error = errorMesage;
                                        failedRecords.Add(customerEligibility);

                                        _logger.Info("Record not parsed " + errorMesage);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    customerEligibility.Error = "Some error occurred while saving record.";
                                    failedRecords.Add(customerEligibility);
                                    _logger.Error(string.Format("Error occurred while saving record for AcesId: {0}.\nMessage: {1}\n\tStackTrace: {2}", customerEligibility.AcesId, ex.Message, ex.StackTrace));
                                }
                            }
                        }
                        CreateFailedUploadFile(fileName, failedFolder, failedRecords);
                        MoveFile(file, Path.Combine(archiveFolder, fileName));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Error occurred while processing the {0}.\nMessage: {1}\n\tStackTrace: {2}", file, ex.Message, ex.StackTrace));

                        MoveFile(file, Path.Combine(failedFolder, fileName));
                    }
                }
                _logger.Info("File parsing completed @ " + DateTime.Now);

                try
                {
                    _logger.Info("Copying failed file at SFTP");
                    var failedFiles = DirectoryOperationsHelper.GetFiles(failedFolder, "*.txt");
                    if (failedFiles.IsNullOrEmpty())
                    {
                        _logger.Info("No failed files found to copy at SFTP.");
                        return;
                    }

                    _logger.Info("Creating failed folder at SFTP " + sftpFileLocation);
                    var sftpFailedFolder = Path.Combine(sftpFileLocation, "FailedCustomerRecords", DateTime.Today.ToString("yyyyMMdd"));
                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(sftpFailedFolder);

                    foreach (var file in failedFiles)
                    {
                        var failedFileName = Path.GetFileName(file);
                        try
                        {
                            DirectoryOperationsHelper.Copy(file, Path.Combine(sftpFailedFolder, failedFileName));
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Copying faield file not succeed for {0}. \nException Message: {1}\n\tStackTrace:{2}", failedFileName, ex.Message, ex.StackTrace));
                        }
                    }
                    _logger.Info("All failed files copied at " + sftpFailedFolder + " location.");
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Exception occurred during copying failed file at SFTP. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace));
                    return;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Exception occurred during execution of servcie. \nException Message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace));
                return;
            }
        }