Esempio n. 1
0
        public void TestQueryable()
        {
            var someGenericClass = new SomeGenericClass("veryGenericKey", "veryGenericValue");

            someGenericClass.Id = ObjectId.Parse("5c9a0d8afe28b239e7da280d");

            MongoDbHandler.InsertRecordToDb(someGenericClass);

            var queryable = MongoDbHandler.GetQueryable <CaseReport>().Where(x => x.Id == ObjectId.Parse("5c9a0d8afe28b239e7da280d")).ToList();;

            Assert.AreEqual(queryable.Count, 1);
        }
Esempio n. 2
0
        public CaseReportTotals GetCaseReportTotals(DateTimeOffset from, DateTimeOffset to)
        {
            var caseReportTotals = new CaseReportTotals();
            var queryable        = _mongoDBHandler.GetQueryable <CaseReport>()
                                   .Where(x => x.Timestamp >= from && x.Timestamp <= to);

            caseReportTotals.Female = queryable.Sum(x => x.NumberOfFemalesAged5AndOlder) +
                                      queryable.Sum(x => x.NumberOfFemalesUnder5);
            caseReportTotals.Male = queryable.Sum(x => x.NumberOfMalesAged5AndOlder) +
                                    queryable.Sum(x => x.NumberOfMalesUnder5);
            caseReportTotals.Over5 = queryable.Sum(x => x.NumberOfFemalesAged5AndOlder) +
                                     queryable.Sum(x => x.NumberOfMalesAged5AndOlder);
            caseReportTotals.Under5 = queryable.Sum(x => x.NumberOfFemalesUnder5) +
                                      queryable.Sum(x => x.NumberOfMalesUnder5);

            return(caseReportTotals);
        }
        public void Handle(CaseReport caseReport)
        {
            _dbHandler.Insert(caseReport);

            var healthRisks = _dbHandler.GetQueryable <HealthRisk>();
            var healthRisk  = healthRisks.FirstOrDefault(h => h.HealthRiskId == caseReport.HealthRisk);

            if (healthRisk != null)
            {
                healthRisk.ReportReceived(caseReport);
                _dbHandler.Update(healthRisk);
            }
        }
Esempio n. 4
0
        public AnalysisReport GetAggregation(
            DateTimeOffset @from,
            DateTimeOffset to,
            TimeAggregation timeAggregation,
            SelectedSeries[] selectedSeries)
        {
            var dbCaseEntry = _dbHandler.GetQueryable <CaseReport>()
                              .Where(x => x.Timestamp >= from && x.Timestamp < to)
                              .ToList();

            var groups = dbCaseEntry.OrderBy(x => x.Timestamp.Date).GroupBy(x => TimeWindowGrouping(x.Timestamp.Date, timeAggregation));

            var report = new AnalysisReport
            {
                From            = @from,
                To              = to,
                TimeAggregation = timeAggregation,
                Categories      = groups.Select(x => x.Key).ToArray(),
                Series          = GetSeries(groups, selectedSeries),
            };

            return(report);
        }
Esempio n. 5
0
        private void PopulateCaseReportKPIs(KPIs kpi, DateTimeOffset from, DateTimeOffset to)
        {
            var reportedHealthRisks = kpi.GetRecordedHealthRisks();

            var healthRisks = _mongoDBHandler.GetQueryable <HealthRisk>()
                              .Where(x => x.ReportsPerDay.Count != 0).ToList();

            int total = 0;

            foreach (var healthRisk in healthRisks)
            {
                int numReports = healthRisk.ReportsPerDay.Where(x => x.Key >= from && x.Key < to).Sum(x => x.Value);
                if (numReports == 0)
                {
                    continue;
                }

                total += numReports;
                var reportedHealthRisk = reportedHealthRisks.SingleOrDefault(x => x.Name == healthRisk.Name);
                if (reportedHealthRisk == null)
                {
                    reportedHealthRisks.Add(new ReportedHealthRisk
                    {
                        Name            = healthRisk.Name,
                        NumberOfReports = numReports
                    });
                }
                else
                {
                    reportedHealthRisk.AddNumberOfReports(numReports);
                }
            }

            kpi.CaseReports.TotalNumberOfReports = total;
            kpi.SetRecordedHealthRisks(reportedHealthRisks);
        }
Esempio n. 6
0
        public string GetDataOwner(Guid dataOwnerId)
        {
            // Fetch the data owner from db
            var dbDataOwnerEntry = _dbHandler.GetQueryable <DataOwner>().Where(x => x.DataOwnerId.Equals(dataOwnerId)).ToList();

            foreach (var dataOwner in dbDataOwnerEntry)
            {
                // Create the DataCollectorReport
                var dataCollectorReports = new List <DataCollectorReport>();
                foreach (var dataCollector in dataOwner.DataCollectors)
                {
                    var dbCaseEntries       = _dbHandler.GetQueryable <CaseReport>().Where(x => x.DataCollectorId.Equals(dataCollector)).ToList();
                    var dataCollectorReport = new DataCollectorReport()
                    {
                        DataCollectorId             = dataCollector,
                        HealthRiskAggregatedReports = new List <HealthRiskAggregatedReport>()
                    };

                    foreach (var entry in dbCaseEntries)
                    {
                        dataCollectorReport.Longitude = entry.Longitude;
                        dataCollectorReport.Latitude  = entry.Latitude;

                        HealthRiskAggregatedReport report = dataCollectorReport.HealthRiskAggregatedReports.Find(x => x.HealthRiskId.Equals(entry.HealthRisk));
                        if (report != null)
                        {
                            // Aggregate numbers
                            report.NumberOfFemalesUnder5        += entry.NumberOfFemalesUnder5;
                            report.NumberOfMalesUnder5          += entry.NumberOfMalesUnder5;
                            report.NumberOfFemalesAged5AndOlder += entry.NumberOfFemalesAged5AndOlder;
                            report.NumberOfMalesAged5AndOlder   += entry.NumberOfMalesAged5AndOlder;
                        }
                        else
                        {
                            // Add a new health risk
                            dataCollectorReport.HealthRiskAggregatedReports.Add(new HealthRiskAggregatedReport()
                            {
                                HealthRiskId                 = entry.HealthRisk,
                                NumberOfMalesUnder5          = entry.NumberOfMalesUnder5,
                                NumberOfFemalesUnder5        = entry.NumberOfFemalesUnder5,
                                NumberOfMalesAged5AndOlder   = entry.NumberOfMalesAged5AndOlder,
                                NumberOfFemalesAged5AndOlder = entry.NumberOfFemalesAged5AndOlder
                            });
                        }
                    }

                    dataCollectorReports.Add(dataCollectorReport);
                }

                // Create the DataOwnerReport
                var dataOwnerReport = new DataOwnerReport()
                {
                    DataOwnerId          = dataOwner.DataOwnerId,
                    Longitude            = dataOwner.Longitude,
                    Latitude             = dataOwner.Latitude,
                    DataCollectorReports = dataCollectorReports
                };

                return(JsonConvert.SerializeObject(dataOwnerReport));
            }

            return(null);
        }