Changeset 5183 for openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Person.java
- Timestamp:
- 08/06/08 17:17:55 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/Person.java
r4297 r5183 427 427 attributeMap = null; 428 428 } 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 } 429 446 430 447 /** … … 435 452 public PersonAttribute getAttribute(String attributeName) { 436 453 if (attributeName != null) 437 for (PersonAttribute attribute : getA ctiveAttributes()) {454 for (PersonAttribute attribute : getAttributes()) { 438 455 PersonAttributeType type = attribute.getAttributeType(); 439 if (type != null && attributeName.equals(type.getName()) ) {456 if (type != null && attributeName.equals(type.getName()) && !attribute.isVoided()) { 440 457 return attribute; 441 458 } … … 452 469 public PersonAttribute getAttribute(Integer attributeTypeId) { 453 470 for (PersonAttribute attribute : getActiveAttributes()) { 454 if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId()) ) {471 if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId()) && !attribute.isVoided()) { 455 472 return attribute; 456 473 } 457 } 458 474 } 459 475 return null; 460 476 } … … 466 482 */ 467 483 public List<PersonAttribute> getAttributes(String attributeName) { 468 List<PersonAttribute> attributes= new Vector<PersonAttribute>();484 List<PersonAttribute> ret = new Vector<PersonAttribute>(); 469 485 470 486 for (PersonAttribute attribute : getActiveAttributes()) { 471 487 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); 474 490 } 475 491 } 476 492 477 return attributes;493 return ret; 478 494 } 479 495 … … 484 500 */ 485 501 public List<PersonAttribute> getAttributes(Integer attributeTypeId) { 486 List<PersonAttribute> attributes= new Vector<PersonAttribute>();502 List<PersonAttribute> ret = new Vector<PersonAttribute>(); 487 503 488 504 for (PersonAttribute attribute : getActiveAttributes()) { 489 if (attributeTypeId.equals(attribute.get PersonAttributeId())) {490 attributes.add(attribute);505 if (attributeTypeId.equals(attribute.getAttributeType().getPersonAttributeTypeId()) && !attribute.isVoided()) { 506 ret.add(attribute); 491 507 } 492 508 } 493 509 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; 495 527 } 496 528 … … 588 620 */ 589 621 public PersonName getPersonName() { 590 if ( names!= null && names.size() > 0) {622 if (getNames() != null && names.size() > 0) { 591 623 return (PersonName) names.toArray()[0]; 592 624 } else { … … 688 720 689 721 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); 690 740 } 691 741