Exemplo n.º 1
0
        public ActionResult Select(long eventId, int screeningTime, IEnumerable <long> selectedSlotIds, long packageId, IEnumerable <long> testIds, IEnumerable <long> bookedSlotIds = null)
        {
            if (testIds != null && testIds.Any() && screeningTime > 0)
            {
                var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, testIds);
                //testIds = eventTests.Where(et => et.Test.ScreeningTime > 0).Select(et => et.TestId).ToArray();
                testIds = eventTests.Select(et => et.TestId).ToArray();
            }

            screeningTime = _eventSchedulingSlotService.GetScreeningTime(testIds, eventId, packageId);

            var model = _eventSchedulingSlotService.GetAppointmentSelectionModel(eventId, screeningTime, selectedSlotIds, packageId, testIds, bookedSlotIds);

            return(PartialView(model));
        }
Exemplo n.º 2
0
        public SourceCodeApplyEditModel ApplySourceCode(long packageId, IEnumerable <long> addOnTestIds, decimal orderTotal, string sourceCode, long eventId, long customerId, SignUpMode signUpMode, decimal shippingAmount = 0, decimal productAmount = 0)
        {
            var model = new SourceCodeApplyEditModel
            {
                OrderTotal = orderTotal,
                SourceCode = sourceCode,
                SignUpMode = (int)signUpMode,
                CustomerId = customerId,
                EventId    = eventId
            };

            if (packageId > 0)
            {
                var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId);
                if (eventPackage != null)
                {
                    model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price);
                }
            }
            if (addOnTestIds != null && addOnTestIds.Count() > 0)
            {
                var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, addOnTestIds);
                if (eventTests != null && eventTests.Count > 0)
                {
                    model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, packageId > 0 ? et.WithPackagePrice : et.Price));
                }
            }

            model = ApplySourceCode(model);
            return(model);
        }
