Example #1
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);
            }
        }
        private void GenerateReport(EventScheduleListModelFilter eventScheduleModelFilter, PotentialPcpChangeReportModelFilter filter, CorporateAccount account)
        {
            var stateIds = (IReadOnlyCollection <long>)_eventRepository.GetEventStateByAccountId(eventScheduleModelFilter);

            if (stateIds.IsNullOrEmpty())
            {
                _logger.Info("No State found for Wellmed");             //Do not return from here as we are updating last transaction date at last
            }

            var states = _stateRepository.GetStates(stateIds);

            foreach (var state in states)
            {
                try
                {
                    _logger.Info("Generating Report for State: " + state.Name);

                    var dataGen = new ExportableDataGenerator <PotentialPcpChangeReportViewModel, PotentialPcpChangeReportModelFilter>(_potentialPcpChangeReportService.GetPotentialPcpChangeData, _logger);
                    filter.StateId = state.Id;
                    var model = dataGen.GetData(filter);

                    if (model != null && !model.Collection.IsNullOrEmpty())
                    {
                        var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <PotentialPcpChangeReportViewModel>();

                        var path           = string.Format(_pcpChangeReportPath, account.FolderName);
                        var reportfilePath = Path.Combine(path, state.Name);

                        DirectoryOperationsHelper.CreateDirectoryIfNotExist(reportfilePath);
                        reportfilePath = Path.Combine(reportfilePath, string.Format("WellMed_PCP_Change_Report_{0}.csv", filter.StartDate.ToString("yyyyMM")));
                        _logger.Info("File path : " + reportfilePath);

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

                        if (_sendReportToSftp && DirectoryOperationsHelper.IsFileExist(reportfilePath))
                        {
                            _logger.Info("Starting to post Potential Pcp Change report on sftp for StateId: " + state.Id + " State: " + state.Name);

                            var sftpResultExportDirectory = string.Format(_sftpPathForPcpChangeReport, state.Name);
                            var processFtp = new ProcessFtp(_logger, _sftpHost, _sftpUserName, _sftpPassword);
                            processFtp.UploadSingleFile(reportfilePath, sftpResultExportDirectory, "");

                            _logger.Info("Potential Pcp Change report posted on sftp for StateId: " + state.Id + " State: " + state.Name);
                        }
                        _logger.Info("Potential Pcp Change Report generation completed for StateId: " + state.Id + " State: " + state.Name);
                    }
                    else
                    {
                        _logger.Info("No data found for StateId: " + state.Id + " State: " + state.Name);
                    }
                }
                catch (Exception exception)
                {
                    _logger.Error("Error occurred during generation of report for StateId: " + state.Id);
                    _logger.Error("Message:  " + exception.Message);
                    _logger.Error("Stack Trace:  " + exception.StackTrace);
                }
            }

            //update custom setting XML
            var customSetting = _customSettingManager.Deserialize(_pcpCustomSetting);

            customSetting.LastTransactionDate = filter.EndDate;
            _customSettingManager.SerializeandSave(_pcpCustomSetting, customSetting);
        }
        public void PollForPotentialPcpChange()
        {
            try
            {
                var timeOfDay = DateTime.Now;
                _logger.Info("Time of day : " + timeOfDay.ToString("HH:mm:ss"));

                if (!_settings.IsDevEnvironment && _runningDate != DateTime.Today.Day)
                {
                    _logger.Info("Report is generated only in 1st week of the month , currently selected run Date is " + _settings.PcpChangeReportRunDate);
                    return;
                }

                if (_accountId <= 0)
                {
                    _logger.Info("Account Id Not Provided");
                    return;
                }
                var account = _corporateAccountRepository.GetById(_accountId);
                if (account == null)
                {
                    _logger.Info("Account not exists");
                    return;
                }

                var             customSetting = _customSettingManager.Deserialize(_pcpCustomSetting);
                List <DateTime> toDates       = null;
                if (customSetting.LastTransactionDate != null)
                {
                    toDates = GetToDates(customSetting.LastTransactionDate.Value.AddMonths(1));             //to pick correct records
                    _logger.Info("Generating Potential Pcp change Report for Month " + customSetting.LastTransactionDate.Value.AddMonths(1));
                }
                else
                {
                    _logger.Info("Generating report for first time as LastTransactionDate is missing from custom setting XML");
                    toDates = GetToDates(_cutoffDate);
                }

                foreach (var todate in toDates)
                {
                    var filter = new PotentialPcpChangeReportModelFilter
                    {
                        AccountId = _accountId,
                        StartDate = new DateTime(todate.Year, todate.Month, 1),
                        EndDate   = todate
                    };
                    _logger.Info(string.Format("Generating report for date: {0} to {1}", filter.StartDate, filter.EndDate));
                    var eventScheduleModelFilter = new EventScheduleListModelFilter
                    {
                        AccountId = _accountId,
                        FromDate  = filter.StartDate,
                        ToDate    = filter.EndDate
                    };
                    GenerateReport(eventScheduleModelFilter, filter, account);

                    _logger.Info(string.Format("Completed Generating Report for Potential Pcp Change"));
                }
            }
            catch (Exception exception)
            {
                _logger.Error("Some error occurred ");
                _logger.Error("Message:  " + exception.Message);
                _logger.Error("Stack Trace:  " + exception.StackTrace);
            }
        }
