コード例 #1
0
 public override ReportResult Run(SavedReport report)
 {
     repo = new ReportRepository();
     ReportResult result = new ReportResult();
     result.DataTableResults = repo.RunRedistrictingReport();
     result.ChartData = null;
     return result;
 }
コード例 #2
0
        public override ReportResult Run(SavedReport report)
        {
            PersonsTreatedCoverageReportOptions standardOpts = (PersonsTreatedCoverageReportOptions)report.StandardReportOptions;

            // Options
            report.ReportOptions.IsByLevelAggregation = true;
            report.ReportOptions.IsCountryAggregation = false;
            report.ReportOptions.IsNoAggregation = false;

            // Get all admin levels
            if (report.ReportOptions.IsAllLocations)
                report.ReportOptions.SelectedAdminLevels = DemoRepo.GetAdminLevelByLevel(standardOpts.DistrictType.LevelNumber).Where(a => a.LevelNumber == standardOpts.DistrictType.LevelNumber).ToList();

            List<int> filteredIntvIds;
            if (this.GetType() == typeof(PersonsTreatedCoverageDrugPackageReportGenerator))
            {
                // Determine intervention types
                IntvTypes = DetermineIntvTypes(standardOpts);
                // Get all the matching interventions based on the report options
                List<IntvBase> intvs = GetIntvsByReportOptions(IntvTypes, report.ReportOptions);
                // Determine the diseases
                Diseases = DetermineDiseases(standardOpts, intvs);
                // Drug package report does not need to be filtered
                filteredIntvIds = null;
            }
            else
            {
                // It is a disease report, so first set the diseases thats were selected
                Diseases = DetermineDiseases(standardOpts);
                // Deterine the interventions associated to the diseases
                IntvTypes = DetermineIntvTypes(Diseases);
                // Determine which interventions should be used in the report
                filteredIntvIds = DetermineInterventionsByDiseasesTargeted(standardOpts.AvailableDrugPackages, report.ReportOptions, Diseases);
            }

            // There was no data at this reporting level
            if (Diseases == null || IntvTypes == null || Diseases.Count < 1 || IntvTypes.Count < 1)
            {
                ReportResult result = new ReportResult();
                result.DataTableResults = new DataTable();
                return result;
            }

            // Run the distribution report for the disease dist related data
            ReportResult distReportResult = RunDistributionReport(CloneReport(report), standardOpts);
            // Aggregate the dist data
            AggregateDistData(distReportResult);

            // Run the intervention report
            ReportResult intvReportResult = RunIntvReport(CloneReport(report), standardOpts, filteredIntvIds);
            // Remove the district and year columns from the intervention report result
            RemovePastColumn(intvReportResult.DataTableResults, TranslationLookup.GetValue("Year"));
            // Aggregate the Report data
            DataTable intvDataTable = AggregateIntvData(intvReportResult);

            // Merge the results
            CopyDataTableToSameRows(intvDataTable, distReportResult.DataTableResults);

            distReportResult.ChartData = distReportResult.DataTableResults.Copy();
            distReportResult.DataTableResults.Columns.Remove(TranslationLookup.GetValue("Type"));
            return distReportResult;
        }