Exemplo n.º 3
0
        private decimal GetAmountCoveredByInsurance(long eventId, long packageId, IEnumerable <long> testIds)
        {
            decimal amount = 0;

            var billingAccountTests = _billingAccountRepository.GetAllBillingAccountTests();

            if (billingAccountTests == null || !billingAccountTests.Any())
            {
                return(amount);
            }

            var insuredTestIds = billingAccountTests.Select(bat => bat.TestId).ToList();

            var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId);

            if (eventPackage != null)
            {
                amount = eventPackage.Package.Tests.Where(t => insuredTestIds.Contains(t.Id)).Sum(t => t.PackagePrice);
            }

            if (!testIds.IsNullOrEmpty())
            {
                var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, testIds);
                amount += eventTests.Where(t => insuredTestIds.Contains(t.TestId)).Sum(t => t.Price);
            }

            return(decimal.Round(amount, 2));
        }
        public int GetScreeningTime(long eventId, long packageId, IEnumerable <long> testIds)
        {
            var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId);
            var eventTests   = !testIds.IsNullOrEmpty() ? _eventTestRepository.GetByEventAndTestIds(eventId, testIds) : null;

            return(GetScreeningTime(eventPackage, eventTests));
        }
        public void SavePreQualifiedTestAnswers(string questionAnsTestId, string disqualified, long?eventCustomerId, long customerId, long eventId, long orgUserId)
        {
            if (!string.IsNullOrEmpty(questionAnsTestId))
            {
                long version             = _eventCustomerQuestionAnswerRepository.GetLatestVersion(customerId, eventId);
                long disqualifiedVersion = _disqualifiedTestRepository.GetLatestVersion(customerId, eventId);
                using (var scope = new TransactionScope())
                {
                    var model = _eventCustomerQuestionAnswerFactory.GetEventCustomerQuestionAnswerListModel(questionAnsTestId, customerId, eventId, version, orgUserId);
                    _eventCustomerQuestionAnswerRepository.DeleteEventCustomerQuestionAnswers(customerId, eventId, orgUserId);
                    _eventCustomerQuestionAnswerRepository.SaveAnswer(model);

                    _disqualifiedTestRepository.DeleteDisqualifiedTests(customerId, eventId, orgUserId);
                    _dependentDisqualifiedTestRepository.DeleteDependentDisqualifiedTests(customerId, eventId, orgUserId);

                    if (!string.IsNullOrEmpty(disqualified))
                    {
                        var disqualifiedTests = disqualified.Split('|');

                        var disqualifiedTestIds = new List <long>();
                        foreach (var disqualifiedTest in disqualifiedTests)
                        {
                            var dtArray            = disqualifiedTest.Split(',');
                            var disqualifiedTestId = Convert.ToInt64(dtArray[0]);
                            disqualifiedTestIds.Add(disqualifiedTestId);
                        }

                        var disqualifiedEventTests       = _eventTestRepository.GetByEventAndTestIds(eventId, disqualifiedTestIds);
                        var disqualifiedTestTemplateIds  = disqualifiedEventTests.Where(x => x.PreQualificationQuestionTemplateId.HasValue).Select(x => x.PreQualificationQuestionTemplateId.Value);
                        var dependentDisqualifiedTestIds = _preQualificationTemplateDependentTestRepository.GetByTemplateIds(disqualifiedTestTemplateIds.ToArray())
                                                           .Where(x => disqualifiedTestTemplateIds.Contains(x.TemplateId)).Select(x => x.TestId);

                        var disqualifiedModel = _eventCustomerQuestionAnswerFactory.GetDisqualifiedTestListModel(disqualified, customerId, eventId, disqualifiedVersion, orgUserId);
                        _disqualifiedTestRepository.SaveAnswer(disqualifiedModel);

                        if (!dependentDisqualifiedTestIds.IsNullOrEmpty())
                        {
                            var dependentDisqualifiedVersion = _dependentDisqualifiedTestRepository.GetLatestVersion(customerId, eventId);
                            var dependentDisqualifiedTests   = _eventCustomerQuestionAnswerFactory.GetDependentDisqualifiedTestDomains(customerId, eventId, dependentDisqualifiedTestIds, dependentDisqualifiedVersion, orgUserId, eventCustomerId);
                            _dependentDisqualifiedTestRepository.Save(dependentDisqualifiedTests);
                        }
                    }
                    scope.Complete();
                }
            }
        }
Exemplo n.º 6
0
        public void GetByEventidAndTestIds_ValidId_Tester()
        {
            var eventTests = _eventTestRepository.GetByEventAndTestIds(24762, (new long[] { 1, 3 }).ToList());

            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));
        }
