/** * @see Obs#getValueAsBoolean() */ @Test public void getValueAsBoolean_shouldReturnNullForValue_numericConceptsIfValueIsNeither1Nor0() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(24.8); Assert.assertNull(obs.getValueAsBoolean()); }
/** * @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 saveObs_shouldNotChangeStatusOfPreliminaryWhenModifyingAnObs() throws Exception { Obs existing = obsService.getObs(9); existing.setValueNumeric(175.0); Obs newObs = obsService.saveObs(existing, "testing"); assertThat(newObs.getValueNumeric(), is(175.0)); assertThat(newObs.getStatus(), is(Obs.Status.PRELIMINARY)); }
/** * @see Obs#getValueAsBoolean() */ @Test public void getValueAsBoolean_shouldReturnFalseForValue_numericConceptsIfValueIs0() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(0.0); Assert.assertEquals(false, obs.getValueAsBoolean()); }
@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#getValueAsBoolean() */ @Test public void getValueAsBoolean_shouldReturnTrueForValue_numericConceptsIfValueIs1() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(1.0); Assert.assertEquals(true, obs.getValueAsBoolean()); }
/** * @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)); }
/** * @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)); }
@Test public void saveObs_shouldSetStatusToAmendedWhenModifyingAnObsWithFinalStatus() throws Exception { Obs existing = obsService.getObs(7); existing.setValueNumeric(60.0); Obs amended = obsService.saveObs(existing, "testing"); assertThat(amended.getValueNumeric(), is(60.0)); assertThat(amended.getStatus(), is(Obs.Status.AMENDED)); assertThat(existing.getStatus(), is(Obs.Status.FINAL)); }
@Test public void saveObs_shouldLetYouChangeStatusFromPreliminaryToFinalWhenModifyingAnObs() throws Exception { Obs existing = obsService.getObs(9); existing.setValueNumeric(175.0); existing.setStatus(Obs.Status.FINAL); Obs newObs = obsService.saveObs(existing, "testing"); assertThat(newObs.getValueNumeric(), is(175.0)); assertThat(newObs.getStatus(), is(Obs.Status.FINAL)); }
private Obs buildObs() { Obs newObs = new Obs(); newObs.setConcept(Context.getConceptService().getConcept(1)); newObs.setValueNumeric(50d); newObs.setLocation(new Location(2)); return newObs; }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldVoidTheGivenObsInTheDatabase() { Obs obs = Context.getObsService().getObs(7); obs.setValueNumeric(1.0); Context.getObsService().saveObs(obs, "just testing"); // fetch the obs from the database again obs = Context.getObsService().getObs(7); Assert.assertTrue(obs.getVoided()); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfAllValuesPresent() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasErrors()); }
@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)); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfPersonIdIsNull() { Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.hasFieldErrors("person")); assertFalse(errors.hasFieldErrors("concept")); assertFalse(errors.hasFieldErrors("obsDatetime")); assertFalse(errors.hasFieldErrors("valueNumeric")); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfConceptIsNull() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasFieldErrors("person")); assertTrue(errors.hasFieldErrors("concept")); assertFalse(errors.hasFieldErrors("obsDatetime")); assertFalse(errors.hasFieldErrors("valueNumeric")); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldSetCreatorAndDateCreatedOnNewObs() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o.setValueNumeric(50d); Context.getObsService().saveObs(o, null); assertNotNull(o.getDateCreated()); assertNotNull(o.getCreator()); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldCopyTheFormNamespaceAndPathFieldInEditedObs() { executeDataSet(INITIAL_OBS_XML); Obs obs = Context.getObsService().getObs(7); obs.setValueNumeric(5.0); Obs o2 = Context.getObsService().saveObs(obs, "just testing"); Assert.assertNotNull(obs.getFormFieldNamespace()); // fetch the obs from the database again obs = Context.getObsService().getObs(o2.getObsId()); Assert.assertNotNull(obs.getFormFieldNamespace()); Assert.assertNotNull(obs.getFormFieldPath()); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfObsDatetimeIsNull() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setValueNumeric(1.0); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasFieldErrors("person")); assertFalse(errors.hasFieldErrors("concept")); assertTrue(errors.hasFieldErrors("obsDatetime")); assertFalse(errors.hasFieldErrors("valueNumeric")); }