/** * Checks whether the name is explicitly marked as preferred in a locale with a matching * language. E.g 'en_US' and 'en_UK' for language en * * @see #isPreferredForLocale(Locale) * @param language ISO 639 2-letter code for a language * @return true if the name is preferred in a locale with a matching language code, otherwise * false */ public Boolean isPreferredInLanguage(String language) { return !StringUtils.isBlank(language) && this.locale != null && isPreferred() && this.locale.getLanguage().equals(language); }
/** * Checks whether the name is explicitly marked as preferred in a locale with a matching country * code E.g 'fr_RW' and 'en_RW' for country RW * * @see #isPreferredForLocale(Locale) * @param country ISO 3166 2-letter code for a country * @return true if the name is preferred in a locale with a matching country code, otherwise * false */ public Boolean isPreferredInCountry(String country) { return !StringUtils.isBlank(country) && this.locale != null && isPreferred() && this.locale.getCountry().equals(country); }
/** * Gets the synonyms in the given locale. Returns a list of names from the same language with * the preferred synonym sorted first, or an empty list if none found. * * @param locale * @return Collection of ConceptNames which are synonyms for the Concept in the given locale */ public Collection<ConceptName> getSynonyms(Locale locale) { List<ConceptName> syns = new ArrayList<>(); ConceptName preferredConceptName = null; for (ConceptName possibleSynonymInLoc : getSynonyms()) { if (locale.equals(possibleSynonymInLoc.getLocale())) { if (possibleSynonymInLoc.isPreferred()) { preferredConceptName = possibleSynonymInLoc; } else { syns.add(possibleSynonymInLoc); } } } // Add preferred name first in the list. if (preferredConceptName != null) { syns.add(0, preferredConceptName); } log.debug("returning: " + syns); return syns; }
if ((nameInLocale.isFullySpecifiedName() || nameInLocale.isPreferred()) && !isNameUniqueInLocale(connection, nameInLocale, conceptId)) { if (localeDuplicateNamesMap == null) {
conceptName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); } else { if (conceptName.isPreferred() && !conceptName.isIndexTerm() && conceptName.getLocale() != null) { ConceptName prefName = getPreferredName(conceptName.getLocale()); if (prefName != null) {
/** * @see ConceptServiceImpl#saveConcept(Concept) */ @Test public void saveConcept_shouldNotSetDefaultPreferredNameToShortOrIndexTerms() { Locale loc = new Locale("fr", "CA"); ConceptName shortName = new ConceptName("short name", loc); shortName.setConceptNameType(ConceptNameType.SHORT); //be explicit for test case ConceptName indexTerm = new ConceptName("indexTerm", loc); indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM); //synonyms are id'd by a null type Concept c = new Concept(); HashSet<ConceptName> allNames = new HashSet<>(4); allNames.add(indexTerm); allNames.add(shortName); c.setNames(allNames); //The API will throw a validation error because preferred name is an index term //ignore it so we can test the set default preferred name functionality try { Context.getConceptService().saveConcept(c); } catch (org.openmrs.api.APIException e) { //ignore it } assertNull("there's a preferred name", c.getPreferredName(loc)); assertFalse("name was explicitly marked preferred", shortName.isPreferred()); assertFalse("name was explicitly marked preferred", indexTerm.isPreferred()); }
assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred()); assertEquals("name matches", c.getPreferredName(loc).getName(), synonym.getName()); assertEquals("fully specified name unchanged", c.getPreferredName(otherLocale).getName(),
@Test public void validate_shouldPassIfTheDuplicateNameInTheLocaleForTheConceptBeingValidatedIsVoided() { ConceptName otherName = conceptService.getConceptName(1439); //sanity check since names should only be unique amongst preferred and fully specified names Assert.assertTrue(otherName.isFullySpecifiedName() || otherName.isPreferred()); Assert.assertFalse(otherName.getVoided()); Assert.assertFalse(otherName.getConcept().getRetired()); //change to a duplicate name in the same locale ConceptName duplicateName = conceptService.getConceptName(2477); duplicateName.setName(otherName.getName()); Concept concept = duplicateName.getConcept(); concept.setPreferredName(duplicateName); //ensure that the name has been marked as preferred in its locale Assert.assertEquals(duplicateName, concept.getPreferredName(duplicateName.getLocale())); Assert.assertTrue(duplicateName.isPreferred()); duplicateName.setVoided(true); Errors errors = new BindException(concept, "concept"); validator.validate(concept, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see Concept#addName(ConceptName) */ @Test public void addName_shouldReplaceTheOldPreferredNameWithACurrentOne() { Concept concept = new Concept(); ConceptName oldPreferredName = new ConceptName("some name", Context.getLocale()); oldPreferredName.setLocalePreferred(true); concept.addName(oldPreferredName); ConceptName newPreferredName = new ConceptName("new name", Context.getLocale()); newPreferredName.setLocalePreferred(true); concept.addName(newPreferredName); Assert.assertEquals(false, oldPreferredName.isPreferred()); Assert.assertEquals("new name", concept.getPreferredName(Context.getLocale()).getName()); }
c.setConceptClass(new ConceptClass(1)); assertFalse("check test assumption - the API didn't automatically set preferred vlag", c.getFullySpecifiedName(loc).isPreferred()); assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred()); assertEquals("name matches", c.getPreferredName(loc).getName(), fullySpecifiedName.getName());
assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred()); assertEquals("name matches", c.getPreferredName(loc).getName(), indexTerm.getName());
String ds = res.getConcept().getDisplayString(); out.print("{ \"value\":\""); if (res.getConceptName().isPreferred() || res.getConceptName().getName().equalsIgnoreCase(ds)) { out.print(WebUtil.escapeQuotes(res.getConceptName().getName()));
for (ConceptName conceptname : concept.getNames()) { if (conceptname.getName().equalsIgnoreCase(name) && (conceptname.isPreferred() || conceptname.isFullySpecifiedName())) { isPreferredOrFullySpecified = true; break;