Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public void GetbyIds_ValidId_Tester()
        {
            var eventPackages = _eventPackageRepository.GetByIds(new long[] { 73563, 73562 });

            Assert.IsNotNull(eventPackages);
            Assert.IsNotEmpty(eventPackages.ToArray());

            var eventPackageIds = eventPackages.Select(ep => ep.Id).ToArray();
            var packageIds      = eventPackages.Select(ep => ep.PackageId).ToArray();
            var eventIds        = eventPackages.Select(ep => ep.EventId).ToArray();

            Assert.IsTrue(eventPackageIds.Contains(73563));
            Assert.IsTrue(eventPackageIds.Contains(73562));

            Assert.IsTrue(packageIds.Contains(124));
            Assert.IsTrue(packageIds.Contains(107));

            Assert.IsTrue(eventIds.Contains(24759));

            Assert.IsNotNull(eventPackages.First().Tests);
            Assert.IsNotEmpty(eventPackages.First().Tests.ToArray());
        }
Exemplo n.º 3
0
        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);
        }