/** * @see PersonService#getPersonByUuid(String) */ @Test public void getPersonByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() throws Exception { Assert.assertNull(Context.getPersonService().getPersonByUuid("some invalid uuid")); }
@Test public void shouldClearMillisecondsWhenUpdatingAnExistingObject() { Date dateWithMillisecond = new Date(567L); Date dateWithoutMillisecond = new Date(0L); Person person = personService.getPerson(1); person.setBirthdate(dateWithMillisecond); personService.savePerson(person); Context.flushSession(); assertThat(person.getBirthdate(), is(dateWithoutMillisecond)); }
/** * @see org.openmrs.api.PersonService#getAllPersonAttributeTypes() */ @Override @Transactional(readOnly = true) public List<PersonAttributeType> getAllPersonAttributeTypes() throws APIException { return Context.getPersonService().getAllPersonAttributeTypes(true); }
/** * @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); } }
@Test public void getPersonAttributeTypes_shouldReturnAllPersonAttributeTypesWithViewTypeNull() { List<PersonAttributeType> expected = personService.getAllPersonAttributeTypes(); List<PersonAttributeType> result = personService.getPersonAttributeTypes(null, null); assertThat(result, containsInAnyOrder(expected.toArray())); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotThrowExceptionIfVoidReasonIsNullForUnsupportedTypes() { Person p = Context.getPersonService().getPerson(1); Context.getPersonService().voidPerson(p, null); } }
@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()); }
sibling.setPersonA(p1); sibling.setPersonB(p2); sibling.setRelationshipType(personService.getRelationshipType(4)); personService.saveRelationship(sibling); doctor.setPersonB(p1); doctor.setPersonA(p2); doctor.setRelationshipType(personService.getRelationshipType(3)); personService.saveRelationship(doctor); List<Relationship> allRels = personService.getAllRelationships(); for (Relationship r : allRels) { personService.voidRelationship(r, "Because of a JUnit test."); List<Relationship> updatedARels = personService.getRelationshipsByPerson(p1, new Date()); List<Relationship> updatedBRels = personService.getRelationshipsByPerson(p2, new Date());
personOb = personService.getPersonByUuid(person); personAOb = personService.getPersonByUuid(personA); personBOb = personService.getPersonByUuid(personB); relatedPersonOb = personService.getPersonByUuid(relatedPerson); if (personService.getRelationshipTypeByUuid(relation) != null) { relationshipType = personService.getRelationshipTypeByUuid(relation); } else { List<RelationshipType> relationshipTypes = personService.getAllRelationshipTypes(); for (RelationshipType temp : relationshipTypes) { if (temp.getbIsToA().equalsIgnoreCase(relation) || temp.getaIsToB().equalsIgnoreCase(relation)) { tempList = personService.getRelationships(personOb, relatedPersonOb, null); tempList.addAll(personService.getRelationships(relatedPersonOb, personOb, null)); relationshipList = tempList; } else if (personOb != null && relationshipType != null) { tempList = personService.getRelationships(personOb, null, relationshipType); tempList.addAll(personService.getRelationships(null, personOb, relationshipType)); relationshipList = tempList; } else if (personOb != null) { relationshipList = personService.getRelationshipsByPerson(personOb); } else if (personAOb != null && personBOb != null && relationshipType != null) { relationshipList = personService.getRelationships(personAOb, personBOb, relationshipType); } else if (personAOb != null && personBOb != null) { relationshipList = personService.getRelationships(personAOb, personBOb, null); } else if (personAOb != null && relationshipType != null) {
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date) */ @Test public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception { PersonService personService = Context.getPersonService(); Person secondPerson = personService.getPerson(7); List<Relationship> relationships = personService.getRelationships(null, secondPerson, null, new Date(), new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the to person", relationships.size() > 0); }
if (Context.getPersonService().getPersonByUuid(uuid) != null) { throw new HL7Exception("Non-unique UUID '" + uuid + "' for new person"); Context.getPatientService().savePatient((Patient) person); } else { Context.getPersonService().savePerson(person);
/** * @see PersonService#saveRelationship(Relationship) */ @Test public void saveRelationship_shouldCreateNewObjectWhenRelationshipIdIsNull() throws Exception { PersonService personService = Context.getPersonService(); Relationship relationship = new Relationship(); relationship.setPersonA(personService.getPerson(1)); relationship.setPersonB(personService.getPerson(2)); relationship.setRelationshipType(personService.getRelationshipType(1)); Assert.assertNull(relationship.getRelationshipId()); Relationship savedRelationship = personService.saveRelationship(relationship); Assert.assertNotNull(savedRelationship.getRelationshipId()); }
/** * @see org.openmrs.api.PersonService#unvoidPerson(org.openmrs.Person) */ @Override public Person unvoidPerson(Person person) throws APIException { if (person == null) { return null; } return Context.getPersonService().savePerson(person); }
/** * @see PersonService#purgePerson(Person) */ @Test public void purgePerson_shouldDeletePersonFromTheDatabase() throws Exception { PersonService personService = Context.getPersonService(); User user = Context.getAuthenticatedUser(); Person person = new Person(); person.setPersonCreator(user); person.setPersonDateCreated(new Date()); person.setPersonChangedBy(user); person.setPersonDateChanged(new Date()); person.setGender("F"); Assert.assertNull(person.getId()); person.addName(new PersonName("givenName", "middleName", "familyName")); person = personService.savePerson(person); Assert.assertNotNull(person.getId()); personService.purgePerson(person); Person deletedPerson = personService.getPerson(person.getId()); Assert.assertNull(deletedPerson); }
Set<String> existingRelationships = new HashSet<>(); for (Relationship rel : personService.getRelationshipsByPerson(preferred)) { existingRelationships.add(relationshipHash(rel, preferred)); for (Relationship rel : personService.getRelationshipsByPerson(notPreferred)) { if (!rel.getVoided()) { boolean personAisPreferred = rel.getPersonA().equals(preferred); personService.voidRelationship(rel, "person " + (personAisNotPreferred ? "A" : "B") + " was merged to person " + (personAisPreferred ? "A" : "B")); } else if (existingRelationships.contains(relHash)) { personService.voidRelationship(rel, "person " + (personAisNotPreferred ? "A" : "B") + " was merged and a relationship already exists"); } else { Relationship persisted = personService.saveRelationship(tmpRel); mergedData.addCreatedRelationship(persisted.getUuid()); personService.voidRelationship(rel, "person " + (personAisNotPreferred ? "A" : "B") + " was merged, relationship copied to #" + tmpRel.getRelationshipId());
Context.getPersonService().savePerson(p); log.debug("creating relationships" + r.getRelationshipType().getDescription()); Context.getPersonService().saveRelationship(r); log.debug("voiding relationships" + r.getId()); Context.getPersonService().voidRelationship(r, "htmlformentry"); log.debug("editing relationships" + r.getId()); Context.getPersonService().saveRelationship(r); Context.getPersonService().savePerson(patient);
Person relative = personService.getPersonByUuid("2178037d-f86b-4f12-8d8b-be3ebc220029"); Assert.assertNotNull("a new person was not created", relative); List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3)); Assert.assertTrue("new relationship was not created", !rels.isEmpty() && rels.size() == 1);
@SuppressWarnings("unchecked") @Test public void shouldNotShowVoidedAddressesInFullRepresentation() throws Exception { executeDataSet("PersonControllerTest-otherPersonData.xml"); Person person = service.getPersonByUuid(getUuid()); assertEquals(2, person.getAddresses().size()); PersonAddress voidedAddress = service.getPersonAddressByUuid("8a806d8c-822d-11e0-872f-18a905e044dc"); String voidedAddressUuid = voidedAddress.getUuid(); assertTrue(voidedAddress.isVoided()); MockHttpServletRequest req = newGetRequest(getURI() + "/" + getUuid(), new Parameter( RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL)); req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(req)); List<SimpleObject> addresses = (List<SimpleObject>) PropertyUtils.getProperty(result, "addresses"); assertEquals(1, addresses.size()); assertFalse(voidedAddressUuid.equals(PropertyUtils.getProperty(addresses.get(0), "uuid"))); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date) */ @Test public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception { PersonService personService = Context.getPersonService(); RelationshipType relationshipType = personService.getRelationshipType(1); List<Relationship> relationships = personService.getRelationships(null, null, relationshipType, new Date(), new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the relationship type", relationships.size() > 0); }