From 9887a4949e6fe0163a4156939b8cf04758fcc2fb Mon Sep 17 00:00:00 2001 From: gita cliff Date: Mon, 11 Nov 2019 11:42:58 +0300 Subject: [PATCH] REPORT-602:Add the ability to specify the locale in the EvaluationContext --- .../evaluation/EvaluationContext.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/reporting/evaluation/EvaluationContext.java b/api/src/main/java/org/openmrs/module/reporting/evaluation/EvaluationContext.java index 59dcf0bbb6..a15a14a935 100644 --- a/api/src/main/java/org/openmrs/module/reporting/evaluation/EvaluationContext.java +++ b/api/src/main/java/org/openmrs/module/reporting/evaluation/EvaluationContext.java @@ -9,6 +9,12 @@ */ package org.openmrs.module.reporting.evaluation; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codehaus.jackson.annotate.JsonIgnore; @@ -18,6 +24,7 @@ import org.openmrs.api.APIException; import org.openmrs.api.context.Context; import org.openmrs.calculation.patient.PatientCalculationContext; +import org.openmrs.module.reporting.ReportingConstants; import org.openmrs.module.reporting.cohort.CohortUtil; import org.openmrs.module.reporting.cohort.PatientIdSet; import org.openmrs.module.reporting.common.DateUtil; @@ -28,11 +35,6 @@ import org.openmrs.module.reporting.evaluation.parameter.Parameterizable; import org.openmrs.module.reporting.query.IdSet; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - /** * The EvaluationContext provides the following capabilities: * - A baseCohort, i.e. the universe of patients relevant to this context (defaults to all patients) @@ -235,6 +237,7 @@ public void setNow(Date date) { /** * Add a value to the cache with a given key */ + @Override public void addToCache(String key, Object value) { getCache().put(key, value); } @@ -244,6 +247,7 @@ public void addToCache(String key, Object value) { * * @param key */ + @Override public void removeFromCache(String key) { getCache().remove(key); } @@ -253,6 +257,7 @@ public void removeFromCache(String key) { * * @param key */ + @Override public Object getFromCache(String key) { return getCache().get(key); } @@ -404,4 +409,12 @@ public long getEvaluationId() { public int getEvaluationLevel() { return evaluationLevel; } + + public static Locale getDefaultLocale(Locale locale) { + if (locale == null) { + locale = ReportingConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE(); + return locale; + } + return locale = Context.getLocale(); + } }