public void TestBuild()
        {
            var areaTypeId = AreaTypeIds.CountyAndUnitaryAuthority;
            var profileId = ProfileIds.Phof;
            var profile = ReaderFactory.GetProfileReader().GetProfile(profileId);

            var parentArea = new ParentArea(AreaCodes.Gor_NorthEast, areaTypeId);
            ComparatorMap comparatorMap = new ComparatorMapBuilder(parentArea).ComparatorMap;

            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = profile.GroupIds[0],
                ChildAreaTypeId = areaTypeId,
                ProfileId = profile.Id,
                ComparatorMap = comparatorMap,
                AssignData = true
            }.Build();

            IList<TrendRoot> trendRoots = new TrendRootBuilder().Build(data.GroupRoots, comparatorMap, areaTypeId, profileId,
                data.IndicatorMetadata, false);
            Assert.IsTrue(trendRoots.Count > 0);
            Assert.IsTrue(trendRoots[0].Periods.Count > 0);
            Assert.IsNotNull(trendRoots[0].Limits);
            Assert.IsTrue(trendRoots[0].ComparatorValueFs.Count > 0);

            string s = trendRoots[0].ComparatorValueFs[0][ComparatorIds.Subnational];
            Assert.AreNotEqual("-", s);
        }
        public void Build_Returns_Results_With_Trends()
        {
            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.Phof_WiderDeterminantsOfHealth,
                ProfileId = ProfileIds.Phof,
                ComparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102()),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority
            }.Build();

            Assert.IsTrue(data.GroupRoots.Count > 0
                && data.GroupRoots.FirstOrDefault().RecentTrends.Count > 0
                );
        }
        public void TestPhofWiderDeterminantsOfHealth()
        {
            var data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.Phof_WiderDeterminantsOfHealth,
                ProfileId = ProfileIds.Phof,
                ComparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102()),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority
            }.Build();

            Assert.IsTrue(data.GroupRoots.Count > 15);
            Assert.IsTrue(data.Areas.Count > 10);
            Assert.AreEqual(AreaCodes.Gor_EastOfEngland,
                data.GroupRoots.First().Grouping.First().ComparatorData.AreaCode);
        }
        public void TestPhofHealthProtection()
        {
            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.Phof_HealthProtection,
                ProfileId = ProfileIds.Phof,
                ComparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102()),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority
            }.Build();

            Assert.IsTrue(data.GroupRoots.Count > 10);
            Assert.IsTrue(data.Areas.Count > 10);
            var comparatorData = data
                .GroupRoots.First()
                .Grouping.First(x => x.ComparatorId == ComparatorIds.Subnational)
                .ComparatorData;
            Assert.AreEqual(AreaCodes.Gor_EastOfEngland, comparatorData.AreaCode);
        }
        public void TestDataIsAssigned()
        {
            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.SubstanceMisuse_Over18Misuse,
                ProfileId = ProfileIds.SubstanceMisuse,
                ComparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102()),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority,
                AssignData = false
            }.Build();

            Assert.IsTrue(data.IsDataOk);
            foreach (GroupRoot groupRoot in data.GroupRoots)
            {
                Assert.AreEqual(0, groupRoot.Data.Count);
                foreach (Grouping grouping in groupRoot.Grouping)
                {
                    Assert.IsNull(grouping.ComparatorData);
                }
            }
        }
        public void Build_Returns_Results_With_Trends()
        {
            var comparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102());

            var data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.Phof_WiderDeterminantsOfHealth,
                ProfileId = ProfileIds.Phof,
                ComparatorMap = comparatorMap,
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority
            }.Build();

            var trendRoots = new TrendRootBuilder().Build(data.GroupRoots, comparatorMap,
                AreaTypeIds.CountyAndUnitaryAuthority, ProfileIds.Phof,
               data.IndicatorMetadata, false);

            var trendRoot = trendRoots.FirstOrDefault();
            Assert.IsTrue(trendRoots.Any()
                && trendRoot != null
                && trendRoot.RecentTrends != null
                && trendRoot.RecentTrends.Count > 0
                );
        }
        public void TestSubstanceMisuseOver18Misuse()
        {
            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.SubstanceMisuse_Over18Misuse,
                ProfileId = ProfileIds.SubstanceMisuse,
                ComparatorMap = GetComparatorMap(ComparatorMapBuilderTest.GetRegion102()),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority
            }.Build();

            Assert.IsTrue(data.GroupRoots.Count > 20);
            Assert.AreEqual(9, data.Areas.Count);
            Assert.AreEqual(AreaCodes.Gor_EastOfEngland,
                data.GroupRoots.First().Grouping.First().ComparatorData.AreaCode);
        }
        private void CreateFileByProfile()
        {
            foreach (ParentArea parentArea in _parentAreas)
            {
                InitParentArea(parentArea);

                //Get deciles for all relevant areas
                var categoryAreaType = _subnationalAreaType as CategoryAreaType;
                if (categoryAreaType != null)
                {
                    BuildCategoryAreaMap(categoryAreaType, parentArea);
                }

                foreach (int groupId in _profile.GroupIds)
                {
                    GroupData data = new GroupDataBuilderByGroupings
                    {
                        ProfileId = _profile.Id,
                        GroupId = groupId,
                        ChildAreaTypeId = parentArea.ChildAreaTypeId,
                        ComparatorMap = _comparatorMap,
                        AssignData = false
                    }.Build();
                    WriteCoreData(data, parentArea);
                }
            }

            WriteIndicatorMetadata();
        }
        public void TestDiabetesPrevAndRiskHighestQuintileExists()
        {
            var areaTypeId = AreaTypeIds.Ccg;
            var profileId = ProfileIds.Diabetes;

            var parentArea = new ParentArea(AreaCodes.CommissioningRegionLondon, areaTypeId);
            ComparatorMap comparatorMap = new ComparatorMapBuilder(parentArea).ComparatorMap;

            GroupData data = new GroupDataBuilderByGroupings
            {
                GroupId = GroupIds.Diabetes_PrevalenceAndRisk,
                ChildAreaTypeId = areaTypeId,
                ProfileId = ProfileIds.Diabetes,
                ComparatorMap = comparatorMap,
                AssignData = true
            }.Build();

            IList<TrendRoot> trendRoots = new TrendRootBuilder().Build(data.GroupRoots, comparatorMap, areaTypeId, profileId,
                data.IndicatorMetadata, false);

            var highestQuintileCount = trendRoots.Select(x => x.DataPoints.Values.FirstOrDefault()[0].Significance).Count(significances => significances.ContainsValue((Significance)5));

            Assert.AreNotEqual(highestQuintileCount, 0);
        }