public int GetScreeningTime(Order order)
        {
            var          eventPackageOrderItem = order.OrderDetails.SingleOrDefault(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.DetailType == OrderItemType.EventPackageItem);
            EventPackage eventPackage          = null;

            if (eventPackageOrderItem != null)
            {
                var eventPackageId = eventPackageOrderItem.OrderItem.ItemId;
                eventPackage = _eventPackageRepository.GetById(eventPackageId);
            }

            var eventTestIds = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.DetailType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId).ToArray();
            var eventTests   = eventTestIds.Any() ? _eventTestRepository.GetbyIds(eventTestIds) : null;

            return(GetScreeningTime(eventPackage, eventTests));
        }
        public GoogleAnalyticsEnableReportingDataModel GetGoogleAnalyticsViewModel(TempCart tempCart)
        {
            if (tempCart == null || !tempCart.IsCompleted)
            {
                return(new GoogleAnalyticsEnableReportingDataModel());
            }

            var model = new GoogleAnalyticsEnableReportingDataModel();

            if (tempCart.EventPackageId.HasValue)
            {
                model.EventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);
            }

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                var testIdStrings = tempCart.TestId.Split(new[] { ',' });
                if (testIdStrings.Any())
                {
                    long id;
                    var  testIds = testIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray();
                    if (testIds.Count() > 0)
                    {
                        model.EventTests = _eventTestRepository.GetbyIds(testIds);
                    }
                }
            }

            if (!string.IsNullOrEmpty(tempCart.ProductId))
            {
                var productIdStrings = tempCart.ProductId.Split(new[] { ',' });
                if (productIdStrings.Any())
                {
                    long id;
                    var  productIds = productIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray();
                    if (productIds.Count() > 0)
                    {
                        model.Products = _productRepository.GetByIds(productIds);
                    }
                }
            }

            if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0)
            {
                model.Shipping = _shippingOptionRepository.GetById(tempCart.ShippingId.Value).Price;
            }

            Order order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value);

            model.TotalPrice = order.DiscountedTotal;

            model.CustomerId = tempCart.CustomerId.Value;

            var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value);

            model.Address = _addressService.GetAddress(customer.Address.Id);

            return(model);
        }
