public IList<TrendRoot> Build(IList<GroupRoot> groupRoots, ComparatorMap comparatorMap,
            int childAreaTypeId, int profileId, IList<IndicatorMetadata> indicatorMetadataList, bool isNearestNeighbour)
        {
            _isParentAreaNearestNeighbour = isNearestNeighbour;

            List<TrendRoot> trendRoots = new List<TrendRoot>();
            ITrendDataReader trendReader = ReaderFactory.GetTrendDataReader();

            var childAreaCodes = GetChildAreaCodes(comparatorMap, childAreaTypeId, profileId);

            if (groupRoots != null)
            {
                var metadataCollection = new IndicatorMetadataCollection(indicatorMetadataList);
                foreach (GroupRoot root in groupRoots)
                {
                    Grouping grouping = root.Grouping.FirstOrDefault();

                    if (grouping != null)
                    {
                        IndicatorMetadata indicatorMetadata = metadataCollection.GetIndicatorMetadataById(root.IndicatorId);
                        GroupRootTrendBuilderBase builder = GroupRootTrendBuilderBase.New(grouping, indicatorMetadata);
                        TrendRoot trendRoot = builder.BuildTrendRoot(comparatorMap, root, trendReader, childAreaCodes);
                        trendRoots.Add(trendRoot);
                    }
                }
            }

            return trendRoots;
        }
 public void TestDuplicateIndicatorIdsIgnored()
 {
     IndicatorMetadataCollection collection = new IndicatorMetadataCollection(new List<IndicatorMetadata>{
         new IndicatorMetadata { IndicatorId = 1 },
         new IndicatorMetadata{IndicatorId = 1}
     });
     Assert.AreEqual(1, collection.IndicatorMetadata.Count);
 }
        public void TestAddIndicatorMetadataList()
        {
            IndicatorMetadataCollection collection = new IndicatorMetadataCollection(new List<IndicatorMetadata>());
            Assert.AreEqual(0, collection.IndicatorMetadata.Count);

            // Add metadata
            collection.AddIndicatorMetadata(new List<IndicatorMetadata>{
                new IndicatorMetadata{IndicatorId = 1}
            });

            Assert.AreEqual(1, collection.IndicatorMetadata.Count);
        }
        public HealthProfilesKeyMessageDataBuilder(IArea area, CoreDataSetProvider coreDataSetProvider,
            CoreDataSetProvider benchmarkDataProvider, IndicatorMetadataCollection indicatorMetadataCollection,
            HealthProfilesGroupRootSelector groupRootSelector)
        {
            _area = area;
            keyMessageData.Area = area;
            this.coreDataSetProvider = coreDataSetProvider;
            this.benchmarkDataProvider = benchmarkDataProvider;
            this.groupRootSelector = groupRootSelector;
            this.indicatorMetadataCollection = indicatorMetadataCollection;

            _indicatorComparerFactory = new IndicatorComparerFactory {PholioReader = pholioReader};
        }
        private void AssignRecentTrends()
        {
            if (GroupData.Areas != null)
            {
                var trendCalculator = new TrendMarkerCalculator();
                var trendReader = ReaderFactory.GetTrendDataReader();
                var trendMarkersProvider = new TrendMarkersProvider(trendReader, trendCalculator);

                var areas = GroupData.Areas.ToList();
                AddParentAreas(areas);

                var metadataCollection = new IndicatorMetadataCollection(GroupData.IndicatorMetadata);
                foreach (var groupRoot in GroupData.GroupRoots)
                {
                    var grouping = groupRoot.Grouping.FirstOrDefault();

                    var indicatorMetaData = metadataCollection.GetIndicatorMetadataById(groupRoot.IndicatorId);

                    var recentTrends = indicatorMetaData == null
                        ? new Dictionary<string, TrendMarkerResult>()
                        : trendMarkersProvider.GetTrendResults(areas, indicatorMetaData, grouping);

                    groupRoot.RecentTrends = recentTrends;
                }
            }
        }
        private IList<IndicatorMetadata> AddTopicData(Area area, IEnumerable<Area> parentAreas)
        {
            IndicatorMetadataCollection allMetadata = new IndicatorMetadataCollection();

            foreach (var groupId in GroupIds)
            {
                IList<Grouping> groupings = groupDataReader.GetGroupingsByGroupId(groupId);

                IList<GroupRoot> roots = new GroupRootBuilder().BuildGroupRoots(groupings);

                IndicatorMetadataCollection metadataCollection =
                    IndicatorMetadataRepository.Instance.GetIndicatorMetadataCollection(groupings);

                allMetadata.AddIndicatorMetadata(metadataCollection.IndicatorMetadata);

                foreach (GroupRoot root in roots)
                {
                    Grouping grouping = root.FirstGrouping;

                    // Add indicator information
                    IndicatorMetadata metadata = metadataCollection.GetIndicatorMetadataById(grouping.IndicatorId);
                    IList<TimePeriod> periods = grouping.GetTimePeriodIterator(metadata.YearType).TimePeriods;
                    writer.AddPracticeIndicatorTitles(metadata, periods);
                    writer.AddCcgIndicatorTitles(metadata, periods);

                    foreach (TimePeriod timePeriod in periods)
                    {
                        // Add data
                        writer.AddPracticeIndicatorData(GetPracticeDataMap(area, grouping, timePeriod));
                        writer.AddAreaIndicatorData(GetParentAreaDataMap(grouping, timePeriod, parentAreas, metadata));
                    }
                }
            }
            return allMetadata.IndicatorMetadata;
        }
 public void InitIndicatorMetadata(IndicatorMetadataCollection metadataCollection)
 {
     this.metadataCollection = metadataCollection;
 }