/** * @return Returns the names. */ public Collection<ConceptName> getNames() { return getNames(false); }
/** * Gets the list of all non-retired concept names which are index terms for this concept * * @return a collection of concept names which are index terms for this concept * @since 1.7 */ public Collection<ConceptName> getIndexTerms() { return getNames().stream() .filter(ConceptName::isIndexTerm) .collect(Collectors.toSet()); }
/** * Gets all the non-retired synonyms. * * @return Collection of ConceptNames which are synonyms for the Concept or an empty list if * none is found * @since 1.7 */ public Collection<ConceptName> getSynonyms() { return getNames().stream() .filter(ConceptName::isSynonym) .collect(Collectors.toSet()); }
/** * Returns all names available in a specific locale. <br> * <br> * This is recommended when managing the concept dictionary. * * @param locale locale for which names should be returned * @return Collection of ConceptNames with the given locale */ public Collection<ConceptName> getNames(Locale locale) { return getNames().stream() .filter(n -> n.getLocale().equals(locale)) .collect(Collectors.toSet()); }
/** * @param name A name * @return whether this concept has the given name in any locale */ public boolean isNamed(String name) { return getNames().stream().anyMatch(cn -> name.equals(cn.getName())); }
/** * A convenience method to get the concept-name (if any) which has a particular tag. This does * not guarantee that the returned name is the only one with the tag. * * @param conceptNameTag the tag for which to look * @return the tagged name, or null if no name has the tag */ public ConceptName findNameTaggedWith(ConceptNameTag conceptNameTag) { ConceptName taggedName = null; for (ConceptName possibleName : getNames()) { if (possibleName.hasTag(conceptNameTag)) { taggedName = possibleName; break; } } return taggedName; }
/** * Returns all names available for locale language "or" country. <br> * <br> * * @param locale locale for which names should be returned * @return Collection of ConceptNames with the given locale language or country */ private Collection<ConceptName> getPartiallyCompatibleNames(Locale locale) { String language = locale.getLanguage(); String country = locale.getCountry(); return getNames().stream() .filter(n -> language.equals(n.getLocale().getLanguage()) || StringUtils.isNotBlank(country) && country.equals(n.getLocale().getCountry())) .collect(Collectors.toSet()); }
/** * @see Concept#getNames(Locale) */ @Test public void getNamesLocale_shouldReturnEmptyCollection() { Locale localeToSearch = new Locale("en"); Concept concept = new Concept(); Collection<ConceptName> cns = concept.getNames(localeToSearch); Assert.assertEquals(cns.size(), 0); }
/** * @see Concept#setPreferredName(ConceptName) */ @Test public void setPreferredName_shouldAddTheNameToTheListOfNamesIfItNotAmongThemBefore() { Locale primaryLocale = Locale.US; Concept testConcept = createConcept(1, primaryLocale); ConceptName newPreferredName = createConceptName(3, "Aspirin", primaryLocale, null, false); assertEquals(false, testConcept.getNames(primaryLocale).contains(newPreferredName)); testConcept.setPreferredName(newPreferredName); assertEquals(true, testConcept.getNames(primaryLocale).contains(newPreferredName)); }
/** * @see Concept#setFullySpecifiedName(ConceptName) */ @Test public void setFullySpecifiedName_shouldAddTheNameToTheListOfNamesIfItNotAmongThemBefore() { Concept concept = createConcept(1, Context.getLocale()); int expectedNumberOfNames = concept.getNames().size() + 1; concept.setFullySpecifiedName(new ConceptName("some name", Context.getLocale())); Assert.assertEquals(expectedNumberOfNames, concept.getNames().size()); }
/** * @see Concept#setShortName(ConceptName) */ @Test public void setShortName_shouldAddTheNameToTheListOfNamesIfItNotAmongThemBefore() { Concept concept = createConcept(1, Context.getLocale()); int expectedNumberOfNames = concept.getNames().size() + 1; concept.setShortName(new ConceptName("some name", Context.getLocale())); Assert.assertEquals(expectedNumberOfNames, concept.getNames().size()); }
/** * @see Concept#getNames(Boolean) */ @Test public void getNamesBoolean_shouldNotReturnVoidedConceptName() { Locale localeToSearch = new Locale("en"); Concept concept = new Concept(); ConceptName conceptName = new ConceptName("some name", localeToSearch); conceptName.setVoided(true); concept.addName(conceptName); Collection<ConceptName> cns = concept.getNames(false); Assert.assertNotNull(cns); Assert.assertEquals(cns.size(), 0); cns = concept.getNames(true); Assert.assertEquals(cns.size(), 1); }
/** * @see org.openmrs.api.ConceptService#purgeConcept(Concept) */ @Override public void purgeConcept(Concept concept) throws APIException { checkIfLocked(); if (concept.getConceptId() != null) { for (ConceptName conceptName : concept.getNames()) { if (hasAnyObservation(conceptName)) { throw new ConceptNameInUseException("Can't delete concept with id : " + concept.getConceptId() + " because it has a name '" + conceptName.getName() + "' which is being used by some observation(s)"); } } } dao.purgeConcept(concept); }
@Test public void validate_shouldFailIfThereIsNoNameExplicitlyMarkedAsFullySpecified() { Concept concept = cd4Count; for (ConceptName name : concept.getNames()) { name.setConceptNameType(null); } Errors errors = new BindException(concept, "concept"); validator.validate(concept, errors); assertThat(errors, hasGlobalErrors("Concept.error.no.FullySpecifiedName")); }
/** * @see Concept#getNames(Locale) */ @Test public void getNamesLocale_shouldReturnNonVoidedConceptName() { Locale localeToSearch = new Locale("en"); Concept concept = new Concept(); ConceptName conceptName = new ConceptName("some name", localeToSearch); conceptName.setVoided(true); concept.addName(conceptName); Collection<ConceptName> cns = concept.getNames(localeToSearch); Assert.assertEquals(cns.size(), 0); }
/** * This test verifies that {@link ConceptName}s are fetched correctly from the hibernate cache. * (Or really, not fetched from the cache but instead are mapped with lazy=false. For some * reason Hibernate isn't able to find objects in the cache if a parent object was the one that * loaded them) * * @throws Exception */ @Test public void shouldFetchNamesForConceptsThatWereFirstFetchedAsNumerics() { Concept concept = Context.getConceptService().getConcept(5089); ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(5089); conceptNumeric.getNames().size(); concept.getNames().size(); }
/** * @see Concept#getNames() */ @Test public void getNames_shouldNotReturnVoidedConceptName() { Locale localeToSearch = new Locale("en"); Concept concept = new Concept(); ConceptName conceptName = new ConceptName("some name", localeToSearch); conceptName.setVoided(true); concept.addName(conceptName); Collection<ConceptName> cns = concept.getNames(); Assert.assertNotNull(cns); Assert.assertEquals(cns.size(), 0); }
/** * When asked for a collection of compatible names, the returned collection should not include * any incompatible names. * * @see Concept#getCompatibleNames(Locale) */ @Test public void getCompatibleNames_shouldExcludeIncompatibleCountryLocales() { Locale primaryLocale = Locale.US; Concept testConcept = createConcept(1, primaryLocale); // concept should only have US and generic english names. // add an incompatible name -- en_UK int initialNameCollectionSize = testConcept.getNames().size(); ConceptName name_en_UK = createConceptName(initialNameCollectionSize + 1, "Labour", Locale.UK, ConceptNameType.FULLY_SPECIFIED, false); testConcept.addName(name_en_UK); Collection<ConceptName> compatibleNames = testConcept.getCompatibleNames(primaryLocale); assertFalse(compatibleNames.contains(name_en_UK)); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldVoidTheConceptNameIfTheTextOfTheNameHasChanged() { Concept concept = conceptService.getConceptByName("cd4 count"); Assert.assertEquals(false, conceptService.getConceptName(1847).getVoided()); for (ConceptName cn : concept.getNames()) { if (cn.getConceptNameId().equals(1847)) { cn.setName("new name"); } } //ensure that the conceptName has actually been found and replaced Assert.assertEquals(true, concept.hasName("new name", new Locale("en", "GB"))); conceptService.saveConcept(concept); Assert.assertEquals(true, conceptService.getConceptName(1847).getVoided()); }
@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()); }