private void makeLocaleNotPreferred(ConceptName conceptName) { if (conceptName.getLocalePreferred()) { conceptName.setLocalePreferred(false); } }
private void ensurePreferredNameForLocale(Concept concept) { //Ensure if there's a name for a locale that at least one suitable name is marked preferred in that locale //Order of preference is: // 1) any name that concept.getPreferredName returns // 2) fully specified name // 3) any synonym // short name and index terms are never preferred. Set<Locale> checkedLocales = new HashSet<>(); for (ConceptName n : concept.getNames()) { Locale locale = n.getLocale(); if (checkedLocales.contains(locale)) { continue; //we've already checked this locale } //getPreferredName(locale) returns any name marked preferred, //or the fullySpecifiedName even if not marked preferred ConceptName possiblePreferredName = concept.getPreferredName(locale); if (possiblePreferredName != null) { //do nothing yet, but stick around to setLocalePreferred(true) } else if (concept.getFullySpecifiedName(locale) != null) { possiblePreferredName = concept.getFullySpecifiedName(locale); } else if (!CollectionUtils.isEmpty(concept.getSynonyms(locale))) { concept.getSynonyms(locale).iterator().next().setLocalePreferred(true); } //index terms are never used as preferred name if (possiblePreferredName != null) { //there may have been none possiblePreferredName.setLocalePreferred(true); } checkedLocales.add(locale); } }
conceptName.setLocale(!StringUtils.isBlank(localeString) ? LocaleUtility.fromSpecification(localeString) : null); conceptName.setLocalePreferred(rs.getBoolean("locale_preferred")); conceptName.setVoided(false);
oldPreferredName.setLocalePreferred(false); preferredName.setLocalePreferred(true);
private Concept createConceptWithName(String name) { Concept concept = new Concept(new Random().nextInt()); ConceptName conceptName = new ConceptName(); conceptName.setName(name); conceptName.setLocale(Context.getLocale()); conceptName.setLocalePreferred(true); concept.addName(conceptName); return concept; }
if (nameInLocale.getLocalePreferred() && !preferredNameForLocaleFound) { if (nameInLocale.isIndexTerm()) { nameInLocale.setLocalePreferred(false); reportUpdatedName(nameInLocale, "Preferred name '" + nameInLocale.getName() + "' in locale '" + conceptNameLocale.getDisplayName() + "' has been dropped as the preferred name because it is a search term"); } else if (nameInLocale.isShort()) { nameInLocale.setLocalePreferred(false); reportUpdatedName(nameInLocale, "Preferred name '" + nameInLocale.getName() + "' in locale '" + conceptNameLocale.getDisplayName() nameInLocale.setLocalePreferred(false); reportUpdatedName( nameInLocale, nameInLocale.setLocalePreferred(false); reportUpdatedName(nameInLocale, "The locale preferred property of name '" + nameInLocale.getName() + "' in locale '" + conceptNameLocale.getDisplayName() cn.setLocalePreferred(true); preferredNameForLocaleFound = true; break; for (ConceptName cn : localeConceptNamesMap.get(conceptNameLocale)) { if (cn.isSynonym()) { cn.setLocalePreferred(true); break; conceptName.setLocalePreferred(false);
ConceptName prefName = getPreferredName(conceptName.getLocale()); if (prefName != null) { prefName.setLocalePreferred(false);
/** * @see Concept#getName(Locale,null) */ @Test public void getName_shouldReturnExactNameLocaleMatchGivenExactEqualsTrue() { Locale definedNameLocale = new Locale("en", "US"); Locale localeToSearch = new Locale("en", "US"); Concept concept = new Concept(); ConceptName fullySpecifiedName = new ConceptName("some name", definedNameLocale); fullySpecifiedName.setConceptNameId(1); fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); fullySpecifiedName.setLocalePreferred(false); concept.addName(fullySpecifiedName); Assert.assertNotNull(concept.getName(localeToSearch, true)); Assert.assertEquals("some name", concept.getName(localeToSearch, true).getName()); }
/** * @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()); }
@Test public void getSynonyms_shouldSortPreferredFirst() { Concept concept = new Concept(); ConceptName conceptNameNotPreferred = new ConceptName("Non Preferred", Locale.ENGLISH); ConceptName conceptNameNotPreferred2 = new ConceptName("Non Preferred2", Locale.ENGLISH); ConceptName conceptNamePreferred = new ConceptName("Preferred", Locale.ENGLISH); conceptNamePreferred.setLocalePreferred(true); concept.addName(conceptNameNotPreferred); concept.addName(conceptNameNotPreferred2); concept.addName(conceptNamePreferred); conceptNameNotPreferred.setConceptNameType(null); conceptNameNotPreferred2.setConceptNameType(null); conceptNamePreferred.setConceptNameType(null); ConceptName conceptNameExpectedPreferred = concept.getSynonyms(Locale.ENGLISH).iterator().next(); assertEquals("Preferred", conceptNameExpectedPreferred.getName()); }
/** * @see ConceptService#getConcepts(String,List,boolean,List,List,List,List,Concept,Integer,Integer) */ @Test public void getConcepts_shouldReturnPreferredNamesHigher() { Concept hivProgram = conceptService.getConceptByName("hiv program"); ConceptName synonym = new ConceptName("synonym", Context.getLocale()); hivProgram.addName(synonym); conceptService.saveConcept(hivProgram); Concept mdrTbProgram = conceptService.getConceptByName("mdr-tb program"); synonym = new ConceptName("synonym", Context.getLocale()); synonym.setLocalePreferred(true); mdrTbProgram.addName(synonym); conceptService.saveConcept(mdrTbProgram); updateSearchIndex(); List<ConceptSearchResult> concepts = conceptService.getConcepts("synonym", null, false, null, null, null, null, null, null, null); assertThat(concepts, contains(hasConcept(is(mdrTbProgram)), hasConcept(is(hivProgram)))); }
/** * @see Concept#setPreferredName(ConceptName) */ @Test(expected = APIException.class) public void setPreferredName_shouldFailIfThePreferredNameToSetToIsAnIndexTerm() { Concept concept = new Concept(); concept.addName(new ConceptName("some name", Context.getLocale())); ConceptName preferredName = new ConceptName("some pref name", Context.getLocale()); preferredName.setLocalePreferred(true); preferredName.setConceptNameType(ConceptNameType.INDEX_TERM); concept.setPreferredName(preferredName); }
/** * Convenient factory method to create a populated Concept name. * * @param id id for the conceptName * @param locale the locale or context locale if null * @param conceptNameType the conceptNameType of the concept * @param isLocalePreferred if this name should be marked as preferred in its locale */ private ConceptName createConceptName(int id, String name, Locale locale, ConceptNameType conceptNameType, Boolean isLocalePreferred) { ConceptName result = new ConceptName(); result.setConceptNameId(id); result.setName(name); if (locale == null) { result.setLocale(Context.getLocale()); } else { result.setLocale(locale); } result.setConceptNameType(conceptNameType); result.setLocalePreferred(isLocalePreferred); return result; }
cn1b.setLocalePreferred(true); c1.addName(cn1b); cs.saveConcept(c1);
indexTerm.setLocalePreferred(true);
@Test public void testForcingLocale() throws Exception { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); ConceptName primaryName = new ConceptName("Weight", Locale.ENGLISH); primaryName.setLocalePreferred(true); primaryName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); ConceptNumeric weight = new ConceptNumeric(); String units = "kg"; weight.setUnits(units); weight.setDatatype(numeric); weight.addName(primaryName); weight.addName(new ConceptName("Pwa", LocaleUtility.fromSpecification("ht"))); mockStatic(HtmlFormEntryUtil.class); mockStatic(Context.class); PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight); PowerMockito.when(Context.getRegisteredComponent("htmlformentry.ConceptCompatibility", ConceptCompatibility.class)).thenReturn(new ConceptCompatibility1_9()); params.put("conceptId", "5089"); params.put("locale", "ht"); params.put("labelNameTag", "default"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); assertTrue(html.startsWith("Pwa")); }
fullySpecifiedName.setConceptNameId(1); fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); fullySpecifiedName.setLocalePreferred(false); concept.addName(fullySpecifiedName);