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

internationalization rtl changes #19

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
Expand Up @@ -3,8 +3,10 @@
import net.sf.dynamicreports.jasper.builder.JasperConcatenatedReportBuilder;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.jasper.builder.export.Exporters;
import net.sf.dynamicreports.jasper.builder.export.JasperHtmlExporterBuilder;
import net.sf.dynamicreports.jasper.builder.export.JasperXlsExporterBuilder;
import net.sf.dynamicreports.report.exception.DRException;

import org.apache.log4j.Logger;
import org.bahmni.reports.template.Templates;
import org.bahmni.reports.web.ReportParams;
Expand All @@ -31,7 +33,13 @@ public void convertToResponseType(ReportParams reportParams,
JasperConcatenatedReportBuilder concatenatedReportBuilder) throws DRException {
switch (reportParams.getResponseType()) {
case TEXT_HTML:
concatenatedReportBuilder.toHtml(outputStream);
if ("ar".equalsIgnoreCase(reportParams.getLanguageTag())) {
JasperHtmlExporterBuilder htmlBuilder = Exporters.htmlExporter(outputStream);
htmlBuilder.setHtmlHeader("<html dir='rtl'>");
concatenatedReportBuilder.toHtml(htmlBuilder);
} else {
concatenatedReportBuilder.toHtml(outputStream);
}
break;
case APPLICATION_VND_MS_EXCEL:
concatenatedReportBuilder.toXlsx(outputStream);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
package org.bahmni.reports.template;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.column.Columns;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.constant.PageType;
import net.sf.dynamicreports.report.definition.datatype.DRIDataType;

import org.apache.commons.lang3.StringUtils;
import org.bahmni.reports.model.Config;
import org.bahmni.reports.model.Report;
import org.bahmni.reports.report.BahmniReportBuilder;

import java.sql.Connection;
import java.util.List;
import java.util.ResourceBundle;

public abstract class BaseReportTemplate<T extends Config> {
private static ResourceBundle localeBundle = null;

public static class col {
public static <V> TextColumnBuilder<V> column(String title, String fieldName, Class<V> valueClass) {
return net.sf.dynamicreports.report.builder.DynamicReports.col.column(title, fieldName, valueClass);
}

public static <V> TextColumnBuilder<V> column(String title, String fieldName, DRIDataType<? super V, V> dataType) {
return Columns.column(getResourceBundleLabel(title), fieldName, dataType);
}
}

public void setLocaleBundle(ResourceBundle lBundle) {
localeBundle = lBundle;
}

public ResourceBundle getLocaleBundle() {
return localeBundle;
}

public static String getResourceBundleLabel(String key) {
try {
String newKey = "";
if (!StringUtils.isEmpty(key)) {
newKey = key.trim();
newKey = newKey.replaceAll(" ", "_");
}
if (localeBundle!=null) {
return new String(localeBundle.getString(newKey).getBytes("8859_1"), "UTF-8");
}
} catch (Exception e) {
}
return key;
}

public abstract BahmniReportBuilder build(Connection connection, JasperReportBuilder jasperReport, Report<T> report,
String startDate, String endDate, List<AutoCloseable> resources, PageType pageType) throws Exception;
String startDate, String endDate, List<AutoCloseable> resources,
PageType pageType) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Date;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;
import static org.bahmni.reports.template.Templates.minimalColumnStyle;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;
Expand All @@ -30,7 +30,7 @@ public class IpdPatientsReportTemplate extends BaseReportTemplate<IpdPatientsCon
@Override
public BahmniReportBuilder build(Connection connection, JasperReportBuilder jasperReport, Report<IpdPatientsConfig> report,
String startDate, String endDate, List<AutoCloseable> resources, PageType pageType) throws SQLException {
CommonComponents.addTo(jasperReport, report, pageType);
CommonComponents.addTo(jasperReport, report, pageType);

PatientAttributesHelper patientAttributesHelper = new PatientAttributesHelper(report.getConfig().getPatientAttributes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.sf.dynamicreports.report.constant.PageType;
import net.sf.dynamicreports.report.constant.WhenNoDataType;
import org.apache.commons.lang3.StringUtils;
import org.bahmni.reports.BahmniReportsProperties;
import org.bahmni.reports.model.ObsCannedReportTemplateConfig;
import org.bahmni.reports.model.Report;
import org.bahmni.reports.model.UsingDatasource;
Expand All @@ -19,7 +18,7 @@
import java.util.ArrayList;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.sql.*;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Date;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;
import static org.bahmni.reports.template.Templates.minimalColumnStyle;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.sql.Types;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;

public class SqlReportTemplate extends BaseReportTemplate<SqlReportConfig> {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bahmni/reports/template/Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import net.sf.dynamicreports.report.definition.ReportParameters;

import java.awt.*;
import java.util.Locale;
//import java.util.Locale;

import static net.sf.dynamicreports.report.builder.DynamicReports.*;

Expand Down Expand Up @@ -100,7 +100,7 @@ public class Templates {
.setHeadingStyle(0, stl.style(rootStyle).bold());

reportTemplate = template()
.setLocale(Locale.ENGLISH)
//.setLocale(Locale.ENGLISH)
.setColumnStyle(columnStyle)
.setColumnTitleStyle(columnTitleStyle)
.setGroupStyle(groupStyle)
Expand All @@ -115,7 +115,7 @@ public class Templates {
.setTableOfContentsCustomizer(tableOfContentsCustomizer);

excelReportTemplate = template()
.setLocale(Locale.ENGLISH)
//.setLocale(Locale.ENGLISH)
.setColumnStyle(columnStyle)
.setColumnTitleStyle(columnTitleStyle)
.setGroupStyle(groupStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.sql.SQLException;
import java.util.List;

import static net.sf.dynamicreports.report.builder.DynamicReports.col;
//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;
import static org.bahmni.reports.template.Templates.minimalColumnStyle;
import static org.bahmni.reports.util.FileReaderUtil.getFileContent;
Expand Down Expand Up @@ -61,14 +61,14 @@ public BahmniReportBuilder build(Connection connection, JasperReportBuilder jasp
TextColumnBuilder<String> genderColumn = col.column("Gender", "Gender", type.stringType()).setStyle(minimalColumnStyle);

jasperReport.setShowColumnTitle(true)
.setResourceBundle(getLocaleBundle())
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL)
.columns(patientIdColumn, patientNameColumn, genderColumn);

addColumns(jasperReport, report.getConfig().getVisitAttributes(), minimalColumnStyle);
addColumns(jasperReport, report.getConfig().getPersonAttributes(), minimalColumnStyle);

String sqlString = getSqlString(personAttributes, visitAttributes, startDate, endDate);

JasperReportBuilder jasperReportBuilder = SqlUtil.executeReportWithStoredProc(jasperReport, connection, sqlString);
return new BahmniReportBuilder(jasperReportBuilder);
}
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/org/bahmni/reports/util/BahmniReportUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import net.sf.dynamicreports.report.base.DRReport;
import net.sf.dynamicreports.report.base.column.DRColumn;
import net.sf.dynamicreports.report.constant.PageType;
import net.sf.jasperreports.engine.JRParameter;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.bahmni.reports.BahmniReportsProperties;
import org.bahmni.reports.model.Config;
import org.bahmni.reports.model.GenericReportsConfig;
Expand All @@ -19,17 +22,41 @@
import java.sql.Connection;
import java.util.*;

//import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
//import static net.sf.dynamicreports.report.builder.DynamicReports.type;
//import static org.bahmni.reports.template.Templates.minimalColumnStyle;


public class BahmniReportUtil {

public static String getResourceBundleLabel(String key, ResourceBundle reportLocaleBundle) {
try {
String newKey = "";
if (!StringUtils.isEmpty(key)) {
newKey = key.trim();
newKey = newKey.replaceAll(" ", "_");
}
if (reportLocaleBundle!=null) {
return new String(reportLocaleBundle.getString(newKey).getBytes("8859_1"), "UTF-8");
}
} catch (Exception e) {
}
return key;
}

public static BahmniReportBuilder build(Report report, Connection connection,
String startDate, String endDate,
List<AutoCloseable> resources, PageType pageType,
BahmniReportsProperties bahmniReportsProperties) throws Exception {
BaseReportTemplate reportTemplate = report.getTemplate(bahmniReportsProperties);
ResourceBundle reportLocaleBundle = reportTemplate.getLocaleBundle();
JasperReportBuilder reportBuilder = report();
reportBuilder = new ReportHeader().add(reportBuilder, report.getName(), startDate, endDate);
reportBuilder = new ReportHeader().add(reportBuilder, getResourceBundleLabel(report.getName(), reportLocaleBundle), startDate, endDate);
reportBuilder = reportBuilder.setResourceBundle(reportLocaleBundle);
reportBuilder = reportBuilder.setLocale(reportLocaleBundle.getLocale());
//reportBuilder = reportBuilder.setParameter(JRParameter.REPORT_RESOURCE_BUNDLE, reportLocaleBundle);
//reportBuilder = reportBuilder.setParameter(JRParameter.REPORT_LOCALE, reportLocaleBundle.getLocale());
BahmniReportBuilder build = reportTemplate.build(connection, reportBuilder, report, startDate, endDate, resources, pageType);
excludeColumns(report.getConfig(), reportBuilder);
orderColumns(report.getConfig(), reportBuilder);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/bahmni/reports/web/ReportGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.sf.dynamicreports.jasper.builder.JasperConcatenatedReportBuilder;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.bahmni.reports.BahmniReportsProperties;
import org.bahmni.reports.filter.JasperResponseConverter;
Expand All @@ -17,6 +19,8 @@
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import static net.sf.dynamicreports.report.builder.DynamicReports.concatenatedReport;

Expand All @@ -41,10 +45,21 @@ public ReportGenerator(ReportParams reportParams, OutputStream outputStream, All
public void invoke() throws Exception {
ArrayList<AutoCloseable> resources = new ArrayList<>();
try {
Locale currentLoc = Locale.ENGLISH;
if (!StringUtils.isEmpty(reportParams.getLanguageTag())) {
currentLoc = Locale.forLanguageTag(reportParams.getLanguageTag());
}
ResourceBundle reportLocaleBundle = null;
if (currentLoc!=null) {
reportLocaleBundle = ResourceBundle.getBundle("ReportLabels", currentLoc);
}
Report report = Reports.find(reportParams.getName(), bahmniReportsProperties.getConfigFileUrl(),httpClient);
report.setHttpClient(httpClient);
validateResponseTypeSupportedFor(report, reportParams.getResponseType());
BaseReportTemplate reportTemplate = report.getTemplate(bahmniReportsProperties);
if (reportLocaleBundle!=null) {
reportTemplate.setLocaleBundle(reportLocaleBundle);
}
Connection connection = allDatasources.getConnectionFromDatasource(reportTemplate);
BahmniReportBuilder reportBuilder = BahmniReportUtil.build(report, connection, reportParams.getStartDate(),
reportParams.getEndDate(), resources, reportParams.getPaperSize(), bahmniReportsProperties);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/bahmni/reports/web/ReportParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ReportParams implements Serializable {
private String paperSize;
private String appName;
private String userName;
private String languageTag;

public String getStartDate() {
return startDate;
Expand Down Expand Up @@ -80,4 +81,12 @@ public String getUserName() {
public void setUserName(String userName) {
this.userName = userName;
}

public String getLanguageTag() {
return languageTag;
}

public void setLanguageTag(String languageTag) {
this.languageTag = languageTag;
}
}
39 changes: 39 additions & 0 deletions src/main/resources/ReportLabels.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Visit_Report=Visit Report
IPD_Patients_Report=IPD Patients Report
identifier=Patient Identifier
Patient_ID=Patient ID
Patient_Name=Patient Name
Gender=Gender
Age=Age
Patient_Id=Patient Id
Patient_Name=Patient Name
Birth_Date=Birth Date
First_Name=First Name
Family_Name=Family Name
Death_Date=Death Date
Cause_Of_Death=Cause Of Death
Address1=Address1
Address2=Address2
Address3=Address3
City/Village=City/Village
State/Province=State/Province
County/District=County/District
Registration_Date=Registration Date

New_OPD=New OPD
Old_OPD=Old OPD
Total_OPD=Total OPD
New_IPD=New IPD
Old_IPD=Old IPD
Total_IPD=Total IPD

Department=Department
Test=Test
Total_Count=Total Count
Positive_Count=Positive Count
Negative_Count=Negative Count

Diagnosis=Diagnosis
Date_of_Admission=Date of Admission
Date_of_Discharge=Date of Discharge
Visit_Type=Visit Type
38 changes: 38 additions & 0 deletions src/main/resources/ReportLabels_ar.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Visit_Report=جوجل
IPD_Patients_Report=جوج
identifier=جوجل
Patient_ID=جوج
Patient_Name=جوجل
Gender=شيلبا
Age=شيلبا
Birthdate=جوج
Birth_Date=جوج
First_Name=جوج
Family_Name=جوج
Death_Date=جوج
Cause_Of_Death=جوج
Address1=جوج
Address2=جوج
Address3=جوج
City/Village=جوج
State/Province=جوج
County/District=جوج
Registration_Date=جوج

New_OPD=شيلبا
Old_OPD=شيلبا
Total_OPD=شيلبا
New_IPD=شيلبا
Old_IPD=شيلبا
Total_IPD=شيلبا

Department=شيلبا
Test=شيلبا
Total_Count=شيلبا
Positive_Count=شيلبا
Negative_Count=شيلبا

Diagnosis=شيلبا
Date_of_Admission=شيلبا
Date_of_Discharge=شيلبا
Visit_Type=شيلبا