@SuppressWarnings("unused") public static JSONObject createJsonObservation(Obs obs) { JSONObject jsonObs = new JSONObject(); jsonObs.put("observation_id", obs.getObsId()); jsonObs.put("concept_name", obs.getConcept().getDisplayString()); Date obsDate = obs.getObsDatetime() == null ? new Date() : obs.getObsDatetime(); SimpleDateFormat formatDateJava = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); String dateStr = obsDate.getTime() + ""; jsonObs.put("date", dateStr); if (obs.getConcept().getDatatype().isNumeric()) { // ADD MORE DATATYPES ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(obs.getConcept().getId()); jsonObs.put("units_of_measurement", conceptNumeric.getUnits()); jsonObs.put("absolute_high", conceptNumeric.getHiAbsolute()); jsonObs.put("absolute_low", conceptNumeric.getLowAbsolute()); jsonObs.put("critical_high", conceptNumeric.getHiCritical()); jsonObs.put("critical_low", conceptNumeric.getLowCritical()); jsonObs.put("normal_high", conceptNumeric.getHiNormal()); jsonObs.put("normal_low", conceptNumeric.getLowNormal()); } jsonObs.put("value_type", obs.getConcept().getDatatype().getName()); jsonObs.put("value", obs.getValueAsString(Context.getLocale())); jsonObs.put("location", obs.getLocation().getDisplayString()); jsonObs.put("creator", obs.getCreator().getDisplayString()); Set<EncounterProvider> encounterProviders = obs.getEncounter().getEncounterProviders(); if (encounterProviders != null && encounterProviders.iterator().hasNext()) { EncounterProvider provider = encounterProviders.iterator().next(); if (provider.getProvider() != null) { jsonObs.put("provider", provider.getProvider().getName()); } } SearchAPI searchAPI = SearchAPI.getInstance(); if (!searchAPI.getSearchPhrase().getPhrase().equals("") && !searchAPI.getSearchPhrase().getPhrase().equals("*")) { for (ChartListItem item : searchAPI.getResults()) { if (item != null && item instanceof ObsItem && ((ObsItem) item).getObsId() != null) { if (((ObsItem) item).getObsId() == obs.getObsId()) { jsonObs.put("chosen", "true"); } } } } return jsonObs; }