Changeset 4417 for openmrs/branches/complex-obs/src/api/org/openmrs/api/db/hibernate/HibernateCohortDAO.java
- Timestamp:
- 05/28/08 05:16:52 (8 months ago)
- 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 24 24 import org.openmrs.api.db.DAOException; 25 25 26 /** 27 * Hibernate implementation of the CohortDAO 28 * 29 * @see CohortDAO 30 */ 26 31 public class HibernateCohortDAO implements CohortDAO { 27 32 … … 36 41 } 37 42 38 public void createCohort(Cohort cohort) throws DAOException {39 sessionFactory.getCurrentSession().persist(cohort);40 }41 42 43 public Cohort getCohort(Integer id) throws DAOException { 43 44 return (Cohort) sessionFactory.getCurrentSession().get(Cohort.class, id); 44 45 } 45 46 46 public List<Cohort> getCohorts() throws DAOException {47 return (List<Cohort>) sessionFactory.getCurrentSession().createQuery("from Cohort order by name").list();48 }49 50 47 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"); 52 49 query.setInteger("patientId", patientId); 53 50 return (List<Cohort>) query.list(); 54 51 } 55 52 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; 58 92 } 59 93