Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/09/08 10:53:35 (2 months ago)
Author:
bwolfe
Message:

Merging report-api-refactoring to trunk [2696]:[4157]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/api/db/hibernate/HibernatePatientSetDAO.java

    r4095 r4158  
    5353import org.hibernate.criterion.Restrictions; 
    5454import org.hibernate.type.StringType; 
     55import org.openmrs.Cohort; 
    5556import org.openmrs.Concept; 
    5657import org.openmrs.Drug; 
     
    8687import org.openmrs.api.db.DAOException; 
    8788import org.openmrs.api.db.PatientSetDAO; 
    88 import org.openmrs.reporting.PatientSet; 
    8989import org.w3c.dom.Document; 
    9090import org.w3c.dom.Element; 
     
    110110        } 
    111111         
    112         public String exportXml(PatientSet ps) throws DAOException { 
     112        public String exportXml(Cohort ps) throws DAOException { 
    113113                // TODO: This is inefficient for large patient sets. 
    114114                StringBuffer ret = new StringBuffer("<patientset>"); 
    115                 for (Integer patientId : ps.getPatientIds()) { 
     115                for (Integer patientId : ps.getMemberIds()) { 
    116116                        ret.append(exportXml(patientId)); 
    117117                } 
     
    450450         
    451451        @SuppressWarnings("unchecked") 
    452         public PatientSet getAllPatients() { 
    453                  
    454                 Query query = sessionFactory.getCurrentSession().createQuery("select distinct patientId from Patient p where p.voided = 0 order by patientId"); 
    455                  
    456                 List<Integer> ids = new ArrayList<Integer>(); 
     452        public Cohort getAllPatients() { 
     453                 
     454                Query query = sessionFactory.getCurrentSession().createQuery("select distinct patientId from Patient p where p.voided = 0"); 
     455                 
     456                Set<Integer> ids = new HashSet<Integer>(); 
    457457                ids.addAll(query.list()); 
    458458                 
    459                 PatientSet patientSet = new PatientSet(); 
    460                 patientSet.setPatientIds(ids); 
    461                  
    462                 return patientSet; 
     459                return new Cohort(ids); 
    463460        } 
    464461         
     
    472469         * @return 
    473470         */ 
    474         public PatientSet getPatientsByProgramAndState(Program program, List<ProgramWorkflowState> stateList, Date fromDate, Date toDate) { 
     471        public Cohort getPatientsByProgramAndState(Program program, List<ProgramWorkflowState> stateList, Date fromDate, Date toDate) { 
    475472                Integer programId = program == null ? null : program.getProgramId(); 
    476473                List<Integer> stateIds = null; 
     
    522519                        query.setDate("toDate", toDate); 
    523520 
    524                 PatientSet ret = new PatientSet(); 
    525                 ret.copyPatientIds(query.list()); 
    526                 return ret; 
     521                return new Cohort(query.list()); 
    527522        } 
    528523         
     
    533528         * if toDate != null, then only those patients who were in the program at any time before that date 
    534529         */ 
    535         public PatientSet getPatientsInProgram(Integer programId, Date fromDate, Date toDate) { 
     530        public Cohort getPatientsInProgram(Integer programId, Date fromDate, Date toDate) { 
    536531                String sql = "select patient_id from patient_program pp where pp.voided = false and pp.program_id = :programId "; 
    537532                if (fromDate != null) 
     
    550545                        query.setDate("toDate", toDate); 
    551546                 
    552                 Set<Integer> ptIds = new HashSet<Integer>(); 
    553                 ptIds.addAll(query.list()); 
    554                 PatientSet ret = new PatientSet(); 
    555                 ret.copyPatientIds(ptIds); 
    556                 return ret; 
    557         } 
    558  
    559         public PatientSet getPatientsHavingObs(Integer conceptId, PatientSetService.TimeModifier timeModifier, PatientSetService.Modifier modifier, Object value, Date fromDate, Date toDate) { 
     547                return new Cohort(query.list()); 
     548        } 
     549 
     550        public Cohort getPatientsHavingObs(Integer conceptId, PatientSetService.TimeModifier timeModifier, PatientSetService.Modifier modifier, Object value, Date fromDate, Date toDate) { 
    560551                if (conceptId == null && value == null) 
    561552                        throw new IllegalArgumentException("Can't have conceptId == null and value == null"); 
     
    690681                        query.setDate("toDate", toDate); 
    691682 
    692                 PatientSet ret; 
     683                Cohort ret; 
    693684                if (doInvert) { 
    694685                        ret = getAllPatients(); 
    695                         ret.removeAllIds(query.list()); 
     686                        ret.getMemberIds().removeAll(query.list()); 
    696687                } else { 
    697                         ret = new PatientSet(); 
    698                         List patientIds = query.list(); 
    699                         ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
     688                        ret = new Cohort(query.list()); 
    700689                } 
    701690 
     
    714703         *   * patients with up to maxCount of the given encounters 
    715704         */ 
    716         public PatientSet getPatientsHavingEncounters(List<EncounterType> encounterTypeList, Location location, Form form, Date fromDate, Date toDate, Integer minCount, Integer maxCount) { 
     705        public Cohort getPatientsHavingEncounters(List<EncounterType> encounterTypeList, Location location, Form form, Date fromDate, Date toDate, Integer minCount, Integer maxCount) { 
    717706                List<Integer> encTypeIds = null; 
    718707                if (encounterTypeList != null) { 
     
    769758                        query.setInteger("maxCount", maxCount); 
    770759 
    771                 PatientSet ret = new PatientSet(); 
    772                 ret.copyPatientIds(query.list()); 
    773                 return ret; 
     760                return new Cohort(query.list()); 
    774761        } 
    775762         
     
    785772         */ 
    786773        @SuppressWarnings("unchecked") 
    787         public PatientSet getPatientsHavingDateObs(Integer conceptId, Date startTime, Date endTime) { 
     774        public Cohort getPatientsHavingDateObs(Integer conceptId, Date startTime, Date endTime) { 
    788775                StringBuffer sb = new StringBuffer(); 
    789776                sb.append("select o.person_id from obs o " + 
     
    799786                query.setDate("endValue", endTime); 
    800787                 
    801                 PatientSet ret = new PatientSet(); 
    802                 List patientIds = query.list(); 
    803                 ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
    804  
    805                 return ret; 
    806         } 
    807          
    808         @SuppressWarnings("unchecked") 
    809         public PatientSet getPatientsHavingNumericObs(Integer conceptId, PatientSetService.TimeModifier timeModifier, PatientSetService.Modifier modifier, Number value, Date fromDate, Date toDate) { 
     788                return new Cohort(query.list()); 
     789        } 
     790         
     791        @SuppressWarnings("unchecked") 
     792        public Cohort getPatientsHavingNumericObs(Integer conceptId, PatientSetService.TimeModifier timeModifier, PatientSetService.Modifier modifier, Number value, Date fromDate, Date toDate) { 
    810793                 
    811794                Concept concept = Context.getConceptService().getConcept(conceptId); 
     
    875858                        query.setDate("toDate", fromDate); 
    876859 
    877                 PatientSet ret; 
     860                Cohort ret; 
    878861                if (doInvert) { 
    879862                        ret = getAllPatients(); 
    880                         ret.removeAllIds(query.list()); 
     863                        ret.getMemberIds().removeAll(query.list()); 
    881864                } else { 
    882                         ret = new PatientSet(); 
    883                         List patientIds = query.list(); 
    884                         ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
     865                        ret = new Cohort(query.list()); 
    885866                } 
    886867 
     
    889870         
    890871        @SuppressWarnings("unchecked") 
    891         public PatientSet getPatientsByCharacteristics(String gender, Date minBirthdate, Date maxBirthdate, 
     872        public Cohort getPatientsByCharacteristics(String gender, Date minBirthdate, Date maxBirthdate, 
    892873                        Integer minAge, Integer maxAge, Boolean aliveOnly, Boolean deadOnly) throws DAOException { 
     874                return getPatientsByCharacteristics(gender, minBirthdate, maxBirthdate, minAge, maxAge, aliveOnly, deadOnly, null); 
     875        } 
     876                 
     877        @SuppressWarnings("unchecked") 
     878        public Cohort getPatientsByCharacteristics(String gender, Date minBirthdate, Date maxBirthdate, 
     879                        Integer minAge, Integer maxAge, Boolean aliveOnly, Boolean deadOnly, Date effectiveDate) throws DAOException { 
     880                 
     881                if (effectiveDate == null) { 
     882                        effectiveDate = new Date(); 
     883                } 
    893884                 
    894885                StringBuffer queryString = new StringBuffer("select patientId from Patient patient"); 
     
    908899                } 
    909900                if (aliveOnly != null && aliveOnly) { 
    910                         clauses.add("patient.dead = false"); 
     901                        clauses.add("patient.dead = false");  // TODO: Should this use effectiveDate?  What if deathDate is null? 
    911902                } 
    912903                if (deadOnly != null && deadOnly) { 
    913                         clauses.add("patient.dead = true"); 
     904                        clauses.add("patient.dead = true");  // TODO: Should this use effectiveDate?  What if deathDate is null? 
    914905                } 
    915906 
     
    917908                if (minAge != null) { 
    918909                        Calendar cal = new GregorianCalendar(); 
     910                        cal.setTime(effectiveDate); 
    919911                        cal.add(Calendar.YEAR, -minAge); 
    920912                        maxBirthFromAge = cal.getTime(); 
     
    924916                if (maxAge != null) { 
    925917                        Calendar cal = new GregorianCalendar(); 
     918                        cal.setTime(effectiveDate); 
    926919                        cal.add(Calendar.YEAR, -(maxAge + 1)); 
    927920                        minBirthFromAge = cal.getTime(); 
     
    956949                } 
    957950                 
    958                 List<Integer> patientIds = query.list(); 
    959                  
    960                 PatientSet ret = new PatientSet(); 
    961                 ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
    962  
    963                 return ret; 
     951                return new Cohort(query.list()); 
    964952        } 
    965953 
     
    998986         
    999987        @SuppressWarnings("unchecked") 
    1000         public Map<Integer, Map<String, Object>> getCharacteristics(PatientSet patients) throws DAOException { 
     988        public Map<Integer, Map<String, Object>> getCharacteristics(Cohort patients) throws DAOException { 
    1001989                Map<Integer, Map<String, Object>> ret = new HashMap<Integer, Map<String, Object>>(); 
    1002                 Collection<Integer> ids = patients.getPatientIds(); 
     990                Collection<Integer> ids = patients.getMemberIds(); 
    1003991                Query query = sessionFactory.getCurrentSession().createQuery("select patient.personId, patient.gender, patient.birthdate from Patient patient where patient.voided = false"); 
    1004992                query.setCacheMode(CacheMode.IGNORE); 
     
    10301018         * TODO: finish this.  
    10311019         */ 
    1032         public Map<Integer, List<Obs>> getObservations(PatientSet patients, Concept concept, Date fromDate, Date toDate) throws DAOException { 
     1020        public Map<Integer, List<Obs>> getObservations(Cohort patients, Concept concept, Date fromDate, Date toDate) throws DAOException { 
    10331021                Map<Integer, List<Obs>> ret = new HashMap<Integer, List<Obs>>(); 
    10341022                 
     
    10601048                // only add this where clause if patients were passed in 
    10611049                if (patients != null) 
    1062                         criteria.add(Restrictions.in("person.personId", patients.getPatientIds())); 
     1050                        criteria.add(Restrictions.in("person.personId", patients.getMemberIds())); 
    10631051                 
    10641052                criteria.add(Restrictions.eq("voided", false)); 
     
    10791067        } 
    10801068         
    1081         public Map<Integer, List<List<Object>>> getObservationsValues(PatientSet patients, Concept c, List<String> attributes) { 
     1069        public Map<Integer, List<List<Object>>> getObservationsValues(Cohort patients, Concept c, List<String> attributes) { 
    10821070                Map<Integer, List<List<Object>>> ret = new HashMap<Integer, List<List<Object>>>(); 
    10831071                 
     
    11511139                // only restrict on patient ids if some were passed in 
    11521140                if (patients != null) 
    1153                         criteria.add(Restrictions.in("obs.personId", patients.getPatientIds())); 
     1141                        criteria.add(Restrictions.in("obs.personId", patients.getMemberIds())); 
    11541142                 
    11551143                criteria.add(Expression.eq("obs.concept", c)); 
     
    12271215         
    12281216        @SuppressWarnings("unchecked") 
    1229         public Map<Integer, Encounter> getEncountersByType(PatientSet patients, List<EncounterType> encTypes) { 
     1217        public Map<Integer, Encounter> getEncountersByType(Cohort patients, List<EncounterType> encTypes) { 
    12301218                Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); 
    12311219                 
     
    12361224                // this "where clause" is only necessary if patients were passed in 
    12371225                if (patients != null && patients.size() > 0) 
    1238                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1226                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    12391227                 
    12401228                criteria.add(Restrictions.eq("voided", false)); 
     
    12651253         */ 
    12661254        @SuppressWarnings("unchecked") 
    1267         public List<Encounter> getEncountersByForm(PatientSet patients, List<Form> forms) { 
     1255        public List<Encounter> getEncountersByForm(Cohort patients, List<Form> forms) { 
    12681256                 
    12691257                // default query 
     
    12731261                // this "where clause" is only necessary if patients were passed in 
    12741262                if (patients != null && patients.size() > 0) 
    1275                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1263                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    12761264                 
    12771265                criteria.add(Restrictions.eq("voided", false)); 
     
    12881276         
    12891277         
    1290         public Map<Integer, Object> getEncounterAttrsByType(PatientSet patients, List<EncounterType> encTypes, String attr, Boolean earliestFirst) { 
     1278        public Map<Integer, Object> getEncounterAttrsByType(Cohort patients, List<EncounterType> encTypes, String attr, Boolean earliestFirst) { 
    12911279                Map<Integer, Object> ret = new HashMap<Integer, Object>(); 
    12921280                 
     
    12971285                // this "where clause" is only necessary if patients were specified 
    12981286                if (patients != null) 
    1299                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1287                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    13001288                 
    13011289                criteria.add(Restrictions.eq("voided", false)); 
     
    13281316         
    13291317        @SuppressWarnings("unchecked") 
    1330         public Map<Integer, Encounter> getEncounters(PatientSet patients) { 
     1318        public Map<Integer, Encounter> getEncounters(Cohort patients) { 
    13311319                Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); 
    13321320                 
     
    13371325                // only include this where clause if patients were passed in 
    13381326                if (patients != null) 
    1339                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1327                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    13401328                 
    13411329                criteria.add(Restrictions.eq("voided", false)); 
     
    13571345                 
    13581346        @SuppressWarnings("unchecked") 
    1359         public Map<Integer, Encounter> getFirstEncountersByType(PatientSet patients, List<EncounterType> types) { 
     1347        public Map<Integer, Encounter> getFirstEncountersByType(Cohort patients, List<EncounterType> types) { 
    13601348                Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); 
    13611349                 
     
    13661354                // this "where clause" is only needed if patients were specified 
    13671355                if (patients != null) 
    1368                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1356                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    13691357                 
    13701358                criteria.add(Restrictions.eq("voided", false)); 
     
    13901378        @SuppressWarnings("unchecked") 
    13911379        // TODO: this method seems to be missing a check for voided==false. 
    1392         public Map<Integer, Object> getPatientAttributes(PatientSet patients, String className, String property, boolean returnAll) throws DAOException { 
     1380        public Map<Integer, Object> getPatientAttributes(Cohort patients, String className, String property, boolean returnAll) throws DAOException { 
    13931381                Map<Integer, Object> ret = new HashMap<Integer, Object>(); 
    13941382                 
     
    14161404                         
    14171405                        if (patients != null) 
    1418                                 criteria.add(Restrictions.in("person.personId", patients.getPatientIds())); 
     1406                                criteria.add(Restrictions.in("person.personId", patients.getMemberIds())); 
     1407                         
     1408                        // do not include voided person rows 
     1409                        criteria.add(Expression.eq("personVoided", false)); 
    14191410                } 
    14201411                else { 
     
    14231414                         
    14241415                        if (patients != null) 
    1425                                 criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     1416                                criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
     1417                         
     1418                        // do not include voided patients 
     1419                        criteria.add(Expression.eq("voided", false)); 
    14261420                } 
    14271421                criteria.setProjection(projectionList); 
    1428                  
    1429                 //criteria.addOrder(org.hibernate.criterion.Order.desc("voided")); 
    1430                 criteria.add(Expression.eq("voided", false)); 
    14311422                 
    14321423                // add 'preferred' sort order if necessary 
     
    14781469         
    14791470        /** 
    1480          * @see org.openmrs.api.db.PatientSetDAO#getPersonAttributes(org.openmrs.reporting.PatientSet, java.lang.String, java.lang.String, java.lang.String, boolean) 
     1471         * @see org.openmrs.api.db.PatientSetDAO#getPersonAttributes(org.openmrs.Cohort, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) 
    14811472         */ 
    1482         public Map<Integer, Object> getPersonAttributes(PatientSet patients, String attributeTypeName, String joinClass, String joinProperty, String outputColumn, boolean returnAll) { 
     1473        public Map<Integer, Object> getPersonAttributes(Cohort patients, String attributeTypeName, String joinClass, String joinProperty, String outputColumn, boolean returnAll) { 
    14831474                Map<Integer, Object> ret = new HashMap<Integer, Object>(); 
    14841475                 
     
    15111502                // this where clause is only necessary if patients were passed in 
    15121503                if (patients != null) 
    1513                         query.setParameterList("ids", patients.getPatientIds()); 
     1504                        query.setParameterList("ids", patients.getMemberIds()); 
    15141505                 
    15151506                query.setString("typeName", attributeTypeName); 
     
    15511542        // TODO: don't return voided patients. Also, remove this method 
    15521543        @SuppressWarnings("unchecked") 
    1553         public PatientSet getPatientsHavingTextObs(Integer conceptId, String value, TimeModifier timeModifier) throws DAOException { 
     1544        public Cohort getPatientsHavingTextObs(Integer conceptId, String value, TimeModifier timeModifier) throws DAOException { 
    15541545                Query query; 
    15551546                StringBuffer sb = new StringBuffer(); 
     
    15851576                } 
    15861577 
    1587                 PatientSet ret = new PatientSet(); 
    1588                 List patientIds = query.list(); 
    1589                 ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
    1590  
    1591                 return ret; 
     1578                return new Cohort(query.list()); 
    15921579        } 
    15931580         
    15941581        //TODO: the encounter variants may return voided patients 
    15951582        @SuppressWarnings("unchecked") 
    1596         public PatientSet getPatientsHavingLocation(Integer locationId, PatientSetService.PatientLocationMethod method) throws DAOException { 
     1583        public Cohort getPatientsHavingLocation(Integer locationId, PatientSetService.PatientLocationMethod method) throws DAOException { 
    15971584                 
    15981585                // TODO this needs to be retired after the cohort builder is in place 
     
    16391626                query.setInteger("location_id", locationId); 
    16401627 
    1641                 PatientSet ret = new PatientSet(); 
    1642                 List<Integer> patientIds = query.list(); 
    1643                 ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
    1644                  
    1645                 return ret; 
    1646         } 
    1647  
    1648         public PatientSet convertPatientIdentifier(List<String> identifiers) throws DAOException { 
     1628                return new Cohort(query.list()); 
     1629        } 
     1630 
     1631        public Cohort convertPatientIdentifier(List<String> identifiers) throws DAOException { 
    16491632                 
    16501633                StringBuffer sb = new StringBuffer(); 
     
    16541637                query.setCacheMode(CacheMode.IGNORE); 
    16551638                query.setParameterList("identifiers", identifiers, new StringType()); 
    1656                 PatientSet ret = new PatientSet(); 
    1657                 List<Integer> patientIds = query.list(); 
    1658                 ret.setPatientIds(new ArrayList<Integer>(patientIds)); 
    1659                  
    1660                 return ret; 
     1639                return new Cohort(query.list()); 
    16611640        } 
    16621641         
     
    17361715 
    17371716        @SuppressWarnings("unchecked") 
    1738         public Map<Integer, PatientState> getCurrentStates(PatientSet ps, ProgramWorkflow wf) throws DAOException { 
     1717        public Map<Integer, PatientState> getCurrentStates(Cohort ps, ProgramWorkflow wf) throws DAOException { 
    17391718                Map<Integer, PatientState> ret = new HashMap<Integer, PatientState>(); 
    17401719                 
     
    17471726                // only include this where clause if patients were passed in 
    17481727                if (ps != null) 
    1749                         criteria.createCriteria("patientProgram").add(Restrictions.in("patient.personId", ps.getPatientIds())); 
     1728                        criteria.createCriteria("patientProgram").add(Restrictions.in("patient.personId", ps.getMemberIds())); 
    17501729                 
    17511730                //criteria.add(Restrictions.eq("state.programWorkflow", wf)); 
     
    17711750         */ 
    17721751        @SuppressWarnings("unchecked") 
    1773         public Map<Integer, PatientProgram> getPatientPrograms(PatientSet ps, Program program, 
     1752        public Map<Integer, PatientProgram> getPatientPrograms(Cohort ps, Program program, 
    17741753                        boolean includeVoided, boolean includePast) throws DAOException { 
    17751754                Map<Integer, PatientProgram> ret = new HashMap<Integer, PatientProgram>(); 
     
    17821761                // this "where clause" is only necessary if patients were passed in 
    17831762                if (ps != null) 
    1784                         criteria.add(Restrictions.in("patient.personId", ps.getPatientIds())); 
     1763                        criteria.add(Restrictions.in("patient.personId", ps.getMemberIds())); 
    17851764                 
    17861765                criteria.add(Restrictions.eq("program", program)); 
     
    18011780 
    18021781        @SuppressWarnings("unchecked") 
    1803         public Map<Integer, List<DrugOrder>> getCurrentDrugOrders(PatientSet ps, List<Concept> drugConcepts) throws DAOException { 
     1782        public Map<Integer, List<DrugOrder>> getCurrentDrugOrders(Cohort patients, List<Concept> drugConcepts) throws DAOException { 
    18041783                Map<Integer, List<DrugOrder>> ret = new HashMap<Integer, List<DrugOrder>>(); 
    18051784                 
     
    18101789                 
    18111790                // this "where clause" is only necessary if patients were passed in 
    1812                 if (ps != null) 
    1813                         criteria.add(Restrictions.in("patient.personId", ps.getPatientIds())); 
     1791                if (patients != null) 
     1792                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    18141793                 
    18151794                //criteria.add(Restrictions.in("encounter.patient.personId", ids)); 
     
    18391818         
    18401819        @SuppressWarnings("unchecked") 
    1841         public Map<Integer, List<DrugOrder>> getDrugOrders(PatientSet ps, List<Concept> drugConcepts) throws DAOException { 
     1820        public Map<Integer, List<DrugOrder>> getDrugOrders(Cohort patients, List<Concept> drugConcepts) throws DAOException { 
    18421821                Map<Integer, List<DrugOrder>> ret = new HashMap<Integer, List<DrugOrder>>(); 
    18431822 
     
    18461825                 
    18471826                // only include this where clause if patients were passed in 
    1848                 if (ps != null) 
    1849                         criteria.add(Restrictions.in("patient.personId", ps.getPatientIds())); 
     1827                if (patients != null) 
     1828                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    18501829                 
    18511830                if (drugConcepts != null) 
     
    18731852         */ 
    18741853        @SuppressWarnings("unchecked") 
    1875         public Map<Integer, List<Person>> getRelatives(PatientSet ps, RelationshipType relType, boolean forwards) { 
     1854        public Map<Integer, List<Person>> getRelatives(Cohort patients, RelationshipType relType, boolean forwards) { 
    18761855                if (relType == null) 
    18771856                        throw new IllegalArgumentException("Must give a relationship type"); 
    18781857                Map<Integer, List<Person>> ret = new HashMap<Integer, List<Person>>(); 
    1879                 if (ps != null) 
    1880                         if (ps.size() == 0) 
     1858                if (patients != null) 
     1859                        if (patients.size() == 0) 
    18811860                                return ret; 
    18821861 
    18831862                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Relationship.class); 
    18841863                criteria.add(Restrictions.eq("voided", false)); 
    1885                 if (ps != null) { 
     1864                if (patients != null) { 
    18861865                        if (forwards) { 
    1887                                 criteria.add(Restrictions.in("personA.personId", ps.getPatientIds())); 
     1866                                criteria.add(Restrictions.in("personA.personId", patients.getMemberIds())); 
    18881867                        } else { 
    1889                                 criteria.add(Restrictions.in("personB.personId", ps.getPatientIds())); 
     1868                                criteria.add(Restrictions.in("personB.personId", patients.getMemberIds())); 
    18901869                        } 
    18911870                } 
     
    19091888        // TODO: Refactor this completely to make it useful now that relationships are bidirectional. (Or delete it.)  
    19101889        @SuppressWarnings("unchecked") 
    1911         public Map<Integer, List<Relationship>> getRelationships(PatientSet ps, RelationshipType relType) { 
     1890        public Map<Integer, List<Relationship>> getRelationships(Cohort patients, RelationshipType relType) { 
    19121891                Map<Integer, List<Relationship>> ret = new HashMap<Integer, List<Relationship>>(); 
    19131892                 
     
    19181897                 
    19191898                // this "where clause" is only useful if patients were passed in 
    1920                 if (ps != null) 
    1921                         criteria.createCriteria("personB").add(Restrictions.in("personId", ps.getPatientIds())); 
     1899                if (patients != null) 
     1900                        criteria.createCriteria("personB").add(Restrictions.in("personId", patients.getMemberIds())); 
    19221901                 
    19231902                criteria.add(Restrictions.eq("voided", false)); 
     
    19361915        } 
    19371916         
    1938         public PatientSet getPatientsHavingPersonAttribute(PersonAttributeType attribute, String value) { 
     1917        public Cohort getPatientsHavingPersonAttribute(PersonAttributeType attribute, String value) { 
    19391918                StringBuilder sb = new StringBuilder(); 
    19401919                sb.append(" select pat.patient_id from person p inner join patient pat on pat.patient_id = p.person_id inner join person_attribute a on p.person_id = a.person_id "); 
     
    19531932                        query.setString("value", value); 
    19541933                 
    1955                 PatientSet ps = new PatientSet(); 
    1956                 ps.copyPatientIds(query.list()); 
    1957                 return ps; 
     1934                return new Cohort(query.list()); 
    19581935        } 
    19591936         
    19601937        // TODO: don't return voided patients 
    1961         public PatientSet getPatientsHavingDrugOrder( 
     1938        public Cohort getPatientsHavingDrugOrder( 
    19621939                        List<Drug> drugList, List<Concept> drugConceptList, 
    19631940                        Date startDateFrom, Date startDateTo, 
     
    20472024                } 
    20482025                 
    2049                 PatientSet ps = new PatientSet(); 
    2050                 ps.copyPatientIds(query.list()); 
    2051                 return ps; 
     2026                return new Cohort(query.list()); 
    20522027        } 
    20532028         
     
    20612036         */ 
    20622037        @SuppressWarnings("unchecked") 
    2063         public Map<Integer, PatientIdentifier> getPatientIdentifierByType(PatientSet patients, List<PatientIdentifierType> types) { 
     2038        public Map<Integer, PatientIdentifier> getPatientIdentifierByType(Cohort patients, List<PatientIdentifierType> types) { 
    20642039                Map<Integer, PatientIdentifier> patientIdentifiers = new HashMap<Integer, PatientIdentifier>(); 
    20652040                 
     
    20702045                // Add patient restriction if necessary 
    20712046                if (patients != null) 
    2072                         criteria.add(Restrictions.in("patient.personId", patients.getPatientIds())); 
     2047                        criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); 
    20732048                 
    20742049                // all identifiers must be non-voided