public PcpSummaryLogReportListModel Create(IEnumerable <ShippingDetail> shippingDetails, IEnumerable <OrderedPair <long, long> > shippingDetailIdEventCustomerIdPairs, IEnumerable <EventCustomer> eventCustomers, IEnumerable <Customer> customers, IEnumerable <PrimaryCarePhysician> primarycarePhysicians, IEnumerable <Event> eventsCollection) { var listModel = new PcpSummaryLogReportListModel(); var collection = new List <PcpSummaryLogReportModel>(); var vendorCode = "HLTF"; var lineOfBusiness = "EMR"; foreach (var shippingDetail in shippingDetails) { var eventCustomerId = shippingDetailIdEventCustomerIdPairs.Where(sdec => sdec.FirstValue == shippingDetail.Id).Select(sdec => sdec.SecondValue).First(); var eventCustomer = eventCustomers.First(ec => ec.Id == eventCustomerId); var eventData = eventsCollection.First(x => x.Id == eventCustomer.EventId); var customer = customers.First(c => c.CustomerId == eventCustomer.CustomerId); var pcp = primarycarePhysicians.FirstOrDefault(p => p.CustomerId == eventCustomer.CustomerId); var model = new PcpSummaryLogReportModel() { VendorCode = vendorCode, MedicareNumber = customer.Hicn, LineOfBusiness = lineOfBusiness, MemberState = customer.Address.State, MemberCounty = customer.AdditionalField4, MemberFirstName = customer.Name.FirstName, MemberLastName = customer.Name.LastName, SubscriberID = customer.CustomerId.ToString(), MemberID = customer.AdditionalField3, DOB = customer.DateOfBirth, Gender = customer.Gender.GetDescription(), PcpFirstName = pcp != null && pcp.Name != null ? pcp.Name.FirstName : string.Empty, PcpLastName = pcp != null && pcp.Name != null ? pcp.Name.LastName : string.Empty, PcpPhoneNumber = pcp != null && pcp.Primary != null ? pcp.Primary.DomesticPhoneNumber : string.Empty, PcpAddress1 = pcp != null && pcp.Address != null ? pcp.Address.StreetAddressLine1 : string.Empty, PcpAddress2 = pcp != null && pcp.Address != null ? pcp.Address.StreetAddressLine2 : string.Empty, PcpCity = pcp != null && pcp.Address != null ? pcp.Address.City : string.Empty, PcpState = pcp != null && pcp.Address != null ? pcp.Address.State : string.Empty, PcpZIP = pcp != null && pcp.Address != null && pcp.Address.ZipCode != null ? pcp.Address.ZipCode.Zip : string.Empty, EventDate = eventData.EventDate, EventId = eventData.Id, PcpMailedDate = shippingDetail.ShipmentDate, ResultFileName = customer.CustomerId + "_" + eventData.EventDate.ToString("MMddyyyy") + ".pdf" //file name format: customerId_eventDate.pdf }; collection.Add(model); } listModel.Collection = collection; return(listModel); }
public void PollForPcpLogSummaryReportExport() { try { if (_wellCarePcpSummaryLogReportDayOfWeek != DateTime.Today.DayOfWeek) { _logger.Info("Report is schedule to run on " + _wellCarePcpSummaryLogReportDayOfWeek); _logger.Info("Today is day of week " + DateTime.Today.DayOfWeek); _logger.Info(string.Format("Set day of week to {0} to run today ", ((int)DateTime.Today.DayOfWeek))); return; } if (_accountIds.IsNullOrEmpty()) { _logger.Info("No Account Ids found"); return; } var directoryPath = _destinationFolderPdfPath + "\\"; CreateDestinationDirectory(directoryPath); var toDate = DateTime.Now; var fileName = string.Format("PCPSummaryLog-HealthFair-{0}.csv", toDate.ToString("yyyyMMdd")); var accounts = _corporateAccountRepository.GetByIds(_accountIds); var model = new PcpSummaryLogReportListModel(); foreach (var account in accounts) { _logger.Info("Running Report for Tag: " + account.Tag); try { var serviceReportSettings = string.Format(_wellCarePcpSummaryLogReportSettingPath, account.Tag); var customSettings = _customSettingManager.Deserialize(serviceReportSettings); var fromDate = (customSettings.LastTransactionDate != null) ? customSettings.LastTransactionDate.Value : _cutOfDate; var listModel = PcpSummaryLogReport(account, fromDate, toDate, directoryPath, fileName); if (listModel != null && !listModel.Collection.IsNullOrEmpty()) { if (model.Collection.IsNullOrEmpty()) { model.Collection = listModel.Collection; } else { model.Collection = model.Collection.Concat(listModel.Collection); } } customSettings.LastTransactionDate = toDate; _customSettingManager.SerializeandSave(serviceReportSettings, customSettings); } catch (Exception ex) { _logger.Error("Some Error occurred for Tag" + account.Tag); _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } } if (model != null && !model.Collection.IsNullOrEmpty()) { model.Collection = model.Collection.OrderBy(x => x.PcpMailedDate).ThenBy(x => x.EventId); var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <PcpSummaryLogReportModel>(); _logger.Info("Record count" + model.Collection.Count()); if (File.Exists(directoryPath + fileName) && !FirstReportGenerated) { File.Delete(directoryPath + fileName); } FirstReportGenerated = _baseExportableReportHelper.GenerateCsv(directoryPath + fileName, exporter, model.Collection, skipHeader: FirstReportGenerated); _logger.Info("Destination file " + directoryPath + fileName); } else { _logger.Info(string.Format("No Data found for PCP summary log Period {0} ", toDate)); } if (_settings.SendPdfToWellCareSftp) { ExportResultOnWellCareSftp(fileName, directoryPath + fileName); } } catch (Exception ex) { _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } }