示例#1
0
        public void GenerateHtml(string body, string destinationPath, string pageUrl, string destinationPdfPath)
        {
            DirectoryOperationsHelper.DeleteFileIfExist(destinationPath);
            var cssPath = _settings.AppUrl + "/Config/Content/ResultPacket/content/FinalPdf.css";

            using (FileStream fs = new FileStream(destinationPath, FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    w.WriteLine("<html>");
                    w.WriteLine("<head>");
                    w.WriteLine("<link rel='Stylesheet' type='text/css' href='" + cssPath + "'>");
                    w.WriteLine("</head>");
                    w.WriteLine("<body>");
                    w.WriteLine("<div class='mainContainer-wopb'>");
                    w.WriteLine("<div style='margin-left:60px'>");
                    w.WriteLine("<div style='width: 810px; padding: 20px; height: 960px; margin: 0px auto; font-size: 12px;'>");
                    w.WriteLine(body);
                    w.WriteLine("</div>");
                    w.WriteLine("</div>");
                    w.WriteLine("</div>");
                    w.WriteLine("</body>");
                    w.WriteLine("</html>");
                }
            }
            if (DirectoryOperationsHelper.IsFileExist(destinationPath))
            {
                DirectoryOperationsHelper.DeleteFileIfExist(destinationPdfPath);
                GeneratePdf(pageUrl, destinationPdfPath);
            }
        }
        public void CopyOverMedia(long eventId, long customerId, string saveFilePath, IEnumerable <ResultMedia> resultMedia)
        {
            if (resultMedia == null || resultMedia.Count() < 1)
            {
                return;
            }
            var destinationDirectory = Path.GetDirectoryName(saveFilePath);

            var supportDestDirectoryPath = destinationDirectory + @"\" + StringforMediaDirectory;

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

            var mediaPath = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath;

            foreach (var media in resultMedia)
            {
                if (media.File.Type == FileType.Image)
                {
                    DirectoryOperationsHelper.DeleteFileIfExist(supportDestDirectoryPath + "\\" + media.File.Path);
                    System.IO.File.Copy(mediaPath + media.File.Path, supportDestDirectoryPath + "\\" + media.File.Path);
                }
            }
        }
        private bool GenerateReport(string destinationFolder, string fileName, GiftCertificateReportFilter filter)
        {
            var completePath = Path.Combine(destinationFolder, fileName);

            var dataGen = new ExportableDataGenerator <GiftCertificateReportOptumViewModel, GiftCertificateReportFilter>(_giftCerificateOptumReportService.GetGiftCertificateOptumReport, _logger);

            var model = dataGen.GetData(filter);

            if (model != null && !model.Collection.IsNullOrEmpty())
            {
                _logger.Info("Writing Gift Certificate Report");
                var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <GiftCertificateReportOptumViewModel>();

                _logger.Info("Record count" + model.Collection.Count());

                DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFolder);

                DirectoryOperationsHelper.DeleteFileIfExist(completePath);

                _baseExportableReportHelper.GenerateCsv(completePath, exporter, model.Collection);

                _logger.Info("completed Gift Certificate Report for account tag " + filter.Tag);

                _logger.Info("Destination Path: " + completePath);

                return(true);
            }

            return(false);
        }
        private void CopyMediaFile(string mediaPath, string destinationPath, string mediaFile, string newFileName)
        {
            var sourceFileName = Path.Combine(mediaPath, mediaFile);

            try
            {
                DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationPath);

                if (DirectoryOperationsHelper.IsFileExist(sourceFileName))
                {
                    DirectoryOperationsHelper.DeleteFileIfExist(Path.Combine(destinationPath, newFileName));
                    DirectoryOperationsHelper.Copy(sourceFileName, Path.Combine(destinationPath, newFileName));
                    _logger.Info("Media file ( " + sourceFileName + " ) successfully copied with new Name " + newFileName + " on location " + destinationPath);
                }
                else
                {
                    _logger.Info("Media file ( " + sourceFileName + " ) does not exist on Media file Location");
                }
            }
            catch (Exception ex)
            {
                _logger.Error("");
                _logger.Error("Message: Media file ( " + sourceFileName + " ) does not exist on Media file Location. Exception : " + ex.Message);
                _logger.Error("StackTrace:" + ex.StackTrace);
            }
        }
 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");
     }
 }
示例#6
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));
            }
        }
示例#7
0
        private void PatientReportWithnoCustomTag(long[] customerIds, string accountTag)
        {
            _logger.Info("Entering Patient Report with no Custom Tag @" + DateTime.Now);

            _logger.Info(customerIds.Count() + " Customer found.");
            var destinationFoler = Path.Combine(_memberUploadbyAcesSourceFolderPath, "PatientReportWithnoCustomTag", DateTime.Today.ToString("yyyyMMdd"));

            DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler);

            var fileName        = "PatientReportWithnoCustomTag_" + accountTag + "_" + DateTime.Now.AddDays(-1).ToString("MMddyyyyHHmmss") + ".txt";
            var destinationFile = Path.Combine(destinationFoler, fileName);

            DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);

            WriteCsvHeader(destinationFile);

            var collection = new List <PatientWithNoCustomTagViewModel>();

            var pageNumber   = 1;
            int totalRecords = customerIds.Count();
            var totalPages   = (totalRecords / PageSize) + (totalRecords % PageSize != 0 ? 1 : 0);

            do
            {
                var pagedCustomers    = customerIds.Skip(PageSize * (pageNumber - 1)).Take(PageSize);
                var parsedCustomerIds = pagedCustomers.ToArray();
                var customers         = _customerRepository.GetCustomersWoithoutLoginAndAddressDetails(parsedCustomerIds);

                var preapprovedTest        = _preApprovedTestRepository.GetPreApprovedTests(parsedCustomerIds);
                var preApprovedPackageTest = _preApprovedPackageRepository.GetPreApprovedPackageTestByCustomerIds(parsedCustomerIds);

                foreach (var customer in customers)
                {
                    var tests       = preapprovedTest.Where(x => x.FirstValue == customer.CustomerId).Select(x => x.SecondValue);
                    var packageTest = preApprovedPackageTest.Where(x => x.FirstValue == customer.CustomerId).Select(x => x.SecondValue);

                    var allTest = tests.Union(packageTest).Distinct().ToArray();

                    string testName = string.Empty;
                    if (!allTest.IsNullOrEmpty())
                    {
                        testName = string.Join(",", allTest);
                    }

                    var patientData = _patientWithNoCustomTagFactory.Create(customer, testName);
                    collection.Add(patientData);
                }

                WriteCsv(collection, destinationFile);
                pageNumber++;
            }while (totalPages >= pageNumber);

            _logger.Info("Customer With No customer Tags: " + destinationFile);

            _logger.Info("Patient Report with no Custom Tag Completed.");
        }
示例#8
0
        private string SaveFile(string byteData, MediaLocation mediaLocation, string fileName)
        {
            var filePath = Path.Combine(mediaLocation.PhysicalPath, fileName);

            DirectoryOperationsHelper.DeleteFileIfExist(filePath);
            var dataBytes = Convert.FromBase64String(byteData);

            File.WriteAllBytes(filePath, dataBytes);
            return(Path.Combine(mediaLocation.Url, fileName));
        }
示例#9
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 MoveFile(string sourceFile, string destinationFile)
 {
     try
     {
         DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);
         DirectoryOperationsHelper.Move(sourceFile, destinationFile);
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("Exception occurred while moving file {0} to {1}. \nException Message: {2}\n\tStackTrace:{3}", sourceFile, destinationFile, ex.Message, ex.StackTrace));
     }
 }
示例#12
0
        private void DeleteIffileExist(string destinationPath)
        {
            var files = Directory.GetFiles(destinationPath, "*.zip");

            foreach (var file in files)
            {
                if (!string.IsNullOrEmpty(file) && file.Contains("ResultPdf_"))
                {
                    if (DirectoryOperationsHelper.IsFileExist(file))
                    {
                        DirectoryOperationsHelper.DeleteFileIfExist(file);
                    }
                }
            }
        }
