@Test public void getValueAsString_shouldReturnDateInCorrectFormat() throws Exception { Obs obs = new Obs(); obs.setValueDatetime(new Date()); Concept cn = new Concept(); ConceptDatatype cdt = new ConceptDatatype(); cdt.setHl7Abbreviation("DT"); cn.setDatatype(cdt); obs.setConcept(cn); Date utilDate = new Date(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String dateString = dateFormat.format(utilDate); Assert.assertEquals(dateString, obs.getValueAsString(Locale.US)); }
/** * @see Obs#getValueAsString(Locale) */ @Test public void getValueAsString_shouldNotUseThousandSeparator() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(123456789.0); String str = "123456789.0"; Assert.assertEquals(str, obs.getValueAsString(Locale.ENGLISH)); }
/** * @see Obs#getValueAsString(Locale) */ @Test public void getValueAsString_shouldUseCommasOrDecimalPlacesDependingOnLocale() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(123456789.3); String str = "123456789,3"; Assert.assertEquals(str, obs.getValueAsString(Locale.GERMAN)); }
@Test public void getValueAsString_shouldNotReturnLongDecimalNumbersAsScientificNotation() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(123456789.0); String str = "123456789.0"; Assert.assertEquals(str, obs.getValueAsString(Locale.US)); }
/** * @see Obs#getValueAsString(Locale) */ @Test public void getValueAsString_shouldReturnRegularNumberForSizeOfZeroToOrGreaterThanTenDigits() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(1234567890.0); String str = "1234567890.0"; Assert.assertEquals(str, obs.getValueAsString(Locale.ENGLISH)); }
/** * @see Obs#getValueAsString(Locale) */ @Test public void getValueAsString_shouldReturnRegularNumberIfDecimalPlacesAreAsHighAsSix() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(123456789.012345); String str = "123456789.012345"; Assert.assertEquals(str, obs.getValueAsString(Locale.ENGLISH)); }
sb.append(", "); sb.append(groupMember.getValueAsString(locale));
@Test public void getValueAsString_shouldReturnNonPreciseValuesForNumericConcepts() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(25.125); ConceptNumeric cn = new ConceptNumeric(); ConceptDatatype cdt = new ConceptDatatype(); cdt.setHl7Abbreviation("NM"); cn.setDatatype(cdt); cn.setAllowDecimal(false); obs.setConcept(cn); String str = "25"; Assert.assertEquals(str, obs.getValueAsString(Locale.US)); }
@Test public void getValueAsString_shouldReturnLocalizedCodedConcept() throws Exception { ConceptDatatype cdt = new ConceptDatatype(); cdt.setHl7Abbreviation("CWE"); Concept cn = new Concept(); cn.setDatatype(cdt); cn.addName(new ConceptName(VERO, Locale.ITALIAN)); Obs obs = new Obs(); obs.setValueCoded(cn); obs.setConcept(cn); obs.setValueCodedName(new ConceptName("True", Locale.US)); Assert.assertEquals(VERO, obs.getValueAsString(Locale.ITALIAN)); }
/** * * format the obs value * * @param locale * @param o * @return */ public static String getObsValueAsString(Locale locale, Obs o){ String ret = ""; if (o.getConcept() != null){ String abbrev = o.getConcept().getDatatype().getHl7Abbreviation(); if (abbrev.equals("DT")){ return (o.getValueDatetime() == null ? "" : Context.getDateFormat().format(o.getValueDatetime())); } else if (abbrev.equals("TS") && o.getValueDatetime() != null){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(o.getValueDatetime()); } else { ret = o.getValueAsString(locale); } } return ret; }
private String printObsHelper(Obs obs) { return obs.getConcept().getName(Context.getLocale()) + " = " + obs.getValueAsString(Context.getLocale()); }
/** * Display string for Obs * * @param obs * @return String ConceptName = value */ @PropertyGetter("display") public String getDisplayString(Obs obs) { if (obs.getConcept() == null) return ""; return obs.getConcept().getName() + ": " + obs.getValueAsString(Context.getLocale()); }
String oldString = existingObs.getValueAsString(Context.getLocale()); String newString = newObs.getValueAsString(Context.getLocale()); if (log.isDebugEnabled() && concept != null) { log.debug("For concept " + concept.getName(Context.getLocale()) + ": " + oldString + " -> " + newString);
/** * Removes any Obs that are empty or which have only empty children */ public static void removeEmptyObs(Collection<Obs> obsList) { if (obsList != null) { Set<Obs> obsToRemove = new HashSet<Obs>(); for (Obs o : obsList) { removeEmptyObs(o.getGroupMembers()); boolean valueEmpty = StringUtils.isEmpty(o.getValueAsString(Context.getLocale())); boolean membersEmpty = o.getGroupMembers() == null || o.getGroupMembers().isEmpty(); if (valueEmpty && membersEmpty) { obsToRemove.add(o); } } for (Obs o : obsToRemove) { if (o.getObsGroup() != null) { o.getObsGroup().removeGroupMember(o); o.setObsGroup(null); } if (o.getEncounter() != null) { o.getEncounter().removeObs(o); o.setEncounter(null); } obsList.remove(o); } } }
public void printEncounterCreated() { if (encounterCreated == null) { System.out.println("No encounter created"); } else { System.out.println("=== Encounter created ==="); System.out.println("Created: " + encounterCreated.getDateCreated() + " Edited: " + encounterCreated.getDateChanged()); System.out.println("Date: " + encounterCreated.getEncounterDatetime()); System.out.println("Location: " + encounterCreated.getLocation().getName()); System.out.println("Provider: " + getProvider(encounterCreated).getPersonName()); System.out.println(" (obs)"); Collection<Obs> obs = encounterCreated.getAllObs(false); if (obs == null) { System.out.println("None"); } else { for (Obs o : obs) { System.out.println(o.getConcept().getName() + " -> " + o.getValueAsString(Context.getLocale())); } } } }
public boolean matches(Obs obs) { if (!obs.getConcept().getConceptId().equals(conceptId)) { return false; } String valueAsString = null; if(value instanceof Date){ valueAsString = formatObsValueDate((Date)value); }else{ valueAsString = TestUtil.valueAsStringHelper(value); } return OpenmrsUtil.nullSafeEquals(valueAsString, obs.getValueAsString(Context.getLocale())); } }
private void assertObsExists(boolean lookForVoided, int conceptId, Object value) { // quick checks Assert.assertNotNull(encounterCreated); Collection<Obs> temp = encounterCreated.getAllObs(lookForVoided); Assert.assertNotNull(temp); String valueAsString = null; if(value instanceof Date){ valueAsString = formatObsValueDate((Date)value); }else{ valueAsString = TestUtil.valueAsStringHelper(value); } for (Obs obs : temp) { if (lookForVoided && !obs.isVoided()) continue; if (obs.getConcept().getConceptId() == conceptId) { if (valueAsString == null) return; if (valueAsString.equals(obs.getValueAsString(Context.getLocale()))) return; } } Assert.fail("Could not find obs with conceptId " + conceptId + " and value " + valueAsString); }