diff --git a/api/src/main/java/org/openmrs/module/reporting/report/ReportRequest.java b/api/src/main/java/org/openmrs/module/reporting/report/ReportRequest.java index 4a20b510eb..5ec2731366 100644 --- a/api/src/main/java/org/openmrs/module/reporting/report/ReportRequest.java +++ b/api/src/main/java/org/openmrs/module/reporting/report/ReportRequest.java @@ -47,6 +47,7 @@ public class ReportRequest extends BaseOpenmrsObject { private Date renderCompleteDatetime; private Integer minimumDaysToPreserve; private String description; + private String clientTimezone; //***** CONSTRUCTORS ****** @@ -340,6 +341,14 @@ public void setDescription(String description) { this.description = description; } + public String getClientTimezone() { + return clientTimezone; + } + + public void setClientTimezone(String clientTimezone) { + this.clientTimezone = clientTimezone; + } + //***** ENUMS ***** /** diff --git a/api/src/main/java/org/openmrs/module/reporting/report/service/ReportServiceImpl.java b/api/src/main/java/org/openmrs/module/reporting/report/service/ReportServiceImpl.java index 41d9602c06..b1d16477fc 100644 --- a/api/src/main/java/org/openmrs/module/reporting/report/service/ReportServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/reporting/report/service/ReportServiceImpl.java @@ -10,6 +10,7 @@ package org.openmrs.module.reporting.report.service; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -23,6 +24,9 @@ import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.module.reporting.common.ObjectUtil; import org.openmrs.module.reporting.common.Timer; +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.evaluation.EvaluationContext; import org.openmrs.module.reporting.evaluation.EvaluationException; import org.openmrs.module.reporting.report.Report; @@ -52,6 +56,8 @@ import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -479,6 +485,26 @@ public Report runReport(ReportRequest request) { renderReportDataToBytes = !(renderer instanceof InteractiveReportRenderer); } + for (Map.Entry e : reportData.getDataSets().entrySet()) { + DataSet dataset = e.getValue(); + for (DataSetRow row : dataset ) { + for (Map.Entry dataSetColumn : row.getColumnValues().entrySet()) { + Object value = dataSetColumn.getValue(); + if (value instanceof LocalDateTime) { + LocalDateTime localDateTime = (LocalDateTime) value; + if (StringUtils.isNotEmpty(request.getClientTimezone())) { + ZoneId clientZoneId = ZoneId.of(request.getClientTimezone()); + localDateTime = ((LocalDateTime) value).atZone(ZoneId.systemDefault()) + .withZoneSameInstant(clientZoneId) + .toLocalDateTime(); + } + Date dateValue = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + dataSetColumn.setValue(dateValue); + } + } + } + } + if (renderReportDataToBytes) { logReportMessage(request, "Generating Rendered Report...."); ReportRenderer renderer = request.getRenderingMode().getRenderer(); @@ -838,4 +864,4 @@ public void setReportData(ReportData reportData) { this.reportData = reportData; } } -} \ No newline at end of file +} diff --git a/api/src/main/resources/ReportRequest.hbm.xml b/api/src/main/resources/ReportRequest.hbm.xml index 7a78c49134..11afca48a1 100644 --- a/api/src/main/resources/ReportRequest.hbm.xml +++ b/api/src/main/resources/ReportRequest.hbm.xml @@ -57,6 +57,7 @@ + diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index 75b128df0d..9685b7bc7b 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -289,6 +289,18 @@ + + + + + + Add client_timezone property to ReportRequest + + + + + +