Changeset 4969 for openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Cohort.java
- Timestamp:
- 07/17/08 15:20:10 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/data_synchronization_bidirectional
- Property svn:ignore changed from
build*
dist*
${env.CATALINA_HOME}
docs
.metadata
setup.inf
setup.rpt
to
build*
dist*
${env.CATALINA_HOME}
docs
.metadata
setup.inf
setup.rpt
*.iws
*.ipr
*.iml
- Property svn:ignore changed from
openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Cohort.java
r4661 r4969 15 15 16 16 import java.io.Serializable; 17 import java.util.Arrays; 17 18 import java.util.Collection; 18 19 import java.util.Date; … … 55 56 private Date dateVoided; 56 57 private String voidReason; 58 private User changedBy; 59 private Date dateChanged; 57 60 private Set<Integer> memberIds; 58 61 private CohortDefinition cohortDefinition; … … 74 77 } 75 78 76 public Cohort(Set<Integer> memberIds) { 77 this.memberIds = memberIds; 78 } 79 80 public Cohort(Collection<Integer> memberIds) { 81 this.memberIds = new HashSet<Integer>(); 82 this.memberIds.addAll(memberIds); 83 } 84 79 /** 80 * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 81 * @param name 82 * @param description optional description 83 * @param ids option array of Integer ids 84 */ 85 public Cohort(String name, String description, Integer[] ids) { 86 this.name = name; 87 this.description = description; 88 memberIds = new HashSet<Integer>(); 89 if (ids != null) 90 memberIds.addAll(Arrays.asList(ids)); 91 } 92 93 /** 94 * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 95 * @param name 96 * @param description optional description 97 * @param patients optional array of patients 98 */ 99 public Cohort(String name, String description, Patient[] patients) { 100 this.name = name; 101 this.description = description; 102 memberIds = new HashSet<Integer>(); 103 if (patients != null) 104 for (Patient p : patients) 105 memberIds.add(p.getPatientId()); 106 } 107 108 /** 109 * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 110 * @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. 111 */ 112 @SuppressWarnings("unchecked") 113 public Cohort(Collection patientsOrIds) { 114 this(null, null, patientsOrIds); 115 } 116 117 /** 118 * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 119 * @param name 120 * @param description optional description 121 * @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. 122 */ 123 @SuppressWarnings("unchecked") 124 public Cohort(String name, String description, Collection patientsOrIds) { 125 this.name = name; 126 this.description = description; 127 memberIds = new HashSet<Integer>(); 128 if (patientsOrIds != null) { 129 for (Object o : patientsOrIds) { 130 if (o instanceof Patient) 131 memberIds.add(((Patient) o).getPatientId()); 132 else if (o instanceof Integer) 133 memberIds.add((Integer) o); 134 else 135 memberIds.add(Integer.valueOf(o.toString())); 136 } 137 } 138 } 139 140 /** 141 * Convenience contructor taking in a string that is a list of comma separated patient ids 142 * This constructor does not check whether the database contains patients with the given ids, but @see CohortService.saveCohort(Cohort) will. 143 * 144 * @param commaSeparatedIds 145 */ 85 146 public Cohort(String commaSeparatedIds) { 86 147 memberIds = new HashSet<Integer>(); … … 102 163 } 103 164 165 166 public boolean contains(Patient patient) { 167 return getMemberIds() != null && getMemberIds().contains(patient.getPatientId()); 168 } 169 170 public boolean contains(Integer patientId) { 171 return getMemberIds() != null && getMemberIds().contains(patientId); 172 } 173 104 174 public String toString() { 105 return getMemberIds() == null ? "Cohort with null members" : (getMemberIds().size() + " patients"); 106 } 107 175 StringBuilder sb = new StringBuilder("Cohort id=" + getCohortId()); 176 if (getName() != null) 177 sb.append(" name=" + getName()); 178 if (getMemberIds() != null) 179 sb.append(" size=" + getMemberIds().size()); 180 return sb.toString(); 181 } 182 108 183 public boolean equals(Object obj) { 109 184 if (this.getCohortId() == null) … … 139 214 } 140 215 216 public boolean isEmpty() { 217 return size() == 0; 218 } 219 141 220 // static utility methods 142 221 222 /** 223 * 224 * Returns the union of two cohorts 225 * 226 * @param a The first Cohort 227 * @param b The second Cohort 228 * @return Cohort 229 */ 143 230 public static Cohort union(Cohort a, Cohort b) { 144 231 Cohort ret = new Cohort(); … … 151 238 } 152 239 240 /** 241 * 242 * Returns the intersection of two cohorts 243 * 244 * @param a The first Cohort 245 * @param b The second Cohort 246 * @return Cohort 247 */ 153 248 public static Cohort intersect(Cohort a, Cohort b) { 154 249 Cohort ret = new Cohort(); … … 161 256 } 162 257 258 /** 259 * 260 * Subtracts a cohort from a cohort 261 * 262 * @param a the original Cohort 263 * @param b the Cohort to subtract 264 * @return Cohort 265 */ 163 266 public static Cohort subtract(Cohort a, Cohort b) { 164 267 Cohort ret = new Cohort(); … … 234 337 } 235 338 339 public Boolean isVoided() { 340 return voided; 341 } 342 343 /** 344 * @see #isVoided() 345 * @deprecated use isVoided() 346 */ 236 347 @Attribute(required=false) 237 348 public Boolean getVoided() { … … 287 398 } 288 399 400 401 public User getChangedBy() { 402 return changedBy; 403 } 404 405 public void setChangedBy(User changedBy) { 406 this.changedBy = changedBy; 407 } 408 409 public Date getDateChanged() { 410 return dateChanged; 411 } 412 413 public void setDateChanged(Date dateChanged) { 414 this.dateChanged = dateChanged; 415 } 416 289 417 /** 290 418 * @return the cohortDefinition … … 318 446 this.evaluationContext = evaluationContext; 319 447 } 320 321 448 }