public IEnumerable <EventCusomerAdjustOrderViewModel> MarkcustomerForAdjustOrder(CorporateCustomerEditModel model, IEnumerable <EventCustomer> eventCustomers, long createdByOrgRoleUserId, long customerId, long?corporateUploadId) { var pairs = TestType.A1C.GetNameValuePairs(); var preApprovedTestIds = model.PreApprovedTest.IsNullOrEmpty() ? new long[0] : pairs.Where(x => model.PreApprovedTest.Contains(x.SecondValue.ToLower())).Select(x => (long)x.FirstValue).ToArray(); preApprovedTestIds = _corporateUploadHelper.RemoveFocFromPreApprovedTest(preApprovedTestIds.ToList()).ToArray(); var eventIds = eventCustomers.Select(x => x.EventId); var events = ((IUniqueItemRepository <Event>)_eventRepository).GetByIds(eventIds); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomers.Select(x => x.Id)); var orderIds = orders.Select(o => o.Id).ToArray(); var orderEventPackageIdPairs = _eventPackageRepository.GetEventPackageIdsForOrder(orderIds); // orderId, EventPackaegId var eventPacakageTestIds = _eventPackageRepository.GetOrderIdEventPackageTestIdPairsForOrder(orderIds); //orderId, TestId(package test) var orderIdTestIdPairs = _eventTestRepository.GetOrderIdTestIdPairsForOrders(orderIds); // orderId, TestId var eventPackageIds = orderEventPackageIdPairs.Select(pair => pair.SecondValue).ToArray(); var eventPackages = _eventPackageRepository.GetByIds(eventPackageIds).ToArray(); var list = new List <EventCusomerAdjustOrderViewModel>(); foreach (var eventCustomer in eventCustomers) { var order = orders.FirstOrDefault(x => x.CustomerId == eventCustomer.CustomerId && x.EventId == eventCustomer.EventId); if (order == null) { continue; } var theEvent = events.First(s => s.Id == eventCustomer.EventId); var eventPackagePair = orderEventPackageIdPairs.FirstOrDefault(x => x.FirstValue == order.Id); var preApprovedPackageUpdated = IsPreApprovedPackageUpdated(eventPackagePair, eventPackages, order, model.PreApprovedPackageId); var testIdInPackage = new List <long>(); if (eventPackagePair != null) { testIdInPackage = eventPacakageTestIds.Where(x => x.FirstValue == eventPackagePair.FirstValue).Select(s => s.SecondValue).ToList(); } var preApprovedTestNotInOrder = PreApprovedTestUpdated(orderIdTestIdPairs, order, preApprovedTestIds, testIdInPackage); var preApprovedTestToUpdate = string.Empty; if (preApprovedTestNotInOrder != null) { preApprovedTestToUpdate = string.Join(",", preApprovedTestNotInOrder.Select(x => ((TestType)x).ToString())); } if (preApprovedPackageUpdated || !preApprovedTestNotInOrder.IsNullOrEmpty()) { list.Add(new EventCusomerAdjustOrderViewModel { CustomerId = eventCustomer.CustomerId, EventId = eventCustomer.EventId, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, MemberId = model.MemberId, EventDate = theEvent.EventDate, PreApprovedPackageToAdjust = preApprovedPackageUpdated ? model.PreApprovedPackage : string.Empty, PreApprovedTestsToAdjust = preApprovedTestToUpdate }); long newPackageId = 0; long oldPackageId = 0; if (preApprovedPackageUpdated) { newPackageId = model.PreApprovedPackageId; } if (eventPackagePair != null) { var package = eventPackages.First(x => x.Id == eventPackagePair.SecondValue).Package; oldPackageId = package.Id; } var orderedTestIds = orderIdTestIdPairs.Where(x => x.FirstValue == order.Id).Select(x => x.SecondValue); AdjustCustomerOrder(eventCustomer, order, newPackageId, oldPackageId, createdByOrgRoleUserId, customerId, orderedTestIds, preApprovedTestIds, testIdInPackage, corporateUploadId.HasValue ? corporateUploadId.Value : 0); } } return(list.IsNullOrEmpty() ? null : list); }
public ListModelBase <DailyPatientRecapModel, DailyPatientRecapModelFilter> GetDailyPatientReapModel(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var eventCustomers = _eventCustomerRepository.GetEventsCustomersForDailyPatientRecap(pageNumber, pageSize, filter as DailyPatientRecapModelFilter, out totalRecords); if (eventCustomers.IsNullOrEmpty()) { return(null); } var eventIds = eventCustomers.Select(x => x.EventId).Distinct(); var appointmentids = eventCustomers.Where(ec => ec.AppointmentId.HasValue).Select(ec => ec.AppointmentId.Value).ToList(); var events = _eventRepository.GetEventswithPodbyIds(eventIds); var pods = _podRepository.GetPodsForEvents(eventIds); var eventPods = _eventPodRepository.GetByEventIds(eventIds); var customerIds = eventCustomers.Select(x => x.CustomerId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(customerIds); var eventCustomerIds = eventCustomers.Select(x => x.Id).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 orderIdEventPackageTestIdPairs = _eventPackageRepository.GetOrderIdEventPackageTestIdPairsForOrder(orders.Select(o => o.Id).ToArray()); var orderIdTestIdPairs = _eventTestRepository.GetOrderIdTestIdPairsForOrders(orders.Select(o => o.Id).ToArray()); var testNotPerformedEventCustomerIdTestIdPairs = _testNotPerformedRepository.GetEventCusromerResultIdTestIdPairs(eventCustomerIds); var testIds = orderIdEventPackageTestIdPairs.Select(op => op.SecondValue).Distinct().ToList(); testIds.AddRange(orderIdTestIdPairs.Select(op => op.SecondValue).Distinct().ToArray()); var tests = _testRepository.GetTestNameValuePair(testIds); 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 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 appointments = _appointmentRepository.GetByIds(appointmentids); return(_dailyPatientRecapListModelFactory.CreateListModel(eventCustomers, customers, orders, shippingDetails, cdShippingOption, eventIdHospitalPartnerNamePairs, eventIdCorporateAccounrNamePairs, appointments, pods, eventPods, events, orderIdEventPackageTestIdPairs, orderIdTestIdPairs, testNotPerformedEventCustomerIdTestIdPairs, tests, orderPackageIdNamePair)); }