Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
07/02/08 19:40:36 (5 months ago)
Author:
bmckown
Message:

Merging trunk to complex-obs [4379][4764]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/src/api/org/openmrs/api/db/hibernate/HibernateCohortDAO.java

    r4417 r4785  
    1818import org.apache.commons.logging.Log; 
    1919import org.apache.commons.logging.LogFactory; 
     20import org.hibernate.Criteria; 
    2021import org.hibernate.Query; 
    2122import org.hibernate.SessionFactory; 
     23import org.hibernate.criterion.Order; 
     24import org.hibernate.criterion.Restrictions; 
    2225import org.openmrs.Cohort; 
    2326import org.openmrs.api.db.CohortDAO; 
     
    2831 * 
    2932 * @see CohortDAO 
     33 * @see org.openmrs.api.context.Context 
     34 * @see org.openmrs.api.CohortService 
    3035 */ 
    3136public class HibernateCohortDAO implements CohortDAO { 
     
    3540        private SessionFactory sessionFactory; 
    3641         
    37         public HibernateCohortDAO() { } 
    38          
     42        /** 
     43         * Auto generated method comment 
     44         *  
     45         * @param sessionFactory 
     46         */ 
    3947        public void setSessionFactory(SessionFactory sessionFactory) { 
    4048                this.sessionFactory = sessionFactory; 
    4149        } 
    4250         
     51        /** 
     52         * @see org.openmrs.api.db.CohortDAO#getCohort(java.lang.Integer) 
     53         */ 
    4354        public Cohort getCohort(Integer id) throws DAOException { 
    4455                return (Cohort) sessionFactory.getCurrentSession().get(Cohort.class, id); 
    4556        } 
    4657         
    47         public List<Cohort> getCohortsContainingPatientId(Integer patientId) throws DAOException { 
     58        /** 
     59         * @see org.openmrs.api.db.CohortDAO#getCohortsContainingPatientId(java.lang.Integer) 
     60         */ 
     61        @SuppressWarnings("unchecked") 
     62    public List<Cohort> getCohortsContainingPatientId(Integer patientId) throws DAOException { 
    4863                Query query = sessionFactory.getCurrentSession().createQuery("from Cohort c where :patientId in elements(c.memberIds) order by name"); 
    4964                query.setInteger("patientId", patientId); 
     
    7085     * @see org.openmrs.api.db.CohortDAO#getAllCohorts(boolean) 
    7186     */ 
     87    @SuppressWarnings("unchecked") 
    7288    public List<Cohort> getAllCohorts(boolean includeVoided) throws DAOException { 
    73         String hql = "from Cohort order by name"; 
     89        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Cohort.class); 
     90         
     91        criteria.addOrder(Order.asc("name")); 
     92         
    7493        if (!includeVoided) 
    75                 hql += " where voided = false"; 
    76         return (List<Cohort>) sessionFactory.getCurrentSession().createQuery(hql).list(); 
     94                criteria.add(Restrictions.eq("voided", false)); 
     95         
     96        return (List<Cohort>) criteria.list(); 
    7797    } 
    7898 
     
    81101     */ 
    82102    public Cohort getCohort(String name) { 
    83             return (Cohort) sessionFactory.getCurrentSession().createQuery("from Cohort where name = :name").setString("name", name).uniqueResult(); 
     103        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Cohort.class); 
     104         
     105                criteria.add(Restrictions.eq("name", name)); 
     106         
     107        return (Cohort) criteria.uniqueResult(); 
    84108    } 
    85109