public DiseaseDistroPc Create(DiseaseType disease) { DiseaseDistroPc dd = new DiseaseDistroPc(); dd.Disease = GetDiseaseById((int)disease); GetIndicatorsForDisease(dd.Disease.Id, dd); return dd; }
public DiseaseDistroPcVm(AdminLevel a, DiseaseDistroPc s, ICalcIndicators c) { r = new DiseaseRepository(); this.model = s; adminLevel = a; calc = c; }
public DiseaseDistroPcVm(AdminLevel a, int did, ICalcIndicators c) { adminLevel = a; r = new DiseaseRepository(); model = r.Create((DiseaseType)did); model.AdminLevelId = adminLevel.Id; calc = c; }
protected override void ReloadDropdownValues() { if (cmType != null) { cmType = repo.CreateCm((DiseaseType)cmType.Disease.Id); DropDownValues = cmType.IndicatorDropdownValues; } else { type = repo.Create((DiseaseType)type.Disease.Id); DropDownValues = type.IndicatorDropdownValues; } }
protected override void SetSpecificType(int id) { cmType = null; type = null; var d = repo.GetDiseaseById(id); if (d.DiseaseType == Translations.CM) { cmType = repo.CreateCm((DiseaseType)d.Id); Indicators = cmType.Indicators; DropDownValues = cmType.IndicatorDropdownValues; } else { type = repo.Create((DiseaseType)d.Id); Indicators = type.Indicators; DropDownValues = type.IndicatorDropdownValues; } Calculator = new CalcDistro(); Validator = new DiseaseDistroCustomValidator(); }
protected void AddIndicators(int id, string name, DiseaseDistroPc dd, ReportOptions options) { options.SelectedIndicators.Add(ReportRepository.CreateReportIndicator(id, new KeyValuePair<string, Indicator>(name, dd.Indicators[name]))); }
public void SavePc(DiseaseDistroPc distro, int userId, OleDbConnection connection, OleDbCommand command) { distro.MapIndicatorsToProperties(); distro.MapPropertiesToIndicators(); if (distro.Id > 0) command = new OleDbCommand(@"UPDATE DiseaseDistributions SET DiseaseId=@DiseaseId, AdminLevelId=@AdminLevelId, DateReported=@DateReported, Notes=@Notes, UpdatedById=@UpdatedById, UpdatedAt=@UpdatedAt WHERE ID=@id", connection); else command = new OleDbCommand(@"INSERT INTO DiseaseDistributions (DiseaseId, AdminLevelId, DateReported, Notes, UpdatedById, UpdatedAt, CreatedById, CreatedAt) values (@DiseaseId, @AdminLevelId, @DateReported, @Notes, @UpdatedById, @UpdatedAt, @CreatedById, @CreatedAt)", connection); command.Parameters.Add(new OleDbParameter("@DiseaseId", distro.Disease.Id)); command.Parameters.Add(OleDbUtil.CreateNullableParam("@AdminLevelId", distro.AdminLevelId)); command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@DateReported", distro.DateReported.Value)); command.Parameters.Add(OleDbUtil.CreateNullableParam("@Notes", distro.Notes)); command.Parameters.Add(new OleDbParameter("@UpdatedById", userId)); command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@UpdatedAt", DateTime.Now)); if (distro.Id > 0) command.Parameters.Add(new OleDbParameter("@id", distro.Id)); else { command.Parameters.Add(new OleDbParameter("@CreatedById", userId)); command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@CreatedAt", DateTime.Now)); } command.ExecuteNonQuery(); if (distro.Id <= 0) { command = new OleDbCommand(@"SELECT Max(ID) FROM DiseaseDistributions", connection); distro.Id = (int)command.ExecuteScalar(); } AddIndicatorValues(connection, distro, distro.Id, userId); }
public void Save(DiseaseDistroPc distro, int userId) { bool transWasStarted = false; OleDbConnection connection = new OleDbConnection(DatabaseData.Instance.AccessConnectionString); using (connection) { connection.Open(); try { // START TRANS OleDbCommand command = new OleDbCommand("BEGIN TRANSACTION", connection); command.ExecuteNonQuery(); transWasStarted = true; SavePc(distro, userId, connection, command); // COMMIT TRANS command = new OleDbCommand("COMMIT TRANSACTION", connection); command.ExecuteNonQuery(); transWasStarted = false; } catch (Exception) { if (transWasStarted) { try { OleDbCommand cmd = new OleDbCommand("ROLLBACK TRANSACTION", connection); cmd.ExecuteNonQuery(); } catch { } } throw; } } }
protected string GetIndicatorValue(DiseaseDistroPc dd, string indicatorName) { var indicator = dd.IndicatorValues.FirstOrDefault(i => i.Indicator.DisplayName == indicatorName); if (indicator == null) return Translations.NA; else return indicator.DynamicValue; }
private void GetDiseases() { // Get the Leissh distro LeishDd = DiseaseRepo.Create(DiseaseType.Leish); }
//Worksheet 3: Disease Distribution //aggregate to the reporting level //all Oncho Disease Distribution indicators private void AddDdPage(excel.Worksheet xlsWorksheet, excel.Range rng, List<AdminLevel> districts, DateTime start, DateTime end, int month, DiseaseDistroPc dd) { ReportOptions options = new ReportOptions { MonthYearStarts = month, StartDate = start, EndDate = end, IsCountryAggregation = false, IsByLevelAggregation = true, IsAllLocations = false, IsNoAggregation = false }; options.SelectedAdminLevels = districts; DistributionReportGenerator gen = new DistributionReportGenerator(); AddReportToSheet(xlsWorksheet, dd.Indicators, options, gen, disease.Id, disease.DisplayName, rng); }
private void GetDdForDisease(DateTime start, DateTime end, List<AdminLevel> demography, out DiseaseDistroPc ddType, out Dictionary<int, DataRow> dd, DiseaseType dType) { ReportOptions options = new ReportOptions { MonthYearStarts = start.Month, StartDate = start, EndDate = end, IsCountryAggregation = false, IsByLevelAggregation = true, IsAllLocations = false, IsNoAggregation = false }; options.SelectedAdminLevels = demography; DistributionReportGenerator gen = new DistributionReportGenerator(); ddType = diseaseRepo.Create(dType); foreach (var indicator in ddType.Indicators.Where(i => i.Value.DataTypeId != (int)IndicatorDataType.Calculated)) options.SelectedIndicators.Add(ReportRepository.CreateReportIndicator(ddType.Id, indicator)); ReportResult ddResult = gen.Run(new SavedReport { ReportOptions = options }); dd = new Dictionary<int, DataRow>(); foreach (DataRow dr in ddResult.DataTableResults.Rows) { int id = 0; if (int.TryParse(dr["ID"].ToString(), out id)) { if (dd.ContainsKey(id)) dd[id] = dr; else dd.Add(id, dr); } } }