Exemplo n.º 1
0
        public object GetExamples()
        {
            ProviderResultSummary providerResultSummary = JsonConvert.DeserializeObject <ProviderResultSummary>(Properties.Resources.V1_Sample_Provider_Results);

            providerResultSummary.Provider.ProviderVariation = ProviderVariationExample.GetProviderVariationExample();

            return(providerResultSummary);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetProviderResultsForFundingStreams(string providerId, int startYear, int endYear, string fundingStreamIds, HttpRequest request)
        {
            if (string.IsNullOrEmpty(providerId))
            {
                return(new BadRequestObjectResult("Missing providerId"));
            }

            if (startYear == 0)
            {
                return(new BadRequestObjectResult("Missing start year"));
            }

            if (endYear == 0)
            {
                return(new BadRequestObjectResult("Missing end year"));
            }

            if (string.IsNullOrEmpty(fundingStreamIds))
            {
                return(new BadRequestObjectResult("Missing funding stream ids"));
            }

            string[] fundingStreamIdsArray = new string[0];

            if (!string.IsNullOrWhiteSpace(fundingStreamIds))
            {
                fundingStreamIdsArray = fundingStreamIds.Split(",");
            }

            IList <string> fundingStreamFilters = new List <string>();

            foreach (string fundingStreamId in fundingStreamIdsArray)
            {
                fundingStreamFilters.Add($"fundingStreamId eq '{fundingStreamId}'");
            }

            SearchFeed <AllocationNotificationFeedIndex> searchFeed = await _feedsService.GetFeeds(providerId, startYear, endYear, fundingStreamFilters);

            if (searchFeed == null || searchFeed.Entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            IEnumerable <AllocationNotificationFeedIndex> entries = ValidateFeeds(searchFeed.Entries, checkProfiling: false);

            if (entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            ProviderResultSummary providerResultSummary = CreateProviderResultSummary(entries, request);

            return(Formatter.ActionResult(request, providerResultSummary));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetProviderResultsForAllocations(string providerId, int startYear, int endYear, string allocationLineIds, HttpRequest request)
        {
            if (string.IsNullOrEmpty(providerId))
            {
                return(new BadRequestObjectResult("Missing providerId"));
            }

            if (startYear == 0)
            {
                return(new BadRequestObjectResult("Missing start year"));
            }

            if (endYear == 0)
            {
                return(new BadRequestObjectResult("Missing end year"));
            }

            if (string.IsNullOrEmpty(allocationLineIds))
            {
                return(new BadRequestObjectResult("Missing allocation line ids"));
            }

            string[] allocationLineIdsArray = new string[0];

            if (!string.IsNullOrWhiteSpace(allocationLineIds))
            {
                allocationLineIdsArray = allocationLineIds.Split(",");
            }

            IList <string> allocationLineFilters = new List <string>();

            foreach (string allocationLineId in allocationLineIdsArray)
            {
                allocationLineFilters.Add($"allocationLineId eq '{allocationLineId}'");
            }

            SearchFeed <AllocationNotificationFeedIndex> searchFeed = await _feedsService.GetFeeds(providerId, startYear, endYear, allocationLineFilters);

            if (searchFeed == null || searchFeed.Entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            IEnumerable <AllocationNotificationFeedIndex> entries = ValidateFeeds(searchFeed.Entries, checkProfiling: false);

            if (entries.IsNullOrEmpty())
            {
                return(new NotFoundResult());
            }

            ProviderResultSummary providerResultSummary = CreateProviderResultSummary(entries.OrderByDescending(o => o.AllocationVersionNumber).DistinctBy(m => m.AllocationLineId), request);

            return(Formatter.ActionResult(request, providerResultSummary));
        }
Exemplo n.º 4
0
        private ProviderResultSummary CreateProviderResultSummary(IEnumerable <AllocationNotificationFeedIndex> entries, HttpRequest request)
        {
            ///TODO: Require permanent fix

            if (entries.First().ProviderUkPrn == "10080459")
            {
                entries = entries.Where(m => m.ProviderStatus == "Closed");
            }

            IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > fundingPeriodResultSummaryGroups = entries.GroupBy(m => m.FundingPeriodId);

            AllocationNotificationFeedIndex firstEntry = entries.First();

            ProviderResultSummary providerResutSummary = new ProviderResultSummary
            {
                Provider = new AllocationProviderModel
                {
                    Name      = firstEntry.ProviderName,
                    LegalName = firstEntry.ProviderLegalName,
                    UkPrn     = firstEntry.ProviderUkPrn,
                    Upin      = firstEntry.ProviderUpin,
                    Urn       = firstEntry.ProviderUrn,
                    DfeEstablishmentNumber = firstEntry.DfeEstablishmentNumber,
                    EstablishmentNumber    = firstEntry.EstablishmentNumber,
                    LaCode         = firstEntry.LaCode,
                    LocalAuthority = firstEntry.Authority,
                    Type           = firstEntry.ProviderType,
                    SubType        = firstEntry.SubProviderType,
                    OpenDate       = firstEntry.ProviderOpenDate,
                    CloseDate      = firstEntry.ProviderClosedDate,
                    CrmAccountId   = firstEntry.CrmAccountId,
                    NavVendorNo    = firstEntry.NavVendorNo,
                    Status         = firstEntry.ProviderStatus
                }
            };

            foreach (IGrouping <string, AllocationNotificationFeedIndex> fundingPeriodResultSummaryGroup in fundingPeriodResultSummaryGroups)
            {
                AllocationNotificationFeedIndex firstPeriodEntry = fundingPeriodResultSummaryGroup.First();

                ProviderPeriodResultSummary providerPeriodResultSummary = new ProviderPeriodResultSummary
                {
                    Period = new Period
                    {
                        Id        = firstPeriodEntry.FundingPeriodId,
                        Name      = firstPeriodEntry.FundingStreamPeriodName,
                        StartYear = firstPeriodEntry.FundingPeriodStartYear,
                        EndYear   = firstPeriodEntry.FundingPeriodEndYear
                    }
                };

                IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > fundingStreamResultSummaryGroups = fundingPeriodResultSummaryGroup.GroupBy(m => m.FundingStreamId);

                foreach (IGrouping <string, AllocationNotificationFeedIndex> fundingStreamResultSummaryGroup in fundingStreamResultSummaryGroups)
                {
                    AllocationNotificationFeedIndex feedIndex = fundingStreamResultSummaryGroup.First();

                    FundingStreamResultSummary fundingStreamResultSummary = new FundingStreamResultSummary
                    {
                        FundingStream = new AllocationFundingStreamModel
                        {
                            Id         = feedIndex.FundingStreamId,
                            Name       = feedIndex.FundingStreamName,
                            ShortName  = feedIndex.FundingStreamShortName,
                            PeriodType = new AllocationFundingStreamPeriodTypeModel
                            {
                                Id         = feedIndex.FundingStreamPeriodId,
                                Name       = feedIndex.FundingStreamPeriodName,
                                StartDay   = feedIndex.FundingStreamStartDay,
                                StartMonth = feedIndex.FundingStreamStartMonth,
                                EndDay     = feedIndex.FundingStreamEndDay,
                                EndMonth   = feedIndex.FundingStreamEndMonth
                            }
                        }
                    };

                    foreach (AllocationNotificationFeedIndex allocationFeedIndex in fundingStreamResultSummaryGroup)
                    {
                        fundingStreamResultSummary.Allocations.Add(new AllocationResult
                        {
                            AllocationLine = new AllocationLine
                            {
                                Id               = allocationFeedIndex.AllocationLineId,
                                Name             = allocationFeedIndex.AllocationLineName,
                                ShortName        = allocationFeedIndex.AllocationLineShortName,
                                FundingRoute     = allocationFeedIndex.AllocationLineFundingRoute,
                                ContractRequired = allocationFeedIndex.AllocationLineContractRequired ? "Y" : "N"
                            },
                            AllocationVersionNumber = (ushort)allocationFeedIndex.AllocationVersionNumber,
                            AllocationStatus        = allocationFeedIndex.AllocationStatus,
                            AllocationAmount        = Convert.ToDecimal(allocationFeedIndex.AllocationAmount),
                            ProfilePeriods          = JsonConvert.DeserializeObject <IEnumerable <ProfilingPeriod> >(allocationFeedIndex.ProviderProfiling).Select(
                                m => new ProfilePeriod(m.Period, m.Occurrence, m.Year.ToString(), m.Type, m.Value, m.DistributionPeriod)).ToArraySafe()
                        });
                    }

                    fundingStreamResultSummary.TotalAmount = fundingStreamResultSummary.Allocations.Sum(m => m.AllocationAmount);

                    if (!string.IsNullOrWhiteSpace(feedIndex.PolicySummaries))
                    {
                        IEnumerable <PublishedProviderResultsPolicySummary> policySummaries = JsonConvert.DeserializeObject <IEnumerable <PublishedProviderResultsPolicySummary> >(feedIndex.PolicySummaries);

                        foreach (PublishedProviderResultsPolicySummary publishedPolicySummaryResult in policySummaries)
                        {
                            PolicyResult policyResult = new PolicyResult
                            {
                                Policy = new Policy
                                {
                                    PolicyId          = publishedPolicySummaryResult.Policy.Id,
                                    PolicyName        = publishedPolicySummaryResult.Policy.Name,
                                    PolicyDescription = publishedPolicySummaryResult.Policy.Description
                                }
                            };

                            foreach (PublishedProviderResultsCalculationSummary publishedCalculationSummary in publishedPolicySummaryResult.Calculations)
                            {
                                policyResult.Calculations.Add(new Models.CalculationResult
                                {
                                    CalculationName          = publishedCalculationSummary.Name,
                                    CalculationVersionNumber = (ushort)publishedCalculationSummary.Version,
                                    CalculationType          = publishedCalculationSummary.CalculationType.ToString(),
                                    CalculationAmount        = publishedCalculationSummary.Amount
                                });
                            }

                            if (!publishedPolicySummaryResult.Policies.IsNullOrEmpty())
                            {
                                foreach (PublishedProviderResultsPolicySummary subPolicy in publishedPolicySummaryResult.Policies)
                                {
                                    PolicyResult subPolicyResult = new PolicyResult
                                    {
                                        Policy = new Policy
                                        {
                                            PolicyId          = subPolicy.Policy.Id,
                                            PolicyName        = subPolicy.Policy.Name,
                                            PolicyDescription = subPolicy.Policy.Description
                                        }
                                    };

                                    foreach (PublishedProviderResultsCalculationSummary publishedCalculationSummary in subPolicy.Calculations)
                                    {
                                        subPolicyResult.Calculations.Add(new Models.CalculationResult
                                        {
                                            CalculationName          = publishedCalculationSummary.Name,
                                            CalculationVersionNumber = (ushort)publishedCalculationSummary.Version,
                                            CalculationType          = publishedCalculationSummary.CalculationType.ToString(),
                                            CalculationAmount        = publishedCalculationSummary.Amount
                                        });
                                    }

                                    subPolicyResult.TotalAmount = subPolicyResult.Calculations.Where(m => m.CalculationType == "Funding").Sum(m => m.CalculationAmount);
                                    policyResult.SubPolicyResults.Add(subPolicyResult);
                                }
                            }

                            policyResult.TotalAmount = policyResult.Calculations.Where(m => m.CalculationType == "Funding").Sum(m => m.CalculationAmount);

                            foreach (PolicyResult subPolicyResult in policyResult.SubPolicyResults)
                            {
                                policyResult.TotalAmount = policyResult.TotalAmount + subPolicyResult.Calculations.Where(m => m.CalculationType == "Funding").Sum(m => m.CalculationAmount);
                            }

                            fundingStreamResultSummary.Policies.Add(policyResult);
                        }
                    }

                    providerResutSummary.TotalAmount += fundingStreamResultSummary.TotalAmount;

                    providerPeriodResultSummary.FundingStreamResults.Add(fundingStreamResultSummary);
                }

                providerResutSummary.FundingPeriodResults = providerResutSummary.FundingPeriodResults.Concat(new[] { providerPeriodResultSummary }).ToArraySafe();
            }

            return(providerResutSummary);
        }
Exemplo n.º 5
0
        private ProviderResultSummary CreateProviderResultSummary(IEnumerable <AllocationNotificationFeedIndex> entries, HttpRequest request)
        {
            IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > fundingPeriodResultSummaryGroups = entries.GroupBy(m => m.FundingPeriodId);

            AllocationNotificationFeedIndex firstEntry = entries.First();

            ProviderVariation providerVariation = CreateProviderVariationFromAllocationNotificationFeedIndexItem(firstEntry);

            ProviderResultSummary providerResutSummary = new ProviderResultSummary
            {
                Provider = new AllocationProviderModel
                {
                    Name      = firstEntry.ProviderName,
                    LegalName = firstEntry.ProviderLegalName,
                    UkPrn     = firstEntry.ProviderUkPrn,
                    Upin      = firstEntry.ProviderUpin,
                    Urn       = firstEntry.ProviderUrn,
                    DfeEstablishmentNumber = firstEntry.DfeEstablishmentNumber,
                    EstablishmentNumber    = firstEntry.EstablishmentNumber,
                    LaCode            = firstEntry.LaCode,
                    LocalAuthority    = firstEntry.Authority,
                    Type              = firstEntry.ProviderType,
                    SubType           = firstEntry.SubProviderType,
                    OpenDate          = firstEntry.ProviderOpenDate,
                    CloseDate         = firstEntry.ProviderClosedDate,
                    CrmAccountId      = firstEntry.CrmAccountId,
                    NavVendorNo       = firstEntry.NavVendorNo,
                    Status            = firstEntry.ProviderStatus,
                    ProviderVariation = providerVariation
                }
            };

            foreach (IGrouping <string, AllocationNotificationFeedIndex> fundingPeriodResultSummaryGroup in fundingPeriodResultSummaryGroups)
            {
                AllocationNotificationFeedIndex firstPeriodEntry = fundingPeriodResultSummaryGroup.First();

                ProviderPeriodResultSummary providerPeriodResultSummary = new ProviderPeriodResultSummary
                {
                    Period = new Period
                    {
                        Id        = firstPeriodEntry.FundingPeriodId,
                        Name      = firstPeriodEntry.FundingStreamPeriodName,
                        StartYear = firstPeriodEntry.FundingPeriodStartYear,
                        EndYear   = firstPeriodEntry.FundingPeriodEndYear
                    }
                };

                IEnumerable <IGrouping <string, AllocationNotificationFeedIndex> > fundingStreamResultSummaryGroups = fundingPeriodResultSummaryGroup.GroupBy(m => m.FundingStreamId);

                foreach (IGrouping <string, AllocationNotificationFeedIndex> fundingStreamResultSummaryGroup in fundingStreamResultSummaryGroups)
                {
                    AllocationNotificationFeedIndex feedIndex = fundingStreamResultSummaryGroup.First();

                    FundingStreamResultSummary fundingStreamResultSummary = new FundingStreamResultSummary
                    {
                        FundingStream = new AllocationFundingStreamModel
                        {
                            Id         = feedIndex.FundingStreamId,
                            Name       = feedIndex.FundingStreamName,
                            ShortName  = feedIndex.FundingStreamShortName,
                            PeriodType = new AllocationFundingStreamPeriodTypeModel
                            {
                                Id         = feedIndex.FundingStreamPeriodId,
                                Name       = feedIndex.FundingStreamPeriodName,
                                StartDay   = feedIndex.FundingStreamStartDay,
                                StartMonth = feedIndex.FundingStreamStartMonth,
                                EndDay     = feedIndex.FundingStreamEndDay,
                                EndMonth   = feedIndex.FundingStreamEndMonth
                            },
                            //todo Version = feedIndex.FundingStreamVersionNumber
                            //todo Version = feedIndex.FundingStreamVersion
                        }
                    };

                    foreach (AllocationNotificationFeedIndex allocationFeedIndex in fundingStreamResultSummaryGroup)
                    {
                        IEnumerable <PublishedProviderResultsPolicySummary> policySummaries = JsonConvert.DeserializeObject <IEnumerable <PublishedProviderResultsPolicySummary> >(feedIndex.PolicySummaries);
                        IList <CalculationResult> calculations = new List <CalculationResult>();

                        if (!string.IsNullOrWhiteSpace(feedIndex.PolicySummaries))
                        {
                            foreach (PublishedProviderResultsPolicySummary publishedPolicySummaryResult in policySummaries)
                            {
                                foreach (PublishedProviderResultsCalculationSummary publishedCalculationSummary in publishedPolicySummaryResult.Calculations)
                                {
                                    calculations.Add(new Models.CalculationResult
                                    {
                                        CalculationName          = publishedCalculationSummary.Name,
                                        CalculationVersionNumber = (ushort)publishedCalculationSummary.Version,
                                        CalculationType          = publishedCalculationSummary.CalculationType.ToString(),
                                        CalculationValue         = publishedCalculationSummary.Amount,
                                        PolicyId = publishedPolicySummaryResult.Policy.Id,

                                        //todo CalculationDisplayName = publishedCalculationSummary.DisplayName,
                                        //todo AssociatedWithAllocation = publishedCalculationSummary.AssociatedWithAllocation ? true
                                    });
                                }
                            }
                        }

                        fundingStreamResultSummary.Allocations.Add(new AllocationResult
                        {
                            AllocationLine = new AllocationLine
                            {
                                Id               = allocationFeedIndex.AllocationLineId,
                                Name             = allocationFeedIndex.AllocationLineName,
                                ShortName        = allocationFeedIndex.AllocationLineShortName,
                                FundingRoute     = allocationFeedIndex.AllocationLineFundingRoute,
                                ContractRequired = allocationFeedIndex.AllocationLineContractRequired ? "Y" : "N"
                            },
                            AllocationMajorVersion = feedIndex.MajorVersion ?? 0,
                            AllocationMinorVersion = feedIndex.MinorVersion ?? 0,
                            AllocationStatus       = allocationFeedIndex.AllocationStatus,
                            AllocationAmount       = Convert.ToDecimal(allocationFeedIndex.AllocationAmount),
                            ProfilePeriods         = new Collection <ProfilePeriod>(JsonConvert.DeserializeObject <IEnumerable <ProfilingPeriod> >(allocationFeedIndex.ProviderProfiling)
                                                                                    .Select(m => new ProfilePeriod(m.Period, m.Occurrence, m.Year.ToString(), m.Type, m.Value, m.DistributionPeriod))
                                                                                    .ToArraySafe()),
                            Calculations = new Collection <CalculationResult>(calculations)
                        });
                    }

                    fundingStreamResultSummary.FundingStreamTotalAmount = fundingStreamResultSummary.Allocations.Sum(m => m.AllocationAmount);

                    providerResutSummary.FundingStreamTotalAmount += fundingStreamResultSummary.FundingStreamTotalAmount;

                    providerPeriodResultSummary.FundingStreamResults.Add(fundingStreamResultSummary);
                }

                providerResutSummary.FundingPeriodResults = new Collection <ProviderPeriodResultSummary>(
                    providerResutSummary.FundingPeriodResults.Concat(new[] { providerPeriodResultSummary }).ToArraySafe());
            }

            return(providerResutSummary);
        }