Example #3
0
        public void ReleaseSlotsOnScreeningtimeChanged(TempCart tempCart, long newEventPackageId, string newEventTestIds)
        {
            var newEvenTestIds = new List <long>();

            if (!string.IsNullOrEmpty(newEventTestIds))
            {
                newEventTestIds.Split(',').ToList().ForEach(t => newEvenTestIds.Add(Convert.ToInt64(t)));
                newEvenTestIds.RemoveAll(t => t == 0);
            }

            //var existingEventTestIds = new List<long>();
            //if (!string.IsNullOrEmpty(tempCart.TestId))
            //{
            //    tempCart.TestId.Split(',').ToList().ForEach(t => existingEventTestIds.Add(Convert.ToInt64(t)));
            //    existingEventTestIds.RemoveAll(t => t == 0);
            //}

            //var isOrderChanged = newEventPackageId != tempCart.EventPackageId || (!newEvenTestIds.All(existingEventTestIds.Contains) || !existingEventTestIds.All(newEvenTestIds.Contains));

            var screeningTime = _eventPackageSelectorService.GetScreeningTime(tempCart.EventPackageId.Value, newEvenTestIds);

            if (!tempCart.InChainAppointmentSlotIds.IsNullOrEmpty())//&& isOrderChanged
            {
                var testIds = new List <long>();
                if (newEvenTestIds != null && newEvenTestIds.Any())
                {
                    var eventTests = _eventTestRepository.GetbyIds(newEvenTestIds);
                    if (eventTests != null && !eventTests.IsNullOrEmpty())
                    {
                        eventTests.ForEach(et => testIds.Add(et.TestId));
                    }
                }

                var newPackageId = _eventPackageRepository.GetById(newEventPackageId).PackageId;

                var theEvent = _eventRepository.GetById(tempCart.EventId.Value);

                var slots = _eventSchedulingSlotService.AdjustAppointmentSlot(tempCart.EventId.Value, screeningTime, tempCart.InChainAppointmentSlotIds, newPackageId, testIds, theEvent.LunchStartTime, theEvent.LunchDuration);

                if (slots == null)
                {
                    _eventSchedulingSlotRepository.ReleaseSlots(tempCart.InChainAppointmentSlotIds);
                    tempCart.AppointmentId           = null;
                    tempCart.InChainAppointmentSlots = null;
                    tempCart.PreliminarySelectedTime = null;
                }
                else
                {
                    var eventSchedulingSlots = slots as EventSchedulingSlot[] ?? slots.ToArray();
                    tempCart.AppointmentId           = eventSchedulingSlots.OrderBy(s => s.StartTime).First().Id;
                    tempCart.PreliminarySelectedTime = eventSchedulingSlots.OrderBy(s => s.StartTime).First().StartTime;
                    tempCart.InChainAppointmentSlots = string.Join(",", eventSchedulingSlots.Select(s => s.Id.ToString()).ToArray());
                }

                _tempcartService.SaveTempCart(tempCart);
            }
        }
        public HafModel Get(HafFilter filter)
        {
            var theEvent = _eventRepository.GetById(filter.EventId);

            if (!theEvent.HealthAssessmentTemplateId.HasValue || theEvent.HealthAssessmentTemplateId.Value <= 0)
            {
                return(null);
            }

            var customer = _customerRepository.GetCustomer(filter.CustomerId);

            var template           = _healthAssessmentTemplateRepository.GetById(theEvent.HealthAssessmentTemplateId.Value);
            var genericQuestionIds = new List <long>();
            var list = new List <KeyValuePair <long, List <long> > >();

            IsFemale = customer.Gender == Gender.Female;

            //Get Generic Question from Event Templates
            genericQuestionIds.AddRange(template.QuestionIds);

            var order          = _orderRepository.GetOrder(filter.CustomerId, filter.EventId);
            var eventpackageId = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventPackageItem).Select(od => od.OrderItem.ItemId).FirstOrDefault();

            var isKynIntegrationEnabled = _eventPodRepository.IsKynIntegrationEnabled(filter.EventId);
            var eventTestIds            = new List <long>();

            if (eventpackageId > 0)
            {
                var eventPackage = _eventPackageRepository.GetById(eventpackageId);

                if (eventPackage.HealthAssessmentTemplateId.HasValue && eventPackage.HealthAssessmentTemplateId.Value > 0)
                {
                    var packageTemplate = _healthAssessmentTemplateRepository.GetById(eventPackage.HealthAssessmentTemplateId.Value);
                    genericQuestionIds.AddRange(packageTemplate.QuestionIds);
                }

                eventTestIds.AddRange(eventPackage.Tests.Select(t => t.Id));
            }
            list.Add(new KeyValuePair <long, List <long> >(0, genericQuestionIds));

            eventTestIds.AddRange(order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId));
            var eventTests = _eventTestRepository.GetbyIds(eventTestIds);

            var testWiseQuestion = GetTestQuestionKeyValuePairs(eventTestIds, isKynIntegrationEnabled, eventTests);

            if (testWiseQuestion != null)
            {
                list.AddRange(testWiseQuestion);
            }

            var hafModel = GetHafModel(list, eventTests, filter.EventId, filter.CustomerId, filter.SetChildQuestion, filter.VersionNumber) ?? new HafModel();

            hafModel.EventId    = filter.EventId;
            hafModel.CustomerId = filter.CustomerId;
            return(hafModel);
        }
