Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added links to the reference modules

Table of Contents
outlinetrue
indent20px
stylenone
printablefalse

Anchor
BuildingReportsDev
BuildingReportsDev

...

Code Block
titleMyReportSetup.java

// 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);

...

You can add a custom web report renderer to your report by implementing the following components. The given code is not complete but it should allow you to implement your custom web report renderer.

  1. Implement WebReportRenderer interface

    Code Block
    titleMyReportWebRenderer.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 ("myReport Data Set".equals(def.getName())) {
    				ret.add(new RenderingMode(this, this.getLabel() , name, Integer.MAX_VALUE - 10));
    	    	}
    		}
    		return ret;
    	}
    	
    }
    
  2. Save WebReportRenderer

    Code Block
    titleMyReportSetup.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);
    
  3. To display results add a Controller and a JSP

    Code Block
    titleRenderMyReportController.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
    languageHTML
    titlerender.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>
    

Getting Started with the basicreportmodule

IMPORTANT-- This module does not exist as of .  For now, see the following modules for ideas:

rwandareports

pihmalawi

mdrtb