Example #1
0
 /** Sets an attribute on a person. */
 public static void setPersonAttributeValue(
     Patient patient, PersonAttributeType attrType, String value) {
   PersonService personService = Context.getPersonService();
   PersonAttribute attribute = patient.getAttribute(attrType);
   if (attribute == null) {
     attribute = new PersonAttribute();
     attribute.setAttributeType(attrType);
     attribute.setValue(value);
     patient.addAttribute(attribute);
   } else {
     attribute.setValue(value);
   }
   personService.savePerson(patient);
 }
  /**
   * Sets a attribute value of this person. If the value is blank then any existing attribute will
   * be voided.
   *
   * @param attrTypeUuid the attribute type UUID
   * @param value the value
   */
  protected void setAsAttribute(String attrTypeUuid, String value) {
    PersonAttribute attr = findFirstAttribute(attrTypeUuid);

    if (StringUtils.isNotBlank(value)) {
      if (attr == null) {
        attr = new PersonAttribute();
        attr.setAttributeType(MetadataUtils.existing(PersonAttributeType.class, attrTypeUuid));
        attr.setValue(value);
        target.addAttribute(attr);
      } else {
        attr.setValue(value);
      }
    } else if (attr != null) {
      attr.setVoided(true);
      attr.setDateVoided(new Date());
      attr.setVoidedBy(Context.getAuthenticatedUser());
    }
  }