コード例 #3
0
        protected void AggregateDistData(ReportResult result)
        {
            // See if the pop at risk columns should be combined
            bool CombineAtRiskCols = this.GetType() == typeof(PersonsTreatedCoverageDiseaseReportGenerator)
                || (Diseases.Count <= 1 && this.GetType() == typeof(PersonsTreatedCoverageDrugPackageReportGenerator));

            // Add the combined pop at risk column if necesssarsy
            if (CombineAtRiskCols)
                result.DataTableResults.Columns.Add(new DataColumn(TranslationLookup.GetValue("EliminationAtRisk")));

            // Aggregate each distribution row
            for (int i = 0; i < result.DataTableResults.Rows.Count; i++)
            {
                DataRow row = result.DataTableResults.Rows[i];

                double totalAtRisk = 0;
                totalAtRisk += GetColumnDouble(TranslationLookup.GetValue("DDLFPopulationAtRisk") + " - " + TranslationLookup.GetValue("LF"), result.DataTableResults, row);
                totalAtRisk += GetColumnDouble(TranslationLookup.GetValue("DDTraPopulationAtRisk") + " - " + TranslationLookup.GetValue("Trachoma"), result.DataTableResults, row);
                totalAtRisk += GetColumnDouble(TranslationLookup.GetValue("DDOnchoPopulationAtRisk") + " - " + TranslationLookup.GetValue("Oncho"), result.DataTableResults, row);
                totalAtRisk += GetColumnDouble(TranslationLookup.GetValue("DDSTHPopulationAtRisk") + " - " + TranslationLookup.GetValue("STH"), result.DataTableResults, row);
                totalAtRisk += GetColumnDouble(TranslationLookup.GetValue("DDSchistoPopulationAtRisk") + " - " + TranslationLookup.GetValue("Schisto"), result.DataTableResults, row);

                // Add the total pop at risk to the map
                RowToPopAtRisk.Add(i, totalAtRisk);

                // Add the total to the pop at risk column if necessary
                if (CombineAtRiskCols)
                    row[TranslationLookup.GetValue("EliminationAtRisk")] = totalAtRisk;
            }

            // Remove original columns that were just used for aggregation
            if (CombineAtRiskCols)
            {
                TryRemoveColumn(TranslationLookup.GetValue("DDLFPopulationAtRisk") + " - " + TranslationLookup.GetValue("LF"), result.DataTableResults);
                TryRemoveColumn(TranslationLookup.GetValue("DDTraPopulationAtRisk") + " - " + TranslationLookup.GetValue("Trachoma"), result.DataTableResults);
                TryRemoveColumn(TranslationLookup.GetValue("DDOnchoPopulationAtRisk") + " - " + TranslationLookup.GetValue("Oncho"), result.DataTableResults);
                TryRemoveColumn(TranslationLookup.GetValue("DDSTHPopulationAtRisk") + " - " + TranslationLookup.GetValue("STH"), result.DataTableResults);
                TryRemoveColumn(TranslationLookup.GetValue("DDSchistoPopulationAtRisk") + " - " + TranslationLookup.GetValue("Schisto"), result.DataTableResults);
            }
        }
コード例 #4
0
        protected DataTable AggregateIntvData(ReportResult result)
        {
            // Aggregate data into objects
            Dictionary<int, Dictionary<string, ReportColumn>> intvDataDict = new Dictionary<int, Dictionary<string, ReportColumn>>();
            for (int i = 0; i < result.DataTableResults.Rows.Count; i++)
            {
                Dictionary<string, ReportColumn> data = new Dictionary<string, ReportColumn>();
                DataRow row = result.DataTableResults.Rows[i];
                foreach (DataColumn col in result.DataTableResults.Columns)
                {
                    AggregateRounds(data, row, col, TranslationLookup.GetValue("PcIntvNumEligibleIndividualsTargeted"));
                    AggregateRounds(data, row, col, TranslationLookup.GetValue("PcIntvNumIndividualsTreated"));
                    AggregateRounds(data, row, col, TranslationLookup.GetValue("PcIntvPsacTreated"));
                    AggregateRounds(data, row, col, TranslationLookup.GetValue("PcIntvNumSacTreated"));
                }

                intvDataDict.Add(i, data);
            }
            DataTable intvDataTable = new DataTable();
            foreach (KeyValuePair<int, Dictionary<string, ReportColumn>> entry in intvDataDict)
            {
                // Instantiate a new row
                DataRow row = intvDataTable.NewRow();

                // Add the data columns
                foreach (KeyValuePair<string, ReportColumn> dataEntry in entry.Value)
                {
                    // Iterate through each aggregate column
                    foreach (KeyValuePair<int, double> roundEntry in dataEntry.Value.RoundValues)
                    {
                        // Determine the col name + round number string
                        string roundColName;
                        if (roundEntry.Key == -1)
                            roundColName = dataEntry.Value.ColumnName;
                        else
                            roundColName = string.Format("{0} - {1} {2}", dataEntry.Value.ColumnName, TranslationLookup.GetValue("Round"), roundEntry.Key);

                        // Add the column
                        if (!intvDataTable.Columns.Contains(roundColName))
                            intvDataTable.Columns.Add(new DataColumn(roundColName));
                        // Add the value
                        row[roundColName] = roundEntry.Value;

                        // Calculate epi and program coverage
                        if (dataEntry.Value.ColumnName == TranslationLookup.GetValue("PcIntvNumIndividualsTreated"))
                        {
                            CalculateEpi(row, entry.Key, roundEntry.Key, roundEntry.Value);
                            CalculateProgramCoverage(row, entry.Key, roundEntry.Key, roundEntry.Value, entry.Value);
                        }
                    }
                }

                // Add the row
                intvDataTable.Rows.Add(row);
            }

            return intvDataTable;
        }
