Esempio n. 1
0
        public IEnumerable <OrderedPair <long, decimal> > GetHealthplanRevenue(IEnumerable <HealthPlanRevenue> healthPlanRevenues)
        {
            if (healthPlanRevenues == null || !healthPlanRevenues.Any())
            {
                return(null);
            }

            var revenueItems = _healthPlanRevenueItemRepository.GetAllHealthPlanRevenueItemByIds(healthPlanRevenues.Select(x => x.Id));
            var list         = new List <OrderedPair <long, decimal> >();

            foreach (var revenue in healthPlanRevenues)
            {
                var accountRevenueItems = revenueItems.Where(x => x.HealthPlanRevenueId == revenue.Id);

                if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerCustomer)
                {
                    var revenueItem = revenueItems.Single(x => x.HealthPlanRevenueId == revenue.Id);
                    GetReveneuePairByCustomer(revenue, revenueItem, list);
                }
                else if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerPackage)
                {
                    GetRevenuePairByPacakge(accountRevenueItems, revenue, list);
                }
                else if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerTest)
                {
                    GetRevenuePairByTest(accountRevenueItems, revenue, list);
                }
            }

            return(list);
        }
        public HealthPlanRevenueDetailsListModel GetHealthPlanRevenueDetails(long healthPlanId)
        {
            var currentHealthPlanRevenue = _healthPlanRevenueRepository.GetHealthPlanRevenueId(healthPlanId);

            var healthPlanRevenueList = _healthPlanRevenueRepository.GetListByHealthPlanId(healthPlanId);

            if (healthPlanRevenueList == null && !healthPlanRevenueList.Any())
            {
                return(null);
            }

            if (currentHealthPlanRevenue == null)
            {
                currentHealthPlanRevenue = healthPlanRevenueList.OrderBy(x => x.DataRecorderMetaData.DateCreated).First();
            }

            var packages = GetHealthPlansPackages(healthPlanId);
            var tests    = GetHealthPlansTests(healthPlanId);
            var healthPlanRevenueItemList = _healthPlanRevenueItemRepository.GetAllHealthPlanRevenueItemByIds(healthPlanRevenueList.Select(x => x.Id));
            var maleCustomerCount         = 0;
            var femaleCustomerCount       = 0;
            //foreach (var revenue in healthPlanRevenueList)
            //{
            //    var accountRevenueItems = healthPlanRevenueItemList.Where(x => x.HealthPlanRevenueId == revenue.Id);

            //    if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerCustomer)
            //    {
            //        //var maleFemaleCountByCustomer = _eventCustomerRepository.GetCustomerMaleFemaleCountForHealthPlanRevenueByCustomer(healthPlanId, revenue.DateFrom, revenue.DateTo ?? DateTime.Today.AddDays(1));
            //        //if (maleFemaleCountByCustomer != null)
            //        //{
            //        //    maleCustomerCount = maleCustomerCount + maleFemaleCountByCustomer.FirstValue;
            //        //    femaleCustomerCount = femaleCustomerCount + maleFemaleCountByCustomer.SecondValue;
            //        //}
            //    }
            //    else if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerPackage)
            //    {
            //        var packageRevenueItems = accountRevenueItems.Where(x => x.PackageId.HasValue);
            //        var packageIds = packageRevenueItems.Select(x => x.PackageId.Value).Distinct();
            //        var maleFemaleCountByPackages = _eventCustomerRepository.GetMaleFemaleCountForHealthPlanRevenueByPackage(healthPlanId, revenue.DateFrom, revenue.DateTo ?? DateTime.Today.AddDays(1), packageIds);
            //        if (maleFemaleCountByPackages != null)
            //        {
            //            maleCustomerCount = maleCustomerCount + maleFemaleCountByPackages.FirstValue;
            //            femaleCustomerCount = femaleCustomerCount + maleFemaleCountByPackages.SecondValue;
            //        }
            //    }
            //    else if (revenue.RevenueItemTypeId == (long)HealthPlanRevenueType.PerTest)
            //    {
            //        var testIdRevenueItems = accountRevenueItems.Where(x => x.TestId.HasValue);
            //        var testIds = testIdRevenueItems.Select(x => x.TestId.Value).Distinct();
            //        var maleFemaleCountByPackageTest = _eventCustomerRepository.GetMaleFemaleCountForHealthPlanRevenueByPackageTest(healthPlanId, revenue.DateFrom, revenue.DateTo ?? DateTime.Today.AddDays(1), testIds);
            //        var maleFemaleCountByTest = _eventCustomerRepository.GetMaleFemaleCountForHealthPlanRevenueByTest(healthPlanId, revenue.DateFrom, revenue.DateTo ?? DateTime.Today.AddDays(1), testIds);

            //        if (maleFemaleCountByTest != null)
            //        {
            //            maleCustomerCount = maleCustomerCount + maleFemaleCountByTest.FirstValue;
            //            femaleCustomerCount = femaleCustomerCount + maleFemaleCountByTest.SecondValue;
            //        }
            //        if (maleFemaleCountByPackageTest != null)
            //        {
            //            maleCustomerCount = maleCustomerCount + maleFemaleCountByPackageTest.FirstValue;
            //            femaleCustomerCount = femaleCustomerCount + maleFemaleCountByPackageTest.SecondValue;
            //        }
            //    }
            //}
            var healthPlanCustomerAndRevenuePairs = _healthPlanRevenueHelper.GetHealthplanRevenue(healthPlanRevenueList);
            var corporateAccount = ((IUniqueItemRepository <CorporateAccount>)_corporateAccountRepository).GetById(healthPlanId);

            return(_healthplanRevenueListFactory.CreateHealthPlanDetails(currentHealthPlanRevenue, healthPlanCustomerAndRevenuePairs, corporateAccount, healthPlanRevenueList, healthPlanRevenueItemList, packages, tests, maleCustomerCount, femaleCustomerCount));
        }