Skip to content

Commit

Permalink
TRUNK-4367 Post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jun 23, 2014
1 parent 27423e4 commit 51e2dae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
1 change: 0 additions & 1 deletion api/src/main/java/org/openmrs/api/ConceptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ public interface ConceptService extends OpenmrsService {
* @throws APIException
* @return the found Concept
* @should get concept by name
* @should get concept by partial name
* @should return null given null parameter
* @should find concepts with names in more specific locales
* @should find concepts with names in more generic locales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1689,37 +1689,47 @@ public List<Concept> getConceptsByName(final String name, final Locale locale, f
*/
@Override
public Concept getConceptByName(final String name) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptName.class);

Locale locale = Context.getLocale();
Query query = sessionFactory.getCurrentSession().createQuery(
"from ConceptName cn where cn.name = :name and (cn.locale = :locale or cn.locale like :locale2)");
query.setParameter("name", name);
query.setParameter("locale", locale);
String a = locale.getLanguage() + "%";
query.setParameter("locale2", new Locale(a));
List<ConceptName> cn = query.list();
Locale language = new Locale(locale.getLanguage() + "%");
criteria.add(Restrictions.or(Restrictions.eq("locale", locale), Restrictions.like("locale", language)));

if (cn.size() == 0) {
query.setParameter("name", name.toUpperCase());
cn = query.list();
if (cn.size() == 0)
return null;
if (Context.getConceptService().isConceptNameSearchCaseSensitive()) {
criteria.add(Restrictions.ilike("name", name));
} else {
criteria.add(Restrictions.eq("name", name));
}

if (cn.size() > 1) {
criteria.add(Restrictions.eq("voided", false));

criteria.createAlias("concept", "concept");
criteria.add(Restrictions.eq("concept.retired", false));

@SuppressWarnings("unchecked")
List<ConceptName> list = criteria.list();

if (list.size() == 1) {
return list.get(0).getConcept();
} else {
log.warn("Multiple concepts found for '" + name + "'");
List<Concept> concepts = Lists.transform(cn, transformNameToConcept);
for (Concept c : concepts) {
if (c.getName(locale).getName().compareTo(name) == 0) {
return c;

List<Concept> concepts = Lists.transform(list, transformNameToConcept);
for (Concept concept : concepts) {
for (ConceptName conceptName : concept.getNames(locale)) {
if (conceptName.getName().equalsIgnoreCase(name)) {
return concept;
}
}
for (ConceptName indexTerm : c.getIndexTermsForLocale(locale)) {
if (indexTerm.getName().compareTo(name) == 0) {
return c;
for (ConceptName indexTerm : concept.getIndexTermsForLocale(locale)) {
if (indexTerm.getName().equalsIgnoreCase(name)) {
return concept;
}
}
}
}
return cn.get(0).getConcept();

return null;
}

/**
Expand Down

0 comments on commit 51e2dae

Please sign in to comment.