Example #5
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));
        }
        public void GetByIds_ValidId_Tester()
        {
            var eventTests = _eventTestRepository.GetbyIds((new long[] { 196415, 196414 }));

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

            var eventIds     = eventTests.Select(et => et.EventId);
            var testIds      = eventTests.Select(et => et.TestId);
            var eventTestIds = eventTests.Select(et => et.Id);

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

            Assert.IsTrue(eventTestIds.Contains(196415));
            Assert.IsTrue(eventTestIds.Contains(196414));

            Assert.IsTrue(testIds.Contains(1));
            Assert.IsTrue(testIds.Contains(3));
        }
        public SourceCodeApplyEditModel GetSourceCodeApplied(TempCart tempCart, SourceCodeApplyEditModel sourceCodeModel = null)
        {
            var model = new SourceCodeApplyEditModel
            {
                SignUpMode = (int)SignUpMode.Online,
                SourceCodeHelpDescription = _toolTipRepository.GetToolTipContentByTag(ToolTipType.SourceCodeHelp)
            };

            if (tempCart == null)
            {
                return(model);
            }

            if (tempCart.EventId.HasValue)
            {
                model.EventId = tempCart.EventId.Value;
            }

            if (tempCart.CustomerId.HasValue)
            {
                model.CustomerId = tempCart.CustomerId.Value;
            }

            decimal orderTotal = 0;

            if (tempCart.EventPackageId.HasValue)
            {
                var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);
                model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price);
                orderTotal   += model.Package.SecondValue;
            }

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                var eventTestIds = tempCart.TestId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim()));
                var eventTests   = _eventTestRepository.GetbyIds(eventTestIds);
                model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, tempCart.EventPackageId.HasValue ? et.WithPackagePrice : et.Price)).ToArray();
                orderTotal         += model.SelectedTests.Sum(s => s.SecondValue);
            }

            if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0)
            {
                var shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value);
                model.ShippingAmount = shippingOption.Price;
                orderTotal          += model.ShippingAmount;
            }

            if (!string.IsNullOrEmpty(tempCart.ProductId))
            {
                var productids = tempCart.ProductId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim()));
                var products   = _productRepository.GetByIds(productids);
                model.ProductAmount = products.Sum(p => p.Price);
                orderTotal         += model.ProductAmount;
            }

            model.OrderTotal = orderTotal;

            if (sourceCodeModel != null && sourceCodeModel.SourceCodeId > 0)
            {
                var sourceCode = _sourceCodeRepository.GetSourceCodeById(sourceCodeModel.SourceCodeId);
                model.SourceCode = sourceCode.CouponCode;
                model            = ApplySourceCode(model);
            }
            else if (tempCart.SourceCodeId.HasValue && tempCart.SourceCodeId > 0)
            {
                var sourceCode = _sourceCodeRepository.GetSourceCodeById(tempCart.SourceCodeId.Value);
                model.SourceCode = sourceCode.CouponCode;
                model            = ApplySourceCode(model);
            }

            return(model);
        }
        private void UpdateCustomerOrder(long eventId, long customerId, IEnumerable <long> testIds, long orgUserId)
        {
            var order = _orderRepository.GetOrder(customerId, eventId);

            if (order != null && !order.OrderDetails.IsEmpty())
            {
                var orderDetail = _orderController.GetActiveOrderDetail(order);

                var eventTestOrderDetails = order.OrderDetails.Where(od => od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od).ToArray();

                var packageId = 0L;
                if (orderDetail.OrderItem.OrderItemType == OrderItemType.EventPackageItem)
                {
                    var eventPackage = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId);
                    packageId = eventPackage.PackageId;
                }

                var orderables      = new List <IOrderable>();
                var selectedTestIds = testIds.ToList();



                if (packageId > 0)
                {
                    IEventPackageRepository eventPackageRepository = new EventPackageRepository();
                    var eventPackage = eventPackageRepository.GetByEventAndPackageIds(eventId, packageId);
                    orderables.Add(eventPackage);

                    RemoveTestsAlreadyInPackage(eventId, packageId, selectedTestIds);
                }

                if (!eventTestOrderDetails.IsNullOrEmpty())
                {
                    var eventTestIds     = eventTestOrderDetails.Select(od => od.OrderItem.ItemId).ToArray();
                    var eventTestInOrder = _eventTestRepository.GetbyIds(eventTestIds);

                    var testAlreadyInOrders = eventTestInOrder.Select(et => et.TestId).ToArray();
                    selectedTestIds = selectedTestIds.Where(x => !testAlreadyInOrders.Contains(x)).ToList();

                    if (testAlreadyInOrders.Any(x => AbiGroup.Contains(x)))
                    {
                        selectedTestIds.RemoveAll(AbiGroup.Contains);
                    }

                    if (testAlreadyInOrders.Any(x => DpnMonofilamentGroup.Contains(x)))
                    {
                        selectedTestIds.RemoveAll(DpnMonofilamentGroup.Contains);
                    }

                    var activeEventTestOrderDetails = order.OrderDetails.Where(od => od.OrderItem.OrderItemType == OrderItemType.EventTestItem && od.IsCompleted).Select(od => od).ToArray();
                    if (!activeEventTestOrderDetails.IsNullOrEmpty())
                    {
                        var activEventTestIds         = activeEventTestOrderDetails.Select(od => od.OrderItem.ItemId).ToArray();
                        var activeTestAlreadyInOrders = eventTestInOrder.Where(x => activEventTestIds.Contains(x.Id)).Select(et => et.TestId).ToArray();

                        selectedTestIds.AddRange(activeTestAlreadyInOrders);
                    }
                }

                if (!selectedTestIds.IsNullOrEmpty())
                {
                    var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, selectedTestIds);
                    if (AddMissingTestToEvent(eventId, selectedTestIds, eventTests))
                    {
                        eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, selectedTestIds);
                    }

                    if (packageId > 0)
                    {
                        foreach (var eventTest in eventTests)
                        {
                            eventTest.Price = eventTest.WithPackagePrice;
                        }
                    }

                    orderables.AddRange(eventTests);

                    bool indentedLineItemsAdded = false;

                    foreach (var orderable in orderables)
                    {
                        if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem))
                        {
                            _orderController.AddItem(orderable, 1, customerId, orgUserId, null, null, null, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare);
                            indentedLineItemsAdded = true;
                        }
                        else
                        {
                            _orderController.AddItem(orderable, 1, customerId, orgUserId, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare);
                        }
                    }

                    _orderController.PlaceOrder(order);
                }
            }
        }
