Esempio n. 1
0
        public IEnumerable <EventCustomerDiagnosis> GetForConditionInboundReport(ConditionInboundFilter filter, int pageNumber, int pageSize, out int totalRecords)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);

                var account = filter.AccountId > 0 ? (from a in linqMetaData.Account where a.AccountId == filter.AccountId select a).SingleOrDefault() : null;

                var query = (from ecd in linqMetaData.EventCustomerDiagnosis
                             join ec in linqMetaData.EventCustomers on ecd.EventCustomerId equals ec.EventCustomerId
                             join cp in linqMetaData.CustomerProfile on ec.CustomerId equals cp.CustomerId
                             where (filter.StartDate == null || (ecd.DateCreated != null && ecd.DateCreated >= filter.StartDate)) &&
                             (filter.EndDate == null || (ecd.DateCreated != null && ecd.DateCreated <= filter.EndDate)) &&
                             (account == null || cp.Tag == account.Tag)
                             select new { ecd, ec.CustomerId });

                if (!filter.CustomTags.IsNullOrEmpty())
                {
                    var customTagCustomersIds = (from ct in linqMetaData.CustomerTag where ct.IsActive && filter.CustomTags.Contains(ct.Tag) select ct.CustomerId);
                    query = (from q in query where customTagCustomersIds.Contains(q.CustomerId) select q);
                }

                var entities = (from q in query select q.ecd);

                totalRecords = entities.Count();
                var results = entities.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToArray();

                return(Mapper.Map <IEnumerable <EventCustomerDiagnosisEntity>, IEnumerable <EventCustomerDiagnosis> >(results));
            }
        }
        private void GenerateConditionInboundReport(ConditionInboundFilter filter)
        {
            var dataGen = new ExportableDataGenerator <ConditionInboundViewModel, ConditionInboundFilter>(_conditionInboundReportService.GetConditionInboundReportList, _logger);
            var model   = dataGen.GetData(filter);

            var account = _corporateAccountRepository.GetById(filter.AccountId);

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

                _pipeDelimitedReportHelper.Write(model.Collection, folder, fileName + ".txt");

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

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

                        _logger.Info("File sent to SFTP.");
                    }
                    catch (Exception ex)
                    {
                        _logger.Info("Error sending file to SFTP.");
                        _logger.Error("Message : " + ex.Message);
                        _logger.Error("Stack Trace : " + ex.StackTrace);
                    }
                }
            }
            else
            {
                _logger.Info("No record found for " + account.Tag);
            }
        }
        public void PollForConditionInboundReport()
        {
            try
            {
                if (DateTime.Today.DayOfWeek != _dayOfWeek)
                {
                    _logger.Info(string.Format("Today is {0}. Job is set to run on {1}.", DateTime.Today.DayOfWeek, _dayOfWeek));
                    return;
                }

                var accountIds = _settings.FloridaBlueAccountId.Split(',');

                if (accountIds.IsNullOrEmpty())
                {
                    _logger.Info("No accounts found for Response Vendor Report.");
                    return;
                }

                _logger.Info("Starting Condition Inbound Report generation.");

                var customSettingFilePath = string.Format(_customSettingFile, ReportType.ConditionInbound);
                var customSettings        = _customSettingManager.Deserialize(customSettingFilePath);

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

                foreach (var accountId in accountIds)
                {
                    var filter = new ConditionInboundFilter
                    {
                        StartDate  = exportFromTime,
                        EndDate    = exportToTime,
                        AccountId  = Convert.ToInt32(accountId),
                        CustomTags = _settings.FloridaBlueMedicareCustomTags
                    };

                    if (filter.AccountId == _settings.FloridaBlueCommercialId)
                    {
                        filter.CustomTags = _settings.FloridaBlueCommercialCustomTags;
                    }
                    else if (filter.AccountId == _settings.FloridaBlueMammoId)
                    {
                        filter.CustomTags = _settings.FloridaBlueMammoCustomTags;
                    }
                    else if (filter.AccountId == _settings.FloridaBlueGapsId)
                    {
                        filter.CustomTags = _settings.FloridaBlueGapsCustomTags;
                    }

                    GenerateConditionInboundReport(filter);

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

                _logger.Info("Completed Condition Inbound Report generation.");
            }
            catch (Exception ex)
            {
                _logger.Error("Some error occured while generating Condition Inbound Report");
                _logger.Error("Exception: " + ex.Message);
                _logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }