Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
08/06/08 17:17:55 (5 months ago)
Author:
mseaton
Message:

synchronization_bidirectional_branch: merge from [4734] to [5181].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Patient.java

    r4969 r5183  
    215215         
    216216        /** 
    217          * Convenience method to get the "preferred" identifier for patient. 
     217         * Convenience method to get the first "preferred" identifier for a patient. 
     218         * Otherwise, returns the first non-voided identifier 
     219         * Otherwise, null 
    218220         *  
    219221         * @return Returns the "preferred" patient identifier. 
    220222         */ 
    221223        public PatientIdentifier getPatientIdentifier() { 
    222                 if (getIdentifiers() != null && identifiers.size() > 0) { 
    223                         return (PatientIdentifier) identifiers.toArray()[0]; 
    224                 } else { 
     224                if (getIdentifiers() != null && getIdentifiers().size() > 0) { 
     225                        for (PatientIdentifier id : getIdentifiers()) { 
     226                                        if (id.isPreferred() && !id.isVoided()) 
     227                                                return id; 
     228                        } 
     229                        for (PatientIdentifier id : getIdentifiers()) { 
     230                                if (!id.isVoided()) 
     231                                        return id; 
     232                        } 
    225233                        return null; 
    226                 } 
     234                }  
     235                return null; 
     236 
     237        } 
     238         
     239        /** 
     240         *  
     241         * Returns the first (preferred) patient identifier matching a <code>PatientIdentifierType</code> 
     242         * Otherwise, returns the first non-voided identifier 
     243         * Otherwise, null 
     244         *  
     245         * @param identifierType 
     246         * @return 
     247         */ 
     248        public PatientIdentifier getPatientIdentifier(PatientIdentifierType pit) { 
     249                if (getIdentifiers() != null && getIdentifiers().size() > 0) { 
     250                        for (PatientIdentifier id : getIdentifiers()) { 
     251                                        if (id.isPreferred() && !id.isVoided() && pit.equals(id.getIdentifierType())) 
     252                                                return id; 
     253                        } 
     254                        for (PatientIdentifier id : getIdentifiers()) { 
     255                                if (!id.isVoided() && pit.equals(id.getIdentifierType())) 
     256                                        return id; 
     257                        } 
     258                        return null; 
     259                }  
     260                return null; 
    227261        } 
    228262         
     
    232266         * @param identifierTypeId 
    233267         * @return preferred patient identifier 
     268         * 
    234269         */ 
    235270        public PatientIdentifier getPatientIdentifier(Integer identifierTypeId) { 
    236                 if (getIdentifiers() != null && identifiers.size() > 0) { 
    237                         PatientIdentifier found = null; 
    238                         for (PatientIdentifier id : identifiers) { 
    239                                 if (id.getIdentifierType().getPatientIdentifierTypeId().equals(identifierTypeId)) { 
    240                                         found = id; 
    241                                         if (found.isPreferred()) 
    242                                                 return found; 
    243                                 } 
    244                         } 
    245                         return found; 
    246                 } else { 
     271                if (getIdentifiers() != null && getIdentifiers().size() > 0) { 
     272                        for (PatientIdentifier id : getIdentifiers()) { 
     273                                        if (id.isPreferred() && !id.isVoided() && identifierTypeId.equals(id.getIdentifierType().getPatientIdentifierTypeId())) 
     274                                                return id; 
     275                        } 
     276                        for (PatientIdentifier id : getIdentifiers()) { 
     277                                if (!id.isVoided() && identifierTypeId.equals(id.getIdentifierType().getPatientIdentifierTypeId())) 
     278                                        return id; 
     279                        } 
    247280                        return null; 
    248                 } 
    249         } 
    250          
    251         /** 
    252          * Return's the first (preferred) patient identifier matching <code>identifierTypeName</code> 
     281                }  
     282                return null; 
     283        } 
     284         
     285        /** 
     286         * Return's the (preferred) patient identifier matching <code>identifierTypeName</code> 
     287         * Otherwise returns that last <code>PatientIdenitifer</code> 
    253288         *  
    254289         * @param identifierTypeName 
     
    256291         */ 
    257292        public PatientIdentifier getPatientIdentifier(String identifierTypeName) { 
    258                 if (getIdentifiers() != null && identifiers.size() > 0) { 
    259                         PatientIdentifier found = null; 
    260                         for (PatientIdentifier id : identifiers) { 
    261                                 if (id.getIdentifierType().getName().equals(identifierTypeName)) { 
    262                                         found = id; 
    263                                         if (found.isPreferred()) 
    264                                                 return found; 
    265                                 } 
    266                         } 
    267                         return found; 
    268                 } else { 
     293                if (getIdentifiers() != null && getIdentifiers().size() > 0) { 
     294                        for (PatientIdentifier id : getIdentifiers()) { 
     295                                        if (id.isPreferred() && !id.isVoided() && identifierTypeName.equals(id.getIdentifierType().getName())) 
     296                                                return id; 
     297                        } 
     298                        for (PatientIdentifier id : getIdentifiers()) { 
     299                                if (!id.isVoided() && identifierTypeName.equals(id.getIdentifierType().getName())) 
     300                                        return id; 
     301                        } 
    269302                        return null; 
    270                 }                
     303                }  
     304                return null;             
    271305        } 
    272306         
     
    276310         *  
    277311         * @return list of non-voided identifiers for this patient 
    278          *  
    279312         * @see #getIdentifiers() 
    280313         */ 
     
    282315                List<PatientIdentifier> ids = new Vector<PatientIdentifier>(); 
    283316                if (getIdentifiers() != null) { 
    284                         for (PatientIdentifier pi : identifiers) { 
     317                        for (PatientIdentifier pi : getIdentifiers()) { 
    285318                                if (pi.isVoided() == false) 
    286319                                        ids.add(pi); 
     
    290323        } 
    291324         
     325         
     326        /** 
     327         * Returns only the non-voided identifiers for this patient. 
     328         * If you want <u>all</u> identifiers, use {@link #getIdentifiers()} 
     329         *  
     330         * @return list of non-voided identifiers for this patient 
     331         * @param identifierType 
     332         * @see #getIdentifiers() 
     333         */ 
     334        public List<PatientIdentifier> getPatientIdentifiers(PatientIdentifierType pit) { 
     335                List<PatientIdentifier> ids = new Vector<PatientIdentifier>(); 
     336                if (getIdentifiers() != null) { 
     337                        for (PatientIdentifier pi : getIdentifiers()) { 
     338                                if (pi.isVoided() == false && pit.equals(pi.getIdentifierType())) 
     339                                        ids.add(pi); 
     340                        } 
     341                } 
     342                return ids; 
     343        } 
     344         
    292345        public String toString() { 
    293346                return "Patient#" + patientId;