/** * @see PersonService#getRelationshipType(Integer) */ @Test public void getRelationshipType_shouldReturnRelationshipTypeWithTheGivenRelationshipTypeId() throws Exception { RelationshipType relationshipType = Context.getPersonService().getRelationshipType(1); Assert.assertNotNull(relationshipType); assertTrue("Expecting the return is of a relationship type", relationshipType.getClass().equals( RelationshipType.class)); }
/** * @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); }
/** * @see PersonService#getRelationshipType(Integer) */ @Test public void getRelationshipType_shouldReturnNullWhenNoRelationshipTypeMatchesGivenRelationshipTypeId() throws Exception { RelationshipType relationshipType = Context.getPersonService().getRelationshipType(10000); Assert.assertNull(relationshipType); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date) */ @Test public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception { PersonService personService = Context.getPersonService(); RelationshipType relationshipType = personService.getRelationshipType(1); List<Relationship> relationships = personService.getRelationships(null, null, relationshipType, new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the relationship type", relationships.size() > 0); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType) */ @Test public void getRelationships_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception { PersonService personService = Context.getPersonService(); RelationshipType relationshipType = personService.getRelationshipType(1); List<Relationship> relationships = personService.getRelationships(null, null, relationshipType); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the relationship type", relationships.size() > 0); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date) */ @Test public void getRelationships3_shouldReturnEmptyListWhenNoRelationshipMatchingGivenParametersExist() throws Exception { PersonService personService = Context.getPersonService(); Person firstPerson = personService.getPerson(501); Person secondPerson = personService.getPerson(2); RelationshipType relationshipType = personService.getRelationshipType(1); List<Relationship> relationships = personService.getRelationships(firstPerson, secondPerson, relationshipType, new Date(), new Date()); Assert.assertNotNull(relationships); assertTrue("There should be no relationship found given the from person", relationships.isEmpty()); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date) */ @Test public void getRelationships2_shouldReturnEmptyListWhenNoRelationshipMatchingGivenParametersExist() throws Exception { PersonService personService = Context.getPersonService(); Person firstPerson = personService.getPerson(501); Person secondPerson = personService.getPerson(2); RelationshipType relationshipType = personService.getRelationshipType(1); List<Relationship> relationships = personService.getRelationships(firstPerson, secondPerson, relationshipType, new Date()); Assert.assertNotNull(relationships); assertTrue("There should be no relationship found given the from person", relationships.isEmpty()); }
/** * @see PersonService#getRelationshipMap(RelationshipType) */ @Test public void getRelationshipMap_shouldReturnEmptyMapWhenNoRelationshipHasTheMatchingRelationshipType() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml"); PersonService personService = Context.getPersonService(); RelationshipType relationshipType = personService.getRelationshipType(15); Map<Person, List<Person>> relationshipMap = personService.getRelationshipMap(relationshipType); Assert.assertNotNull(relationshipMap); assertTrue("There should be no element in the map", relationshipMap.isEmpty()); }
/** * @see PersonService#saveRelationship(Relationship) */ @Test public void saveRelationship_shouldUpdateExistingObjectWhenRelationshipIdIsNotNull() throws Exception { PersonService personService = Context.getPersonService(); Relationship savedRelationship = personService.getRelationship(1); Assert.assertNotNull(savedRelationship.getRelationshipId()); savedRelationship.setRelationshipType(personService.getRelationshipType(2)); Relationship updatedRelationship = personService.saveRelationship(savedRelationship); Assert.assertEquals(personService.getRelationshipType(2), updatedRelationship.getRelationshipType()); }
RelationshipType relType = Context.getPersonService().getRelationshipType(relTypeId); if (relType == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.relationshipTypeNotFound",
@Test public void retireRelationshipType_shouldRetireGivenRelationshipType() { RelationshipType rt = personService.getRelationshipType(1); assertFalse(rt.getRetired()); String reason = "reason"; personService.retireRelationshipType(rt, reason); assertTrue(rt.getRetired()); assertThat(rt.getRetiredBy(), is(Context.getAuthenticatedUser())); assertNotNull(rt.getDateRetired()); assertThat(rt.getRetireReason(), is(reason)); }
/** * @see PersonService#saveRelationshipType(RelationshipType) */ @Test public void saveRelationshipType_shouldUpdateExistingObjectWhenRelationshipTypeIdIsNotNull() throws Exception { RelationshipType savedRelationshipType = Context.getPersonService().getRelationshipType(1); Assert.assertNotNull(savedRelationshipType.getRelationshipTypeId()); savedRelationshipType.setPreferred(true); RelationshipType updatedRelationshipType = personService.saveRelationshipType(savedRelationshipType); Assert.assertEquals(true, updatedRelationshipType.getPreferred()); }
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);
@Test public void unretireRelationshipType_shouldRetireGivenRelationshipType() { RelationshipType rt = personService.getRelationshipType(1); personService.retireRelationshipType(rt, "reason"); assertTrue(rt.getRetired()); personService.unretireRelationshipType(rt); assertFalse(rt.getRetired()); assertNull(rt.getRetiredBy()); assertNull(rt.getDateRetired()); assertNull(rt.getRetireReason()); }
/** * @see PersonService#purgeRelationshipType(RelationshipType) */ @Test public void purgeRelationshipType_shouldDeleteRelationshipTypeFromTheDatabase() throws Exception { PersonService personService = Context.getPersonService(); RelationshipType relationshipType = new RelationshipType(); relationshipType.setDescription("Test relationship"); relationshipType.setaIsToB("Sister"); relationshipType.setbIsToA("Brother"); relationshipType = personService.saveRelationshipType(relationshipType); assertNotNull(relationshipType.getId()); personService.purgeRelationshipType(relationshipType); RelationshipType deletedRelationshipType = personService.getRelationshipType(relationshipType.getId()); Assert.assertNull(deletedRelationshipType); }
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);
/** * @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()); }