Example #9
0
        public EventAppointmentOnlineListModel SaveEventAppointmentSlotOnline(TempCart tempCart)
        {
            if (tempCart.EventPackageId == null || tempCart.AppointmentId == null)
            {
                return(GetEventAppointmentSlotOnline(tempCart));
            }


            var selectedAppointmentId = tempCart.AppointmentId.Value;

            if (tempCart.InChainAppointmentSlotIds != null && tempCart.InChainAppointmentSlotIds.Any())
            {
                _eventSchedulingSlotRepository.ReleaseSlots(tempCart.InChainAppointmentSlotIds);
                tempCart.AppointmentId           = null;
                tempCart.InChainAppointmentSlots = null;
                tempCart.PreliminarySelectedTime = null;
            }


            var eventTestIds = new List <long>();
            var testIds      = new List <long>();

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                tempCart.TestId.Split(',').ForEach(x => eventTestIds.Add(Convert.ToInt64(x)));
                var eventTests = _eventTestRepository.GetbyIds(eventTestIds).ToList();
                if (eventTests != null && !eventTests.IsNullOrEmpty())
                {
                    eventTests.ForEach(et => testIds.Add(et.TestId));
                }
            }

            var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);


            var screeningTime = _eventPackageSelectorService.GetScreeningTime(tempCart.EventPackageId.Value, eventTestIds);
            var result        = _eventSchedulingSlotService.BookSlotTemporarily(selectedAppointmentId, screeningTime, eventPackage.PackageId, testIds);

            if (result == null)
            {
                throw new Exception("The slot selected by you is no longer available as it is booked for another customer. Please Choose another slot or select any other preferable hour.");
            }

            var eventSchedulingSlots = result as EventSchedulingSlot[] ?? result.ToArray();
            var selectedSlotIds      = eventSchedulingSlots.Select(x => x.Id).ToList();

            if (!selectedSlotIds.Any())
            {
                tempCart.AppointmentId           = null;
                tempCart.InChainAppointmentSlots = string.Empty;
                tempCart.IsUsedAppointmentSlotExpiryExtension = null;
                return(GetEventAppointmentSlotOnline(tempCart));
            }


            var slotFirst = eventSchedulingSlots.OrderBy(s => s.StartTime).First();

            tempCart.AppointmentId           = slotFirst.Id;
            tempCart.PreliminarySelectedTime = slotFirst.StartTime;
            tempCart.InChainAppointmentSlots = string.Join(",", selectedSlotIds);
            tempCart.IsUsedAppointmentSlotExpiryExtension = null;
            _tempcartService.SaveTempCart(tempCart);

            return(GetEventAppointmentSlotOnline(tempCart));
        }
