/** * @should set using id * @should set using uuid * * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) */ @Override public void setAsText(String text) throws IllegalArgumentException { PersonService ps = Context.getPersonService(); if (StringUtils.hasText(text)) { try { Integer personId = Integer.valueOf(text); setValue(ps.getPerson(personId)); } catch (NumberFormatException e) { Person person = ps.getPersonByUuid(text); setValue(person); if (person == null) { throw new IllegalArgumentException("Failed to find person for value [" + text + "]"); } } } else { setValue(null); } }
Person p = Context.getPersonService().getPersonByUuid(hl7PersonId); if (p != null) { return p;
/** * @see PersonService#getPersonByUuid(String) */ @Test public void getPersonByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() throws Exception { Assert.assertNull(Context.getPersonService().getPersonByUuid("some invalid uuid")); }
/** * @see PersonService#getPersonByUuid(String) */ @Test public void getPersonByUuid_shouldFindObjectGivenValidUuid() throws Exception { String uuid = "ba1b19c2-3ed6-4f63-b8c0-f762dc8d7562"; Person person = Context.getPersonService().getPersonByUuid(uuid); Assert.assertEquals(1, (int) person.getPersonId()); }
if (Context.getPersonService().getPersonByUuid(uuid) != null) { throw new HL7Exception("Non-unique UUID '" + uuid + "' for new person");
/** * @throws HL7Exception * @see HL7Service#createPersonFromNK1(NK1) */ @Test public void getPersonFromNK1_shouldReturnASavedNewPerson() throws HL7Exception { HL7Service hl7service = Context.getHL7Service(); Message message = hl7service .parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220022^^^UUID^v4||||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212"); ORU_R01 oru = (ORU_R01) message; List<NK1> nk1List = new ORUR01Handler().getNK1List(oru); Person result = hl7service.createPersonFromNK1(nk1List.get(0)); Assert.assertNotNull("should have returned a person", result); Assert.assertNotNull("the person should exist", Context.getPersonService().getPersonByUuid(result.getUuid())); }
Person relative = personService.getPersonByUuid("2178037d-f86b-4f12-8d8b-be3ebc220029"); Assert.assertNotNull("a new person was not created", relative);
private Person findByPersonIdAndReturnPerson(String personId) { Person person = personService.getPersonByUuid(personId); if (person != null) { return person; } else { person = getPersonById(personId); if (person != null) { return person; } } return null; }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public Person getByUniqueId(String uuid) { return Context.getPersonService().getPersonByUuid(uuid); }
/** * @see MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getPersonByUuid(PERSON_UUID).getNames().size(); }
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getPersonByUuid(RestTestConstants1_8.PERSON_UUID).getAttributes().size(); } }
@Test public void shouldAddAttributeToPerson() throws Exception { int before = service.getPersonByUuid(personUuid).getAttributes().size(); String json = "{ \"attributeType\":\"b3b6d540-a32e-44c7-91b3-292d97667518\", \"value\":\"testing\"}"; handle(newPostRequest(getURI(), json)); int after = service.getPersonByUuid(personUuid).getAttributes().size(); assertThat(after, is(before + 1)); }
@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); }
@Override public void removePerson(MRSPerson person) { Person existingPerson = personService.getPersonByUuid(person.getPersonId()); if (existingPerson == null) { existingPerson = getPersonById(person.getPersonId()); } if (existingPerson != null) { personService.purgePerson(existingPerson); eventRelay.sendEventMessage(new MotechEvent(EventKeys.DELETED_PERSON_SUBJECT, EventHelper.personParameters(person))); } }
@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")); }
@Test public void shouldPurgeAPerson() throws Exception { final String uuid = "86526ed6-3c11-11de-a0ba-001e378eb67e"; assertNotNull(service.getPersonByUuid(uuid)); MockHttpServletRequest req = newDeleteRequest(getURI() + "/" + uuid, new Parameter("purge", "true")); handle(req); assertNull(service.getPersonByUuid(uuid)); }
@Test public void shouldAddAnAddressToAPerson() throws Exception { int before = service.getPersonByUuid(RestTestConstants1_8.PERSON_UUID).getAddresses().size(); SimpleObject address = new SimpleObject(); address.add("address1", "test address"); address.add("country", "USA"); address.add("preferred", "true"); MockHttpServletRequest req = newPostRequest(getURI(), address); handle(req); int after = service.getPersonByUuid(RestTestConstants1_8.PERSON_UUID).getAddresses().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 shouldGetAPersonByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); Person person = service.getPersonByUuid(getUuid()); assertEquals(person.getUuid(), PropertyUtils.getProperty(result, "uuid")); assertNotNull(PropertyUtils.getProperty(result, "preferredName")); assertEquals(person.getGender(), PropertyUtils.getProperty(result, "gender")); assertNull(PropertyUtils.getProperty(result, "auditInfo")); }
@Test public void shouldExcludeVoidedAddressesForAPerson() throws Exception { // For test purposes, we need to void all addresses Person person = service.getPersonByUuid(RestTestConstants1_8.PERSON_UUID); for (PersonAddress addr : person.getAddresses()) { addr.setVoided(true); } service.savePerson(person); MockHttpServletRequest req = request(RequestMethod.GET, getURI()); SimpleObject result = deserialize(handle(req)); Assert.assertEquals(0, Util.getResultsSize(result)); }