示例#13
0
        private string GetOutreachFilePath(CorporateAccount healthPlan, int year)
        {
            var folderLocation = string.Format(_healthPlanOutreachReportExportDownloadPath, healthPlan.FolderName, year);
            var filePath       = folderLocation + "\\" + "OutreachCallReport.csv";

            if (healthPlan.Id == _settings.ConnecticareAccountId || healthPlan.Id == _settings.ConnecticareMaAccountId)
            {
                folderLocation = string.Format(_settings.HealthPlanDownloadPath, healthPlan.FolderName);
                filePath       = folderLocation + "\\" + "OutreachCallReport_" + DateTime.Today.ToString("yyyy-MM-dd") + ".csv";
            }

            DirectoryOperationsHelper.CreateDirectoryIfNotExist(folderLocation);

            DirectoryOperationsHelper.DeleteFileIfExist(filePath);

            return(filePath);
        }
        public void CopyOverSupportDirectorytotheDestination(string saveFilePath, string sourceFilePath, IEnumerable <CustomerScreeningEvaluatinPhysicianViewModel> physicians, bool moveSupportMediaFolder = false, bool copySupportMediaOtherThanPhysician = true)
        {
            var destinationDirectory = Path.GetDirectoryName(saveFilePath);
            var sourceDirectory      = Path.GetDirectoryName(sourceFilePath);

            var supportDestDirectoryPath = destinationDirectory + @"\" + StringforContentDirectory;

            if (!Directory.Exists(supportDestDirectoryPath))
            {
                Directory.CreateDirectory(supportDestDirectoryPath);
            }

            if (copySupportMediaOtherThanPhysician)
            {
                foreach (var filePath in Directory.GetFiles(sourceDirectory + @"\" + StringforContentDirectory))
                {
                    var fileName = Path.GetFileName(filePath);
                    if (fileName == AutoRunShell || fileName == AutoRuninf)
                    {
                        DirectoryOperationsHelper.DeleteFileIfExist(destinationDirectory + @"\" + Path.GetFileName(filePath));
                        File.Copy(filePath, destinationDirectory + @"\" + Path.GetFileName(filePath));
                    }
                    else
                    {
                        DirectoryOperationsHelper.DeleteFileIfExist(supportDestDirectoryPath + @"\" + Path.GetFileName(filePath));
                        File.Copy(filePath, supportDestDirectoryPath + @"\" + Path.GetFileName(filePath));
                    }
                }
            }

            if (moveSupportMediaFolder)
            {
                var supportmediaDestDirectoryPath = destinationDirectory + @"\" + StringforMediaDirectory;
                if (!Directory.Exists(supportmediaDestDirectoryPath))
                {
                    Directory.CreateDirectory(supportmediaDestDirectoryPath);
                }

                foreach (var filePath in Directory.GetFiles(sourceDirectory + @"\" + StringforMediaDirectory))
                {
                    File.Copy(filePath, supportmediaDestDirectoryPath + @"\" + Path.GetFileName(filePath));
                }
            }

            CopyOverRequiredFiletosupportDirectory(supportDestDirectoryPath, physicians);
        }
        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);
        }
示例#16
0
        private void MovedParsedFile(string sourceFileName)
        {
            try
            {
                string destinationFile = Path.Combine(_labReportArchivedPath, DateTime.Today.ToString("ddMMyyyy"));

                string fileName = new FileInfo(sourceFileName).Name;
                DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFile);
                destinationFile = Path.Combine(destinationFile, Guid.NewGuid() + "_" + fileName);
                DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);
                DirectoryOperationsHelper.Move(sourceFileName, destinationFile);
            }
            catch (Exception ex)
            {
                _labParseEventLogger.Error(" Issue on File Move(" + sourceFileName + ") !  Message: " + ex.Message + "\n\t" + ex.StackTrace);
            }
        }
示例#17
0
        private void SaveResultNotPosted(string tag)
        {
            var filePath = GetResultNotPostedXmlFilePath(tag);

            DirectoryOperationsHelper.DeleteFileIfExist(filePath);

            if (_resultPdfNotPosted != null)
            {
                _resultPdfNotPostedSerializer.SerializeandSave(GetResultNotPostedXmlFilePath(tag), _resultPdfNotPosted);

                if (_resultPdfNotPosted.EventCustomer.Count > 0)
                {
                    _resultPdfEmailNotificationHelper.SendEmailNotificationForFileNotPosted(tag, _resultPdfNotPosted.EventCustomer.Count, _logger);
                }

                _resultPdfNotPosted = null;
            }
        }
示例#18
0
        public void SerializeandSave(string fileName, T records)
        {
            if (records == null)
            {
                return;
            }

            var serializer = new XmlSerializer(records.GetType());

            DirectoryOperationsHelper.CreateDirectoryIfNotExist(Path.GetDirectoryName(fileName));

            DirectoryOperationsHelper.DeleteFileIfExist(fileName);

            var stream = new StreamWriter(fileName);

            serializer.Serialize(stream, records);

            stream.Close();
            stream.Dispose();
        }
示例#19
0
        public void PollForDailyVolumeReport()
        {
            try
            {
                _logger.Info("Setting filter to pull data for Daily Volume Report");
                var filter = new DailyVolumeListModelFilter
                {
                    FromDate = new DateTime(DateTime.Today.Year, 1, 1),
                    ToDate   = new DateTime(DateTime.Today.Year, 12, 31)
                };

                _logger.Info("fetching Daily Volume Report");
                var dataGen = new ExportableDataGenerator <DailyVolumeModel, DailyVolumeListModelFilter>(_eventReportingService.GetDailyVolumeReport, _logger);
                var model   = dataGen.GetData(filter);

                if (model != null && !model.Collection.IsNullOrEmpty())
                {
                    _logger.Info("Writing Daily volume Report");
                    var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <DailyVolumeModel>();

                    _logger.Info("Record count" + model.Collection.Count());
                    var dailyVolumeReportPath = Path.Combine(_settings.DailyVolumeReportPath, DateTime.Today.Year.ToString());

                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(dailyVolumeReportPath);
                    var reportName     = "HF_DailyVolume_" + DateTime.Today.ToString("yyyyMMdd") + ".csv";
                    var reportfilePath = Path.Combine(dailyVolumeReportPath, reportName);

                    DirectoryOperationsHelper.DeleteFileIfExist(reportfilePath);

                    _baseExportableReportHelper.GenerateCsv(reportfilePath, exporter, model.Collection);

                    _logger.Info("Daily Volume Report File Posted " + reportfilePath);
                }
            }
            catch (Exception exception)
            {
                _logger.Error("Some error occurred ");
                _logger.Error("Message:  " + exception.Message);
                _logger.Error("Stack Trace:  " + exception.StackTrace);
            }
        }
示例#20
0
        private void CreateFailedUploadFile(string file, MediaLocation mediaLocation, List <MemberUploadbyAcesFailedCustomerModel> failedRecords, CorporateUpload corportateUpload)
        {
            if (failedRecords.Any())
            {
                try
                {
                    var nameWithoutExt = Path.GetFileNameWithoutExtension(file);

                    var fileName             = nameWithoutExt + "_Failed_" + DateTime.Now.ToString("MMddyyyyHHmmss") + ".txt";
                    var sourceFailedLocation = Path.Combine(mediaLocation.PhysicalPath, fileName);

                    DirectoryOperationsHelper.DeleteFileIfExist(sourceFailedLocation);

                    _logger.Info("Number of failed Records: " + failedRecords.Count);
                    _logger.Info("Creating file for failed records...");

                    _pipeDelimitedReportHelper.Write(failedRecords.OrderBy(x => x.CustomerId), mediaLocation.PhysicalPath, fileName);
                    _logger.Info("failed records file created.");

                    _logger.Info("Failed file Coping in Client Location.");

                    var targetFailedFoler = Path.Combine(_memberUploadbyAcesSourceFolderPath, DateTime.Today.ToString("yyyyMMdd"), "Failed");
                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(targetFailedFoler);

                    var targetFailedLocation = Path.Combine(targetFailedFoler, fileName);

                    DirectoryOperationsHelper.CopyWithReplace(sourceFailedLocation, targetFailedLocation);

                    _memberUploadByAcesHelper.UploadFailedFile(sourceFailedLocation, corportateUpload);

                    _logger.Info("Failed Record Path:" + sourceFailedLocation);
                    _logger.Info("Client Failed Record Path:" + targetFailedLocation);

                    _logger.Info("Failed file Copied in Client Location.");
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Error occurred while creating failed records file. \nException Message: {0}\n\tStackTrace: {1}", ex.Message, ex.StackTrace));
                }
            }
        }
示例#21
0
        public void CreateCsvForFileShared(IEnumerable <CustomerInfo> customersInfo, string folderPath, string fileName)
        {
            _logger.Info("Creating csv file..");

            DirectoryOperationsHelper.CreateDirectoryIfNotExist(folderPath);

            try
            {
                var years = customersInfo.Where(x => x.EventDate.HasValue).Select(x => x.EventDate.Value.Year).Distinct();

                foreach (var year in years)
                {
                    var tempfileName = fileName + "_" + year + ".csv";

                    var destinationFileName = Path.Combine(folderPath, tempfileName);
                    //if (year < DateTime.Today.Year && DirectoryOperationsHelper.IsFileExist(destinationFileName))
                    //{
                    //    continue;
                    //}

                    DirectoryOperationsHelper.DeleteFileIfExist(destinationFileName);

                    _logger.Info("Count Records " + customersInfo.Count());

                    _logger.Info("destination Path: " + destinationFileName);

                    WriteCsv(destinationFileName, customersInfo.Where(x => x.EventDate.HasValue && x.EventDate.Value.Year == year));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Some Error occurred while Creating Csv log:");
                _logger.Error("Message:" + ex.Message);
                _logger.Error("Stack trace:" + ex.StackTrace);
            }

            _logger.Info("Created csv file..");
        }
        private void WriteCsvDailyPatientRecap(IEnumerable <DailyPatientRecapCustomModel> modelData, string fileName)
        {
            DirectoryOperationsHelper.DeleteFileIfExist(fileName);

            var fileWriter = new StreamWriter(fileName);

            try
            {
                var members = (typeof(DailyPatientRecapCustomModel)).GetMembers();

                var header = new List <string>();

                foreach (var memberInfo in members)
                {
                    if (memberInfo.MemberType != MemberTypes.Property)
                    {
                        continue;
                    }

                    var propInfo = (memberInfo as PropertyInfo);
                    if (propInfo != null)
                    {
                        if (propInfo.PropertyType == typeof(FeedbackMessageModel))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    string propertyName = memberInfo.Name;
                    bool   isHidden     = false;

                    var attributes = propInfo.GetCustomAttributes(false);
                    if (!attributes.IsNullOrEmpty())
                    {
                        foreach (var attribute in attributes)
                        {
                            if (attribute is HiddenAttribute)
                            {
                                isHidden = true;
                                break;
                            }
                            if (attribute is DisplayNameAttribute)
                            {
                                propertyName = (attribute as DisplayNameAttribute).DisplayName;
                            }
                        }
                    }

                    if (isHidden)
                    {
                        continue;
                    }

                    header.Add(propertyName);
                }

                fileWriter.WriteLine(string.Join(",", header.ToArray()));

                var sanitizer = new CSVSanitizer();

                foreach (var model in modelData)
                {
                    var values = new List <string>();
                    foreach (var memberInfo in members)
                    {
                        if (memberInfo.MemberType != MemberTypes.Property)
                        {
                            continue;
                        }

                        var propInfo = (memberInfo as PropertyInfo);
                        if (propInfo != null)
                        {
                            if (propInfo.PropertyType == typeof(FeedbackMessageModel))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }


                        bool            isHidden  = false;
                        FormatAttribute formatter = null;

                        var attributes = propInfo.GetCustomAttributes(false);
                        if (!attributes.IsNullOrEmpty())
                        {
                            foreach (var attribute in attributes)
                            {
                                if (attribute is HiddenAttribute)
                                {
                                    isHidden = true;
                                    break;
                                }
                                if (attribute is FormatAttribute)
                                {
                                    formatter = (FormatAttribute)attribute;
                                }
                            }
                        }

                        if (isHidden)
                        {
                            continue;
                        }
                        var obj = propInfo.GetValue(model, null);
                        if (obj == null)
                        {
                            values.Add(string.Empty);
                        }
                        else if (formatter != null)
                        {
                            values.Add(formatter.ToString(obj));
                        }
                        else
                        {
                            values.Add(sanitizer.EscapeString(obj.ToString()));
                        }
                    }

                    fileWriter.WriteLine(string.Join(",", values.ToArray()));
                }
            }
            catch (Exception ex)
            {
                _logger.Error((string.Format("File Write: \n Error {0} \n Trace: {1} \n\n\n", ex.Message, ex.StackTrace)));
            }
            finally
            {
                fileWriter.Close();
                fileWriter.Dispose();
            }


            _logger.Info("CSV File Export was succesful!");

            _logger.Info("file Path: " + fileName);
        }
        public void GetCustomerConsentDataReport()
        {
            try
            {
                var accounts = _corporateAccountRepository.GetAllCorporateAccountToSendConsentData();
                if (accounts.IsNullOrEmpty())
                {
                    _logger.Info("No Account marked to Send Consent Data to Matrix");
                    return;
                }

                foreach (var corporateAccount in accounts)
                {
                    try
                    {
                        _logger.Info("starting for Account " + corporateAccount.Tag);

                        var serviceReportSettings = string.Format(_settings.CustomerConsentDataReportSettingPath, corporateAccount.Tag);
                        var customSettings        = _customSettingManager.Deserialize(serviceReportSettings);

                        var fromDate = customSettings.LastTransactionDate;

                        customSettings.LastTransactionDate = DateTime.Now;
                        _customSettingManager.SerializeandSave(serviceReportSettings, customSettings);

                        var filter = new CustomerConsentDataListModelFilter
                        {
                            AccountId = corporateAccount.Id,
                            Tag       = corporateAccount.Tag,
                            FromDate  = fromDate
                        };
                        var pageNumber       = 1;
                        var destinationFoler = Path.Combine(_settings.CustomerConsentDataFilePath, corporateAccount.Tag);

                        DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler);

                        var fileName        = "CustomerConsentDataReport_" + DateTime.Today.ToString("yyyyMMdd") + ".txt";
                        var destinationFile = Path.Combine(destinationFoler, fileName);

                        DirectoryOperationsHelper.DeleteFileIfExist(destinationFile);

                        WriteHeader(destinationFile);

                        var index = 1;
                        while (true)
                        {
                            int totalRecords = 0;
                            var customers    = _customerRepository.GetCustomerConsentDataReport(filter, pageNumber, PageSize, out totalRecords);

                            if (customers != null)
                            {
                                foreach (var customer in customers)
                                {
                                    _logger.Info("CustomerId:" + customer.CustomerId);

                                    _logger.Info(index + " out of " + totalRecords);
                                    index++;

                                    var model = new CustomerConsentDataViewModel();
                                    model.AcesId = customer.AcesId;

                                    if (!string.IsNullOrEmpty(customer.HomePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneHomeConsentUpdateDate.HasValue && customer.PhoneHomeConsentUpdateDate.Value >= fromDate)))
                                    {
                                        model.TelephoneNumber = customer.HomePhoneNumber.FormatPhoneNumber;
                                        model.ConsentType     = ((PatientConsent)customer.PhoneHomeConsentId).GetDescription();
                                        model.ConsentDateTime = customer.PhoneHomeConsentUpdateDate;
                                        WriteData(model, destinationFile);
                                    }

                                    if (!string.IsNullOrEmpty(customer.MobilePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneCellConsentUpdateDate.HasValue && customer.PhoneCellConsentUpdateDate.Value >= fromDate)))
                                    {
                                        model.TelephoneNumber = customer.MobilePhoneNumber.FormatPhoneNumber;
                                        model.ConsentType     = ((PatientConsent)customer.PhoneCellConsentId).GetDescription();
                                        model.ConsentDateTime = customer.PhoneCellConsentUpdateDate;
                                        WriteData(model, destinationFile);
                                    }

                                    if (!string.IsNullOrEmpty(customer.OfficePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneOfficeConsentUpdateDate.HasValue && customer.PhoneOfficeConsentUpdateDate.Value >= fromDate)))
                                    {
                                        model.TelephoneNumber = customer.OfficePhoneNumber.FormatPhoneNumber;
                                        model.ConsentType     = ((PatientConsent)customer.PhoneOfficeConsentId).GetDescription();
                                        model.ConsentDateTime = customer.PhoneOfficeConsentUpdateDate;
                                        WriteData(model, destinationFile);
                                    }
                                }
                            }

                            if ((pageNumber * PageSize) >= totalRecords)
                            {
                                break;
                            }

                            pageNumber++;
                        }

                        if (_settings.CustomerConsentDataReportSendToSftp)
                        {
                            if (ExportReportOnMatrixSftp(fileName, destinationFile))
                            {
                                _logger.Info("File posted on client SFTP");
                            }
                            else
                            {
                                _logger.Info("File didn't posted,some error occurred.");
                            }
                        }

                        _logger.Info("completed for Account " + corporateAccount.Tag);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("some error occurred while creating customer consent data report for Account " + corporateAccount.Tag);
                        _logger.Error("Message: " + ex.Message);
                        _logger.Error("Stack Trace: " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Message: " + ex.Message);
                _logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }
示例#24
0
        public void PollMailRoundCustomersReport()
        {
            try
            {
                _logger.Info("Entering Matrix Report Polling Agent");

                var healthPlans = _corporateAccountRepository.GetAllHealthPlan();
                var callQueues  = _callQueueRepository.GetAll(false, true);

                if (callQueues.IsNullOrEmpty())
                {
                    _logger.Info("No call queue found.");
                    return;
                }
                var mailRoundCallQueue       = callQueues.FirstOrDefault(x => x.Category == HealthPlanCallQueueCategory.MailRound);
                var fillEventCallQueue       = callQueues.FirstOrDefault(x => x.Category == HealthPlanCallQueueCategory.FillEventsHealthPlan);
                var languageBarrierCallQueue = callQueues.FirstOrDefault(x => x.Category == HealthPlanCallQueueCategory.LanguageBarrier);

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

                        var destinationPath = _settings.MailRoundCustomersReportDestinantionPath;

                        var filePath = Path.Combine(destinationPath, string.Format(@"MatrixReport_{0}_{1}.csv", healthPlan.Tag, DateTime.Now.ToString("MMddyyyy")));

                        DirectoryOperationsHelper.CreateDirectory(destinationPath);

                        var customers = new List <MailRoundCustomersReportViewModel>();

                        _logger.Info("Fetching customers for fill event call queue");
                        var fillEventCustomers = GetCustomersForMatrixReport(healthPlan.Id, fillEventCallQueue);
                        if (!fillEventCustomers.IsNullOrEmpty())
                        {
                            customers.AddRange(fillEventCustomers);
                        }
                        else
                        {
                            _logger.Info("No customers found for fill event call queue");
                        }


                        _logger.Info("Fetching customers for mail round call queue");
                        var mailRoundCustomers = GetCustomersForMatrixReport(healthPlan.Id, mailRoundCallQueue);
                        if (!mailRoundCustomers.IsNullOrEmpty())
                        {
                            if (!customers.IsNullOrEmpty())
                            {
                                var existingCustomerIds = customers.Select(c => c.CustomerID);
                                mailRoundCustomers = mailRoundCustomers.Where(x => !existingCustomerIds.Contains(x.CustomerID)).ToList();
                            }
                            customers.AddRange(mailRoundCustomers);
                        }
                        else
                        {
                            _logger.Info("No customers found for mail round call queue");
                        }


                        _logger.Info("Fetching customers for language barrier call queue");
                        var languageBarrierCustomers = GetCustomersForMatrixReport(healthPlan.Id, languageBarrierCallQueue);
                        if (!languageBarrierCustomers.IsNullOrEmpty())
                        {
                            if (!customers.IsNullOrEmpty())
                            {
                                var existingCustomerIds = customers.Select(c => c.CustomerID);
                                languageBarrierCustomers = languageBarrierCustomers.Where(x => !existingCustomerIds.Contains(x.CustomerID)).ToList();
                            }
                            customers.AddRange(languageBarrierCustomers);
                        }
                        else
                        {
                            _logger.Info("No customers found for language barrier call queue");
                        }


                        if (customers.Any())
                        {
                            var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <MailRoundCustomersReportViewModel>();

                            DirectoryOperationsHelper.DeleteFileIfExist(filePath);

                            _baseExportableReportHelper.GenerateCsv(filePath, exporter, customers);
                            _logger.Error(string.Format("Successfully Matrix Report Generated for AccountId {0} and Account Tag {1}.", healthPlan.Id, healthPlan.Tag));
                        }
                        else
                        {
                            _logger.Error(string.Format("No records found for AccountId {0} and Account Tag {1}. \n\n", healthPlan.Id, healthPlan.Tag));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Error occured while generating Matrix Report for AccountId {0} and Account Tag {1} : \n Error {2} \n Trace: {3} ", healthPlan.Id, healthPlan.Tag, ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error occured while generating Matrix Report : \n Error {0} \n Trace: {1} ", ex.Message, ex.StackTrace));
            }
        }
        public void CreateCumulativeFileAndPost(string incrementalFilePath, string cumulativeFilePath, string finalFilename)
        {
            var incrementalDataTable = CreateDataTable(incrementalFilePath);
            var cumulativeDataTable  = CreateDataTable(cumulativeFilePath);

            DirectoryOperationsHelper.DeleteFileIfExist(finalFilename);

            _logger.Info("Cumulative file Path: " + cumulativeFilePath);
            _logger.Info("Incremental file Path: " + incrementalFilePath);
            _logger.Info("final file Path: " + finalFilename);

            if (cumulativeDataTable == null || cumulativeDataTable.Rows == null || cumulativeDataTable.Rows.Count <= 0)
            {
                if (incrementalDataTable != null && incrementalDataTable.Rows != null && incrementalDataTable.Rows.Count > 0)
                {
                    DirectoryOperationsHelper.DeleteFileIfExist(cumulativeFilePath);
                    DirectoryOperationsHelper.Copy(incrementalFilePath, cumulativeFilePath);
                    DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename);
                }
            }
            else if (incrementalDataTable == null || incrementalDataTable.Rows == null || incrementalDataTable.Rows.Count <= 0)
            {
                if (cumulativeDataTable.Rows != null && cumulativeDataTable.Rows.Count > 0)
                {
                    DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename);
                }
            }
            else
            {
                var nameOfCustomerIdColumn = GetColumnName(cumulativeDataTable, "Id_$$");
                var nameOfEventIdColumn    = GetColumnName(cumulativeDataTable, "Event Id_$$");
                var nameOfEventDateColumn  = GetColumnName(cumulativeDataTable, "Event Date_$$");

                var tempAccumulativeDataTable = CreateAccumulativeDataTable(cumulativeDataTable, incrementalDataTable, nameOfCustomerIdColumn, nameOfEventIdColumn, nameOfEventDateColumn);

                if (tempAccumulativeDataTable != null && tempAccumulativeDataTable.Rows != null &&
                    tempAccumulativeDataTable.Rows.Count > 0)
                {
                    if (DirectoryOperationsHelper.IsFileExist(cumulativeFilePath))
                    {
                        _logger.Info("Final Record: " + tempAccumulativeDataTable.Rows.Count);
                    }

                    _csvReader.ConvertDataTableToCsv(tempAccumulativeDataTable, cumulativeFilePath, "_$$");

                    if (DirectoryOperationsHelper.IsFileExist(cumulativeFilePath))
                    {
                        _logger.Info("Final Record: " + tempAccumulativeDataTable.Rows.Count);
                    }

                    if (DirectoryOperationsHelper.IsDirectoryExist(Path.GetDirectoryName(cumulativeFilePath)))
                    {
                        _logger.Info("cumulativeFilePath: " + cumulativeFilePath + " exists");
                    }
                    else
                    {
                        _logger.Info("cumulativeFilePath: " + cumulativeFilePath + " Not exists");
                    }

                    DirectoryOperationsHelper.Copy(cumulativeFilePath, finalFilename);
                }
            }
        }
        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));
            }
        }
        private void GenerateReportForShortName(IEnumerable <CorporateAccount> accounts)
        {
            var distinctAcesClientShortName = accounts.Where(x => !string.IsNullOrWhiteSpace(x.AcesClientShortName)).Select(t => t.AcesClientShortName)
                                              .Distinct();

            foreach (var acesClientShortName in distinctAcesClientShortName)
            {
                var accountShortNamewise = accounts.Where(d => d.AcesClientShortName == acesClientShortName);

                if (!accountShortNamewise.IsNullOrEmpty())
                {
                    _logger.Info("starting for Shortname " + acesClientShortName);
                    var destinationFoler = _settings.UniversalProviderFilePath;

                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler);
                    DirectoryOperationsHelper.CreateDirectoryIfNotExist(_folderArchivedPath);

                    var fileNameWithoutExtention = acesClientShortName + "_Universal_Provider";
                    var fileName = fileNameWithoutExtention + ".txt";

                    var destinationFile = Path.Combine(destinationFoler, fileName);

                    if (DirectoryOperationsHelper.IsFileExist(destinationFile))
                    {
                        var archiveFileName = fileNameWithoutExtention + "_" + DateTime.Today.AddDays(-1).ToString("ddMMyyyy") + ".txt";
                        var archiveFilePath = Path.Combine(_folderArchivedPath, archiveFileName);
                        DirectoryOperationsHelper.DeleteFileIfExist(archiveFilePath);
                        DirectoryOperationsHelper.Move(destinationFile, archiveFilePath);
                    }

                    WriteCsvHeader(destinationFile);

                    foreach (var account in accountShortNamewise)
                    {
                        try
                        {
                            _logger.Info("starting for account " + account.Tag);

                            GenerateUniversalProviderList(account, destinationFile);

                            _logger.Info("completed for Account " + account.Tag);
                        }
                        catch (Exception exception)
                        {
                            _logger.Error("some error occurred while created Member List for Account " + account.Tag);
                            _logger.Error("Message: " + exception.Message);
                            _logger.Error("Stack Trace: " + exception.StackTrace);
                        }
                    }

                    if (DirectoryOperationsHelper.IsFileExist(destinationFile))
                    {
                        _logger.Info("Universal Provider Report generated : " + destinationFile);

                        DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.UniversalProviderFileSftpPath);

                        _logger.Info("Deleting old files from SFTP.");
                        DirectoryOperationsHelper.DeleteFileIfExist(Path.Combine(_settings.UniversalProviderFileSftpPath, acesClientShortName + "_Universal_Provider.txt"));
                        _logger.Info("Old files deleted from SFTP.");

                        _logger.Info("Copying file to SFTP location : " + _settings.UniversalProviderFileSftpPath);
                        var sftpFilePath = Path.Combine(_settings.UniversalProviderFileSftpPath, fileName);
                        DirectoryOperationsHelper.Copy(destinationFile, sftpFilePath);
                        _logger.Info("File copied : " + sftpFilePath);
                    }
                }
            }
        }
