/** * Utility method which loads the previous version of a concept to check if the datatype has * changed. * * @param concept to be modified * @return boolean indicating change in the datatype */ private boolean hasDatatypeChanged(Concept concept) { ConceptDatatype oldConceptDatatype = dao.getSavedConceptDatatype(concept); return !oldConceptDatatype.equals(concept.getDatatype()); }
String abbrev = getConcept().getDatatype().getHl7Abbreviation(); if ("BIT".equals(abbrev)) { setValueBoolean(Boolean.valueOf(s));
/** * Returns the boolean value if the concept of this obs is of boolean datatype * * @return true or false if value is set otherwise null * @should return true if value coded answer concept is true concept * @should return false if value coded answer concept is false concept */ public Boolean getValueBoolean() { if (getConcept() != null && valueCoded != null && getConcept().getDatatype().isBoolean()) { Concept trueConcept = Context.getConceptService().getTrueConcept(); return trueConcept != null && valueCoded.getId().equals(trueConcept.getId()); } return null; }
/** * Sets the value of this obs to the specified valueBoolean if this obs has a boolean concept. * * @param valueBoolean the boolean value matching the boolean coded concept to set to */ public void setValueBoolean(Boolean valueBoolean) { if (getConcept() != null && getConcept().getDatatype() != null && getConcept().getDatatype().isBoolean()) { if (valueBoolean != null) { setValueCoded(valueBoolean ? Context.getConceptService().getTrueConcept() : Context .getConceptService().getFalseConcept()); } else { setValueCoded(null); } } }
/** * Utility method to check if the concept is already attached to an observation (including * voided ones) and if the datatype of the concept has changed, an exception indicating that the * datatype cannot be modified will be reported if the concept is attached to an observation. * This method will only allow changing boolean concepts to coded. * * @param concept * @throws ConceptInUseException */ private void checkIfDatatypeCanBeChanged(Concept concept) { if (concept.getId() != null && hasAnyObservation(concept) && hasDatatypeChanged(concept)) { // allow boolean concepts to be converted to coded if (!(dao.getSavedConceptDatatype(concept).isBoolean() && concept.getDatatype().isCoded())) { throw new ConceptInUseException(); } if (log.isDebugEnabled()) { log.debug("Converting datatype of concept with id " + concept.getConceptId() + " from Boolean to Coded"); } } }
/** * @see ConceptService#getConceptDatatypeByName(String) */ @Test public void changeConceptFromBooleanToCoded_shouldConvertTheDatatypeOfABooleanConceptToCoded() { Concept concept = conceptService.getConcept(18); Assert.assertEquals(conceptService.getConceptDatatypeByName("Boolean").getConceptDatatypeId(), concept.getDatatype() .getConceptDatatypeId()); conceptService.convertBooleanConceptToCoded(concept); Assert.assertEquals(conceptService.getConceptDatatypeByName("Coded").getConceptDatatypeId(), concept.getDatatype() .getConceptDatatypeId()); }
/** * @see org.openmrs.api.ConceptService#convertBooleanConceptToCoded(org.openmrs.Concept) */ @Override public void convertBooleanConceptToCoded(Concept conceptToChange) throws APIException { if (conceptToChange != null) { if (!conceptToChange.getDatatype().isBoolean()) { throw new APIException("Concept.datatype.invalid", (Object[]) null); } conceptToChange.setDatatype(getConceptDatatypeByName("Coded")); conceptToChange.addAnswer(new ConceptAnswer(getTrueConcept())); conceptToChange.addAnswer(new ConceptAnswer(getFalseConcept())); Context.getConceptService().saveConcept(conceptToChange); } }
/** * @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); }
conceptDatatype = concept.getDatatype();
assertThat(copyConcept.getDatatype(), is(originalConcept.getDatatype())); assertThat(copyConcept.getDateCreated(), is(originalConcept.getDateCreated())); assertThat(copyConcept.getCreator(), is(originalConcept.getCreator()));
this.setConceptId(c.getConceptId()); this.setCreator(c.getCreator()); this.setDatatype(c.getDatatype()); this.setDateChanged(c.getDateChanged()); this.setDateCreated(c.getDateCreated());
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#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#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 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()); }
/** * Constructor from Concept. * * @param c */ public ConceptComplex(Concept c) { this.setAnswers(c.getAnswers(true)); this.setChangedBy(c.getChangedBy()); this.setConceptClass(c.getConceptClass()); this.setConceptId(c.getConceptId()); this.setConceptSets(c.getConceptSets()); this.setCreator(c.getCreator()); this.setDatatype(c.getDatatype()); this.setDateChanged(c.getDateChanged()); this.setDateCreated(c.getDateCreated()); this.setSet(c.getSet()); this.setNames(c.getNames()); this.setDescriptions(c.getDescriptions()); this.setConceptMappings(c.getConceptMappings()); this.setRetired(c.getRetired()); this.setVersion(c.getVersion()); this.setUuid(c.getUuid()); this.handler = ""; }
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);
ConceptDatatype dt = c.getDatatype(); if (dt != null) { if (dt.isBoolean() && obs.getValueBoolean() == null) {