...
Code Block | ||
---|---|---|
| ||
// Tested with reporting module 0.6.3
PeriodIndicatorReportDefinition rd = new PeriodIndicatorReportDefinition();
rd.setName("myReport");
rd.setupDataSetDefinition();
// add cohort queries, indicators, etc. here
ReportDefinitionService rds = (ReportDefinitionService) Context.getService(ReportDefinitionService.class);
rds.saveDefinition(rd);
|
...
- Implement WebReportRenderer interface
Code Block title MyReportWebRenderer.java // Tested with reporting module 0.6.3 public class MyReportWebRenderer extends IndicatorReportWebRenderer implements WebReportRenderer { /** * @see org.openmrs.report.ReportRenderer#getLabel() */ @Override public String getLabel() { return "Web Report"; } /** * @see org.openmrs.module.reporting.web.renderers.WebReportRenderer#getLinkUrl(org.openmrs.module.reporting.report.definition.ReportDefinition) */ @Override public String getLinkUrl(ReportDefinition arg0) { return "module/myreports/render.form"; } /** * @see org.openmrs.report.ReportRenderer#getRenderingModes(org.openmrs.report.ReportDefinition) */ @Override public Collection<RenderingMode> getRenderingModes(ReportDefinition definition) { List<RenderingMode> ret = new ArrayList<RenderingMode>(); for (Map.Entry<String, Mapped<? extends DataSetDefinition>> e : definition.getDataSetDefinitions().entrySet()) { String name = e.getKey(); DataSetDefinition def = e.getValue().getParameterizable(); if ("My report Data Set".equals(def.getName())) { ret.add(new RenderingMode(this, this.getLabel() , name, Integer.MAX_VALUE - 10)); } } return ret; } }
- Save WebReportRenderer
Code Block title MyReportSetup.java final ReportDesign design = new ReportDesign(); design.setName(name); design.setReportDefinition(rd); design.setRendererType(MyReportWebRenderer.class); ReportService rs = Context.getService(ReportService.class); rs.saveReportDesign(design);
- To display results add a Controller and a JSP
Code Block title RenderMyReportController.java // Tested with reporting module 0.6.3 @Controller public class RenderMyReportController { @RequestMapping("/module/myreports/render") public String showReport(Model model, HttpSession session, @RequestParam(required = false, value = "start") Integer start, @RequestParam(required = false, value = "size") Integer size) { String renderArg = (String) session.getAttribute(ReportingConstants.OPENMRS_REPORT_ARGUMENT); ReportData data = null; try { data = (ReportData) session.getAttribute(ReportingConstants.OPENMRS_REPORT_DATA); } catch (ClassCastException ex) { // pass } if (data == null) return "redirect:../reporting/dashboard/index.form"; return null; }
Code Block language HTML title render.jsp <%-- This page assumes a ReportData object in the session as the attribute '__openmrs_report_data' --%> <c:set var="dataSetMaps" value="${__openmrs_report_data.dataSets}" /> <c:set var="mapDataSet" value="${dataSetMaps['defaultDataSet'].data}"/> <openmrs:portlet url="currentReportHeader" moduleId="reporting" parameters="showDiscardButton=true"/> <div> Indicator value: ${mapDataSet.columnValuesByKey["myKey"].value} </a> </div>
...