/** @see {@link ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)} */ @Test @Verifies( value = "should fail if the parent obs has values", method = "validate(java.lang.Object, org.springframework.validation.Errors)") public void validate_shouldFailIfParentObshasValues() throws Exception { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(18)); obs.setValueBoolean(false); obs.setValueCoded(Context.getConceptService().getConcept(18)); obs.setValueComplex("test"); obs.setValueDatetime(new Date()); obs.setValueDrug(Context.getConceptService().getDrug(3)); obs.setValueGroupId(getLoadCount()); obs.setValueModifier("test"); obs.setValueNumeric(1212.0); obs.setValueText("test"); Set<Obs> group = new HashSet<Obs>(); group.add(Context.getObsService().getObs(7)); group.add(Context.getObsService().getObs(9)); obs.setGroupMembers(group); Errors errors = new BindException(obs, "obs"); new ObsValidator().validate(obs, errors); Assert.assertFalse(errors.hasFieldErrors("person")); Assert.assertFalse(errors.hasFieldErrors("concept")); Assert.assertTrue(errors.hasFieldErrors("valueCoded")); Assert.assertTrue(errors.hasFieldErrors("valueDrug")); Assert.assertTrue(errors.hasFieldErrors("valueDatetime")); Assert.assertTrue(errors.hasFieldErrors("valueNumeric")); Assert.assertTrue(errors.hasFieldErrors("valueModifier")); Assert.assertTrue(errors.hasFieldErrors("valueText")); Assert.assertTrue(errors.hasFieldErrors("valueBoolean")); Assert.assertTrue(errors.hasFieldErrors("valueComplex")); }
/** * Sets the value for the obs from a string depending on the datatype of the question concept * * @param s the string to coerce to a boolean * @should set value as boolean if the datatype of the question concept is boolean * @should fail if the value of the string is null * @should fail if the value of the string is empty */ public void setValueAsString(String s) throws ParseException { if (log.isDebugEnabled()) log.debug("getConcept() == " + getConcept()); if (getConcept() != null && !StringUtils.isBlank(s)) { String abbrev = getConcept().getDatatype().getHl7Abbreviation(); if (abbrev.equals("BIT")) { setValueBoolean(Boolean.valueOf(s)); } else if (abbrev.equals("CWE")) { throw new RuntimeException("Not Yet Implemented"); } else if (abbrev.equals("NM") || abbrev.equals("SN")) { setValueNumeric(Double.valueOf(s)); } else if (abbrev.equals("DT") || abbrev.equals("TM") || abbrev.equals("TS")) { setValueDatetime(df.parse(s)); } else if (abbrev.equals("ST")) { setValueText(s); } else { throw new RuntimeException("Don't know how to handle " + abbrev); } } else { throw new RuntimeException("concept is null for " + this); } }
private void updateRevisedFlag( Obs diagnosisObs, boolean value, Concept bahmniDiagnosisRevisedConcept) { Obs obs = findOrCreateObs(diagnosisObs, bahmniDiagnosisRevisedConcept); obs.setValueBoolean(value); addToObsGroup(diagnosisObs, obs); }