public IEnumerable <BloodworksLabelViewModel> GetBloodworksLabel(long eventId) { var eventCustomers = _eventCustomerRepository.GetbyEventId(eventId); eventCustomers = eventCustomers.Where(ec => ec.AppointmentId.HasValue).Select(ec => ec); if (eventCustomers.IsNullOrEmpty()) { return(null); } var orderIdEventCustomerIdPairs = _orderRepository.GetOrderEventCustomerIdPairforEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray()).ToArray(); var orderIdEventTestIdPairs = _eventTestRepository.GetEventTestIdForOrders(orderIdEventCustomerIdPairs.Select(pair => pair.FirstValue).ToArray()).ToArray(); var eventTests = _eventTestRepository.GetbyIds(orderIdEventTestIdPairs.Select(pair => pair.SecondValue).ToArray()); var eventTestIds = eventTests.Where(et => et.TestId == (long)TestType.Liver || et.TestId == (long)TestType.Lipid).Select(et => et.Id).ToArray(); var eventCustomerIdsFromTest = (from oet in orderIdEventTestIdPairs join oec in orderIdEventCustomerIdPairs on oet.FirstValue equals oec.FirstValue where eventTestIds.Contains(oet.SecondValue) select oec.SecondValue).ToArray(); var orderIdEventPackageIdPairs = _eventPackageRepository.GetEventPackageIdsForOrder(orderIdEventCustomerIdPairs.Select(pair => pair.FirstValue).ToArray()); var eventPackages = _eventPackageRepository.GetByIds(orderIdEventPackageIdPairs.Select(pair => pair.SecondValue).ToArray()).ToArray(); var eventPackageIds = eventPackages.Where(ep => ep.Tests.Where(t => t.TestId == (long)TestType.Liver || t.TestId == (long)TestType.Lipid || t.TestId == (long)TestType.Crp || t.TestId == (long)TestType.Thyroid || t.TestId == (long)TestType.Psa || t.TestId == (long)TestType.Testosterone).Count() > 0).Select(ep => ep.Id).ToArray(); var eventCustomerIdsFromPackage = (from oep in orderIdEventPackageIdPairs join oec in orderIdEventCustomerIdPairs on oep.FirstValue equals oec.FirstValue where eventPackageIds.Contains(oep.SecondValue) select oec.SecondValue).ToArray(); eventCustomers = eventCustomers.Where( ec => eventCustomerIdsFromTest.Contains(ec.Id) || eventCustomerIdsFromPackage.Contains(ec.Id)). Select(ec => ec).ToArray(); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray()); var eventData = _eventRepository.GetById(eventId); return(_bloodworksLabelViewModelFactory.Create(customers, eventData)); }
public EventScreeningAuthorizationEditModel GetCustomersForAuthorization(long physicianId) { var eventData = _eventRepository.GetEventForAuthorization(physicianId); if (eventData == null) { return(null); } var host = _hostRepository.GetHostForEvent(eventData.Id); var eventTests = _eventTestRepository.GetTestsForEvent(eventData.Id); var eventPackages = _eventPackageRepository.GetPackagesForEvent(eventData.Id); var eventCustomers = _eventCustomerRepository.GetEventCustomersForAuthorization(eventData.Id); if (eventCustomers == null || eventCustomers.Count() < 1) { return(null); } var eventCustomerIds = eventCustomers.Select(ec => ec.Id).ToArray(); var assignments = _physicianAssignmentService.GetPhysicianAssignmentsByEventcustomerIds(eventCustomerIds); if (!assignments.Any(a => a.Primary.PhysicianId == physicianId)) { return(null); } eventCustomerIds = assignments.Where(a => a.Primary.PhysicianId == physicianId).Select(a => a.EventCustomerId).ToArray(); eventCustomers = eventCustomers.Where(ec => eventCustomerIds.Contains(ec.Id)).ToArray(); var orderIdEventCustomerIdPairs = _orderRepository.GetOrderEventCustomerIdPairforEventCustomerIds(eventCustomerIds); var orderIds = orderIdEventCustomerIdPairs.Select(p => p.FirstValue).ToArray(); var orderIdTestIdPairs = _eventTestRepository.GetEventTestIdForOrders(orderIds); var orderIdpackageIdPairs = _eventPackageRepository.GetEventPackageIdsForOrder(orderIds); var ecIdTestIdPairs = (from ec in orderIdEventCustomerIdPairs join ot in orderIdTestIdPairs on ec.FirstValue equals ot.FirstValue select new OrderedPair <long, long>(ec.SecondValue, ot.SecondValue)).ToArray(); var ecIdpackageIdPairs = (from ec in orderIdEventCustomerIdPairs join op in orderIdpackageIdPairs on ec.FirstValue equals op.FirstValue select new OrderedPair <long, long>(ec.SecondValue, op.SecondValue)).ToArray(); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray()); return(_eventScreeningAuthorizationEditModelFactory.Create(eventData, eventTests, eventCustomers, customers, eventPackages, ecIdpackageIdPairs, ecIdTestIdPairs, host)); }
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); }