public Dictionary<string, IArea> GetAreaMapping(string parentAreaCode, int childAreaTypeId,
            int parentAreaTypeId)
        {
            var areasReader = ReaderFactory.GetAreasReader();
            var childAreas = new ChildAreaListBuilder(areasReader, parentAreaCode, childAreaTypeId).ChildAreas;

            Dictionary<string, IArea> map = new Dictionary<string, IArea>();

            IArea parentArea = AreaFactory.NewArea(areasReader, parentAreaCode);
            if (parentArea is Area)
            {
                foreach (var childArea in childAreas)
                {
                    var parentAreaOfSpecificType = areasReader.GetParentAreas(childArea.Code)
                        .FirstOrDefault(x => x.AreaTypeId == parentAreaTypeId);
                    map.Add(childArea.Code, parentAreaOfSpecificType);
                }
            }
            else
            {
                throw new FingertipsException("CategoryAreas not supported");
            }

            return map;
        }
        public void TestChildAreas_WhenParentIsCcgAndChildAreaTypeIsGpPractice()
        {
            var areas = new ChildAreaListBuilder(ReaderFactory.GetAreasReader(),
                AreaCodes.Ccg_Barnet, AreaTypeIds.GpPractice).ChildAreas;

            var count = areas.Count;
            Assert.IsTrue(count > 20 && count < 100);
        }
        public void TestChildAreas_WhenParentIsArea()
        {
            var areas = new ChildAreaListBuilder(ReaderFactory.GetAreasReader(),
                AreaCodes.Gor_EastMidlands, AreaTypeIds.CountyAndUnitaryAuthority).ChildAreas;

            var count = areas.Count;
            Assert.IsTrue(count > 5 && count < 10);
        }
        public void TestChildAreas_WhenParentIsCategoryArea()
        {
            var areaCode = CategoryArea.CreateAreaCode(CategoryTypeIds.DeprivationDecileCountyAndUA2010,
                1);

            var areas = new ChildAreaListBuilder(ReaderFactory.GetAreasReader(),
                areaCode, AreaTypeIds.CountyAndUnitaryAuthority).ChildAreas;

            var count = areas.Count;
            Assert.IsTrue(count > 10 && count < 20);
        }
        public IList<IArea> ReadChildAreas(string parentAreaCode, int profileId, int childAreaTypeId)
        {
            IList<IArea> childAreas;
            if (NearestNeighbourArea.IsNearestNeighbourAreaCode(parentAreaCode))
            {
                var nearestNeighbourArea = (NearestNeighbourArea)AreaFactory.NewArea(_areasReader, parentAreaCode);
                childAreas = new NearestNeighbourAreaListBuilder(_areasReader, nearestNeighbourArea).Areas;
            }
            else
            {
                childAreas = new ChildAreaListBuilder(_areasReader, parentAreaCode, childAreaTypeId)
                    .ChildAreas;
            }

            IgnoredAreasFilter filter = IgnoredAreasFilterFactory.New(profileId);
            return filter.RemoveAreasIgnoredEverywhere(childAreas).ToList();
        }
        private IList<string> GetChildAreaCodes(ComparatorMap comparatorMap, int childAreaTypeId, int profileId)
        {
            var parentAreaCode = comparatorMap.GetSubnationalComparator().Area.Code;
            IList<string> childAreaCodes = new ChildAreaListBuilder(areasReader, parentAreaCode,childAreaTypeId)
                .ChildAreas
                .Select(x => x.Code)
                .ToList();

            var filter = IgnoredAreasFilterFactory.New(profileId);
            childAreaCodes = filter.RemoveAreaCodesIgnoredEverywhere(childAreaCodes).ToList();

            // Add parent areacode to child areas for nearest neighbours only
            if (_isParentAreaNearestNeighbour)
            {
                childAreaCodes.Insert(0, parentAreaCode.Substring(5));
            }
            return childAreaCodes;
        }
        public IList<IArea> GetChildAreas(int area_type_id, string parent_area_code,
            int profile_id = ProfileIds.Undefined)
        {
            IAreasReader reader = ReaderFactory.GetAreasReader();

            // Get child areas
            IList<IArea> areas = new ChildAreaListBuilder(reader, parent_area_code, area_type_id)
                .ChildAreas;

            // Remove areas that should be ignored for the profile
            areas = IgnoredAreasFilterFactory.New(profile_id)
                .RemoveAreasIgnoredEverywhere(areas)
                .ToList();

            return areas;
        }