Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
07/17/08 15:20:10 (6 months ago)
Author:
catullus
Message:

sync-bidrectional: partly merge

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
  • openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Cohort.java

    r4661 r4969  
    1515 
    1616import java.io.Serializable; 
     17import java.util.Arrays; 
    1718import java.util.Collection; 
    1819import java.util.Date; 
     
    5556        private Date dateVoided; 
    5657        private String voidReason; 
     58        private User changedBy; 
     59        private Date dateChanged; 
    5760        private Set<Integer> memberIds; 
    5861        private CohortDefinition cohortDefinition; 
     
    7477        } 
    7578         
    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         */ 
    85146        public Cohort(String commaSeparatedIds) { 
    86147                memberIds = new HashSet<Integer>(); 
     
    102163        } 
    103164         
     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                 
    104174        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                 
    108183        public boolean equals(Object obj) { 
    109184                if (this.getCohortId() == null) 
     
    139214        } 
    140215         
     216        public boolean isEmpty() {  
     217                return size() == 0; 
     218        } 
     219         
    141220        // static utility methods 
    142221         
     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         */ 
    143230        public static Cohort union(Cohort a, Cohort b) { 
    144231                Cohort ret = new Cohort(); 
     
    151238        } 
    152239         
     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         */ 
    153248        public static Cohort intersect(Cohort a, Cohort b) { 
    154249                Cohort ret = new Cohort(); 
     
    161256        } 
    162257         
     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         */ 
    163266        public static Cohort subtract(Cohort a, Cohort b) { 
    164267                Cohort ret = new Cohort(); 
     
    234337        } 
    235338         
     339        public Boolean isVoided() { 
     340                return voided; 
     341        } 
     342         
     343        /** 
     344         * @see #isVoided() 
     345         * @deprecated use isVoided() 
     346         */ 
    236347        @Attribute(required=false) 
    237348        public Boolean getVoided() { 
     
    287398        } 
    288399                 
     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         
    289417        /** 
    290418     * @return the cohortDefinition 
     
    318446        this.evaluationContext = evaluationContext; 
    319447    } 
    320          
    321448}