Exemplo n.º 7
0
        private bool AdjustCustomerOrder(EventCustomer eventCustomer, Order currentOrder, long newPackageId, long oldPackageId, long createdByOrgRoleUserId,
                                         long customerId, IEnumerable <long> orderedTestIds, IEnumerable <long> preApprovedTestIds, IEnumerable <long> packageTestIds, long corporateUploadId)
        {
            if (corporateUploadId == 0)
            {
                return(false);
            }

            if (currentOrder != null && !currentOrder.OrderDetails.IsEmpty())
            {
                if (eventCustomer == null)
                {
                    return(false);
                }

                var OrderId = currentOrder.Id;

                var forOrganizationRoleUser = GetForOrganizationRoleUser(customerId);

                IOrderController orderController = new Falcon.App.Infrastructure.Finance.Impl.OrderController();
                var currentPreApprovedTest       = _preApprovedTestRepository.GetByCustomerId(customerId);

                if (IsOldPreApprovedTestSame(currentPreApprovedTest.Select(x => x.TestId), preApprovedTestIds))
                {
                    return(false);
                }

                // var selectedTestIds = orderedTestIds.ToList();
                var selectedTestIds = new List <long>();

                //if (!currentPreApprovedTest.IsNullOrEmpty())
                //{
                //    var testIdToRemove = currentPreApprovedTest.Select(x => x.TestId);
                //    selectedTestIds = selectedTestIds.Where(x => !testIdToRemove.Contains(x)).ToList();
                //}

                //if (newPackageId != oldPackageId && oldPackageId != 0)
                //{
                //    selectedTestIds = selectedTestIds.Where(x => !packageTestIds.Contains(x)).ToList();
                //}

                selectedTestIds.AddRange(preApprovedTestIds);

                var          orderables        = new List <IOrderable>();
                long         oldEventPackageId = 0;
                long         newEventPackageId = 0;
                var          oldEventTestIds   = new List <long>();
                var          newEventTestIds   = new List <long>();
                EventPackage eventPackage      = null;
                EventPackage oldEventPackage   = null;

                if (newPackageId > 0)
                {
                    eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventCustomer.EventId, newPackageId);
                }

                if (oldPackageId > 0)
                {
                    oldEventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventCustomer.EventId, oldPackageId);
                }

                var testIdsInPackage = new List <long>();

                if (eventPackage != null)
                {
                    orderables.Add(eventPackage);
                    newEventPackageId = eventPackage.Id;
                    RemoveTestsAlreadyInPackage(selectedTestIds.ToList(), eventCustomer.EventId, eventPackage);
                    testIdsInPackage = eventPackage.Package.Tests.Select(x => x.Id).ToList();
                }

                if (oldEventPackage != null)
                {
                    oldEventPackageId = oldEventPackage.Id;
                    if (eventPackage == null)
                    {
                        orderables.Add(oldEventPackage);
                        RemoveTestsAlreadyInPackage(selectedTestIds.ToList(), eventCustomer.EventId, oldEventPackage);
                        testIdsInPackage = oldEventPackage.Package.Tests.Select(x => x.Id).ToList();
                    }
                }

                var oldEventTests = _eventTestRepository.GetByEventAndTestIds(eventCustomer.EventId, orderedTestIds);
                if (oldEventTests != null)
                {
                    oldEventTestIds = oldEventTests.Select(x => x.Id).ToList();
                }

                var disqualifiedTestIds          = _disqualifiedTestRepository.GetLatestVersionTestId(eventCustomer.CustomerId, eventCustomer.EventId);
                var dependentDisqualifiedTestIds = _dependentDisqualifiedTestRepository.GetLatestVersionTestId(eventCustomer.CustomerId, eventCustomer.EventId);
                disqualifiedTestIds = (disqualifiedTestIds.Concat(dependentDisqualifiedTestIds)).Distinct();

                //removing disqualified test from new order
                selectedTestIds = selectedTestIds.Where(x => !disqualifiedTestIds.Contains(x)).ToList();

                //remove test which are already present in package test
                selectedTestIds = selectedTestIds.Where(x => !testIdsInPackage.Intersect(selectedTestIds).Contains(x)).ToList();

                if (!selectedTestIds.IsNullOrEmpty())
                {
                    var eventTests = _eventTestRepository.GetByEventAndTestIds(eventCustomer.EventId, selectedTestIds);
                    if (newPackageId > 0 || oldPackageId > 0)
                    {
                        foreach (var eventTest in eventTests)
                        {
                            eventTest.Price = eventTest.WithPackagePrice;
                        }
                    }

                    orderables.AddRange(eventTests);
                    newEventTestIds = eventTests.Select(x => x.Id).ToList();
                }

                if (((oldEventPackageId > 0 && newEventPackageId == 0) || (newEventPackageId == oldEventPackageId)) && (newEventTestIds.All(oldEventTestIds.Contains) && newEventTestIds.Count == oldEventTestIds.Count))
                {
                    return(false);
                }

                if (orderables.IsNullOrEmpty())
                {
                    return(false);
                }

                var insurancePayment = currentOrder.PaymentsApplied.Where(pi => pi.PaymentType == Falcon.App.Core.Finance.Enum.PaymentType.Insurance).Select(pi => pi).SingleOrDefault();
                if (insurancePayment != null)
                {
                    _insurancePaymentRepository.Delete(insurancePayment.Id);
                }

                bool indentedLineItemsAdded = false;

                foreach (var orderable in orderables)
                {
                    if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem))
                    {
                        orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, createdByOrgRoleUserId,
                                                null,
                                                null, null, OrderStatusState.FinalSuccess);
                        indentedLineItemsAdded = true;
                    }
                    else
                    {
                        orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, createdByOrgRoleUserId,
                                                OrderStatusState.FinalSuccess);
                    }
                }

                Order newOrder = orderController.PlaceOrder(currentOrder);

                _customerOrderHistoryService.SaveCustomerOrderHistory(eventCustomer, corporateUploadId, oldEventPackageId, newEventPackageId, oldEventTestIds, newEventTestIds);
                return(true);
            }
            return(false);
        }
        public void ChangePackage(CustomerOrderDetail customerOrderDetail)
        {
            using (var scope = new TransactionScope())
            {
                try
                {
                    var eventid    = customerOrderDetail.EventId;
                    var customerid = customerOrderDetail.CustomerId;

                    var order = GetOrder(customerid, eventid);


                    IOrderController orderController = new OrderController();
                    var orderDetail = orderController.GetActiveOrderDetail(order);

                    if (order == null || order.OrderDetails.IsEmpty())
                    {
                        return;
                    }

                    var orderables      = new List <IOrderable>();
                    var selectedTestIds = new List <long>();

                    if (customerOrderDetail.PreApprovedTestIds != null && customerOrderDetail.PreApprovedTestIds.Any())
                    {
                        selectedTestIds = customerOrderDetail.PreApprovedTestIds.ToList();
                    }

                    long packageId = 0;

                    if (customerOrderDetail.PrePackageId > 0)
                    {
                        var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventid, customerOrderDetail.PrePackageId);
                        if (eventPackage != null)
                        {
                            packageId = eventPackage.PackageId;
                        }
                    }

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

                    if (packageId > 0)
                    {
                        orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventid, packageId));
                        selectedTestIds = RemoveTestsAlreadyInPackage(selectedTestIds, eventid, packageId);
                    }

                    if (!selectedTestIds.IsNullOrEmpty())
                    {
                        var eventTests = _eventTestRepository.GetByEventAndTestIds(eventid, selectedTestIds);
                        if (packageId > 0)
                        {
                            foreach (var eventTest in eventTests)
                            {
                                eventTest.Price = eventTest.WithPackagePrice;
                            }
                        }

                        orderables.AddRange(eventTests);
                    }

                    var indentedLineItemsAdded = false;

                    // TODO: applying hook to the system all the indented line items will be attached to the first order item.
                    foreach (var orderable in orderables)
                    {
                        if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem))
                        {
                            _orderController.AddItem(orderable, 1, customerid, 1, null, null, null, OrderStatusState.FinalSuccess);
                            indentedLineItemsAdded = true;
                        }
                        else
                        {
                            _orderController.AddItem(orderable, 1, customerid, 1, OrderStatusState.FinalSuccess);
                        }
                    }

                    _orderController.PlaceOrder(order);


                    scope.Complete();
                }
                catch (Exception exception)
                {
                    _logger.Error("Some Error occured" + exception.Message);
                }
            }
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
        private void SaveTestResults(KynHealthAssessmentEditModel model, long uploadedby)
        {
            TestResultRepository testResultRepository;
            var customerId = model.CustomerId;
            var eventId    = model.EventId;

            var isNewResultFlow = _eventRepository.IsEventHasNewResultFlow(eventId);

            var service = new Service.TestResultService();

            var eventCustomerResultId = SaveEventCustomerResult(eventId, customerId, uploadedby);

            //basic biometric
            var eventCustomer  = _eventCustomerRepository.Get(eventId, customerId);
            var basicBiometric = _basicBiometricRepository.Get(eventId, customerId);

            basicBiometric = _kynHealthAssessmentFactory.GetBasicTestResultBiometricDomain(model, basicBiometric, uploadedby);

            if (basicBiometric != null)
            {
                basicBiometric.Id = eventCustomer.Id;
                ((IRepository <BasicBiometric>)_basicBiometricRepository).Save(basicBiometric);
            }
            long[] kynTestIds = { (long)TestType.Kyn, (long)TestType.HKYN, (long)TestType.MyBioCheckAssessment };
            var    eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, kynTestIds);
            //Kyn Test Result
            var isPurchased           = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Kyn);
            var isKynPurchased        = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.HKYN);
            var isMyBioCheckPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment);

            if (isPurchased)
            {
                var kynTest = eventTests.First(x => x.TestId == (int)TestType.Kyn).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.Kyn, kynTest.IsRecordable, isNewResultFlow);
            }
            else if (isKynPurchased)
            {
                var hKynTest = eventTests.First(x => x.TestId == (int)TestType.HKYN).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.HKYN, hKynTest.IsRecordable, isNewResultFlow);
            }
            else if (isMyBioCheckPurchased)
            {
                var mybioCheckAssessment = eventTests.First(x => x.TestId == (int)TestType.MyBioCheckAssessment).Test;
                SaveKynLabResult(model, uploadedby, customerId, eventId, eventCustomerResultId, (int)TestType.MyBioCheckAssessment, mybioCheckAssessment.IsRecordable, isNewResultFlow);
            }

            //lipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Lipid);

            if (isPurchased)
            {
                testResultRepository = new LipidTestRepository(ReadingSource.Manual);
                var lipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                lipidTestresult = _kynHealthAssessmentFactory.GetLipidTestResultDomain(model, lipidTestresult as LipidTestResult, uploadedby, isNewResultFlow);
                if (lipidTestresult != null)
                {
                    testResultRepository.SaveTestResults(lipidTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvLipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvLipid);

            if (isPurchased)
            {
                testResultRepository = new AwvLipidTestRepository(ReadingSource.Manual);
                var awvLipidTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvLipidTestresult = _kynHealthAssessmentFactory.GetAwvLipidTestResultDomain(model, awvLipidTestresult as AwvLipidTestResult, uploadedby, isNewResultFlow);
                if (awvLipidTestresult != null)
                {
                    testResultRepository.SaveTestResults(awvLipidTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvGlucoseTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvGlucose);

            if (isPurchased)
            {
                testResultRepository = new AwvGlucoseTestRepository(ReadingSource.Manual);
                var awvGlucoseTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvGlucoseTestresult = _kynHealthAssessmentFactory.GetAwvGlucoseTestResultDomain(model, awvGlucoseTestresult as AwvGlucoseTestResult, uploadedby, isNewResultFlow);
                if (awvGlucoseTestresult != null)
                {
                    testResultRepository.SaveTestResults(awvGlucoseTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvLipidTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Cholesterol);

            if (isPurchased)
            {
                testResultRepository = new CholesterolTestRepository(ReadingSource.Manual);
                var cholesterolTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                cholesterolTestresult = _kynHealthAssessmentFactory.GetCholesterolTestResultDomain(model, cholesterolTestresult as CholesterolTestResult, uploadedby, isNewResultFlow);
                if (cholesterolTestresult != null)
                {
                    testResultRepository.SaveTestResults(cholesterolTestresult, customerId, eventId, uploadedby);
                }
            }

            //AwvGlucoseTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Diabetes);

            if (isPurchased)
            {
                testResultRepository = new DiabetesTestRepository(ReadingSource.Manual);
                var diabetesTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                diabetesTestresult = _kynHealthAssessmentFactory.GetDiabetesTestResultDomain(model, diabetesTestresult as DiabetesTestResult, uploadedby, isNewResultFlow);
                if (diabetesTestresult != null)
                {
                    testResultRepository.SaveTestResults(diabetesTestresult, customerId, eventId, uploadedby);
                }
            }

            //Hypertension Test Result
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.Hypertension);
            if (isPurchased)
            {
                testResultRepository = new HypertensionTestRepository(ReadingSource.Manual);
                var hypertensionTestresult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                hypertensionTestresult = _kynHealthAssessmentFactory.GetHypertensionTestResultDomain(model, hypertensionTestresult as HypertensionTestResult, uploadedby, isNewResultFlow);
                if (hypertensionTestresult != null)
                {
                    testResultRepository.SaveTestResults(hypertensionTestresult, customerId, eventId, uploadedby);
                }
            }

            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.A1C);
            if (isPurchased)
            {
                testResultRepository = new HemaglobinTestRepository(ReadingSource.Manual);
                var hemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                hemaglobinTestResult = _kynHealthAssessmentFactory.GetHemaglobinA1CTestResultDomain(model, hemaglobinTestResult as HemaglobinA1CTestResult, uploadedby, isNewResultFlow);
                if (hemaglobinTestResult != null)
                {
                    testResultRepository.SaveTestResults(hemaglobinTestResult, customerId, eventId, uploadedby);
                }
            }

            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.AwvHBA1C);
            if (isPurchased)
            {
                testResultRepository = new AwvHemaglobinTestRepository(ReadingSource.Manual);
                var awvHemaglobinTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                awvHemaglobinTestResult = _kynHealthAssessmentFactory.GetAwvHemaglobinTestResultDomain(model, awvHemaglobinTestResult as AwvHemaglobinTestResult, uploadedby, isNewResultFlow);

                if (awvHemaglobinTestResult != null)
                {
                    testResultRepository.SaveTestResults(awvHemaglobinTestResult, customerId, eventId, uploadedby);
                }
            }

            //MyBioCheckTestresult
            isPurchased = service.IsTestPurchasedByCustomer(eventId, customerId, (long)TestType.MyBioCheckAssessment);

            if (isPurchased)
            {
                testResultRepository = new MyBioAssessmentTestRepository(ReadingSource.Manual);
                var myBioAssessmentTestResult = testResultRepository.GetTestResults(customerId, eventId, isNewResultFlow);
                myBioAssessmentTestResult = _kynHealthAssessmentFactory.GetMyBioCheckAssessmentTestResultDomain(model, myBioAssessmentTestResult as MyBioAssessmentTestResult, uploadedby, isNewResultFlow);
                if (myBioAssessmentTestResult != null)
                {
                    testResultRepository.SaveTestResults(myBioAssessmentTestResult, customerId, eventId, uploadedby);
                }
            }
        }
Exemplo n.º 11
0
        public IEnumerable <OnlineEventViewModel> GetEvents(OnlineSchedulingEventListModelFilter filter, int maxNumberofRecordstoFetch, int pageSize, out int totalRecords)
        {
            var events = _eventRepository.GetEventsbyFilters(filter, out totalRecords);

            if (events == null || !events.Any())
            {
                return(null);
            }

            var todayEventIds = events.Where(e => e.EventDate < DateTime.Now.Date.AddDays(1)).Select(e => e.Id);
            var todaySlots    = _eventSchedulingSlotRepository.GetbyEventIds(todayEventIds);

            var eventIds = events.Select(e => e.Id).Distinct().ToArray();
            var hosts    = _hostRepository.GetEventHosts(eventIds);

            var eventAppointmentStatsModels = _eventAppointmentStatsService.Get(eventIds);

            ZipCode zipCode = null;

            try
            {
                if (!string.IsNullOrEmpty(filter.ZipCode))
                {
                    zipCode = _zipCodeRepository.GetZipCode(filter.ZipCode).FirstOrDefault();
                }
            }
            catch (ObjectNotFoundInPersistenceException <ZipCode> )
            {
                zipCode = null;
            }

            var eventCollection = _onlineEventListModelFactory.Create(events, hosts, eventAppointmentStatsModels, zipCode, todaySlots, filter.EventId, filter.CutOffHourstoMarkEventforOnlineSelection,
                                                                      filter.OrderBy, filter.OrderType, maxNumberofRecordstoFetch, filter.PageNumber, pageSize, out totalRecords);

            eventIds = eventCollection.Select(e => e.EventId).Distinct().ToArray();

            foreach (var theEvent in eventCollection)
            {
                var eventTest = _eventTestRepository.GetByEventAndTestIds(theEvent.EventId, TestGroup.BreastCancer);
                theEvent.HasBreastCancer = eventTest != null && eventTest.Any();
            }


            var eventHpPairs = _hospitalPartnerRepository.GetEventAndHospitalPartnerOrderedPair(eventIds);
            var eventCorporateAccountPairs = _corporateAccountRepository.GetEventIdCorporateAccountPairForSponsoredBy(eventIds);


            var organizations = eventCorporateAccountPairs == null || eventCorporateAccountPairs.Count() < 1 ? null : _organizationRepository.GetOrganizations(eventCorporateAccountPairs.Select(m => m.SecondValue).Distinct().ToArray());
            var fileIds       = organizations != null?organizations.Where(o => o.LogoImageId > 0).Select(o => o.LogoImageId).ToArray() : null;

            var files = fileIds == null ? null : _fileRepository.GetByIds(fileIds);

            if (files != null)
            {
                var location = _mediaRepository.GetOrganizationLogoImageFolderLocation();
                files = files.Select(f =>
                {
                    f.Path = location.Url + f.Path;
                    return(f);
                }).ToArray();

                eventCollection = _onlineEventListModelFactory.ManageSponsoredByLogo(eventCollection, eventCorporateAccountPairs, organizations, files);
            }

            organizations = eventHpPairs == null || eventHpPairs.Count() < 1 ? null : _organizationRepository.GetOrganizations(eventHpPairs.Select(m => m.SecondValue).Distinct().ToArray());
            fileIds       = organizations != null?organizations.Where(o => o.LogoImageId > 0).Select(o => o.LogoImageId).ToArray() : null;

            files = fileIds == null ? null : _fileRepository.GetByIds(fileIds);
            if (files != null)
            {
                var location = _mediaRepository.GetOrganizationLogoImageFolderLocation();
                files = files.Select(f =>
                {
                    f.Path = location.Url + f.Path;
                    return(f);
                }).ToArray();

                eventCollection = _onlineEventListModelFactory.ManageSponsoredByLogo(eventCollection, eventHpPairs, organizations, files);
            }

            return(eventCollection);
        }
        public void ChangePackage(CustomerOrderDetail customerOrderDetail)
        {
            using (var scope = new TransactionScope())
            {
                if (customerOrderDetail.PaymentModel != null)
                {
                    try
                    {
                        _customerPaymentService.ProcessPayment(customerOrderDetail.PaymentModel);
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(exception.Message, exception);
                    }
                }

                try
                {
                    var eventid    = customerOrderDetail.EventId;
                    var customerid = customerOrderDetail.CustomerId;
                    //var eventCustomer = _eventCustomerRepository.Get(eventid, customerid);
                    var order = GetOrder(customerid, eventid);

                    SourceCode sourceCode = null;

                    if (customerOrderDetail.SourceCode != null)
                    {
                        sourceCode = new SourceCode
                        {
                            Id          = customerOrderDetail.SourceCode.SourceCodeId,
                            CouponCode  = customerOrderDetail.SourceCode.SourceCode,
                            CouponValue = customerOrderDetail.SourceCode.DiscountApplied
                        }
                    }
                    ;

                    IOrderController orderController = new OrderController();
                    var orderDetail = orderController.GetActiveOrderDetail(order);

                    if (order == null || order.OrderDetails.IsEmpty())
                    {
                        return;
                    }

                    ShippingDetail shippingDetails = null;

                    if (customerOrderDetail.IsShippingPurchased && customerOrderDetail.ShippingOptions != null && customerOrderDetail.ShippingOptions.Any())
                    {
                        shippingDetails = _patientShippingDetailFactory.GetShippingDetailData(customerOrderDetail);
                    }

                    var orderables      = new List <IOrderable>();
                    var selectedTestIds = new List <long>();

                    if (customerOrderDetail.AlaCarteTests != null && customerOrderDetail.AlaCarteTests.Any())
                    {
                        selectedTestIds = customerOrderDetail.AlaCarteTests.Select(x => x.TestId).ToList();
                    }

                    long packageId = 0;

                    if (customerOrderDetail.PackageModel != null && customerOrderDetail.PackageModel.PackageId > 0)
                    {
                        packageId = customerOrderDetail.PackageModel.PackageId;

                        orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventid, packageId));
                        selectedTestIds = RemoveTestsAlreadyInPackage(selectedTestIds, eventid, packageId);
                    }

                    if (!selectedTestIds.IsNullOrEmpty())
                    {
                        var eventTests = _eventTestRepository.GetByEventAndTestIds(eventid, selectedTestIds);
                        if (packageId > 0)
                        {
                            foreach (var eventTest in eventTests)
                            {
                                eventTest.Price = eventTest.WithPackagePrice;
                            }
                        }

                        orderables.AddRange(eventTests);
                    }

                    ElectronicProduct product = null;
                    if (customerOrderDetail.ProductId.HasValue && customerOrderDetail.ProductId.Value > 0)
                    {
                        var productIsAlreadyPurchased =
                            order.OrderDetails.Any(
                                x =>
                                x.DetailType == OrderItemType.ProductItem &&
                                x.OrderItem.ItemId == customerOrderDetail.ProductId.Value);

                        if (!productIsAlreadyPurchased)
                        {
                            product = _electronicProductRepository.GetById(customerOrderDetail.ProductId.Value);
                            orderables.Add(product);
                        }
                    }

                    if (customerOrderDetail.IsShippingPurchased && shippingDetails != null)
                    {
                        IShippingController shippingController = new ShippingController();
                        var shippingDetail = shippingController.OrderShipping(shippingDetails);

                        var shippingDetailOrderDetail = new ShippingDetailOrderDetail
                        {
                            Amount           = shippingDetail.ActualPrice,
                            IsActive         = true,
                            OrderDetailId    = orderDetail.Id,
                            ShippingDetailId = shippingDetail.Id
                        };

                        _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail);
                    }

                    var indentedLineItemsAdded = false;

                    // TODO: applying hook to the system all the indented line items will be attached to the first order item.
                    foreach (var orderable in orderables)
                    {
                        if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem))
                        {
                            _orderController.AddItem(orderable, 1, customerid, _creatorOrganizationRoleUser, sourceCode, null, null, OrderStatusState.FinalSuccess);
                            indentedLineItemsAdded = true;
                        }
                        else
                        {
                            _orderController.AddItem(orderable, 1, customerid, _creatorOrganizationRoleUser, OrderStatusState.FinalSuccess);
                        }
                    }

                    _orderController.PlaceOrder(order);

                    if (shippingDetails != null)
                    {
                        SaveProductShippingDetail(product, orderDetail, shippingDetails);
                    }
                    scope.Complete();
                }
                catch (Exception exception)
                {
                    if (customerOrderDetail.PaymentModel == null)
                    {
                        throw new Exception("An Exception caused while saving the Order.", exception);
                    }

                    var paymentInstruments = customerOrderDetail.PaymentModel.Payments;
                    var chargeCardPayment  = paymentInstruments.ChargeCard ?? null;

                    if (chargeCardPayment == null || paymentInstruments.Amount <= 0)
                    {
                        throw new Exception("An Exception caused while saving the Order.", exception);
                    }

                    var paymentGateway = IoC.Resolve <IPaymentProcessor>();

                    paymentGateway.VoidRequestforaPreviousResponse(chargeCardPayment.ChargeCardPayment.ProcessorResponse);
                    throw new Exception("An Exception caused while saving the Order.", exception);
                }
            }
        }