/** * Returns only the non-voided attributes for this person * * @return list attributes * @should not get voided attributes * @should not fail with null attributes */ public List<PersonAttribute> getActiveAttributes() { List<PersonAttribute> attrs = new ArrayList<>(); for (PersonAttribute attr : getAttributes()) { if (!attr.getVoided()) { attrs.add(attr); } } return attrs; }
/** * Convenience method for viewing all of the person's current attributes * * @return Returns a string with all the attributes */ public String printAttributes() { StringBuilder s = new StringBuilder(""); for (PersonAttribute attribute : getAttributes()) { s.append(attribute.getAttributeType()).append(" : ").append(attribute.getValue()).append(" : voided? ").append( attribute.getVoided()).append("\n"); } return s.toString(); }
/** * Convenience method to get all of this person's attributes that have a PersonAttributeType * equal to <code>personAttributeType</code>. * * @param personAttributeType */ public List<PersonAttribute> getAttributes(PersonAttributeType personAttributeType) { List<PersonAttribute> ret = new ArrayList<>(); for (PersonAttribute attribute : getAttributes()) { if (personAttributeType.equals(attribute.getAttributeType()) && !attribute.getVoided()) { ret.add(attribute); } } return ret; }
/** * 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; }
private void logPerson(Person person) { String info = "class=" + person.getClass().getCanonicalName() + ", person=" + person.toString() + ", person.names=" + person.getNames().toString() + ", person.attributes=" + person.getAttributes().toString(); log.debug(info); }
for (PersonAttribute attribute : person.getAttributes()) { if (attribute.getDateCreated() == null) { sessionFactory.getCurrentSession().evict(attribute);
/** * Convenience Method to return the first non-voided person attribute matching a person * attribute type. <br> * <br> * Returns null if this person has no non-voided {@link PersonAttribute} with the given * {@link PersonAttributeType}, the given {@link PersonAttributeType} is null, or this person * has no attributes. * * @param pat the PersonAttributeType to look for (can be a stub, see * {@link PersonAttributeType#equals(Object)} for how its compared) * @return PersonAttribute that matches the given type * @should not fail when attribute type is null * @should not return voided attribute * @should return null when existing PersonAttributeType is voided */ public PersonAttribute getAttribute(PersonAttributeType pat) { if (pat != null) { for (PersonAttribute attribute : getAttributes()) { if (pat.equals(attribute.getAttributeType()) && !attribute.getVoided()) { return attribute; } } } return null; }
/** * @see Person#getAttributes(Integer) */ @Test public void getAttributes_shouldReturnListOfPersonAttributesBasedOnAttributeTypeId() { Person person = personHelper(false, 1, 1, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertEquals(2, person.getAttributes(1).size()); }
/** * @see Person#getAttributes(Integer) */ @Test public void getAttributes_shouldReturnEmptyListWhenMatchingPersonAttributeByIdIsVoided() { Person person = personHelper(true, 1, 1, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertEquals(0, person.getAttributes(1).size()); }
/** * @see Person#getAttributes(String) */ @Test public void getAttributes_shouldReturnAllPersonAttributesWithMatchingAttributeTypeNames() { Person person = personHelper(false, 1, 2, 3, "name1", "name1", "name3", "value1", "value2", "value3"); Assert.assertEquals(2, person.getAttributes("name1").size()); }
/** * This test verifies that {@link PersonAttribute}s are fetched correctly from the hibernate * cache. (Or really, not fetched from the cache but instead are mapped with lazy=false. For * some reason Hibernate isn't able to find objects in the cache if a parent object was the one * that loaded them) * * @throws Exception */ @Test public void shouldFetchPersonAttributesForPersonsThatWereFirstFetchedAsPatients() throws Exception { Person person = Context.getPersonService().getPerson(2); Patient patient = Context.getPatientService().getPatient(2); patient.getAttributes().size(); person.getAttributes().size(); }
if (person.getAttributes() != null && !person.getAttributes().isEmpty()) { for (PersonAttribute pAttr : person.getAttributes()) { pAttr.setPerson(person);
/** * @see Person#addAttribute(PersonAttribute) */ @Test public void addAttribute_shouldNotSaveAnAttributeWithABlankStringValue() { Person p = new Person(); // make sure there are no initial attributes Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); PersonAttribute pa1 = new PersonAttribute(); pa1.setValue(""); pa1.setAttributeType(new PersonAttributeType(1)); pa1.setVoided(false); p.addAttribute(pa1); // make sure the attribute was not added Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); }
/** * @see Person#addAttribute(PersonAttribute) */ @Test public void addAttribute_shouldNotSaveAnAttributeWithANullValue() { Person p = new Person(); // make sure there are no initial attributes Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); PersonAttribute pa1 = new PersonAttribute(); pa1.setValue(null); pa1.setAttributeType(new PersonAttributeType(1)); pa1.setVoided(false); p.addAttribute(pa1); // make sure the attribute was not added Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); }
assertNotNull(p.getAttributes()); assertTrue("There should be 1 attribute in the person object but there is actually : " + p.getAttributes().size(), p .getAttributes().size() == 1); assertTrue("There should be 1 attribute in the person object but there is actually : " + p.getAttributes().size(), p .getAttributes().size() == 1); assertTrue("There should be 2 attributes in the person object but there is actually : " + p.getAttributes().size(), p.getAttributes().size() == 2); assertTrue("There should be 2 attributes in the person object but there is actually : " + p.getAttributes().size(), p.getAttributes().size() == 2); assertTrue("There should be 3 attributes in the person object but there is actually : " + p.getAttributes().size(), p.getAttributes().size() == 3); assertTrue("There should be only 2 attribute in the person object now", p.getAttributes().size() == 2); assertTrue("There should be 3 attributes in the person object but there is actually : " + p.getAttributes().size(), p.getAttributes().size() == 3); assertTrue("There should be only 2 attribute in the person object now", p.getAttributes().size() == 2); p.removeAttribute(pa2); assertTrue("There should be only 1 attribute in the person object now", p.getAttributes().size() == 1); p.removeAttribute(pa2); assertTrue("There should still be only 1 attribute in the person object now", p.getAttributes().size() == 1); p.removeAttribute(pa1); assertTrue("There shouldn't be any attributes in the person object now", p.getAttributes().size() == 0);
Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); Assert.assertEquals("The attribute was not added", 1, p.getAttributes().size()); Assert.assertEquals("Something changed ...", 1, p.getAttributes().size()); Assert.assertTrue("The original attribute is not voided", p.getAttributes().iterator().next().getVoided());
private void clearAttributes(User user) { Person person = user.getPerson(); if (person.getNames() != null) { person.getNames().clear(); } if (person.getAttributes() != null) { person.getAttributes().clear(); } if (user.getRoles() != null) { user.getRoles().clear(); } }
addresses = person.getAddresses(); names = person.getNames(); attributes = person.getAttributes();
@Test public void shouldAddConceptAttributeToPerson() throws Exception { executeDataSet("personAttributeTypeWithConcept.xml"); int before = service.getPersonByUuid(personUuid).getAttributes().size(); String json = "{ \"hydratedObject\":\"f102c80f-1yz9-4da3-bb88-8122ce8868dd\", \"attributeType\":\"55e6ce9e-25bf-11e3-a013-3c0754156a5d\"}"; handle(newPostRequest(getURI(), json)); Set<PersonAttribute> attributes = service.getPersonByUuid(personUuid).getAttributes(); int after = attributes.size(); assertThat(after, is(before + 1)); assertThat(getLastPersonAttribute(attributes).getValue(), is("102")); }