Example #10
0
        public Order RegisterOnsiteCustomer(OnSiteRegistrationEditModel model)
        {
            var createdByOrgRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole);
            var customer             = _massRegistrationEditModelFactory.CreateCustomer(model, createdByOrgRoleUser);

            _customerService.SaveCustomer(customer, createdByOrgRoleUser.Id);

            var forOrgRoleUser = _orgRoleUserRepository.GetOrganizationRoleUser(customer.CustomerId);

            var orderables = new List <IOrderable>();

            long packageId             = 0;
            IEnumerable <long> testIds = null;

            if (model.SelectedPackageId > 0)
            {
                var eventPackage = _eventPackageRepository.GetById(model.SelectedPackageId);
                packageId = eventPackage.PackageId;
                orderables.Add(eventPackage);
            }

            if (model.SelectedTestIds != null && model.SelectedTestIds.Count() > 0)
            {
                var eventTests = _eventTestRepository.GetbyIds(model.SelectedTestIds);
                testIds = eventTests.Select(et => et.TestId).ToArray();
                if (model.SelectedPackageId > 0)
                {
                    foreach (var eventTest in eventTests)
                    {
                        eventTest.Price = eventTest.WithPackagePrice;
                    }
                }
                orderables.AddRange(eventTests);
            }

            var screeningTime = _eventPackageSelectorService.GetScreeningTime(model.SelectedPackageId, model.SelectedTestIds);
            var slots         = _eventSchedulingSlotService.BookSlotTemporarily(model.SelectedAppointmentId, screeningTime, packageId, testIds);

            if (slots.IsNullOrEmpty())
            {
                throw new InvalidOperationException("Slot is booked by some other customer.");
            }

            var eventCustomer = SaveEventCustomer(createdByOrgRoleUser, model.SelectedAppointmentId, model.EventId, customer.CustomerId);

            //var shippingAddress = Mapper.Map<AddressEditModel, Address>(model.Address);

            //var shippingDetail = SaveShippingDetail(shippingAddress, createdByOrgRoleUser);

            var order = PlaceOrder(forOrgRoleUser, createdByOrgRoleUser, orderables, eventCustomer, null, null);

            var eventData = _eventRepository.GetById(model.EventId);

            SendNotification(customer, eventData, createdByOrgRoleUser, "/Scheduling/OnSiteRegistration/Create");
            order.CustomerId = customer.CustomerId;

            try
            {
                _eventSchedulingSlotService.SendEventFillingNotification(model.EventId, createdByOrgRoleUser.Id);
            }
            catch (Exception)
            {
            }
            return(order);
        }