public ListModelBase <PcpSummaryLogReportModel, PcpSummaryLogReportModelFilter> GetPcpSummaryLogReport(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var shippingOption = _shippingOptionRepository.GetShippingOptionByProductId((long)Product.UltraSoundImages, true); var shippingDetails = _shippingDetailRepository.GetEventCustomerShippingDetailForFilter(pageNumber, pageSize, filter as PcpSummaryLogReportModelFilter, new[] { shippingOption.Id }, out totalRecords); if (shippingDetails.IsNullOrEmpty()) { return(null); } var shippingDetailIdEventCustomerIdPairs = _shippingDetailRepository.GetShippingDetailIdEventCustomerIdPairs(shippingDetails.Select(sd => sd.Id).ToArray()); var eventCustomers = _eventCustomerRepository.GetByIds(shippingDetailIdEventCustomerIdPairs.Select(sdec => sdec.SecondValue).ToArray()); var customerIds = eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(customerIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); var eventids = eventCustomers.Select(e => e.EventId).Distinct().ToArray(); var eventCollection = ((IUniqueItemRepository <Event>)_eventRepository).GetByIds(eventids); return(_pcpSummaryLogReportListModelFactory.Create(shippingDetails, shippingDetailIdEventCustomerIdPairs, eventCustomers, customers, primaryCarePhysicians, eventCollection)); }
public ListModelBase <CustomAppointmentsBookedModel, CustomAppointmentsBookedListModelFilter> GetCustomAppointmentsBooked(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var customFilter = filter as CustomAppointmentsBookedListModelFilter; customFilter = customFilter ?? new CustomAppointmentsBookedListModelFilter(); var appFilter = new AppointmentsBookedListModelFilter { AccountId = customFilter.AccountId, FromDate = customFilter.FromDate, ToDate = customFilter.ToDate, Tag = customFilter.Tag }; var eventCustomers = _eventCustomerRepository.GetEventCustomersbyRegisterationDate(pageNumber, pageSize, appFilter, out totalRecords); if (eventCustomers.IsNullOrEmpty()) { return(null); } var appointments = _appointmentRepository.GetByIds(eventCustomers.Where(ec => ec.AppointmentId.HasValue).Select(ec => ec.AppointmentId.Value).ToList()); var eventIds = eventCustomers.Select(ec => ec.EventId).Distinct().ToArray(); var model = _eventReportingService.GetEventVolumeModel(eventCustomers.Select(ec => ec.EventId).Distinct().ToArray()); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray()); var customerIds = customers.Select(x => x.CustomerId); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray(), true); var eventPackages = _eventPackageRepository.GetbyEventIds(eventIds); var eventTests = _eventTestRepository.GetByEventIds(eventIds); var orgRoleUserIds = eventCustomers.Where(ec => ec.DataRecorderMetaData != null && ec.DataRecorderMetaData.DataRecorderCreator != null).Select(ec => ec.DataRecorderMetaData.DataRecorderCreator.Id).ToList(); var eventAppointmentChangeLogs = _eventAppointmentChangeLogRepository.GetByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray()).ToArray(); orgRoleUserIds.AddRange(eventAppointmentChangeLogs.Select(eacl => eacl.CreatedByOrgRoleUserId)); var registeredbyAgent = _organizationRoleUserRepository.GetOrganizationRoleUsers(orgRoleUserIds); var roles = _roleRepository.GetAll(); var registeredbyAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds.ToArray()).ToArray(); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray()); var languages = _languageRepository.GetAll(); return(_customAppointmentsBookedModelFactory.Create(eventCustomers, appointments, orders, model, customers, registeredbyAgent, roles, registeredbyAgentNameIdPair, eventAppointmentChangeLogs, primaryCarePhysicians, eventPackages, eventTests, languages)); }
private IEnumerable <HealthPlanExportCustomerViewModel> HomeVisitExportCustomerReport(HealthPlanCustomerExportFilter filter, ILogger logger) { var list = new List <HealthPlanExportCustomerViewModel>(); var pageNumber = 1; while (true) { int totalRecords; var customers = _customerRepository.HealthPlanHomeVisitRequestedCustomerExport(filter, pageNumber, _pageSizeHealthPlanExport, out totalRecords); if (customers == null || !customers.Any()) { break; } var customerIds = customers.Select(x => x.CustomerId).ToArray(); var corporateTags = _corporateCustomerCustomTagRepository.GetByCustomerIds(customerIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); var model = _exportCustomerViewModelFactory.Create(customers, corporateTags, primaryCarePhysicians); list.AddRange(model); logger.Info(string.Format("Page Number {0} Total Records {1}", pageNumber, totalRecords)); pageNumber++; if (list.Count >= totalRecords) { break; } } return(list); }
private void HomeVisitRequestReport(string fileName, CorporateAccount account, HealthPlanCustomerExportFilter filter) { var list = new List <BcbsMiHomeVisitRequestViewModel>(); var pageNumber = 1; while (true) { int totalRecords; var customers = _customerRepository.HealthPlanHomeVisitRequestedCustomerExport(filter, pageNumber, PageSize, out totalRecords); _logger.Info(string.Format("Corporate Tag: {0} StartDate: {1} Total Customer Found: {2} PageNumber {3} ", filter.CorporateTag, filter.StartDate.ToShortDateString(), totalRecords, pageNumber)); if (customers == null || !customers.Any()) { break; } var customerIds = customers.Select(x => x.CustomerId).ToArray(); var corporateTags = _corporateCustomerCustomTagRepository.GetByCustomerIds(customerIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); var model = _healthPlanExportCustomerViewModelFactory.CreateHomeVisitListForBcbsMi(customers, corporateTags, primaryCarePhysicians); list.AddRange(model); pageNumber++; if (list.Count >= totalRecords) { break; } } if (!list.Any()) { _logger.Info(string.Format("No Patients found for Corporate Tag: {0}", filter.CorporateTag)); return; } GenerateReport(fileName, account, list); }
public IEnumerable <PatientInputFileViewModel> GetPatientFileInputByEvent(Event eventData, string tag) { var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsByEventIdTestId(eventData.Id, (long)TestType.IFOBT, tag); if (eventCustomerResults.IsNullOrEmpty()) { return(null); } var listModel = new List <PatientInputFileViewModel>(); var customerIds = eventCustomerResults.Select(ecr => ecr.CustomerId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(customerIds); var pcps = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate; foreach (var eventCustomerResult in eventCustomerResults) { var ifobtTestResult = _testResultRepository.GetTestResults(eventCustomerResult.CustomerId, eventData.Id, isNewResultFlow) as IFOBTTestResult; if (ifobtTestResult == null) { continue; } if (ifobtTestResult.TestNotPerformed != null && ifobtTestResult.TestNotPerformed.TestNotPerformedReasonId > 0) { continue; } var customer = customers.Single(c => c.CustomerId == eventCustomerResult.CustomerId); var pcp = pcps.SingleOrDefault(p => p.CustomerId == eventCustomerResult.CustomerId); var serialKey = ifobtTestResult.SerialKey != null ? ifobtTestResult.SerialKey.Reading : ""; var model = _patientInputFileFactory.Create(customer, eventData, serialKey, pcp); listModel.Add(model); } return(listModel); }
public void PollForIntegration() { _logger.Info("Starting kareo integration for patients."); var fromDate = _settings.SyncStartDate.HasValue ? _settings.SyncStartDate.Value : DateTime.Today.AddDays(7); var toDate = _settings.SyncEndDate.HasValue ? _settings.SyncEndDate.Value : DateTime.Today.AddDays(7); var eventCustomers = _eventCustomerRepository.GetByEventDate(fromDate, toDate).ToList(); var eventCustomersForToday = _eventCustomerRepository.GetByEventDate(DateTime.Today, DateTime.Today); eventCustomers.AddRange(eventCustomersForToday); var customSettingFilePath = string.Format(_customSettingFile, "PatientKareoIntegration"); var customSettings = _customSettingManager.Deserialize(customSettingFilePath); if (customSettings.LastTransactionDate == null) { fromDate = _cutOffDate; toDate = DateTime.Today.AddDays(-1); var pastEventCustomers = _eventCustomerRepository.GetByEventDate(fromDate, toDate).ToList(); eventCustomers.AddRange(pastEventCustomers); } if (eventCustomers.IsNullOrEmpty()) { _logger.Info("No event customers found."); return; } var billingAccounts = _billingAccountRepository.GetAll(); if (billingAccounts.IsNullOrEmpty()) { _logger.Info("No Billing Accounts added."); return; } var billingAccount = billingAccounts.First(); var orderedEventCustomers = eventCustomers.OrderBy(x => x.EventId).ToArray(); var eventIds = orderedEventCustomers.OrderBy(x => x.EventId).Select(x => x.EventId).Distinct().ToArray(); _logger.Info("No. of Events : " + eventIds.Count()); foreach (var eventId in eventIds) { try { _logger.Info("Integrating for EventID : " + eventId); var customerIds = orderedEventCustomers.Where(x => x.EventId == eventId).Select(x => x.CustomerId).ToArray(); var customersAlreadySyncedBySystem = _customerBillingAccountRepository.GetAlreadySyncedCustomers(customerIds, billingAccount.Id); var customersToSync = _customerRepository.GetCustomers(customerIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); foreach (var customer in customersToSync) { try { var pcp = primaryCarePhysicians.FirstOrDefault(x => x.CustomerId == customer.CustomerId); if (customersAlreadySyncedBySystem.Select(x => x.CustomerId).Contains(customer.CustomerId)) { var syncedCustomer = customersAlreadySyncedBySystem.First(x => x.CustomerId == customer.CustomerId); var existingPatientResponse = _kareoApi.GetPatients(customer.Name.FirstName, customer.Name.LastName, customer.DateOfBirth.Value, billingAccount); _kareoApi.UpdatePatient(syncedCustomer.BillingPatientId, customer, pcp, billingAccount); _logger.Info("Updated patient informationon Kareo for Customer ID : " + customer.CustomerId); _logger.Info("\n"); } else { var patientResponse = new GetPatientsResp(); if (customer.DateOfBirth.HasValue) { patientResponse = _kareoApi.GetPatients(customer.Name.FirstName, customer.Name.LastName, customer.DateOfBirth.Value, billingAccount); } if (patientResponse != null && !patientResponse.Patients.IsNullOrEmpty() && patientResponse.Patients.Any(x => !string.IsNullOrEmpty(x.ID))) { _logger.Info(string.Format("Customer : {0} already synced.", customer.CustomerId)); var patient = patientResponse.Patients.First(); var patientId = Convert.ToInt64(patient.ID); _kareoApi.UpdatePatient(patientId, customer, pcp, billingAccount); SaveCustomerBillingAccount(billingAccount, patientId, customer.CustomerId); _logger.Info("Updated patient informationon Kareo for Customer ID : " + customer.CustomerId); _logger.Info("\n"); } else { _logger.Info("Creating patient on Kareo for Customer ID : " + customer.CustomerId); var createPatientResp = _kareoApi.CreatePatientNew(customer, pcp, billingAccount); if (!createPatientResp.PatientID.HasValue) { _logger.Info(string.Format("Patient not created for Event (Id: {0}) and Customer (Id: {1}) and Billing Account {2}", eventId, customer.CustomerId, billingAccount.Name)); _logger.Info("\n"); continue; } SaveCustomerBillingAccount(billingAccount, createPatientResp.PatientID.Value, customer.CustomerId); _logger.Info(string.Format("Customer : {0} synced.", customer.CustomerId)); } } } catch (Exception ex) { _logger.Info(string.Format("Error integrating for EventID : {0} and Customer ID : {1} \nMessage : {2} \nStack Trace : {3}", eventId, customer.CustomerId, ex.Message, ex.StackTrace)); } } _logger.Info("Completed for EventID : " + eventId); _logger.Info("\n"); } catch (Exception ex) { _logger.Info(string.Format("Error integrating for EventID : {0} \nMessage : {1} \nStack Trace : {2}", eventId, ex.Message, ex.StackTrace)); } } customSettings.LastTransactionDate = DateTime.Today; _customSettingManager.SerializeandSave(customSettingFilePath, customSettings); _logger.Info("Kareo integration completed."); }
public void PollforFaxResultNotification() { try { var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.EnablePhysicianPartnerCustomerResultFaxNotification); if (value.ToLower() != bool.TrueString.ToLower()) { return; } var account = _corporateAccountRepository.GetById(_settings.PhysicianPartnerAccountId); DateTime?stopSendingPdftoHealthPlanDate = null; if (account != null && account.IsHealthPlan) { stopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate; } var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsToFax( (int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, DateTime.Now, DateTime.Now.AddHours(-_faxInterval), _settings.PhysicianPartnerAccountId, "", stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate); var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray(); if (eventCustomerResults == null || !customerResults.Any()) { _logger.Info("No event customer result list found for Fax queue."); return; } _logger.Info("Get the event customer result list for Fax queue."); var fileName = _mediaRepository.GetPdfFileNameForPcpResultReport(); var customerIds = customerResults.Select(x => x.CustomerId).ToArray(); var pcpList = _pcpRepository.GetByCustomerIds(customerIds).Where(x => x.Fax != null && !string.IsNullOrEmpty(x.Fax.ToString())); foreach (var ecr in customerResults) { var messageAlreadySent = _eventCustomerNotificationRepository.GetByEventCustomerId(ecr.Id, NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification); if (messageAlreadySent != null) { _logger.Info(string.Format("Fax already queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); continue; } var path = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath; var pdfUrl = path + fileName; if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1) { throw new InvalidDirectoryPathException(); } if (File.Exists(pdfUrl)) { var pcp = pcpList.FirstOrDefault(x => x.CustomerId == ecr.CustomerId); if (pcp == null) { _logger.Error(string.Format("PCP not found/or pcp Fax not found where customerId {0}", ecr.CustomerId)); } else { try { PhoneNotificationModel model = null; var notification = _notifier.NotifyViaFax(NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification, model, pcp.Fax, DirectoryOperationsHelper.ReadAllBytes(pdfUrl), 1, "Faxing Notification"); if (notification != null) { var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = ecr.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; _eventCustomerNotificationRepository.Save(eventCustomerNotification); } _logger.Info(string.Format("Fax queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); } catch (Exception ex) { _logger.Error(string.Format("Fax not queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); _logger.Error("\n"); _logger.Error(ex.Message + "Stack Trace:" + ex.StackTrace); } } } else { _logger.Error(string.Format("Fax queue: File Not found for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); } } } catch (Exception ex) { _logger.Error(ex.Message + "Fax queue: Stack Trace:" + ex.StackTrace); } }
public ListModelBase <HourlyAppointmentBookedModel, HourlyAppointmentsBookedListModelFilter> GetHourlyAppointmentsBooked(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var customFilter = filter as HourlyAppointmentsBookedListModelFilter; customFilter = customFilter ?? new HourlyAppointmentsBookedListModelFilter(); var appFilter = new AppointmentsBookedListModelFilter { AccountId = customFilter.AccountId, FromDate = customFilter.FromDate, ToDate = customFilter.ToDate, ShowCustomersWithAppointment = customFilter.ShowCustomersWithAppointment, IsHealthPlanEvent = true }; var eventCustomers = _eventCustomerRepository.GetEventCustomersbyRegisterationDate(pageNumber, pageSize, appFilter, out totalRecords); if (eventCustomers.IsNullOrEmpty()) { return(null); } var appointments = _appointmentRepository.GetByIds(eventCustomers.Where(ec => ec.AppointmentId.HasValue).Select(ec => ec.AppointmentId.Value).ToList()); var eventIds = eventCustomers.Select(ec => ec.EventId).Distinct().ToArray(); var model = _eventReportingService.GetEventVolumeModel(eventCustomers.Select(ec => ec.EventId).Distinct().ToArray()); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray()); var customerIds = customers.Select(x => x.CustomerId); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray(), true); var customerEligibilities = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIdsAndYear(customerIds, DateTime.Today.Year); if (customerEligibilities.IsNullOrEmpty()) { customerEligibilities = new List <CustomerEligibility>(); } var eventPackages = _eventPackageRepository.GetbyEventIds(eventIds); var eventTests = _eventTestRepository.GetByEventIds(eventIds); var sourceCodes = _sourceCodeRepository.GetSourceCodeByIds(orders.SelectMany(o => o.OrderDetails.Where(od => od.SourceCodeOrderDetail != null && od.SourceCodeOrderDetail.IsActive) .Select(od => od.SourceCodeOrderDetail.SourceCodeId)).Distinct().ToArray()); var orgRoleUserIds = eventCustomers.Where(ec => ec.DataRecorderMetaData != null && ec.DataRecorderMetaData.DataRecorderCreator != null).Select(ec => ec.DataRecorderMetaData.DataRecorderCreator.Id).ToList(); var eventAppointmentChangeLogs = _eventAppointmentChangeLogRepository.GetByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray()).ToArray(); orgRoleUserIds.AddRange(eventAppointmentChangeLogs.Select(eacl => eacl.CreatedByOrgRoleUserId)); var registeredbyAgent = _organizationRoleUserRepository.GetOrganizationRoleUsers(orgRoleUserIds); var roles = _roleRepository.GetAll(); var registeredbyAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds.ToArray()).ToArray(); var callDetails = _callCenterCallRepository.GetCallDetails(customers); var shippingDetailIds = orders.SelectMany(o => o.OrderDetails.SelectMany(od => od.ShippingDetailOrderDetails.Select(sdod => sdod.ShippingDetailId))).ToArray(); var shippingDetails = _shippingDetailRepository.GetByIds(shippingDetailIds); var cdShippingOption = _shippingOptionRepository.GetShippingOptionByProductId((long)Product.UltraSoundImages); var shippingOptions = _shippingOptionRepository.GetAllShippingOptions(); var customTags = _customTagRepository.GetByCustomerIds(customerIds); var tagNames = customers.Where(x => !string.IsNullOrEmpty(x.Tag)).Select(x => x.Tag).ToArray(); var corporateAccount = _corporateAccountRepository.GetByTags(tagNames); var corporateAccountIds = corporateAccount.Select(x => x.Id).ToArray(); var accountAdditionalField = _accountAdditionalFieldRepository.GetAccountAdditionalFieldsByAccountIds(corporateAccountIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray()); var languages = _languageRepository.GetAll(); var pcpAppointments = _pcpAppointmentRepository.GetByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray()); return(_customAppointmentsBookedModelFactory.CreateHourlyModel(eventCustomers, appointments, orders, model, customers, registeredbyAgent, roles, registeredbyAgentNameIdPair, sourceCodes, callDetails, shippingDetails, cdShippingOption, shippingOptions, eventAppointmentChangeLogs, primaryCarePhysicians, eventPackages, eventTests, languages, customTags, corporateAccount, accountAdditionalField, pcpAppointments, customerEligibilities)); }
private HospitalPartnerCustomerListModel GetCustomers(IEnumerable <EventCustomer> eventCustomers, HospitalPartner hospitalPartner) { var eventCustomerIds = eventCustomers.Select(ec => ec.Id).ToArray(); var eventIds = eventCustomers.Select(ec => ec.EventId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray()); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomerIds, true); var orderPackageIdNamePair = _eventPackageRepository.GetPackageNamesForOrder(orders.Select(o => o.Id).ToList()); var orderTestIdNamePair = _eventTestRepository.GetTestNamesForOrders(orders.Select(o => o.Id).ToList()); var hospitalPartnerCustomers = _hospitalPartnerCustomerRepository.GetHospitalPartnerCustomers(eventIds); var orgRoleUserIds = new List <long>(); orgRoleUserIds.AddRange(hospitalPartnerCustomers.Select(hpc => hpc.CareCoordinatorOrgRoleUserId).ToArray()); orgRoleUserIds.AddRange(hospitalPartnerCustomers.Select(hpc => hpc.DataRecorderMetaData.DataRecorderCreator.Id).ToArray()); orgRoleUserIds.AddRange(hospitalPartnerCustomers.Where(hpc => hpc.DataRecorderMetaData.DataRecorderModifier != null).Select(hpc => hpc.DataRecorderMetaData.DataRecorderModifier.Id).ToArray()); orgRoleUserIds = orgRoleUserIds.Select(oru => oru).Distinct().ToList(); var idNamePairs = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds.ToArray()); var eventCustomerResults = _eventCustomerResultRepository.GetByIds(eventCustomerIds); eventCustomerResults = eventCustomerResults.Where(ecr => ecr.ResultState >= (long)TestResultStateNumber.Evaluated).ToArray(); var pods = _podRepository.GetPodsForEvents(eventIds); var events = _eventRepository.GetEventswithPodbyIds(eventIds); var shippingDetailIds = orders.SelectMany(o => o.OrderDetails.SelectMany(od => od.ShippingDetailOrderDetails.Select(sdod => sdod.ShippingDetailId))).ToArray(); var resultStatuses = _eventCustomerResultRepository.GetTestResultStatus(eventCustomerIds); var shippingDetails = _shippingDetailRepository.GetByIds(shippingDetailIds); var cdShippingOption = _shippingOptionRepository.GetShippingOptionByProductId((long)Product.UltraSoundImages); //var eventIdHospitalPartnerIdPairs = _hospitalPartnerRepository.GetEventAndHospitalPartnerOrderedPair(eventIds); var eventHospitalPartners = _hospitalPartnerRepository.GetEventHospitalPartnersByEventIds(eventIds).ToArray(); var organizationIds = eventHospitalPartners.Select(ehp => ehp.HospitalPartnerId).Distinct().ToArray(); var hospitalFacilityIds = eventCustomers.Where(ec => ec.HospitalFacilityId.HasValue && ec.HospitalFacilityId.Value > 0).Select(ec => ec.HospitalFacilityId.Value).ToArray(); organizationIds = organizationIds.Concat(hospitalFacilityIds).ToArray(); var organizations = _organizationRepository.GetOrganizations(organizationIds); var eventIdHospitalPartnerNamePairs = (from ehp in eventHospitalPartners join org in organizations on ehp.HospitalPartnerId equals org.Id select new OrderedPair <long, string>(ehp.EventId, org.Name)).ToArray(); var eventIdCorporateAccounrNamePairs = _corporateAccountRepository.GetEventIdCorporateAccountNamePair(eventIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(eventCustomers.Select(ec => ec.CustomerId).ToArray()); var healthAssessmentQuestions = _healthAssessmentRepository.GetAllQuestions(); var healthAssessmentAnswers = _healthAssessmentRepository.GetByCustomerIds(eventCustomers.Select(ec => ec.CustomerId).ToArray()); var notes = _customerCallNotesRepository.GetNotes(eventCustomers.Select(ec => ec.CustomerId).ToArray(), CustomerRegistrationNotesType.PostScreeningFollowUpNotes); var eventCustomerNotifications = _eventCustomerNotificationRepository.GetByEventCustomerIds(eventCustomerIds, NotificationTypeAlias.CannedMessageNotification); var hospitalFacilities = hospitalFacilityIds.Any() ? _hospitalFacilityRepository.GetByIds(hospitalFacilityIds) : null; var eventCustomerIdHospitalFacilityNamePairs = (from ec in eventCustomers join org in organizations on ec.HospitalFacilityId equals org.Id select new OrderedPair <long, string>(ec.Id, org.Name)).ToArray(); var showScannedDocumentHospitalPartnerIds = _settings.ShowScannedDocumentHospitalPartnerIds; var languages = _languageRepository.GetAll(); return(_hospitalPartnerCustomerViewModelFactory.Create(eventCustomers, orders, customers, orderPackageIdNamePair, orderTestIdNamePair, hospitalPartnerCustomers, idNamePairs, events, shippingDetails, resultStatuses, cdShippingOption, pods, eventIdHospitalPartnerNamePairs, eventIdCorporateAccounrNamePairs, primaryCarePhysicians, healthAssessmentQuestions, healthAssessmentAnswers, eventCustomerResults, hospitalPartner, notes, eventCustomerNotifications, eventHospitalPartners, eventCustomerIdHospitalFacilityNamePairs, hospitalFacilities, showScannedDocumentHospitalPartnerIds, languages)); }
public CustomerEventDetailViewModel GetPatients(PatientSearchFilter filter, long technicianId) { var list = new List <ShortPatientInfoViewModel>(); var patientList = _customerRepository.GetPatientList(filter); if (patientList.IsNullOrEmpty()) { return(new CustomerEventDetailViewModel()); } var customerIds = patientList.Select(x => x.CustomerId); var eventCustomers = _eventCustomerRepository.GetByCustomerIdEventDate(customerIds, DateTime.Today, DateTime.Now.AddDays(-1), technicianId).Where(x => x.AppointmentId.HasValue).ToArray(); if (eventCustomers.IsNullOrEmpty()) { return(new CustomerEventDetailViewModel()); } customerIds = eventCustomers.Select(x => x.CustomerId).Distinct().ToList(); var appointmentIds = eventCustomers.Where(x => x.AppointmentId.HasValue).Select(x => x.AppointmentId.Value).ToArray(); var appointments = _appointmentRepository.GetByIds(appointmentIds); var eventIds = eventCustomers.Select(x => x.EventId).Distinct().ToArray(); var events = _eventRepository.GetEventsByIds(eventIds); var eventModels = _eventService.GetShortEventInfoList(events); var hosts = _hostRepository.GetEventHosts(eventIds); var eventCustomerIds = eventCustomers.Select(x => x.Id); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomerIds); var participationConsentSignatures = _participationConsentSignatureRepository.GetByEventCustomerIds(eventCustomerIds); var fluConsentSignatures = _fluConsentSignatureRepository.GetByEventCustomerIds(eventCustomerIds); var physicianRecordRequestSignatures = _physicianRecordRequestSignatureRepository.GetByEventCustomerIds(eventCustomerIds); var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(customerIds); foreach (var eventCustomer in eventCustomers) { var patient = patientList.First(x => x.CustomerId == eventCustomer.CustomerId); var appointment = appointments.First(x => x.Id == eventCustomer.AppointmentId); var theEvent = events.First(x => x.Id == eventCustomer.EventId); var host = hosts.First(x => x.Id == theEvent.HostId); var order = orders.Single(o => o.CustomerId == eventCustomer.CustomerId); var eventPackages = _eventPackageRepository.GetPackagesForEvent(eventCustomer.EventId); var eventTests = _eventTestRepository.GetTestsForEvent(eventCustomer.EventId); var eventpackageId = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventPackageItem) .Select(od => od.OrderItem.ItemId).SingleOrDefault(); var eventPackage = eventPackages.SingleOrDefault(ep => eventpackageId == ep.Id); var eventTestIds = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId).ToArray(); var eventTestsonOrder = eventTests.Where(et => eventTestIds.Contains(et.Id)).ToArray(); var chaperoneSignature = _chaperoneSignatureRepository.GetByEventCustomerId(eventCustomer.Id); var model = new ShortPatientInfoViewModel { CustomerId = patient.CustomerId, EventCustomerId = eventCustomer.Id, FirstName = patient.Name.FirstName, MiddleName = patient.Name.MiddleName, LastName = patient.Name.LastName, Email = patient.Email.ToString(), HomePhone = patient.HomePhoneNumber.FormatPhoneNumber, MobileNumber = patient.MobilePhoneNumber.FormatPhoneNumber, EventId = eventCustomer.EventId, AppointmentTime = appointment.StartTime, Packages = eventPackage != null ? eventPackage.Package.Name : "", Tests = !eventTestsonOrder.IsNullOrEmpty() ? string.Join(", ", eventTestsonOrder.Select(t => t.Test.Name)) : "", HipaaConsent = eventCustomer.HIPAAStatus, CheckInTime = appointment.CheckInTime, CheckOutTime = appointment.CheckOutTime, MatrixConsent = participationConsentSignatures != null && participationConsentSignatures.SingleOrDefault(x => x.EventCustomerId == eventCustomer.Id) != null, PhysicianRecordRequest = physicianRecordRequestSignatures != null && physicianRecordRequestSignatures.SingleOrDefault(x => x.EventCustomerId == eventCustomer.Id) != null, FluVaccine = fluConsentSignatures != null && fluConsentSignatures.SingleOrDefault(x => x.EventCustomerId == eventCustomer.Id) != null, NoShow = eventCustomer.AppointmentId.HasValue && eventCustomer.NoShow, LeftWithoutScreening = eventCustomer.AppointmentId.HasValue && eventCustomer.LeftWithoutScreeningReasonId.HasValue, ChaperoneConsent = chaperoneSignature != null?true: false }; var pcp = primaryCarePhysicians != null?primaryCarePhysicians.FirstOrDefault(x => x.CustomerId == eventCustomer.CustomerId) : null; if (pcp != null) { var pcpAddress = pcp.Address != null?Mapper.Map <Address, AddressViewModel>(pcp.Address) : null; model.PrimaryCarePhysician = new PcpInfoViewModel { Name = pcp.Name.FullName, Address = pcpAddress, PhoneNumber = pcp.Primary != null ? pcp.Primary.FormatPhoneNumber : pcp.Secondary != null ? pcp.Secondary.FormatPhoneNumber : "", Fax = pcp.Fax != null ? pcp.Fax.FormatPhoneNumber : "" }; } list.Add(model); } return(new CustomerEventDetailViewModel { Customers = list, Events = eventModels }); }