public void TestCcgValue()
        {
            var areasReader = ReaderFactory.GetAreasReader();
            var groupDataReader = ReaderFactory.GetGroupDataReader();

            var size = new QofListSizeProvider(groupDataReader,
                areasReader.GetAreaFromCode(AreaCodes.Ccg_Barnet), GroupId, 0, calendarYearType).Value;
            Assert.IsTrue(size > 5000 && size < 10000);
        }
        public void TestPracticeValues()
        {
            var areasReader = ReaderFactory.GetAreasReader();
            var groupDataReader = ReaderFactory.GetGroupDataReader();

            // Practice
            var size = new QofListSizeProvider(groupDataReader,
                areasReader.GetAreaFromCode(AreaCodes.Gp_MonkfieldCambourne), GroupId, 0, calendarYearType).Value;
            Assert.IsTrue(size > 5000 && size < 10000);
        }
        public void TestDataPointOffset()
        {
            var areasReader = ReaderFactory.GetAreasReader();
            var groupDataReader = ReaderFactory.GetGroupDataReader();

            // Country
            double lastYearSize = -123456;
            for (int dataPointOffset = 0; dataPointOffset < 100; dataPointOffset++)
            {
                var size = new QofListSizeProvider(groupDataReader,
                    areasReader.GetAreaFromCode(AreaCodes.England), GroupId, dataPointOffset, calendarYearType).Value;
                if (size.HasValue == false)
                {
                    if (dataPointOffset == 0)
                    {
                        Assert.Fail("No QOF data found");
                    }
                    break;
                }
                Assert.AreNotEqual(size, lastYearSize);
                lastYearSize = size.Value;
            }
        }
        public void Build()
        {
            var metadataRepo = IndicatorMetadataRepository.Instance;

            const int indicatorId = IndicatorIds.QuinaryPopulations;

            Grouping grouping = groupDataReader.GetGroupingsByGroupIdAndIndicatorId(GroupId, indicatorId);

            area = areasReader.GetAreaFromCode(AreaCode);

            var metadata = metadataRepo.GetIndicatorMetadata(indicatorId);
            period = new DataPointOffsetCalculator(grouping, DataPointOffset, metadata.YearType).TimePeriod;

            // Get data for each sex
            int overallTotal = 0;
            foreach (var sexId in sexIds)
            {
                IEnumerable<double> vals;

                if (area.IsCcg)
                {
                    QuinaryPopulation population = practiceReader.GetCcgQuinaryPopulation(indicatorId, period, AreaCode, sexId);
                    vals = new QuinaryPopulationSorter(population.Values).SortedValues;
                }
                else
                {
                    IList<CoreDataSet> data = groupDataReader.GetCoreDataForAllAges(indicatorId, period, AreaCode, sexId);
                    vals = new QuinaryPopulationSorter(data).SortedValues;
                }

                // Add total
                int total = Convert.ToInt32(Math.Round(vals.Sum(), MidpointRounding.AwayFromZero));
                overallTotal += total;

                Values.Add(sexId, vals);
            }

            // Convert to %
            foreach (var sexId in sexIds)
            {
                Values[sexId] = Values[sexId].Select(x => Math.Round((x / overallTotal) * 100, 2, MidpointRounding.AwayFromZero));
            }

            // List size
            var val = new QofListSizeProvider(groupDataReader, area, GroupId, DataPointOffset, metadata.YearType).Value;
            if (val.HasValue)
            {
                metadata = metadataRepo.GetIndicatorMetadata(QofListSizeProvider.IndicatorId);
                ListSize = new ValueData { Value = val.Value };

                var formatter = NumericFormatterFactory.New(metadata, groupDataReader);
                formatter.Format(ListSize);
            }

            if (area.IsGpPractice && AreOnlyPopulationsRequired == false)
            {
                SetEthnicityText();

                SetDeprivationDecile();

                Shape = practiceReader.GetShape(AreaCode);

                AdHocValues = new PracticePerformanceIndicatorValues(groupDataReader, AreaCode, DataPointOffset).IndicatorToValue;
            }
        }