List<Person> persons = Context.getPersonService().getPeople(givenName + " " + familyName, null); if (persons.size() == 1) { return persons.get(0).getPersonId();
/** * @see PersonService#getPeople(String,Boolean) */ @Test public void getPeople_shouldMatchSearchToFamilyName2() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-extranames.xml"); updateSearchIndex(); List<Person> people = Context.getPersonService().getPeople("Johnson", false); Assert.assertEquals(3, people.size()); assertTrue(TestUtil.containsId(people, 2)); assertTrue(TestUtil.containsId(people, 4)); assertTrue(TestUtil.containsId(people, 5)); }
@Override public List<OpenMRSPerson> findAllPersons() { List<OpenMRSPerson> mrsPersonList = new ArrayList<>(); List<Person> personList = personService.getPeople("", null); for (Person person : personList) { mrsPersonList.add(PersonHelper.openMRSToMRSPerson(person)); } return mrsPersonList; }
@Override public void removeAll() { List<Person> personList = personService.getPeople("", null); for (Person person : personList) { if (person.getPersonId() != 1) { //You can't delete first person in db personService.purgePerson(person); } } }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<Person> doSearch(RequestContext context) { return new NeedsPaging<Person>(Context.getPersonService().getPeople(context.getParameter("q"), null), context); }
for (Person p : ps.getPeople(searchPhrase, null)) {
@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()); }
@Test public void shouldCreateAPersonWithAttributes() throws Exception { long originalCount = service.getPeople("", false).size(); final String birthPlace = "Nsambya"; String json = "{ \"names\": [{ \"givenName\":\"Helen\", \"familyName\":\"of Troy\" }], " + "\"birthdate\":\"2003-01-01\", \"gender\":\"F\", \"attributes\":" + "[{\"attributeType\":\"54fc8400-1683-4d71-a1ac-98d40836ff7c\",\"value\": \"" + birthPlace + "\"}] }"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(birthPlace, person.getAttribute("Birthplace").getValue()); }
@Test public void shouldCreateAPersonWithBooleanAttributeWithQuotes() throws Exception { executeDataSet("personAttributeTypeWithConcept.xml"); long originalCount = service.getPeople("", false).size(); String givenName = "TestName2"; int attributeId = 10; String attributeUuid = "55e6ce9e-25bf-11e3-a013-3c0754156a5f"; String json = "{\"gender\": \"M\", \"attributes\":[{\"value\":\"true\",\"attributeType\":" + "\"" + attributeUuid + "\"}]," + "\"names\": [{\"givenName\":\"" + givenName + "\", \"familyName\":\"TestFamily\"}]}"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(givenName, person.getGivenName()); assertEquals("true", person.getAttribute(attributeId).getValue()); } }
@Test public void shouldCreateAPersonWithBooleanAttributeWithoutQuotes() throws Exception { executeDataSet("personAttributeTypeWithConcept.xml"); long originalCount = service.getPeople("", false).size(); String givenName = "TestName1"; String attributeUuid = "55e6ce9e-25bf-11e3-a013-3c0754156a5f"; int attributeId = 10; String json = "{\"gender\": \"M\", \"attributes\":[{\"value\":true,\"attributeType\":" + "\"" + attributeUuid + "\"}]," + "\"names\": [{\"givenName\":\"" + givenName + "\", \"familyName\":\"TestFamily\"}]}"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(givenName, person.getGivenName()); assertEquals("true", person.getAttribute(attributeId).getValue()); }