示例#28
0
        public void PollForAppointmentEncounterData()
        {
            try
            {
                if (_settings.AppointmentEncounterReportAccountIds.IsNullOrEmpty())
                {
                    _logger.Info("No Account found for AppointmentHeader");
                    return;
                }

                var corporateAccounts = _corporateAccountRepository.GetByIds(_settings.AppointmentEncounterReportAccountIds);
                if (corporateAccounts.IsNullOrEmpty())
                {
                    _logger.Info("No Account found for AppointmentHeader");
                    return;
                }

                foreach (var account in corporateAccounts)
                {
                    try
                    {
                        _logger.Info("running Report for account tag " + account.Tag);

                        var fromDate = DateTime.Today.GetFirstDateOfYear();
                        var toDate   = DateTime.Today.GetLastDateOfYear();

                        var filter = new AppointmentEncounterFilter
                        {
                            AccountId     = account.Id,
                            EventFromDate = fromDate,
                            EventToDate   = toDate,
                            Tag           = account.Tag
                        };

                        var dataGen = new ExportableDataGenerator <AppointmentEncounterModel, AppointmentEncounterFilter>(_appointmentEncounterService.GetAppointmentEncounterReport, _logger);
                        var model   = dataGen.GetData(filter);

                        if (model != null && !model.Collection.IsNullOrEmpty())
                        {
                            _logger.Info("Writing Event Schedule Report");
                            var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <AppointmentEncounterModel>();

                            _logger.Info("Record count" + model.Collection.Count());
                            var folderLocation = string.Format(_settings.AppointmentEncounterReportPath, account.FolderName);

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

                            DirectoryOperationsHelper.CreateDirectoryIfNotExist(folderLocation);
                            var fileName = string.Format("EncounterHeader_{0}.csv", DateTime.Today.ToString("yyyyMMdd"));

                            var completePath = Path.Combine(folderLocation, fileName);
                            DirectoryOperationsHelper.DeleteFileIfExist(completePath);

                            _baseExportableReportHelper.GenerateCsv(completePath, exporter, model.Collection);

                            _logger.Info("completed Report for account tag " + account.Tag);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("some Error occurred While Appointment Encounter for Account Tag: " + account.Tag);
                        _logger.Error("Message: " + ex.Message);
                        _logger.Error("Stack Trace: " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("some Error occurred While Appointment Encounter: ");
                _logger.Error("Message: " + ex.Message);
                _logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }
示例#29
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));
            }
        }
示例#30
0
        public void PollForEventScheduleReort()
        {
            try
            {
                _logger.Info("starting Event Schedule Report");

                var accounts = _corporateAccountRepository.GetByIds(_settings.EventScheduleAccountIds);

                foreach (var account in accounts)
                {
                    _logger.Info("Event Schedule Report for Account Tag" + account.Tag);

                    if ((account.Id == _settings.ConnecticareAccountId || account.Id == _settings.ConnecticareMaAccountId) && DateTime.Today.DayOfWeek != _settings.ConnecticareEventScheduleExportDay)
                    {
                        _logger.Info("today is " + DateTime.Today.DayOfWeek + " while service is configured to run on " + _settings.ConnecticareEventScheduleExportDay);
                        _logger.Info("Please set " + (int)DateTime.Today.DayOfWeek + " to run Service today");
                        continue;
                    }

                    var fromDate = new DateTime(DateTime.Today.Year, 1, 1);
                    var toDate   = new DateTime(DateTime.Today.Year, 12, 31);

                    var filter = new EventScheduleListModelFilter
                    {
                        AccountId = account.Id,
                        FromDate  = fromDate,
                        ToDate    = toDate,
                    };
                    var stateIds = _eventRepository.GetEventStateByAccountId(filter);

                    if (stateIds.IsNullOrEmpty())
                    {
                        _logger.Info("No State found for Account Tag " + account.Tag);
                        continue;
                    }

                    var states = _stateRepository.GetStates(stateIds);
                    foreach (var state in states)
                    {
                        try
                        {
                            _logger.Info("fetching records for State Name " + state.Name);
                            filter.StateId = state.Id;

                            var dataGen = new ExportableDataGenerator <EventScheduleModel, EventScheduleListModelFilter>(_eventReportingService.GetEventScheduleReport, _logger);
                            var model   = dataGen.GetData(filter);

                            if (model != null && !model.Collection.IsNullOrEmpty())
                            {
                                _logger.Info("Writing Event Schedule Report");
                                var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <EventScheduleModel>();

                                _logger.Info("Record count" + model.Collection.Count());
                                var eventScheduleReportPath = Path.Combine(_settings.EventScheduleReportPath, DateTime.Today.Year.ToString());

                                DirectoryOperationsHelper.CreateDirectoryIfNotExist(eventScheduleReportPath);
                                var reportName = "EventScheduleReport_" + account.Tag + "_" + state.Name + "_" + DateTime.Today.ToString("yyyyMMdd") + ".csv";

                                var reportfilePath = Path.Combine(eventScheduleReportPath, reportName);

                                if (account.Id == _settings.ConnecticareAccountId || account.Id == _settings.ConnecticareMaAccountId)
                                {
                                    reportfilePath = Path.Combine(_settings.HealthPlanDownloadPath, account.FolderName);
                                    reportfilePath = Path.Combine(reportfilePath, reportName);
                                }

                                DirectoryOperationsHelper.DeleteFileIfExist(reportfilePath);

                                _baseExportableReportHelper.GenerateCsv(reportfilePath, exporter, model.Collection);

                                _logger.Info("Generated report of Event Schedule Report for Account " + account.Tag + " state " + state.Name);
                                _logger.Info("Path: " + reportfilePath + " state " + state.Name);

                                if (_sendReportToSftp)
                                {
                                    _logger.Info("Sending file to sftp.");
                                    var eventScheduleReportSftpPath = string.Format(_eventScheduleReportSftpPath, fromDate.Year);
                                    var processFtp = new ProcessFtp(_logger, _sftpHost, _sftpUserName, _sftpPassword);

                                    processFtp.UploadSingleFile(reportfilePath, eventScheduleReportSftpPath, "");

                                    _logger.Info("File sent on sftp.");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("some Error occurred while generating report of Event Schedule Report for Account " + account.Tag + " state " + state.Name);
                            _logger.Error("ex: " + ex.Message);
                            _logger.Error("stack Trace: " + ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("some Error occurred while generating report of Event Schedule Report ");
                _logger.Error("ex: " + ex.Message);
                _logger.Error("stack Trace: " + ex.StackTrace);
            }
        }