/** * @since 1.5 * @see org.openmrs.OpenmrsObject#getId() */ @Override public Integer getId() { return getConceptNameId(); }
if (cn.isSynonym()) { cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(cn, "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName() + ") in locale '" + allowedLoc.getDisplayName() + "' has been set as the fully specified name for concept with id : " + conceptId); if (cn.isShort()) { cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(cn, "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName() + ") in locale '" + allowedLoc.getDisplayName() + "' has been changed from short to fully specified name for concept with id : " + conceptId); ConceptName fullySpecName = entry.getValue().get(0); fullySpecName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); reportUpdatedName(fullySpecName, "ConceptName with id " + fullySpecName.getConceptNameId() + " (" + fullySpecName.getName() + ") in locale '" + locale.getDisplayName() + "' has been set as the fully specified name for concept with id : " + conceptId);
pStmt.setInt(8, conceptName.getConceptNameId());
updateWarnings.add("ConceptName with id " + nameInLocale.getConceptNameId() + " (" + nameInLocale.getName() + ") is null, white space character or empty string"); updateWarnings.add("ConceptName with id: " + nameInLocale.getConceptNameId() + " (" + nameInLocale.getName() + ") has a locale (" + conceptNameLocale + ") that isn't listed among the allowed ones by the system admin"); for (ConceptName conceptName : namesWithNoLocale) { conceptName.setLocale(defaultLocale); reportUpdatedName(conceptName, "The locale for ConceptName with id " + conceptName.getConceptNameId() + " (" + conceptName.getName() + ") has been set to '" + defaultLocale.getDisplayName() + "'"); if (!hasFullySpecifiedName) { conceptName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); hasFullySpecifiedName = true; reportUpdatedName(conceptName, "ConceptName with id " + conceptName.getConceptNameId() + " (" + conceptName.getName() + ") in locale '" + defaultLocale.getDisplayName() + "' has been set as the fully specified name for concept with id : " + conceptId); reportUpdatedName(conceptName, "ConceptName with id " + conceptName.getConceptNameId() + " (" + conceptName.getName() + ") is no longer marked as preferred because it had no locale"); if (conceptName.isFullySpecifiedName() || conceptName.isShort()) {
/** * Sets the specified name as the short name for the locale and the current shortName(if any) * ceases to be the short name for the locale. * * @param shortName the new shortName to set * @should set the concept name type of the specified name to short * @should convert the previous shortName if any to a synonym * @should add the name to the list of names if it not among them before * @should void old short name if new one is blank (do not save blanks!) */ public void setShortName(ConceptName shortName) { if (shortName != null) { if (shortName.getLocale() == null) { throw new APIException(CONCEPT_NAME_LOCALE_NULL, (Object[]) null); } ConceptName oldShortName = getShortNameInLocale(shortName.getLocale()); if (oldShortName != null) { oldShortName.setConceptNameType(null); } shortName.setConceptNameType(ConceptNameType.SHORT); if (StringUtils.isNotBlank(shortName.getName()) && (shortName.getConceptNameId() == null || !getNames().contains(shortName))) { //add this name, if it is new or not among this concept's names addName(shortName); } } else { throw new APIException("Concept.error.shortName.null", (Object[]) null); } }
/** * @see ConceptService#getConceptNameByUuid(String) */ @Test public void getConceptNameByUuid_shouldFindObjectGivenValidUuid() { String uuid = "9bc5693a-f558-40c9-8177-145a4b119ca7"; ConceptName conceptName = Context.getConceptService().getConceptNameByUuid(uuid); Assert.assertEquals(1439, (int) conceptName.getConceptNameId()); }
/** * Sets the specified name as the fully specified name for the locale and the current fully * specified (if any) ceases to be the fully specified name for the locale. * * @param fullySpecifiedName the new fully specified name to set * @should set the concept name type of the specified name to fully specified * @should convert the previous fully specified name if any to a synonym * @should add the name to the list of names if it not among them before */ public void setFullySpecifiedName(ConceptName fullySpecifiedName) { if (fullySpecifiedName == null || fullySpecifiedName.getLocale() == null) { throw new APIException(CONCEPT_NAME_LOCALE_NULL, (Object[]) null); } else if (fullySpecifiedName.getVoided()) { throw new APIException("Concept.error.fullySpecifiedName.null", (Object[]) null); } ConceptName oldFullySpecifiedName = getFullySpecifiedName(fullySpecifiedName.getLocale()); if (oldFullySpecifiedName != null) { oldFullySpecifiedName.setConceptNameType(null); } fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); //add this name, if it is new or not among this concept's names if (fullySpecifiedName.getConceptNameId() == null || !getNames().contains(fullySpecifiedName)) { addName(fullySpecifiedName); } }
for (ConceptName conceptName : concept.getNames()) { if (conceptName.getConceptNameId() != null) { ConceptName clone = cloneConceptName(conceptName); clone.setConceptNameId(null); } else { clone.setConceptNameId(conceptName.getConceptNameId());
if (preferredName.getConceptNameId() == null || !getNames().contains(preferredName)) { addName(preferredName);
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldAddNewConceptName() { Concept concept = conceptService.getConcept(3); ConceptName name = new ConceptName("new name", Locale.US); concept.addName(name); conceptService.saveConcept(concept); assertNotNull(name.getConceptNameId()); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldCreateANewConceptNameWhenTheOldNameIsChanged() { Concept concept = conceptService.getConceptByName("cd4 count"); Assert.assertEquals(3, concept.getNames(true).size()); ConceptName oldName = null; for (ConceptName cn : concept.getNames()) { if (cn.getConceptNameId().equals(1847)) { oldName = cn; cn.setName("new name"); } } conceptService.saveConcept(concept); //force Hibernate interceptor to set dateCreated Context.flushSession(); Assert.assertEquals(4, concept.getNames(true).size()); for (ConceptName cn : concept.getNames()) { if (cn.getName().equals("new name")) { Assert.assertTrue(oldName.getDateCreated().before(cn.getDateCreated())); } } }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale for a * concept name is among those listed in the global property 'locale.allowed.list' and default * locale. NOTE that it doesn't test a particular API method directly. */ @Test public void saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { if (!CollectionUtils.isEmpty(concept.getNames())) { for (ConceptName cn : concept.getNames()) { Assert.assertTrue("The locale '" + cn.getLocale() + "' of conceptName with id: " + cn.getConceptNameId() + " is not among those listed in the global property 'locale.allowed.list'", allowedLocales .contains(cn.getLocale())); } } } }
/** * @see {@link * ConceptDAO#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<ConceptClass * >,List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)} */ @SuppressWarnings("unchecked") @Test @Ignore public void getConcepts_shouldReturnCorrectResultsForConceptWithNamesThatContainsWordsWithMoreWeight() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-words.xml"); Concept conceptWithMultipleMatchingNames = dao.getConcept(3000); //recalculate the weights just in case the logic for calculating the weights is changed ConceptService cs = Context.getConceptService(); cs.updateConceptIndex(conceptWithMultipleMatchingNames); cs.updateConceptIndex(dao.getConcept(4000)); List<ConceptSearchResult> searchResults = dao .getConcepts("trust", Collections.singletonList(Locale.ENGLISH), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null); Assert.assertEquals(2, searchResults.size()); //the first concept is the one with a word with the highest weight Assert.assertEquals(conceptWithMultipleMatchingNames, searchResults.get(0).getConcept()); //For conceptId=3000, its search result should ALWAYS match on 'TRUST ME' because it is shorter THAN 'TRUST ALWAYS' Assert.assertEquals(9998, searchResults.get(0).getConceptName().getConceptNameId().intValue()); }
if (valueConceptName != null) { if (log.isDebugEnabled()) { log.debug(" value concept-name-id = " + valueConceptName.getConceptNameId()); log.debug(" value concept-name = " + valueConceptName.getName());
/** * @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()); }
cs.saveConcept(c1); Assert.assertTrue(cn1a.isSynonym()); Assert.assertTrue(cn1b.getConceptNameId() > cn1a.getConceptNameId());