Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPORT-547:Delete The IndicatorReportRenderer #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,109 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.reporting.report.renderer;

import org.openmrs.api.context.Context;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.dataset.DataSet;
import org.openmrs.module.reporting.dataset.DataSetColumn;
import org.openmrs.module.reporting.dataset.DataSetRow;
import org.openmrs.module.reporting.indicator.dimension.CohortIndicatorAndDimensionResult;
import org.openmrs.module.reporting.report.ReportData;
import org.openmrs.module.reporting.report.ReportRequest;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* A Default Renderer Implementation that aims to support all ReportDefinitions
*/
//@Handler
@Localized("reporting.IndicatorReportRenderer")
public class IndicatorReportRenderer extends ReportDesignRenderer {

/**
* @see ReportRenderer#getRenderedContentType(org.openmrs.module.reporting.report.ReportRequest)
* @param request
*/
public String getRenderedContentType(ReportRequest request) {
return "text/html";
}

/**
* @see ReportRenderer#getFilename(org.openmrs.module.reporting.report.ReportRequest)
*/
@Override
public String getFilename(ReportRequest request) {
return getFilenameBase(request) + ".html";
}

/**
* @see ReportRenderer#render(ReportData, String, OutputStream)
*/
public void render(ReportData results, String argument, OutputStream out) throws IOException, RenderingException {

Writer w = new OutputStreamWriter(out,"UTF-8");

Map<String, Object> parameterValues = results.getContext().getParameterValues();


// For each dataset in the report
for (String dataSetKey : results.getDataSets().keySet()) {
DataSet dataset = results.getDataSets().get(dataSetKey);


//MapDataSet mapDataSet = (MapDataSet) dataset;
List<DataSetColumn> columns = dataset.getMetaData().getColumns();
w.write("<h1>" + results.getDefinition().getName() + "</h1>");
w.write("<span>" + results.getDefinition().getDescription() + "</span>");
w.write("<ul>");
for (String key : parameterValues.keySet()) {
String value = "";
Object object = parameterValues.get(key);
if (object instanceof Date) {
value = Context.getDateFormat().format((Date)object);
}
else {
value = object.toString();
}
w.write("<li>" + key + ": <strong>" + value + "</strong></li>");
}
w.write("</ul>");
w.write("<table id=\"indicator-report-dataset-" + dataSetKey +"\" class=\"display indicator-report-dataset\">");
for (DataSetColumn column : columns) {
w.write("<tr>");
w.write("<td>"+column.getName()+"</td>");
w.write("<td>"+column.getLabel()+"</td>");

// Wondering if you can even do this ... iterate over a dataset multiple times (once for each column?)
// If not, then we need to get the actual dataset data (i.e. MapDataSet).
for (DataSetRow row : dataset) {
Object cellValue = row.getColumnValue(column.getName());
if (cellValue instanceof CohortIndicatorAndDimensionResult) {
CohortIndicatorAndDimensionResult result = (CohortIndicatorAndDimensionResult) cellValue;
w.write("<td>" + ((cellValue != null) ? result.getValue() : "n/a") + "</td>");
}
else {
w.write("<td>" + ((cellValue != null) ? cellValue : "n/a") + "</td>");
}
}
w.write("</tr>");
}
w.write("</table>");
}
w.flush();
}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.reporting.web.controller.mapping.renderers;

import org.openmrs.annotation.Handler;
import org.openmrs.module.reporting.report.renderer.ReportRenderer;
import org.openmrs.module.reporting.report.renderer.IndicatorReportRenderer;

/**
* Handler that determines what page is used to edit/create a new IndicatorReportRenderer
*/

@Handler(supports=IndicatorReportRenderer.class, order=50)
public class IndicatorReportRendererMappingHandler extends RendererMappingHandler {

/**
* @see RendererMappingHandler#getCreateUrl(Class)
*/
public String getCreateUrl( Class<? extends ReportRenderer> rendererType ) {
return "/module/reporting/reports/renderers/nonConfigurableReportRenderer.form?type=" + rendererType.getName();
}

}