Calculating percentages in columns for a report using Reporting module


I am using an old version of the reporting module 0.6.2 for an implementation that uses OpenMRS 1.6. I am not very proficient with the module so mine could end up being a very basic query. I have successfully used the reporting module to create reports earlier using CohortCrossTabDataSetDefinition, CohortDefinition’s and their associated Evaluators. I am stuck due to a requirement regarding the following report which needs percentages. I have used the definitions to generate absolute numbers and now need help for the percentages.

I am using the reporting module in the following vain:

Concept newCase = Context.getConceptService().getConcept(TbConcepts.NEW_CASE[0]);
CohortDefinition allNew =Cohorts.getAllSuspectsByInvestigationPurpose(startDate, endDate, newCase,false);

Concept culture = Context.getConceptService().getConcept(TbConcepts.CULTURE_CONSTRUCT[0]);
CohortDefinition allCulture = Cohorts.getAllByTestType(startDate, endDate, culture,true);

dstTable.addRow("Culture", allCulture, null);
dstTable.addRow("1LineDST", allDST1, null);
dstTable.addColumn("AbsNew", allNew, null);
dstTable.addColumn("AbsPrev", allPrevious, null);

report.addDataSetDefinition("tbl", dstTable, null);

I would be glad if I can be pointed to the right choice of Dataset or any other way this can be done. Thanks

Try the #newFractionIndicator method and see if it gets you what you want. You pass it one cohort as numerator and another as denominator and if you are outputting your report to Excel, you’ll just format the cell in which you are mapping the result to percentage.

Hi @rubailly

Great thanks for the response. Can I use it with the CohortCrossTabDataSetDefinition? If you can point me to some examples it would be great.

Thanks, Omar

Hi @omarahmed1, no - the CohortCrossTabDataSetDefinition just deals in Cohorts, not Indicators. You’d need to use a different type of DataSet, or you’d need to calculate the percentage in your renderer (i.e. - just compute the numerator and denominator cohorts in the DSD, and in the renderer do the calculation of the percentage). This is something that is certainly possible with the ExcelTemplateRenderer.