Example #4
0
        public void PollForNonTargetableCustomer()
        {
            try
            {
                var timeOfDay = DateTime.Now;
                _logger.Info("Time of day : " + timeOfDay.ToString("HH:mm:ss"));

                if (!_settings.IsDevEnvironment && _runningDate != DateTime.Today.Day)
                {
                    _logger.Info("Report is generated only in 1st week of the month");
                    return;
                }
                if (_accountId <= 0)
                {
                    _logger.Info("Account Id Not Provided");
                    return;
                }
                var account = _corporateAccountRepository.GetById(_accountId);
                if (account == null)
                {
                    _logger.Info("Account not exists");
                    return;
                }

                _logger.Info(string.Format("Generating Report for Non Target-able Report"));
                var lastMonthDate = (DateTime.Today).AddMonths(-1);

                var endDate = new DateTime(lastMonthDate.Year, lastMonthDate.Month, DateTime.DaysInMonth(lastMonthDate.Year, lastMonthDate.Month));
                var filter  = new NonTargetableReportModelFilter
                {
                    AccountId = _accountId,
                    StartDate = new DateTime(DateTime.Today.Year, 1, 1),
                    EndDate   = endDate
                };

                if (lastMonthDate.Year < DateTime.Today.Year)
                {
                    filter = new NonTargetableReportModelFilter
                    {
                        AccountId = _accountId,
                        StartDate = new DateTime(lastMonthDate.Year, 1, 1),
                        EndDate   = endDate
                    };
                }

                var eventScheduleModelFilter = new EventScheduleListModelFilter
                {
                    AccountId = _accountId,
                    FromDate  = filter.StartDate,
                    ToDate    = filter.EndDate
                };
                var stateIds = _eventRepository.GetEventStateByAccountId(eventScheduleModelFilter);
                if (stateIds.IsNullOrEmpty())
                {
                    _logger.Info("No State found for Wellmed");
                }
                var states = _stateRepository.GetStates(stateIds);

                foreach (var state in states)
                {
                    try
                    {
                        _logger.Info("Generating Report for State: " + state.Name);

                        var dataGen = new ExportableDataGenerator <NonTargetableReportModel, NonTargetableReportModelFilter>(_nonTargetableReportService.GetCustomersForNonTargetableService, _logger);
                        filter.StateId = state.Id;
                        var model = dataGen.GetData(filter);

                        if (model != null && !model.Collection.IsNullOrEmpty())
                        {
                            var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <NonTargetableReportModel>();

                            var path           = string.Format(_nonTargetableReportPath, account.FolderName);
                            var reportfilePath = Path.Combine(path, state.Name);

                            DirectoryOperationsHelper.CreateDirectoryIfNotExist(reportfilePath);
                            reportfilePath = Path.Combine(reportfilePath, string.Format("WellMed_NonTargetable_{0}.csv", DateTime.Now.ToString("yyyyMM")));
                            _logger.Info("File path : " + reportfilePath);

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

                            if (_sendReportToSftp && DirectoryOperationsHelper.IsFileExist(reportfilePath))
                            {
                                _logger.Info("Starting to post non targetable report on sftp for StateId: " + state.Id + " State: " + state.Name);

                                var sftpResultExportDirectory = string.Format(_sftpPathForNonTargetableReport, state.Name);
                                var processFtp = new ProcessFtp(_logger, _sftpHost, _sftpUserName, _sftpPassword);
                                processFtp.UploadSingleFile(reportfilePath, sftpResultExportDirectory, "");

                                _logger.Info("Non targetable report posted on sftp for StateId: " + state.Id + " State: " + state.Name);
                            }
                            _logger.Info("Non targetable Report generation completed for StateId: " + state.Id + " State: " + state.Name);
                        }
                        else
                        {
                            _logger.Info("No customer found for StateId: " + state.Id + " State: " + state.Name);
                        }
                    }
                    catch (Exception exception)
                    {
                        _logger.Error("Error occurred during generation of report for StateId: " + state.Id);
                        _logger.Error("Message:  " + exception.Message);
                        _logger.Error("Stack Trace:  " + exception.StackTrace);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Error("Some error occurred ");
                _logger.Error("Message:  " + exception.Message);
                _logger.Error("Stack Trace:  " + exception.StackTrace);
            }
        }