/** * @see Concept#getName(Locale,null) */ @Test public void getName_shouldReturnNullIfNoNamesAreFoundInLocaleGivenExactEqualsTrue() { Locale nonMatchingNameLocale = new Locale("en", "US"); Locale localeToSearch = new Locale("en"); Concept concept = new Concept(); concept.addName(new ConceptName("some name", nonMatchingNameLocale)); Assert.assertNull(concept.getName(localeToSearch, true)); }
/** * 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 = ""; }
/** * 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"); } } }
/** * 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; }
User user = new User(1); Concept originalConcept = new Concept(); originalConcept.setConceptClass(new ConceptClass(1)); originalConcept.setDatatype(new ConceptDatatype(1)); originalConcept.setUuid("abc123"); originalConcept.setDateCreated(date); originalConcept.setCreator(user); originalConcept.setDateChanged(date); originalConcept.setChangedBy(user); originalConcept.setRetired(true); originalConcept.setRetiredBy(user); originalConcept.setDateRetired(date); originalConcept.setRetireReason("test"); assertThat(copyConcept.getConceptClass(), is(originalConcept.getConceptClass())); assertThat(copyConcept.getDatatype(), is(originalConcept.getDatatype())); assertThat(copyConcept.getDateCreated(), is(originalConcept.getDateCreated())); assertThat(copyConcept.getCreator(), is(originalConcept.getCreator())); assertThat(copyConcept.getDateChanged(), is(originalConcept.getDateChanged())); assertThat(copyConcept.getChangedBy(), is(originalConcept.getChangedBy())); assertThat(copyConcept.getRetired(), is(originalConcept.getRetired())); assertThat(copyConcept.getRetiredBy(), is(originalConcept.getRetiredBy())); assertThat(copyConcept.getDateRetired(), is(originalConcept.getDateRetired())); assertThat(copyConcept.getRetireReason(), is(originalConcept.getRetireReason())); assertThat(copyConcept.getUuid(), is(originalConcept.getUuid()));
@Override public String toString() { if (StringUtils.isNotBlank(reactionNonCoded)) { return reactionNonCoded; } return reaction.getName().getName(); }
/** * @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()); }
/** * @param nonCodedAllergen the nonCodedAllergen to set */ public void setNonCodedAllergen(String nonCodedAllergen) { this.nonCodedAllergen = nonCodedAllergen; if (StringUtils.isNotBlank(nonCodedAllergen) && codedAllergen != null && !codedAllergen.getUuid().equals(getOtherNonCodedConceptUuid())) { codedAllergen = null; } }
@Test public void equals_shouldNotBeTheSameReference() { Concept c = new Concept(123); ConceptNumeric cn = new ConceptNumeric(c); Assert.assertNotSame(c.getAnswers(), cn.getAnswers()); Assert.assertNotSame(c.getConceptSets(), cn.getConceptSets()); Assert.assertNotSame(cn.getConceptSets(), c.getConceptSets()); Assert.assertNotSame(c.getNames(), cn.getNames()); Assert.assertNotSame(c.getConceptMappings(), cn.getConceptMappings()); Assert.assertNotSame(c.getDescriptions(), cn.getDescriptions()); }
/** * @see BaseOpenmrsObject#equals(Object) */ @Test public void equals_shouldReturnTrueIfGivenObjectIsInstanceOfSuperOrExtendingClass() { Concept concept = new Concept(5); Concept numeric = new ConceptNumeric(); numeric.setUuid(concept.getUuid()); Assert.assertTrue(numeric.equals(concept)); Assert.assertTrue(concept.equals(numeric)); }
if (concept.getNames() != null) { for (ConceptName cn : concept.getNames()) { cn.setConcept(concept); if (concept.getConceptSets() != null) { for (ConceptSet set : concept.getConceptSets()) { set.setConceptSet(concept); if (concept.getAnswers(true) != null) { for (ConceptAnswer ca : concept.getAnswers(true)) { ca.setConcept(concept); if (concept.getDescriptions() != null) { for (ConceptDescription cd : concept.getDescriptions()) { if (StringUtils.isBlank(cd.getDescription())) { concept.removeDescription(cd); continue; if (concept.getConceptMappings() != null) { for (ConceptMap map : concept.getConceptMappings()) { map.setConcept(concept);
/** * @see ConceptService#getConceptsByMapping(String,String,Boolean) */ @Test public void getConceptsByMapping_shouldSortNonRetiredConceptsFirst() { List<Concept> concepts = conceptService.getConceptsByMapping("766554", "SSTRM", true); Assert.assertEquals(16, concepts.get(0).getId().intValue()); }
/** * @see Concept#getShortestName(Locale,Boolean) */ @Test public void getShortestName_shouldReturnNullIfTheirAreNoNamesInTheSpecifiedLocaleAndExactIsTrue() { Concept concept = new Concept(); concept.addName(new ConceptName("shortName123", Context.getLocale())); concept.addName(new ConceptName("shortName12", Context.getLocale())); concept.addName(new ConceptName("shortName1", Locale.US)); Assert.assertNull(concept.getShortestName(new Locale("fr"), true)); }
/** * @since 1.5 * @see org.openmrs.OpenmrsObject#getId() */ @Override public Integer getId() { return getConceptId(); }
/** * @see OrderService#getNonCodedDrugConcept() */ @Test public void getNonCodedDrugConcept_shouldReturnAConceptIfGPIsSet() { executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml"); Concept nonCodedDrugConcept = orderService.getNonCodedDrugConcept(); assertNotNull(nonCodedDrugConcept); assertThat(nonCodedDrugConcept.getConceptId(), is(5584)); assertEquals(nonCodedDrugConcept.getName().getName(), "DRUG OTHER"); }
if (conceptToValidate.getNames().isEmpty()) { errors.reject("Concept.name.atLeastOneRequired"); return; for (Locale conceptNameLocale : conceptToValidate.getAllConceptNameLocales()) { boolean fullySpecifiedNameForLocaleFound = false; boolean preferredNameForLocaleFound = false; boolean shortNameForLocaleFound = false; Set<String> validNamesFoundInLocale = new HashSet<>(); Collection<ConceptName> namesInLocale = conceptToValidate.getNames(conceptNameLocale); for (ConceptName nameInLocale : namesInLocale) { if (StringUtils.isBlank(nameInLocale.getName())) { if (CollectionUtils.isNotEmpty(conceptToValidate.getConceptMappings())) { for (ConceptMap map : conceptToValidate.getConceptMappings()) { if (map.getConceptReferenceTerm().getConceptReferenceTermId() == null) { if (CollectionUtils.isNotEmpty(conceptToValidate.getAnswers())) { for (ConceptAnswer conceptAnswer : conceptToValidate.getAnswers()) { if (conceptAnswer.getAnswerConcept().equals(conceptToValidate)) { errors.reject("Concept.contains.itself.as.answer");