Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/28/08 05:16:52 (8 months ago)
Author:
bmckown
Message:

complex_obs branch: Merging trunk to complex-obs [3891] [4378] TODO: sqldiff.

Files:

Legend:

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

    • Property svn:eol-style set to CRLF
    r3685 r4417  
    2424import org.openmrs.api.db.DAOException; 
    2525 
     26/** 
     27 * Hibernate implementation of the CohortDAO 
     28 * 
     29 * @see CohortDAO 
     30 */ 
    2631public class HibernateCohortDAO implements CohortDAO { 
    2732 
     
    3641        } 
    3742         
    38         public void createCohort(Cohort cohort) throws DAOException { 
    39                 sessionFactory.getCurrentSession().persist(cohort); 
    40         } 
    41  
    4243        public Cohort getCohort(Integer id) throws DAOException { 
    4344                return (Cohort) sessionFactory.getCurrentSession().get(Cohort.class, id); 
    4445        } 
    4546         
    46         public List<Cohort> getCohorts() throws DAOException { 
    47                 return (List<Cohort>) sessionFactory.getCurrentSession().createQuery("from Cohort order by name").list(); 
    48         } 
    49          
    5047        public List<Cohort> getCohortsContainingPatientId(Integer patientId) throws DAOException { 
    51                 Query query = sessionFactory.getCurrentSession().createQuery("from Cohort c where :patientId in elements(c.memberIds)"); 
     48                Query query = sessionFactory.getCurrentSession().createQuery("from Cohort c where :patientId in elements(c.memberIds) order by name"); 
    5249                query.setInteger("patientId", patientId); 
    5350                return (List<Cohort>) query.list(); 
    5451        } 
    5552 
    56     public void updateCohort(Cohort cohort) throws DAOException { 
    57         sessionFactory.getCurrentSession().update(cohort); 
     53        /** 
     54     * @see org.openmrs.api.db.CohortDAO#deleteCohort(org.openmrs.Cohort) 
     55     */ 
     56    public Cohort deleteCohort(Cohort cohort) throws DAOException { 
     57            // TODO Auto-generated method stub 
     58            return null; 
     59    } 
     60 
     61        /** 
     62     * @see org.openmrs.api.db.CohortDAO#findCohorts(java.lang.String) 
     63     */ 
     64    public List<Cohort> getCohorts(String nameFragment) throws DAOException { 
     65            // TODO Auto-generated method stub 
     66            return null; 
     67    } 
     68 
     69        /** 
     70     * @see org.openmrs.api.db.CohortDAO#getAllCohorts(boolean) 
     71     */ 
     72    public List<Cohort> getAllCohorts(boolean includeVoided) throws DAOException { 
     73        String hql = "from Cohort order by name"; 
     74        if (!includeVoided) 
     75                hql += " where voided = false"; 
     76        return (List<Cohort>) sessionFactory.getCurrentSession().createQuery(hql).list(); 
     77    } 
     78 
     79        /** 
     80     * @see org.openmrs.api.db.CohortDAO#getCohort(java.lang.String) 
     81     */ 
     82    public Cohort getCohort(String name) { 
     83            return (Cohort) sessionFactory.getCurrentSession().createQuery("from Cohort where name = :name").setString("name", name).uniqueResult(); 
     84    } 
     85 
     86        /** 
     87     * @see org.openmrs.api.db.CohortDAO#saveCohort(org.openmrs.Cohort) 
     88     */ 
     89    public Cohort saveCohort(Cohort cohort) throws DAOException { 
     90            sessionFactory.getCurrentSession().saveOrUpdate(cohort); 
     91            return cohort; 
    5892    } 
    5993