/** * @see org.openmrs.Person#getNames() */ public Set<PersonName> getNames() { return person.getNames(); }
@Override public String toString() { String provider = String.valueOf(providerId) + " providerName:" + ((person != null) ? person.getNames() : ""); return "[Provider: providerId:" + provider + " ]"; }
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 (PersonName name : person.getNames()) { if (name.getDateCreated() == null) { sessionFactory.getCurrentSession().evict(name);
/** * This test verifies that {@link PersonName}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 shouldFetchNamesForPersonsThatWereFirstFetchedAsUsers() { Person person = Context.getPersonService().getPerson(1); User user = userService.getUser(1); user.getNames().size(); person.getNames().size(); }
private void setPreferredPersonName(Person person) { PersonName preferredName = null; PersonName possiblePreferredName = person.getPersonName(); if (possiblePreferredName != null && possiblePreferredName.getPreferred() && !possiblePreferredName.getVoided()) { preferredName = possiblePreferredName; } for (PersonName name : person.getNames()) { if (preferredName == null && !name.getVoided()) { name.setPreferred(true); preferredName = name; continue; } if (!name.equals(preferredName)) { name.setPreferred(false); } } }
/** * This test verifies that {@link PersonName}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 shouldFetchNamesForPersonsThatWereFirstFetchedAsPatients() throws Exception { Person person = Context.getPersonService().getPerson(2); Patient patient = Context.getPatientService().getPatient(2); patient.getNames().size(); person.getNames().size(); }
assertNotNull(p.getNames()); assertTrue("There should be 1 name in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 1); assertTrue("There should be 1 name in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 1); assertTrue("There should be 2 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 2); assertTrue("There should be 2 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 2); assertTrue("There should be 3 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 3); assertTrue("There should be only 2 name in the person object now", p.getNames().size() == 2); assertTrue("There should be 3 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 3); assertTrue("There should be only 2 names in the person object now", p.getNames().size() == 2); assertTrue("There should be only 1 names in the person object now", p.getNames().size() == 1); p.removeName(pa2); assertTrue("There should be only no names in the person object now", p.getNames().size() == 0); p.removeName(pa2); assertTrue("There should still be only no names in the person object now", p.getNames().size() == 0);
/** * @see ProviderService#getCountOfProviders(String,null) */ @Test public void getCountOfProviders_shouldFetchNumberOfProviderMatchingGivenQuery() { assertEquals(1, service.getCountOfProviders("Hippo").intValue()); Person person = Context.getPersonService().getPerson(502); Set<PersonName> names = person.getNames(); for (PersonName name : names) { name.setVoided(true); } PersonName personName = new PersonName("Hippot", "A", "B"); personName.setPreferred(true); person.addName(personName); Context.getPersonService().savePerson(person); assertEquals(1, service.getCountOfProviders("Hippo").intValue()); }
for (PersonName personName : person.getNames()) { errors.pushNestedPath("names[" + index + "]"); personNameValidator.validate(personName, errors);
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SubResource#doGetAll(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public NeedsPaging<PersonName> doGetAll(Person parent, RequestContext context) throws ResponseException { List<PersonName> names = new ArrayList<PersonName>(); if (parent != null) { names.addAll(parent.getNames()); } return new NeedsPaging<PersonName>(names, context); }
/** * Returns non-voided names for a person * * @param instance * @return */ @PropertyGetter("names") public static Set<PersonName> getNames(Person instance) { return RestUtil.removeVoidedData(instance.getNames()); }
/** * @see MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getPersonByUuid(PERSON_UUID).getNames().size(); }
setUuid(person.getUuid()); addresses = person.getAddresses(); names = person.getNames(); attributes = person.getAttributes();
@Test public void shouldAddNameToPerson() throws Exception { int before = service.getPersonByUuid(personUuid).getNames().size(); String json = "{ \"givenName\":\"name1\", \"middleName\":\"name2\", \"familyName\":\"name3\" }"; handle(newPostRequest(getURI(), json)); int after = service.getPersonByUuid(personUuid).getNames().size(); Assert.assertEquals(before + 1, after); }
@Test public void shouldPurgeName() throws Exception { int before = service.getPersonByUuid(personUuid).getNames().size(); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("purge", ""))); int after = service.getPersonByUuid(personUuid).getNames().size(); Assert.assertNull(service.getPersonNameByUuid(getUuid())); Assert.assertEquals(before - 1, after); }
@Test public void shouldCreateAPerson() throws Exception { long originalCount = service.getPeople("", false).size(); String json = "{ \"names\": [{ \"givenName\":\"Helen\", \"familyName\":\"of Troy\" }, " + "{\"givenName\":\"Leda\", \"familyName\":\"Nemesis\"} ], " + "\"birthdate\":\"2003-01-01\", \"gender\":\"F\" }"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(2, person.getNames().size()); assertEquals("Helen of Troy", person.getPersonName().getFullName()); assertEquals(++originalCount, service.getPeople("", false).size()); }