コード例 #5
0
        private void LoadChart(ReportResult result)
        {
            if (result.ChartData == null)
            {
                tabControl1.TabPages.RemoveAt(1);
                return;
            }

            c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear();
            result.ChartData.Columns.Add("xaxis");
            foreach (DataRow dr in result.ChartData.Rows)
                if (report.ReportOptions.IsCountryAggregation)
                    dr["xaxis"] = dr[Translations.Year];
                else
                    dr["xaxis"] = dr[Translations.Location] + " - " + dr[Translations.Year];
            DataView dv = result.ChartData.DefaultView;
            dv.Sort = Translations.Year + ", " + Translations.Location;

            // copy data from table to chart
            int startColumn = result.ChartData.Columns.IndexOf(Translations.Year) + 1;
            int seriesIndex = 0;
            for (int i = startColumn; i < result.ChartData.Columns.Count; i++)
            {
                if (i == startColumn)
                    BindSeries(c1Chart1, seriesIndex, dv, result.ChartData.Columns[i].ColumnName, "xaxis");
                else if (result.ChartData.Columns[i].ColumnName == "xaxis")
                    continue;
                else
                    BindSeries(c1Chart1, seriesIndex, dv, result.ChartData.Columns[i].ColumnName);
                seriesIndex++;
            }
        }
