Summary
Consumption report shows an aggregate consumption of products for all facilities in a specified location (district or zone) of a country for a specified period. The report will help how much is a product consumption based on geographic area.
On current implementation in eLMIS, apart from aggregated report, the report can be seen disaggregate – meaning the report viewer will have the ability to see consumption data for each facility found in a specified geographic area. In addition to that the report can show reported consumption based on regular, emergency or both.
In the report, the aggregate product consumption data of product will be shown in terms of unit of dispensing, number of packs and also adjusted consumption.
...
To access this report, first the user needs to login and should have the right to access the report. Once the user browse to the report, a page with the list of report filters mentioned above will appear.
...
Validation
When the page loads for the first time, all report filters should be unselected except Geographic zone and Consumption type filters. Geographic zone filter should be defaulted to the country (the upper most level) and under Consumption Type the checkbox 'All' should be selected.
To see report data in the report, the report viewer needs to select all the required filters - Program, Schedule, Year and Period. Once all the required fields are selected, the report will try to fetch data from server. If there are some un-selected filters which are required, the report won't try to load a data from server.
All the required filters have an asterisk signed red color coded ({}{*}) will be seen beside the filter label.
...
The Consumption report is developed using Jasper report from PDF and XLS output and HTML and AngularJS for the HTML preview.
In the eLMIS code base, all the reports are place under module called 'reports '
https://bitbucket.org/elmis-tzm/open-lmis/src/develop/modules/report/src/main/java/org/openlmis/report/ |
Under the report module we have three folders
- Java - Java code for fetching data from the database and transforming it to REST API
- Resources - This folder hold compiled jasper reports
- Template - This folder hold Jasper JRXML files. This is the place where we can find the report design to change report implementation.
How to compile report design file
To compile report files, user should navigate to the home directory of the project and issue the following command.
gradle compileJasperReport
Apart from the above command, run gradle task also compiles the report files as part of running the application. compileJasperReport compiles the jrxml files found under Template folder and move the compiled file under folder Resources.
Report End point
Under java folder listed above, we can find all the backend resources for fetching and transforming report data from db. Under this folder there a number of other dedicated folder that their name can give some meaning. Amount all the folder there is one called controller which we can find a REST controller for the starting point for most report data.
For Consumption report, the report will fetch data from InteractiveReportController. We can see lots of REST resource in the class but for our report we will focus on getAggregateConsumptionData method. All export format of the report will call this resource via URL {_}http://ip:port/reports/reportdata/aggregateConsumption.json_ with parameter query string.
Call hierarchy
org.openlmis.report.controller.InteractiveReportController#getAggregateConsumptionData
> org.openlmis.report.service.AggregateConsumptionReportDataProvider#getReportBody
> org.openlmis.report.mapper.AggregateConsumptionReportMapper#getAggregateConsumptionReport
> org.openlmis.report.builder.AggregateConsumptionQueryBuilder#getQuery
How is the HTML report organised
The HTML report is designed with HTML and AngularJS. Basically all report format PDF, XLS and HTML use the same java REST endpoint to fetch a report data from the db. All HTML reports gets loaded by the following file
modules/openlmis-web/src/main/webapp/public/pages/reports/main/index.html
All report related resources like js and css files and also html partial pages will be loaded in to the above file using AngularJS routing feature.
When one browse to the consumption report URL on the site, AngularJs will load index.html page and render
modules/openlmis-web/src/main/webapp/public/pages/reports/main/partials/aggregate-consumption.html partial page in to it.
If one opens and see the aggregate-consumption.html file its possible to see HTML section that will render the list of report filters that we saw on the screenshot. For example, to add a program filter in aggregate-consumption.html we can add with the following code block.
<program-filter class="form-cell horizontalFilters" required="true"></program-filter>
The above code renders the program report filter in the report page. Each report filters are composed as angular directive. One can find the list of filter directive definitions at
modules/openlmis-web/src/main/webapp/public/js/reports/shared/directives/filters.js
Each report filter that one can see in the report can be found in filters.js. Those directives calls a back-end service to populate the filter control with data. The angular services that will be called by each filters and reports are found in
modules/openlmis-web/src/main/webapp/public/js/shared/services/extension-services.js
Once the report get loaded and when the report viewer selected data on all required filters, $scope.OnFilterChanged method will be called in the following js file
modules/openlmis-web/src/main/webapp/public/js/reports/main/controller/aggregate-consumption-controller.js
With in this AngularJS controller method, the java REST endpoint will be called to fetch the report data.
On the report page, there are two buttons at the top of the page for exporting the report on other formats. If a user wants to export the current HTML report to PDF, he/she need to click the button with the label PDF. When that button get clicked, $scope.exportReport method of the aggregate-consumption-controller.js file will be called.