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/Person.java

    r4297 r5183  
    427427                                attributeMap = null; 
    428428        } 
     429                 
     430        /** 
     431         * Convenience Method 
     432         * Returns the first non-voided person attribute matching a person attribute type 
     433         *  
     434         * @param pat 
     435         * @return PersonAttribute 
     436         */ 
     437        public PersonAttribute getAttribute(PersonAttributeType pat) { 
     438                        if (pat != null) 
     439                                for (PersonAttribute attribute : getAttributes()) { 
     440                                        if (pat.equals(attribute.getAttributeType()) && !attribute.isVoided()) { 
     441                                                return attribute; 
     442                                        } 
     443                                }        
     444                return null; 
     445        } 
    429446         
    430447        /** 
     
    435452        public PersonAttribute getAttribute(String attributeName) { 
    436453                if (attributeName != null) 
    437                         for (PersonAttribute attribute : getActiveAttributes()) { 
     454                        for (PersonAttribute attribute : getAttributes()) { 
    438455                                PersonAttributeType type = attribute.getAttributeType(); 
    439                                 if (type != null && attributeName.equals(type.getName())) { 
     456                                if (type != null && attributeName.equals(type.getName()) && !attribute.isVoided()) { 
    440457                                        return attribute; 
    441458                                } 
     
    452469        public PersonAttribute getAttribute(Integer attributeTypeId) { 
    453470                for (PersonAttribute attribute : getActiveAttributes()) { 
    454                         if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId())) { 
     471                        if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId()) && !attribute.isVoided()) { 
    455472                                return attribute; 
    456473                        } 
    457                 } 
    458                  
     474                }        
    459475                return null; 
    460476        } 
     
    466482         */ 
    467483        public List<PersonAttribute> getAttributes(String attributeName) { 
    468                 List<PersonAttribute> attributes = new Vector<PersonAttribute>(); 
     484                List<PersonAttribute> ret = new Vector<PersonAttribute>(); 
    469485                 
    470486                for (PersonAttribute attribute : getActiveAttributes()) { 
    471487                        PersonAttributeType type = attribute.getAttributeType(); 
    472                         if (type != null && attributeName.equals(type.getName())) { 
    473                                 attributes.add(attribute); 
     488                        if (type != null && attributeName.equals(type.getName()) && !attribute.isVoided()) { 
     489                                ret.add(attribute); 
    474490                        } 
    475491                } 
    476492                 
    477                 return attributes
     493                return ret
    478494        } 
    479495         
     
    484500         */ 
    485501        public List<PersonAttribute> getAttributes(Integer attributeTypeId) { 
    486                 List<PersonAttribute> attributes = new Vector<PersonAttribute>(); 
     502                List<PersonAttribute> ret = new Vector<PersonAttribute>(); 
    487503                 
    488504                for (PersonAttribute attribute : getActiveAttributes()) { 
    489                         if (attributeTypeId.equals(attribute.getPersonAttributeId())) { 
    490                                 attributes.add(attribute); 
     505                        if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId()) && !attribute.isVoided()) { 
     506                                ret.add(attribute); 
    491507                        } 
    492508                } 
    493509                 
    494                 return attributes; 
     510                return ret; 
     511        } 
     512         
     513         
     514        /** 
     515         * Convenience Method 
     516         * Returns all of this person's attributes that have a PersonAttributeType equal to <code>personAttributeType</code> 
     517         * @param attribute 
     518         */ 
     519        public List<PersonAttribute> getAttributes(PersonAttributeType personAttributeType) { 
     520                List<PersonAttribute> ret = new Vector<PersonAttribute>();       
     521                for (PersonAttribute attribute : getAttributes()) { 
     522                        if (personAttributeType.equals(attribute.getAttributeType()) && !attribute.isVoided()) { 
     523                                ret.add(attribute); 
     524                        } 
     525                }        
     526                return ret; 
    495527        } 
    496528         
     
    588620         */ 
    589621        public PersonName getPersonName() { 
    590                 if (names != null && names.size() > 0) { 
     622                if (getNames() != null && names.size() > 0) { 
    591623                        return (PersonName) names.toArray()[0]; 
    592624                } else { 
     
    688720                 
    689721                return age; 
     722        } 
     723         
     724        /** 
     725         * Convenience method: sets a person's birth date from an age as of the given date 
     726         * Also sets flag indicating that the birth date is inexact. 
     727         * This sets the person's birth date to January 1 of the year that matches this age and date 
     728         *  
     729         * @param age (the age to set) 
     730         * @param onDate (null defaults to today) 
     731         */ 
     732        public void setBirthdateFromAge(int age, Date ageOnDate) { 
     733                Calendar c = Calendar.getInstance(); 
     734                c.setTime(ageOnDate == null ? new Date() : ageOnDate); 
     735                c.set(Calendar.DATE, 1); 
     736                c.set(Calendar.MONTH, Calendar.JANUARY); 
     737                c.add(Calendar.YEAR, -1*age); 
     738                setBirthdate(c.getTime()); 
     739                setBirthdateEstimated(true); 
    690740        } 
    691741