public void InsertPerHealthRiskAndRegionForComing4Weeks(CaseReport caseReport, HealthRisk healthRisk, District district) { // Insert by health risk and region var today = Day.From(caseReport.Timestamp); var region = _regions.GetById(district.RegionId); var numCases = caseReport.NumberOfMalesUnder5 + caseReport.NumberOfMalesAged5AndOlder + caseReport.NumberOfFemalesUnder5 + caseReport.NumberOfFemalesAged5AndOlder; for (var day = 0; day < 28; day++) { var dayReport = _caseReportsPerRegionLast4Weeks.GetById(day + today); if (dayReport != null) { var healthRiskForDay = dayReport.HealthRisks.FirstOrDefault(d => d.Id == caseReport.HealthRiskId); if (healthRiskForDay != null) { var regionForHealthRisk = healthRiskForDay.Regions.FirstOrDefault(r => r.Name == region.Name); if (regionForHealthRisk != null) { InsertNumCases(regionForHealthRisk, day, numCases); } else { healthRiskForDay.Regions.Add(AddRegionWithCases(region.Name, day, numCases)); } } else { dayReport.HealthRisks.Add(new HealthRisksInRegionsLast4Weeks() { Id = caseReport.HealthRiskId, HealthRiskName = healthRisk.Name, Regions = new[] { AddRegionWithCases(region.Name, day, numCases) } }); } _caseReportsPerRegionLast4Weeks.Update(dayReport); } else { dayReport = new CaseReportsPerRegionLast4Weeks() { Id = day + today, HealthRisks = new[] { new HealthRisksInRegionsLast4Weeks() { Id = caseReport.HealthRiskId, HealthRiskName = healthRisk.Name, Regions = new [] { AddRegionWithCases(region.Name, day, numCases) } } } }; _caseReportsPerRegionLast4Weeks.Insert(dayReport); } } ; }
public void Save(CaseReport caseReport) { var filter = Builders <CaseReport> .Filter.Eq(c => c.Id, caseReport.Id); _collection.ReplaceOne(filter, caseReport, new UpdateOptions { IsUpsert = true }); }
public void Process(CaseReportReceived @event) { var caseReport = new CaseReport(@event.DataCollectorId, @event.HealthRiskId, @event.Origin, @event.Message, @event.NumberOfMalesUnder5, @event.NumberOfMalesAged5AndOlder, @event.NumberOfFemalesUnder5, @event.NumberOfFemalesAged5AndOlder, @event.Longitude, @event.Latitude, @event.Timestamp); _caseReportRepository.Insert(caseReport); }
public void InsertPerHealthRiskAndRegionForDay(CaseReport report, HealthRisk healthRisk, District district) { var numberOfReports = report.NumberOfFemalesAged5AndOlder + report.NumberOfFemalesUnder5 + report.NumberOfMalesAged5AndOlder + report.NumberOfMalesUnder5; var region = _regions.GetById(district.RegionId); var day = Day.From(report.Timestamp); var reportsPerHealthRisk = _caseReportsPerHealthRiskPerDay.GetById(day); if (reportsPerHealthRisk == null) { reportsPerHealthRisk = new CaseReportsPerHealthRiskPerDay() { Id = day, Timestamp = report.Timestamp, ReportsPerHealthRisk = new Dictionary <HealthRiskName, Dictionary <RegionName, int> >() { { healthRisk.Name, new Dictionary <RegionName, int>() { { region.Name, numberOfReports } } } } }; _caseReportsPerHealthRiskPerDay.Insert(reportsPerHealthRisk); } else { if (reportsPerHealthRisk.ReportsPerHealthRisk.TryGetValue(healthRisk.Name, out Dictionary <RegionName, int> reportsPerRegion)) { if (reportsPerRegion.TryGetValue(region.Name, out int totalReports)) { reportsPerRegion[region.Name] = totalReports + numberOfReports; } else { reportsPerRegion.Add(region.Name, numberOfReports); } reportsPerHealthRisk.ReportsPerHealthRisk[healthRisk.Name] = reportsPerRegion; } else { reportsPerHealthRisk.ReportsPerHealthRisk.Add(healthRisk.Name, new Dictionary <RegionName, int>() { { region.Name, numberOfReports } }); } _caseReportsPerHealthRiskPerDay.Update(reportsPerHealthRisk); } }
public void Process(MultipleCaseReportsReceived @event) { var caseReport = new CaseReport(@event.CaseReportId); caseReport.DataCollectorId = @event.DataCollectorId; caseReport.HealthRiskId = @event.HealthRiskId; caseReport.NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5; caseReport.NumberOfFemalesOver5 = @event.NumberOfFemalesOver5; caseReport.NumberOfMalesUnder5 = @event.NumberOfFemalesUnder5; caseReport.NumberOfMalesOver5 = @event.NumberOfMalesOver5; caseReport.Location = new Location(@event.Latitude, @event.Longitude); _caseReports.Save(caseReport); }
public void Process(CaseReportReceived @event) { var caseReport = new CaseReport(@event.CaseReportId); caseReport.DataCollectorId = @event.DataCollectorId; caseReport.HealthRiskId = @event.HealthRiskId; caseReport.NumberOfFemalesUnder5 = @event.Age <= 5 && (Sex)@event.Sex == Sex.Female ? 1 : 0; caseReport.NumberOfFemalesOver5 = @event.Age > 5 && (Sex)@event.Sex == Sex.Female ? 1 : 0; caseReport.NumberOfMalesUnder5 = @event.Age <= 5 && (Sex)@event.Sex == Sex.Male ? 1 : 0; caseReport.NumberOfMalesOver5 = @event.Age > 5 && (Sex)@event.Sex == Sex.Male ? 1 : 0; caseReport.Location = new Location(@event.Latitude, @event.Longitude); _caseReports.Save(caseReport); }
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); } }
public async Task Process(CaseReportReceived @event) { var caseReport = new CaseReport(@event.CaseReportId) { DataCollectorId = @event.DataCollectorId, HealthRiskId = @event.HealthRiskId, NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5, NumberOfFemalesOver5 = @event.NumberOfFemalesOver5, NumberOfMalesUnder5 = @event.NumberOfMalesUnder5, NumberOfMalesOver5 = @event.NumberOfMalesOver5, Location = new Location(@event.Latitude, @event.Longitude), Timestamp = @event.Timestamp }; await _caseReports.Save(caseReport); }
public async Task Process(CaseReportReceived @event) { // Save CaseReport in the CaseReports DB var caseReport = new CaseReport(@event.CaseReportId) { DataCollectorId = @event.DataCollectorId, HealthRiskId = @event.HealthRiskId, NumberOfFemalesAges0To4 = @event.NumberOfFemalesAges0To4, NumberOfFemalesAgedOver4 = @event.NumberOfFemalesAgedOver4, NumberOfMalesAges0To4 = @event.NumberOfMalesAges0To4, NumberOfMalesAgedOver4 = @event.NumberOfMalesAgedOver4, Location = new Location(@event.Latitude, @event.Longitude), Timestamp = @event.Timestamp }; await _caseReports.Save(caseReport); }
public void Process(CaseReportReceived @event) { var caseReport = new CaseReport { NumberOfMalesAged5AndOlder = @event.NumberOfMalesAged5AndOlder, NumberOfFemalesAged5AndOlder = @event.NumberOfFemalesAged5AndOlder, NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5, NumberOfMalesUnder5 = @event.NumberOfMalesUnder5, Timestamp = @event.Timestamp, HealthRisk = @event.HealthRiskId, Longitude = @event.Longitude, Latitude = @event.Latitude }; this.repository.Insert(caseReport); this.calculators.ForEach(c => c.Calculate(caseReport)); }
public void Process(CaseReportReceived @event) { var caseReport = new CaseReport(@event.CaseReportId) { DataCollectorId = @event.DataCollectorId, HealthRiskId = @event.HealthRiskId, NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5, NumberOfFemalesAged5AndOlder = @event.NumberOfFemalesAged5AndOlder, NumberOfMalesUnder5 = @event.NumberOfMalesUnder5, NumberOfMalesAged5AndOlder = @event.NumberOfMalesAged5AndOlder, Location = new Location(@event.Latitude, @event.Longitude), Timestamp = @event.Timestamp, Message = @event.Message }; _caseReports.Update(caseReport); }
public void Process(CaseReportReceived @event, EventSourceId caseReportId) { // Insert CaseReports var caseReport = new CaseReport(caseReportId.Value, @event.DataCollectorId, @event.HealthRiskId, @event.Origin, @event.Message, @event.NumberOfMalesUnder5, @event.NumberOfMalesAged5AndOlder, @event.NumberOfFemalesUnder5, @event.NumberOfFemalesAged5AndOlder, @event.Longitude, @event.Latitude, @event.Timestamp); _caseReportRepository.Insert(caseReport); var healthRisk = _healthRisks.GetById(caseReport.HealthRiskId); var dataCollector = _dataCollectors.GetById(@event.DataCollectorId); var district = _districts.Query.FirstOrDefault(_ => _.Name == dataCollector.District); InsertPerHealthRiskAndRegionForComing4Weeks(caseReport, healthRisk, district); UpdateDataCollectorLastActive(dataCollector, caseReport); InsertPerHealthRiskAndRegionForDay(caseReport, healthRisk, district); }
public void Process(CaseReportReceived @event) { // Insert CaseReports var caseReport = new CaseReport(@event.DataCollectorId, @event.HealthRiskId, @event.Origin, @event.Message, @event.NumberOfMalesUnder5, @event.NumberOfMalesAged5AndOlder, @event.NumberOfFemalesUnder5, @event.NumberOfFemalesAged5AndOlder, @event.Longitude, @event.Latitude, @event.Timestamp); _caseReportRepository.Insert(caseReport); var healthRisk = _healthRisks.GetById(caseReport.HealthRiskId); var dataCollector = _dataCollectors.GetById(caseReport.DataCollectorId); // Insert by health risk and region var today = Day.From(caseReport.Timestamp); var totalCases = caseReport.NumberOfMalesUnder5 + caseReport.NumberOfMalesAged5AndOlder + caseReport.NumberOfFemalesUnder5 + caseReport.NumberOfFemalesAged5AndOlder; Region region = dataCollector.Region; for (var day = today; day < today + 7; day++) { var dayReport = _caseReportsPerRegionLast7DaysRepository.GetById(day); if (dayReport != null) { var healthRiskForDay = dayReport.HealthRisks.FirstOrDefault(d => d.Id == caseReport.HealthRiskId); if (healthRiskForDay != null) { var regionForHealthRisk = healthRiskForDay.Regions.FirstOrDefault(r => r.Id == region); if (regionForHealthRisk != null) { regionForHealthRisk.NumCases += totalCases; } else { healthRiskForDay.Regions.Add(AddRegionWithCases(region, totalCases)); } } else { dayReport.HealthRisks.Add(new HealthRisksInRegionsLast7Days() { Id = caseReport.HealthRiskId, HealthRiskName = healthRisk.Name, Regions = new [] { AddRegionWithCases(region, totalCases) } }); } _caseReportsPerRegionLast7DaysRepository.Update(dayReport); } else { dayReport = new CaseReportsPerRegionLast7Days() { Id = day, HealthRisks = new [] { new HealthRisksInRegionsLast7Days() { Id = caseReport.HealthRiskId, HealthRiskName = healthRisk.Name, Regions = new [] { AddRegionWithCases(region, totalCases) } } } }; _caseReportsPerRegionLast7DaysRepository.Insert(dayReport); } } ; }
public void InsertPerHealthRiskAndRegionForComing4Weeks(CaseReport caseReport, HealthRisk healthRisk, District district) { // Insert by health risk and region var today = Day.From(caseReport.Timestamp); var region = _regions.GetById(district.RegionId); var numCases = caseReport.NumberOfMalesUnder5 + caseReport.NumberOfMalesAged5AndOlder + caseReport.NumberOfFemalesUnder5 + caseReport.NumberOfFemalesAged5AndOlder; for (var day = 0; day < 28; day++) { var dayReport = _caseReportsPerRegionLast4Weeks.GetById(day + today); if (dayReport != null) { if (dayReport.HealthRisks.TryGetValue(healthRisk.Name, out HealthRisksInRegionsLast4Weeks healthRiskForDay)) { if (healthRiskForDay.Regions.TryGetValue(region.Name, out RegionWithHealthRisk regionWithHealthRisk)) { regionWithHealthRisk = InsertNumCases(regionWithHealthRisk, day, numCases); healthRiskForDay.Regions[region.Name] = regionWithHealthRisk; } else { healthRiskForDay.Regions.Add(region.Name, AddRegionWithCases(region.Name, day, numCases)); } dayReport.HealthRisks[healthRisk.Name] = healthRiskForDay; } else { var healthRisksInRegion = new HealthRisksInRegionsLast4Weeks(); healthRisksInRegion.Regions = new Dictionary <RegionName, RegionWithHealthRisk> { { region.Name, AddRegionWithCases(region.Name, day, numCases) } }; dayReport.HealthRisks.Add(healthRisk.Name, healthRisksInRegion); } _caseReportsPerRegionLast4Weeks.Update(dayReport); } else { var healthRisksInRegion = new HealthRisksInRegionsLast4Weeks(); healthRisksInRegion.Regions = new Dictionary <RegionName, RegionWithHealthRisk>() { { region.Name, AddRegionWithCases(region.Name, day, numCases) } }; dayReport = new CaseReportsPerRegionLast4Weeks() { Id = day + today, HealthRisks = new Dictionary <HealthRiskName, HealthRisksInRegionsLast4Weeks>() { { healthRisk.Name, healthRisksInRegion } } }; _caseReportsPerRegionLast4Weeks.Insert(dayReport); } } }
public void UpdateDataCollectorLastActive(DataCollector dataCollector, CaseReport caseReport) { dataCollector.LastActive = caseReport.Timestamp; _dataCollectors.Update(dataCollector); }
public void Save(CaseReport caseReport) { _collection.ReplaceOne(_ => _.Id == caseReport.Id, caseReport, new UpdateOptions { IsUpsert = true }); }
public async Task Save(CaseReport caseReport) { var filter = Builders <CaseReport> .Filter.Eq(c => c.Id, caseReport.Id); await _collection.ReplaceOneAsync(filter, caseReport, new UpdateOptions { IsUpsert = true }); }