diff --git a/omod/src/main/java/org/openmrs/module/reporting/web/taglib/FormatTag.java b/omod/src/main/java/org/openmrs/module/reporting/web/taglib/FormatTag.java index 8e1be720db..ac007bdafa 100644 --- a/omod/src/main/java/org/openmrs/module/reporting/web/taglib/FormatTag.java +++ b/omod/src/main/java/org/openmrs/module/reporting/web/taglib/FormatTag.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.lang.reflect.Method; import java.util.Collection; +import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -48,57 +49,57 @@ public class FormatTag extends TagSupport { public static final long serialVersionUID = 1L; - + private final Log log = LogFactory.getLog(getClass()); - + private String var; - + private Object object; - + private Date date; - + private Integer conceptId; - + private Concept concept; - + private Obs obsValue; - + private Integer userId; - + private User user; - + private Integer encounterId; - + private Encounter encounter; - + private Integer encounterTypeId; - + private EncounterType encounterType; - + private Integer locationId; - + private Location location; - + private String string; - + private ReportData reportData; - + private DataSet dataSet; - + private Cohort cohort; - + public static String format(Object object) { StringBuilder sb = new StringBuilder(); new FormatTag().printObject(sb, object); return sb.toString(); } - + public int doStartTag() { StringBuilder sb = new StringBuilder(); if (object != null) { printObject(sb, object); } - + if (date != null) printDate(sb, date); @@ -107,48 +108,48 @@ public int doStartTag() { if (concept != null) { printConcept(sb, concept); } - + if (obsValue != null) printObsValue(sb, obsValue); - + if (userId != null) user = Context.getUserService().getUser(userId); if (user != null) printUser(sb, user); - + if (encounterId != null) encounter = Context.getEncounterService().getEncounter(encounterId); if (encounter != null) { printEncounter(sb, encounter); } - + if (encounterTypeId != null) encounterType = Context.getEncounterService().getEncounterType(encounterTypeId); if (encounterType != null) { printEncounterType(sb, encounterType); } - + if (locationId != null) location = Context.getLocationService().getLocation(locationId); if (location != null) { printLocation(sb, location); } - + if (reportData != null) { printReportData(sb, reportData); } - + if (dataSet != null) { printDataSet(sb, null, dataSet); } - + if (cohort != null) { printCohort(sb, cohort); } - + if (string != null) sb.append(string); - + if (StringUtils.hasText(var)) { pageContext.setAttribute(var, sb.toString()); } else { @@ -202,7 +203,7 @@ private void printObject(StringBuilder sb, Object o) { printMap(sb, ((BaseData)o).getData()); } else if (o instanceof IdSet) { printCollection(sb, ((IdSet)o).getMemberIds()); - } + } else { sb.append(ObjectUtil.format(o)); } @@ -228,7 +229,7 @@ private void printResult(StringBuilder sb, Result result) { /** * formats a date and prints it to sb - * + * * @param sb * @param date */ @@ -238,7 +239,7 @@ private void printDate(StringBuilder sb, Date date) { /** * formats a location and prints it to sb - * + * * @param sb * @param location */ @@ -248,7 +249,7 @@ private void printLocation(StringBuilder sb, Location location) { /** * formats an encounter type and prints it to sb - * + * * @param sb * @param encounterType */ @@ -258,27 +259,27 @@ private void printEncounterType(StringBuilder sb, EncounterType encounterType) { /** * formats a user and prints it to sb - * + * * @param sb * @param u */ private void printUser(StringBuilder sb, User u) { sb.append(u.getPersonName()); } - + /** * formats a user and prints it to sb - * + * * @param sb * @param u */ private void printUser(StringBuilder sb, Person u) { sb.append(u.getPersonName()); } - + /** * Formats a ReportData and prints it to sb - * + * * @param sb * @param reportData */ @@ -288,11 +289,11 @@ private void printReportData(StringBuilder sb, ReportData reportData) { printDataSet(sb, ds.getKey(), ds.getValue()); } } - - + + /** * Formats a DataSet and prints it to sb - * + * * @param sb * @param title * @param dataSet @@ -335,10 +336,10 @@ private void printDataSet(StringBuilder sb, String title, DataSet dataSet) { sb.append(""); sb.append(""); } - + /** * Formats a DataSet and prints it to sb - * + * * @param sb * @param title * @param dataSet @@ -352,17 +353,17 @@ private void printCohortDimensionResult(StringBuilder sb, CohortDimensionResult } sb.append(""); } - + /** * formats a cohort to sb - * + * * @param sb * @param cohort */ private void printCohort(StringBuilder sb, Cohort cohort) { - sb.append(cohort.size() + " patients"); + printCollection(sb, cohort.getMemberIds()); } - + private void printObsValue(StringBuilder sb, Obs obsValue) { sb.append(obsValue.getValueAsString(Context.getLocale())); } @@ -379,7 +380,7 @@ private void printEncounter(StringBuilder sb, Encounter encounter) { sb.append(" | "); printDate(sb, encounter.getEncounterDatetime()); sb.append(" | "); - + try { Method method = encounter.getClass().getMethod("getProvider", null); Object provider = method.invoke(encounter, null); @@ -389,7 +390,7 @@ private void printEncounter(StringBuilder sb, Encounter encounter) { //should be a newer version that removed the getProvider method } } - + private void printMap(StringBuilder sb, Map, ?> m) { if (m != null) { sb.append("
" + Context.getMessageSourceService().getMessage("reporting.ids") + " |
---|