コード例 #6
0
 void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     try
     {
         currentResult = (ReportResult)e.Result;
         if (currentResult.DataTableResults.Columns.Contains(Translations.Location))
             currentResult.DataTableResults.Columns.Remove(Translations.Location);
         if (currentResult.DataTableResults.Columns.Contains("ID"))
             currentResult.DataTableResults.Columns.Remove("ID");
         grdReport.DataSource = currentResult.DataTableResults;
         LoadChart(currentResult);
         if (!string.IsNullOrEmpty(currentResult.MetaDataWarning))
             MessageBox.Show(currentResult.MetaDataWarning, Translations.ValidationErrorTitle);
         // The results are ready, so show the UI
         ShowIsLoading(false);
     }
     catch (Exception ex)
     {
         Logger log = new Logger();
         log.Error("Error running the custom report. ", ex);
         MessageBox.Show("There was an error running the custom report: " + ex.Message, Translations.ErrorOccured, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #7
0
ファイル: RecentDistro.cs プロジェクト: ericjohnolson/NadaNtd
        /// <summary>
        /// Runs the report with the report options and collects all the disease distribution calculation
        /// </summary>
        /// <param name="mainReportOptions">The report options</param>
        public void Run(ReportOptions mainReportOptions)
        {
            SettingsRepository settingsRepo = new SettingsRepository();

            Report = new SavedReport();
            DistributionReportGenerator gen = new DistributionReportGenerator();

            Report.ReportOptions = new ReportOptions();
            Report.ReportOptions.SelectedIndicators = new List<ReportIndicator>();

            Report.ReportOptions.Years = Util.DeepClone(mainReportOptions.Years);
            Report.ReportOptions.SelectedAdminLevels = Util.DeepClone(mainReportOptions.SelectedAdminLevels);
            Report.ReportOptions.MonthYearStarts = 1;
            Report.ReportOptions.IsByLevelAggregation = true;
            Report.ReportOptions.IsCountryAggregation = false;
            Report.ReportOptions.IsNoAggregation = false;

            // Determine the name of the reporting admin level
            if (mainReportOptions.SelectedAdminLevels.Count > 0)
            {
                int levelNum = mainReportOptions.SelectedAdminLevels[0].LevelNumber;
                AdminLevelType adminLevelType = settingsRepo.GetAdminLevelTypeByLevel(levelNum);
                NameOfReportingAdminLevel = adminLevelType.DisplayName;
            }
            if (NameOfReportingAdminLevel == null)
                throw new ArgumentException("Could not determine reporting level");

            // STH
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.STH,
                        new KeyValuePair<string, Indicator>("DDSTHPopulationRequiringPc", new Indicator { Id = 141, DisplayName = "DDSTHPopulationRequiringPc" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.STH,
                        new KeyValuePair<string, Indicator>("DDSTHPsacAtRisk", new Indicator { Id = 142, DisplayName = "DDSTHPsacAtRisk" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.STH,
                        new KeyValuePair<string, Indicator>("DDSTHSacAtRisk", new Indicator { Id = 143, DisplayName = "DDSTHSacAtRisk" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.STH,
                        new KeyValuePair<string, Indicator>("DDSTHPopulationAtRisk", new Indicator { Id = 140, DisplayName = "DDSTHPopulationAtRisk" })));
            // LF
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Lf,
                    new KeyValuePair<string, Indicator>("DDLFPopulationAtRisk", new Indicator { Id = 98, DisplayName = "DDLFPopulationAtRisk" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Lf,
                        new KeyValuePair<string, Indicator>("DDLFPopulationRequiringPc", new Indicator { Id = 99, DisplayName = "DDLFPopulationRequiringPc" })));
            // Oncho
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Oncho,
                    new KeyValuePair<string, Indicator>("DDOnchoPopulationAtRisk", new Indicator { Id = 111, DisplayName = "DDOnchoPopulationAtRisk" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Oncho,
                        new KeyValuePair<string, Indicator>("DDOnchoPopulationRequiringPc", new Indicator { Id = 112, DisplayName = "DDOnchoPopulationRequiringPc" })));
            // Schisto
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Schisto,
                        new KeyValuePair<string, Indicator>("DDSchistoPopulationAtRisk", new Indicator { Id = 125, DisplayName = "DDSchistoPopulationAtRisk" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Schisto,
                        new KeyValuePair<string, Indicator>("DDSchistoPopulationRequiringPc", new Indicator { Id = 126, DisplayName = "DDSchistoPopulationRequiringPc" })));
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Schisto,
                        new KeyValuePair<string, Indicator>("DDSchistoSacAtRisk", new Indicator { Id = 127, DisplayName = "DDSchistoSacAtRisk" })));
            // Trachoma
            Report.ReportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator((int)DiseaseType.Trachoma,
                    new KeyValuePair<string, Indicator>("DDTraPopulationAtRisk", new Indicator { Id = 161, DisplayName = "DDTraPopulationAtRisk" })));

            // Run the report
            Result = gen.Run(Report);
        }
コード例 #8
0
 private void AddAgeGroupDistToExport(excel.Worksheet xlsWorksheet, excel.Range rng, string cell, string formName,
     string fieldNameGroup1, string fieldNameGroup2, string fieldNameGroup3, ReportResult report)
 {
     // Get the values
     string val1 = GetValueFromCountryAggReport(formName, fieldNameGroup1, report);
     if (string.IsNullOrEmpty(val1))
         val1 = "--";
     string val2 = GetValueFromCountryAggReport(formName, fieldNameGroup2, report);
     if (string.IsNullOrEmpty(val2))
         val2 = "--";
     string val3 = GetValueFromCountryAggReport(formName, fieldNameGroup3, report);
     if (string.IsNullOrEmpty(val3))
         val3 = "--";
     // Concat all the values
     string final = string.Format("{0} / {1} / {2}", val1, val2, val3);
     // Add to the export
     AddValueToRange(xlsWorksheet, rng, cell, final);
 }
コード例 #9
0
 private void AddReportValueToExport(excel.Worksheet xlsWorksheet, excel.Range rng, string cell, string formName, string fieldName, ReportResult report)
 {
     string val = GetValueFromCountryAggReport(formName, fieldName, report);
     if (!string.IsNullOrEmpty(val))
         AddValueToRange(xlsWorksheet, rng, cell, val);
 }
コード例 #10
0
        private string GetValueFromCountryAggReport(string formName, string fieldName, ReportResult report)
        {
            string colName;
            if (string.IsNullOrEmpty(formName))
                colName = fieldName;
            else
                colName = string.Format("{0} - {1}", fieldName, formName);

            if (report.DataTableResults.Columns.Contains(colName))
            {
                // Aggregated to country, so check first row
                DataRow row = report.DataTableResults.Rows[0];
                // Get the value
                return row[colName].ToString();
            }
            return null;
        }
コード例 #11
0
 private void RunLeishCountryAggDdReport()
 {
     // Report options
     ReportOptions reportOptions = new ReportOptions
     {
         MonthYearStarts = 1,
         StartDate = StartDate,
         EndDate = EndDate,
         IsCountryAggregation = true,
         IsByLevelAggregation = false,
         IsAllLocations = false,
         IsNoAggregation = false
     };
     // Add the indicators from the distro
     foreach (var indicator in LeishDd.Indicators)
         reportOptions.SelectedIndicators.Add(ReportRepository.CreateReportIndicator(LeishDd.Id, indicator,
             LeishDd.Disease.DisplayName, LeishDd.Disease.DisplayNameKey));
     // Run the report
     LeishCountryAggDdReport = DdReportGen.Run(new SavedReport { ReportOptions = reportOptions });
 }