Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/24/08 09:37:02 (3 months ago)
Author:
bwolfe
Message:

Merging api-refactoring to trunk [3595]:[4355]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/Cohort.java

    r4158 r4358  
    1515 
    1616import java.io.Serializable; 
     17import java.util.Arrays; 
    1718import java.util.Collection; 
    1819import java.util.Date; 
     
    5455        private Date dateVoided; 
    5556        private String voidReason; 
     57        private User changedBy; 
     58        private Date dateChanged; 
    5659        private Set<Integer> memberIds; 
    5760        private CohortDefinition cohortDefinition; 
     
    7376        } 
    7477         
    75         public Cohort(Set<Integer> memberIds) { 
    76                 this.memberIds = memberIds; 
    77         } 
    78          
    79         public Cohort(Collection<Integer> memberIds) { 
    80                 this.memberIds = new HashSet<Integer>(); 
    81                 this.memberIds.addAll(memberIds); 
    82         } 
    83          
     78        /** 
     79         * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 
     80         * @param name 
     81         * @param description optional description 
     82         * @param ids option array of Integer ids 
     83         */ 
     84        public Cohort(String name, String description, Integer[] ids) { 
     85                this.name = name; 
     86                this.description = description; 
     87                memberIds = new HashSet<Integer>(); 
     88                if (ids != null) 
     89                        memberIds.addAll(Arrays.asList(ids)); 
     90        } 
     91         
     92        /** 
     93         * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 
     94         * @param name 
     95         * @param description optional description 
     96         * @param patients optional array of patients 
     97         */ 
     98        public Cohort(String name, String description, Patient[] patients) { 
     99                this.name = name; 
     100                this.description = description; 
     101                memberIds = new HashSet<Integer>(); 
     102                if (patients != null) 
     103                        for (Patient p : patients) 
     104                                memberIds.add(p.getPatientId()); 
     105        } 
     106         
     107        /** 
     108         * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 
     109         * @param patientsOrIds optional collection which may contain Patients, or patientIds which may be Integers, Strings, or anything whose toString() can be parsed to an Integer. 
     110         */ 
     111        public Cohort(Collection patientsOrIds) { 
     112                 this(null, null, patientsOrIds); 
     113        } 
     114         
     115        /** 
     116         * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 
     117         * @param name 
     118         * @param description optional description 
     119         * @param patientsOrIds optional collection which may contain Patients, or patientIds which may be Integers, Strings, or anything whose toString() can be parsed to an Integer. 
     120         */ 
     121        public Cohort(String name, String description, Collection patientsOrIds) { 
     122                this.name = name; 
     123                this.description = description; 
     124                memberIds = new HashSet<Integer>(); 
     125                if (patientsOrIds != null) { 
     126                        for (Object o : patientsOrIds) { 
     127                                if (o instanceof Patient) 
     128                                        memberIds.add(((Patient) o).getPatientId()); 
     129                                else if (o instanceof Integer) 
     130                                        memberIds.add((Integer) o); 
     131                                else 
     132                                        memberIds.add(Integer.valueOf(o.toString())); 
     133                        } 
     134                } 
     135        } 
     136         
     137        /** 
     138         * Convenience contructor taking in a string that is a list of comma separated patient ids 
     139         * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 
     140         *  
     141         * @param commaSeparatedIds 
     142         */ 
    84143        public Cohort(String commaSeparatedIds) { 
    85144                memberIds = new HashSet<Integer>(); 
     
    89148                } 
    90149        } 
    91                  
     150         
     151        /** 
     152         * Auto generated method comment 
     153         *  
     154         * @return 
     155         */ 
    92156        public String getCommaSeparatedPatientIds() { 
    93157                StringBuilder sb = new StringBuilder(); 
     
    100164                return sb.toString(); 
    101165        } 
     166         
     167        public boolean contains(Patient patient) { 
     168                return getMemberIds() != null && getMemberIds().contains(patient.getPatientId()); 
     169        } 
     170         
     171        public boolean contains(Integer patientId) { 
     172                return getMemberIds() != null && getMemberIds().contains(patientId); 
     173        } 
    102174                 
    103175        public String toString() { 
    104                 return getMemberIds() == null ? "Cohort with null members" : (getMemberIds().size() + " patients"); 
    105         } 
    106          
     176                StringBuilder sb = new StringBuilder("Cohort id=" + getCohortId()); 
     177                if (getName() != null) 
     178                        sb.append(" name=" + getName()); 
     179                if (getMemberIds() != null) 
     180                        sb.append(" size=" + getMemberIds().size()); 
     181                return sb.toString(); 
     182        } 
     183                 
    107184        public boolean equals(Object obj) { 
    108185                if (this.getCohortId() == null) 
     
    233310        } 
    234311         
     312        public Boolean isVoided() { 
     313                return voided; 
     314        } 
     315         
     316        /** 
     317         * @see #isVoided() 
     318         * @deprecated use isVoided() 
     319         */ 
    235320        @Attribute(required=false) 
    236321        public Boolean getVoided() { 
     
    286371        } 
    287372 
     373        public User getChangedBy() { 
     374        return changedBy; 
     375    } 
     376 
     377        public void setChangedBy(User changedBy) { 
     378        this.changedBy = changedBy; 
     379    } 
     380 
     381        public Date getDateChanged() { 
     382        return dateChanged; 
     383    } 
     384 
     385        public void setDateChanged(Date dateChanged) { 
     386        this.dateChanged = dateChanged; 
     387    } 
     388         
    288389        /** 
    289390     * @return the cohortDefinition 
     
    317418        this.evaluationContext = evaluationContext; 
    318419    } 
    319          
    320420}