Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/21/08 02:20:21 (6 months ago)
Author:
bwolfe
Message:

api-refactoring: adding fixes for concepts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/api_refactoring/src/api/org/openmrs/api/db/hibernate/HibernateConceptDAO.java

    r4240 r4290  
    340340                 
    341341                if (classes.size() > 0) 
    342                         criteria.add(Expression.in("conceptClasses", classes)); 
     342                        criteria.add(Expression.in("conceptClass", classes)); 
    343343                 
    344344                if (datatypes.size() > 0) 
    345                         criteria.add(Expression.in("conceptDatatypes", datatypes)); 
     345                        criteria.add(Expression.in("datatype", datatypes)); 
    346346                 
    347347                return criteria.list(); 
     
    358358                        { 
    359359                 
    360                 //String locale = loc.getLanguage().substring(0, 2);            //only get language portion of locale 
     360                //add the language-only portion of locale if its not in the list of locales already 
     361                List<Locale> localesToAdd = new Vector<Locale>(); 
     362                for (Locale locale : locales) { 
     363                        Locale languageOnly = new Locale(locale.getLanguage()); 
     364                        if (locales.contains(languageOnly) == false) 
     365                                localesToAdd.add(languageOnly); 
     366                } 
     367                 
     368                locales.addAll(localesToAdd); 
     369                 
     370                //String locale = loc.getLanguage().substring(0, 2);             
    361371                List<String> words = ConceptWord.getUniqueWords(phrase); //assumes getUniqueWords() removes quote(') characters.  (otherwise we would have a security leak) 
    362372                 
     
    364374                List<Concept> answers = new Vector<Concept>(); 
    365375                 
    366                 if (answersToConcept.getAnswers() != null) { 
     376                if (answersToConcept != null && answersToConcept.getAnswers() != null) { 
    367377                        for (ConceptAnswer conceptAnswer : answersToConcept.getAnswers()) { 
    368378                                answers.add(conceptAnswer.getAnswerConcept()); 
     
    372382                List<ConceptWord> conceptWords = new Vector<ConceptWord>(); 
    373383                 
    374                 if (words.size() > 0) { 
     384                if (words.size() > 0 || !answers.isEmpty()) { 
    375385                 
    376386                        Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(ConceptWord.class, "cw1"); 
     
    386396                                searchCriteria.add(Expression.in("cw1.concept", answers)); 
    387397                         
    388                         Iterator<String> word = words.iterator(); 
    389                         searchCriteria.add(Expression.like("word", word.next(), MatchMode.START)); 
    390                         Conjunction junction = Expression.conjunction(); 
    391                         while (word.hasNext()) { 
    392                                 String w = word.next(); 
    393                                  
    394                                 if (log.isDebugEnabled()) 
    395                                         log.debug("Current word: " + w); 
    396                                  
    397                                 DetachedCriteria crit = DetachedCriteria.forClass(ConceptWord.class) 
    398                                                         .setProjection(Property.forName("concept")) 
    399                                                         .add(Expression.eqProperty("concept", "cw1.concept")) 
    400                                                         .add(Restrictions.like("word", w, MatchMode.START)) 
    401                                                         .add(Expression.in("locale", locales)); 
    402                                 junction.add(Subqueries.exists(crit)); 
    403                         } 
    404                         searchCriteria.add(junction); 
     398                        if (words.size() > 0) { 
     399                                Iterator<String> word = words.iterator(); 
     400                                searchCriteria.add(Expression.like("word", word.next(), MatchMode.START)); 
     401                                Conjunction junction = Expression.conjunction(); 
     402                                while (word.hasNext()) { 
     403                                        String w = word.next(); 
     404                                         
     405                                        if (log.isDebugEnabled()) 
     406                                                log.debug("Current word: " + w); 
     407                                         
     408                                        DetachedCriteria crit = DetachedCriteria.forClass(ConceptWord.class) 
     409                                                                .setProjection(Property.forName("concept")) 
     410                                                                .add(Expression.eqProperty("concept", "cw1.concept")) 
     411                                                                .add(Restrictions.like("word", w, MatchMode.START)) 
     412                                                                .add(Expression.in("locale", locales)); 
     413                                        junction.add(Subqueries.exists(crit)); 
     414                                } 
     415                                searchCriteria.add(junction); 
     416                        } 
    405417                         
    406418                        if (requireClasses.size() > 0)