/** * This method will <i>always</i> return true for ConceptNumeric objects that have a datatype of * Numeric * * @see org.openmrs.Concept#isNumeric() */ @Override public boolean isNumeric() { return "Numeric".equals(getDatatype().getName()); }
/** * @see ConceptService#getConceptDatatypeByName(String) */ @Test public void getConceptDatatypeByName_shouldReturnAnExactMatchOnName() { // given executeDataSet(INITIAL_CONCEPTS_XML); // when ConceptDatatype result = conceptService.getConceptDatatypeByName("Text"); // then assertEquals("Text", result.getName()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailIfQuestionDatatypeIsNeitherBooleanNorNumericNorCoded() throws Exception { 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|2|NM|19^FAVORITE FOOD, NON-CODED^99DCT||1|||||||||20080206"; Assert.assertEquals("Text", Context.getConceptService().getConcept(19).getDatatype().getName()); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
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);
/** * @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()); }
/** * @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#parseObs(Encounter,OBX,OBR,String) */ @Test public void parseObs_shouldAddCommentsToAnObservationFromNTESegments() 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\r" + "NTE|1|L|This is a comment"; // 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("This is a comment", newObservation.getComment()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailIfQuestionDatatypeIsCodedAndABooleanIsNotAValidAnswer() throws Exception { GlobalProperty trueConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_TRUE_CONCEPT, "7", "Concept id of the concept defining the TRUE boolean concept"); GlobalProperty falseConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FALSE_CONCEPT, "8", "Concept id of the concept defining the TRUE boolean concept"); Context.getAdministrationService().saveGlobalProperty(trueConceptGlobalProperty); Context.getAdministrationService().saveGlobalProperty(falseConceptGlobalProperty); 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|2|NM|4^CIVIL STATUS^99DCT||1|||||||||20080206"; Assert.assertEquals("Coded", Context.getConceptService().getConcept(4).getDatatype().getName()); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_CodedMatchingABooleanConceptForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsCoded() 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|2|NM|21^CIVIL STATUS^99DCT||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be coded Assert.assertEquals("Coded", Context.getConceptService().getConcept(21).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); // hacky way to get the newly added obs and make tests on it List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(Context.getConceptService().getTrueConcept(), newObservation.getValueCoded()); }
private String getDatatype(ObsField field) { return field.getQuestion() != null ? field.getQuestion().getDatatype().getName().toLowerCase() : ""; }
Assert.assertEquals("Boolean", Context.getConceptService().getConcept(18).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18)); Message hl7message = parser.parse(hl7string);
when(concept1.getName()).thenReturn(conceptName1); ConceptDatatype datatype1 = mock(ConceptDatatype.class); when(datatype1.getName()).thenReturn("Numeric"); when(concept1.getDatatype()).thenReturn(datatype1); field1.setQuestion(concept1);
/** * Given a FormField, infers the related widget from the ConceptDatatype associated with that FormField. */ public static WidgetTypeHint inferWidgetTypeHint(FormField formField) { ConceptDatatype dt = formField.getField().getConcept().getDatatype(); if (dt.isText()) { return WidgetTypeHint.TEXT; } else if (dt.isNumeric()) { return WidgetTypeHint.NUMBER; } else if (dt.isDate()) { return WidgetTypeHint.DATE; } else if (dt.isCoded()) { if (formField.getField().isSelectMultiple()) return WidgetTypeHint.CHECKBOX_LIST; else if (formField.getField().getDefaultValue() != null) return WidgetTypeHint.CHECKBOX; else return WidgetTypeHint.DROPDOWN; } else if (HtmlFormEntryConstants.COMPLEX_UUID.equals(dt.getUuid())) { return WidgetTypeHint.UPLOAD_WIDGET; } else { throw new IllegalArgumentException( "Autodetecting widget type from concept datatype not yet implemented for " + dt.getName()); } }
when(concept1.getName()).thenReturn(conceptName1); ConceptDatatype datatype1 = mock(ConceptDatatype.class); when(datatype1.getName()).thenReturn("Numeric"); when(concept1.getDatatype()).thenReturn(datatype1); field1.setQuestion(concept1); when(concept2.getName()).thenReturn(conceptName2); ConceptDatatype datatype2 = mock(ConceptDatatype.class); when(datatype2.getName()).thenReturn("Datetime"); when(concept2.getDatatype()).thenReturn(datatype2); field2.setQuestion(concept2);
@Test public void shouldGetAConceptDatatypeByName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/Coded"); SimpleObject result = deserialize(handle(req)); ConceptDatatype conceptDataType = service.getConceptDatatypeByName("Coded"); Assert.assertEquals(conceptDataType.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(conceptDataType.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldGetAConceptDatatypeByName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/Coded"); SimpleObject result = deserialize(handle(req)); ConceptDatatype conceptDataType = service.getConceptDatatypeByName("Coded"); Assert.assertEquals(conceptDataType.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(conceptDataType.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldGetAConceptDatatypeByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); ConceptDatatype conceptDataType = service.getConceptDatatypeByUuid(getUuid()); Assert.assertEquals(conceptDataType.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(conceptDataType.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldGetAConceptDatatypeByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); ConceptDatatype conceptDataType = service.getConceptDatatypeByUuid(getUuid()); Assert.assertEquals(conceptDataType.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(conceptDataType.getName(), PropertyUtils.getProperty(result, "name")); }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("hl7Abbreviation", getObject().getHl7Abbreviation()); assertPropEquals("retired", getObject().getRetired()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("hl7Abbreviation", getObject().getHl7Abbreviation()); assertPropEquals("retired", getObject().getRetired()); assertPropPresent("auditInfo"); }