/** * Coerces a value to a Boolean representation * * @return Boolean representation of the obs value * @should return true for value_numeric concepts if value is 1 * @should return false for value_numeric concepts if value is 0 * @should return null for value_numeric concepts if value is neither 1 nor 0 */ public Boolean getValueAsBoolean() { if (getValueCoded() != null) { if (getValueCoded().equals(Context.getConceptService().getTrueConcept())) { return Boolean.TRUE; } else if (getValueCoded().equals(Context.getConceptService().getFalseConcept())) { return Boolean.FALSE; } } else if (getValueNumeric() != null) { if (getValueNumeric() == 1) { return Boolean.TRUE; } else if (getValueNumeric() == 0) { return Boolean.FALSE; } } //returning null is preferred to defaulting to false to support validation of user input is from a form return null; }
if (getValueNumeric() == null) { return ""; } else { ConceptNumeric cn = (ConceptNumeric) getConcept(); if (!cn.getAllowDecimal()) { double d = getValueNumeric(); int i = (int) d; return Integer.toString(i); } else { df.format(getValueNumeric()); if (getValueNumeric() != null) { return df.format(getValueNumeric()); } else if (getValueCoded() != null) { if (getValueDrug() != null) {
@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)); }
@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)); }
protected Integer getLargestDoseValue(List<Obs> obsList) { Double largestDoseValue = null; for (Obs obs : obsList) { Double obsValue = obs.getValueNumeric(); if (obsValue != null) { if (largestDoseValue == null || obsValue > largestDoseValue) { largestDoseValue = obsValue; } } } if (largestDoseValue != null) { return largestDoseValue.intValue(); } return null; }
.getValueNumeric(), obs.getValueText(), obs);
@Test public void newInstance_shouldCopyMostFields() throws Exception { Obs obs = new Obs(); obs.setStatus(Obs.Status.PRELIMINARY); obs.setInterpretation(Obs.Interpretation.LOW); obs.setConcept(new Concept()); obs.setValueNumeric(1.2); Obs copy = Obs.newInstance(obs); // these fields are not copied assertThat(copy.getObsId(), nullValue()); assertThat(copy.getUuid(), not(obs.getUuid())); // other fields are copied assertThat(copy.getConcept(), is(obs.getConcept())); assertThat(copy.getValueNumeric(), is(obs.getValueNumeric())); assertThat(copy.getStatus(), is(obs.getStatus())); assertThat(copy.getInterpretation(), is(obs.getInterpretation())); // TODO test that the rest of the fields are set }
if (obs.getValueNumeric() != null) { errors.rejectValue("valueNumeric", "error.not.null"); && obs.getValueModifier() == null && obs.getValueNumeric() == null && obs.getValueText() == null && obs.getComplexData() == null) { errors.reject("error.noValue"); errors.rejectValue("groupMembers", "Obs.error.inGroupMember"); } else if (dt.isNumeric() && obs.getValueNumeric() == null) { if (atRootNode) { errors.rejectValue("valueNumeric", "error.null"); ConceptNumeric cn = Context.getConceptService().getConceptNumeric(c.getConceptId()); if (!cn.getAllowDecimal() && Math.ceil(obs.getValueNumeric()) != obs.getValueNumeric()) { if (atRootNode) { errors.rejectValue("valueNumeric", "Obs.error.precision"); if (cn.getHiAbsolute() != null && cn.getHiAbsolute() < obs.getValueNumeric()) { if (atRootNode) { errors.rejectValue("valueNumeric", "error.outOfRange.high"); if (cn.getLowAbsolute() != null && cn.getLowAbsolute() > obs.getValueNumeric()) { if (atRootNode) { errors.rejectValue("valueNumeric", "error.outOfRange.low");
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(450, newObservation.getValueNumeric().intValue()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumericAndTheAnswerIsEither0Or1() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(1, newObservation.getValueNumeric().intValue()); }
@Test public void earliestObs_shouldReturnTheFirstObsGivenThePassedConcepUuid() throws Exception { VelocityFunctions functions = setupFunctionsForPatient(7); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Obs earliestWeight = functions.earliestObs("c607c80f-1ea9-4da3-bb88-6276ce8868dd"); Assert.assertEquals(50, earliestWeight.getValueNumeric().intValue()); // this is a bit of a hack because for some reason the obsDatetime set for this obs in the standard test dataset changed between 1.7 and 1.8 Assert.assertTrue("Obs datetime not correct", (StringUtils.equals("2008-08-01", df.format(earliestWeight.getObsDatetime())) || StringUtils.equals("2008-07-01", df.format(earliestWeight.getObsDatetime())))); }
/** * @see VelocityFunctions#earliestObs(Integer) * @verifies return the first obs given the passed conceptId */ @Test public void earliestObs_shouldReturnTheFirstObsGivenThePassedConceptId() throws Exception { VelocityFunctions functions = setupFunctionsForPatient(7); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Obs earliestWeight = functions.earliestObs(5089); Assert.assertEquals(50, earliestWeight.getValueNumeric().intValue()); // this is a bit of a hack because for some reason the obsDatetime set for this obs in the standard test dataset changed between 1.7 and 1.8 Assert.assertTrue("Obs datetime not correct", (StringUtils.equals("2008-08-01", df.format(earliestWeight.getObsDatetime())) || StringUtils.equals("2008-07-01", df.format(earliestWeight.getObsDatetime())))); }
/** * @see VelocityFunctions#latestObs(Integer) * @verifies return the most recent obs given the passed conceptId */ @Test public void latestObs_shouldReturnTheMostRecentObsGivenThePassedConceptId() throws Exception { VelocityFunctions functions = setupFunctionsForPatient(7); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Obs earliestWeight = functions.latestObs(5089); Assert.assertEquals(61, earliestWeight.getValueNumeric().intValue()); Assert.assertEquals("2008-08-19", df.format(earliestWeight.getObsDatetime())); }
protected void checkBooleanObsValue(Obs obs, boolean expected) { if (OpenmrsConstants.OPENMRS_VERSION_SHORT.equals("1.6")) { Double expectedValue = expected ? 1.0 : 0.0; Assert.assertEquals(expectedValue, obs.getValueNumeric()); } else { String expectedGpProperty = expected ? "concept.true" : "concept.false"; String conceptId = Context.getAdministrationService().getGlobalProperty(expectedGpProperty); Assert.assertEquals(conceptId, obs.getValueCoded().getConceptId().toString()); } } }
@Test public void latestObs_shouldReturnTheMostRecentObsGivenThePassedConceptUuid() throws Exception { VelocityFunctions functions = setupFunctionsForPatient(7); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Obs earliestWeight = functions.latestObs("c607c80f-1ea9-4da3-bb88-6276ce8868dd"); Assert.assertEquals(61, earliestWeight.getValueNumeric().intValue()); Assert.assertEquals("2008-08-19", df.format(earliestWeight.getObsDatetime())); }
@Test public void allObs_shouldReturnObsWithGivenConcept() throws Exception { Encounter encounter = Context.getEncounterService().getEncounter(4); VelocityFunctions functions = setupFunctionsForPatient(7); List<Obs> allObs = functions.allObs(encounter, "5089"); assertThat(allObs.size(), is(1)); assertThat(allObs.get(0).getValueNumeric(), is(55d)); assertThat(functions.allObs(encounter, "3").size(), is(0)); }
assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime()); assertEquals(valueCoded, saved.getValueCoded()); assertEquals(valueNumeric, saved.getValueNumeric()); assertEquals(valueModifier, saved.getValueModifier()); assertEquals(valueText, saved.getValueText());
newObs.setValueGroupId(obsToCopy.getValueGroupId()); newObs.setValueDatetime(obsToCopy.getValueDatetime()); newObs.setValueNumeric(obsToCopy.getValueNumeric()); newObs.setValueModifier(obsToCopy.getValueModifier()); newObs.setValueText(obsToCopy.getValueText());
@Test public void getObs_shouldReturnObsWithGivenConcept() throws Exception { Encounter encounter = Context.getEncounterService().getEncounter(4); VelocityFunctions functions = setupFunctionsForPatient(7); assertThat(functions.getObs(encounter, "5089").getValueNumeric(), is(55d)); assertThat(functions.getObs(encounter, "3"), nullValue()); }