Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed unused parameters

...

  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>
    

...