/** * @see java.lang.Object#toString() */ @Override public String toString() { return getName(); }
/** * Convenience method to get all of this person's attributes that have a * PersonAttributeType.name equal to <code>attributeName</code>. * * @param attributeName * @should return all PersonAttributes with matching attributeType names */ public List<PersonAttribute> getAttributes(String attributeName) { List<PersonAttribute> ret = new ArrayList<>(); for (PersonAttribute attribute : getActiveAttributes()) { PersonAttributeType type = attribute.getAttributeType(); if (type != null && attributeName.equals(type.getName())) { ret.add(attribute); } } return ret; }
/** * Convenience method to get this person's active attributes in map form: <String, * PersonAttribute>. */ public Map<String, PersonAttribute> getAttributeMap() { if (attributeMap != null) { return attributeMap; } if (log.isDebugEnabled()) { log.debug("Current Person Attributes: \n" + printAttributes()); } attributeMap = new HashMap<>(); for (PersonAttribute attribute : getActiveAttributes()) { attributeMap.put(attribute.getAttributeType().getName(), attribute); } return attributeMap; }
/** * Convenience method to get all of this person's attributes (including voided ones) in map * form: <String, PersonAttribute>. * * @return All person's attributes in map form * @since 1.12 */ public Map<String, PersonAttribute> getAllAttributeMap() { if (allAttributeMap != null) { return allAttributeMap; } if (log.isDebugEnabled()) { log.debug("Current Person Attributes: \n" + printAttributes()); } allAttributeMap = new HashMap<>(); for (PersonAttribute attribute : getAttributes()) { allAttributeMap.put(attribute.getAttributeType().getName(), attribute); } return allAttributeMap; }
/** * Convenience method to get this person's first attribute that has a PersonAttributeType.name * equal to <code>attributeName</code>.<br> * <br> * Returns null if this person has no non-voided {@link PersonAttribute} with the given type * name, the given name is null, or this person has no attributes. * * @param attributeName the name string to match on * @return PersonAttribute whose {@link PersonAttributeType#getName()} matchs the given name * string * @should return person attribute based on attributeName * @should return null if AttributeName is voided */ public PersonAttribute getAttribute(String attributeName) { if (attributeName != null) { for (PersonAttribute attribute : getAttributes()) { PersonAttributeType type = attribute.getAttributeType(); if (type != null && attributeName.equals(type.getName()) && !attribute.getVoided()) { return attribute; } } } return null; }
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if name is null * @should fail validation if format is empty * @should fail validation if name already in use * @should pass validation if description is null or empty or whitespace * @should pass validation if all fields are correct * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ @Override public void validate(Object obj, Errors errors) { PersonAttributeType patObj = (PersonAttributeType) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "PersonAttributeType.error.nameEmpty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "format", "PersonAttributeType.error.formatEmpty"); PersonService ps = Context.getPersonService(); PersonAttributeType pat = ps.getPersonAttributeTypeByName(patObj.getName()); if (pat != null && !pat.getUuid().equals(patObj.getUuid())) { errors.rejectValue("name", "PersonAttributeType.error.nameAlreadyInUse"); } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "format", "retireReason"); } }
String newTypeName = type.getName();
/** * @see Person#getAttribute(String) */ @Test public void getAttribute_shouldPersonAttributeBasedOnAttributeName() { Person person = personHelper(false, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertEquals("name3", person.getAttribute("name3").getAttributeType().getName()); }
/** * @see PersonDAO#getSavedPersonAttributeTypeName(org.openmrs.PersonAttributeType) */ @Test public void getSavedPersonAttributeTypeName_shouldGetSavedPersonAttributeTypeNameFromDatabase() { PersonAttributeType pat = Context.getPersonService().getPersonAttributeType(1); // save the name from the db for later checks String origName = pat.getName(); String newName = "Race Updated"; assertFalse(newName.equals(origName)); // change the name on the java pojo (NOT in the database) pat.setName(newName); // the value from the database should match the original name from the // pat right after /it/ was fetched from the database String nameFromDatabase = dao.getSavedPersonAttributeTypeName(pat); assertEquals(origName, nameFromDatabase); }
private void setPersonAttributes(MRSPatient patient, Patient openMRSPatient, List<PersonAttributeType> allPersonAttributeTypes) { MRSPerson mrsPerson = patient.getPerson(); if (CollectionUtils.isNotEmpty(mrsPerson.getAttributes())) { for (MRSAttribute attribute : mrsPerson.getAttributes()) { PersonAttributeType attributeType = (PersonAttributeType) selectUnique(allPersonAttributeTypes, having(on(PersonAttributeType.class).getName(), equalTo(attribute.getName()))); openMRSPatient.addAttribute(new PersonAttribute(attributeType, attribute.getValue())); } } } }
if (patient != null) { for (PersonAttribute att : patient.getActiveAttributes()) { String attName = att.getAttributeType().getName(); if (att.getValue() != null) { attributes.put(attName.replaceAll("'", ""), att.getHydratedObject());
/** * Gets the display string for a person attribute. * * @param pa the person attribute. * @return attribute type + value (for concise display purposes) */ @PropertyGetter("display") public String getDisplayString(PersonAttribute pa) { if (pa.getAttributeType() == null) return ""; if (Concept.class.getName().equals(pa.getAttributeType().getFormat()) && pa.getValue() != null) { Concept concept = Context.getConceptService().getConcept(pa.getValue()); return concept == null ? null : concept.getDisplayString(); } return pa.getAttributeType().getName() + " = " + pa.getValue(); }
@Test public void shouldEditAttribute() throws Exception { String json = "{ \"attributeType\":\"54fc8400-1683-4d71-a1ac-98d40836ff7c\" }"; PersonAttribute personAttribute = service.getPersonAttributeByUuid(getUuid()); assertThat(personAttribute.getAttributeType().getName(), is("Race")); handle(newPostRequest(getURI() + "/" + getUuid(), json)); personAttribute = service.getPersonAttributeByUuid(getUuid()); assertThat(personAttribute.getAttributeType().getName(), is("Birthplace")); }
demo.addAttribute(new PersonAttribute(type, "Test " + type.getName() + " Attribute"));
public static Person createPerson(MRSPerson person, List<PersonAttributeType> allPersonAttributeTypes) { Person converted = new Person(); if (person.getDateOfBirth() != null) { converted.setBirthdate(person.getDateOfBirth().toDate()); } if (person.getDeathDate() != null) { converted.setDeathDate(person.getDeathDate().toDate()); } converted.setBirthdateEstimated((Boolean) ObjectUtils.defaultIfNull(person.getBirthDateEstimated(), false)); converted.setDead(person.isDead()); converted.setGender(person.getGender()); converted.addName(new PersonName(person.getFirstName(), person.getMiddleName(), person.getLastName())); if (person.getAddress() != null) { PersonAddress personAddress = new PersonAddress(); personAddress.setAddress1(person.getAddress()); converted.addAddress(personAddress); } for (MRSAttribute attribute : person.getAttributes()) { PersonAttributeType attributeType = (PersonAttributeType) selectUnique(allPersonAttributeTypes, having(on(PersonAttributeType.class).getName(), equalTo(attribute.getName()))); converted.addAttribute(new PersonAttribute(attributeType, attribute.getValue())); } return converted; }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("format", getObject().getFormat()); assertPropEquals("foreignKey", getObject().getForeignKey()); assertPropEquals("sortWeight", getObject().getSortWeight()); assertPropEquals("searchable", getObject().getSearchable()); assertPropEquals("editPrivilege", getObject().getEditPrivilege()); assertPropEquals("retired", getObject().getRetired()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("format", getObject().getFormat()); assertPropEquals("foreignKey", getObject().getForeignKey()); assertPropEquals("sortWeight", getObject().getSortWeight()); assertPropEquals("searchable", getObject().getSearchable()); assertPropEquals("editPrivilege", getObject().getEditPrivilege()); assertPropEquals("retired", getObject().getRetired()); assertPropPresent("auditInfo"); }