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 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); } } }