/** * Does a shallow copy of this Relationship. Does NOT copy relationshipId * * @return a copy of this relationship */ public Relationship copy() { return copyHelper(new Relationship()); }
Relationship rel = new Relationship(); rel.setPersonA(person); rel.setRelationshipType(relationship);
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfStartDateIsInFuture() { Relationship relationship = new Relationship(1); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, 1); Date nextYear = cal.getTime(); relationship.setStartDate(nextYear); new RelationshipValidator().validate(relationship, errors); Assert.assertTrue(errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfStartDateIsNotInFuture() { Relationship relationship = new Relationship(1); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -1); Date lastYear = cal.getTime(); relationship.setStartDate(lastYear); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Relationship relationship = new Relationship(1); relationship.setVoidReason("voidReason"); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfStartDateIsEmpty() { Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Relationship relationship = new Relationship(1); relationship.setStartDate(null); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); } }
/** * @throws ParseException * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfEndDateIsBeforeStartDate() throws ParseException { Relationship relationship = new Relationship(1); relationship.setStartDate(Context.getDateFormat().parse("18/02/2012")); relationship.setEndDate(Context.getDateFormat().parse("18/02/2001")); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertEquals(true, errors.hasErrors()); }
/** * @throws ParseException * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfEndDateIsAfterStartDate() throws ParseException { Relationship relationship = new Relationship(1); relationship.setStartDate(Context.getDateFormat().parse("18/02/2012")); relationship.setEndDate(Context.getDateFormat().parse("18/03/2012")); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see PersonService#saveRelationship(Relationship) */ @Test(expected = APIException.class) public void saveRelationship_shouldThrowAPIException() { Relationship relationship = new Relationship(); Person person = new Person(); relationship.setPersonA(person); relationship.setPersonB(person); personService.saveRelationship(relationship); }
Relationship r = new Relationship(); // 0 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 1 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 2 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 3 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 4 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 5 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 6 r.setPersonA(personA); r.setPersonB(personB); r = new Relationship(); // 7
Relationship relation = new Relationship(); if (patientCanBeEitherPerson || patientIsPersonA) { relation.setPersonA(patient);
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { Relationship relationship = new Relationship(1); relationship .setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(relationship, "relationship"); new RelationshipValidator().validate(relationship, errors); Assert.assertEquals(true, errors.hasFieldErrors("voidReason")); }
Relationship newRel = new Relationship(); newRel.setRelationshipType(new RelationshipType(3)); newRel.setPersonA(relative);
Relationship sibling = new Relationship(); sibling.setPersonA(p1); sibling.setPersonB(p2); Relationship doctor = new Relationship(); doctor.setPersonB(p1); doctor.setPersonA(p2);
Relationship rel = new Relationship(); rel.setRelationshipType(new RelationshipType(3)); rel.setPersonA(relative);
Relationship sibling = new Relationship(); sibling.setPersonA(p1); sibling.setPersonB(p2); Relationship doctor = new Relationship(); doctor.setPersonB(p1); doctor.setPersonA(p2);
/** * @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()); }
/** * Creates a Mother-Child relationship between two Patients (Mother & Child) * * @param motherId Mother's MOTECH Id * @param childId Child's MOTECH Id * @return the Relationship object from OpenMRS */ public Relationship createMotherChildRelationship(String motherId, String childId) { RelationshipType parentChildRelationshipType = getRelationshipTypeByName(PARENT_CHILD_RELATIONSHIP); Relationship relationship = new Relationship(personService.getPerson(Integer.valueOf(motherId)), personService.getPerson(Integer.valueOf(childId)), parentChildRelationshipType); return personService.saveRelationship(relationship); }
@Override public Patient getPatient() { // preemptively create a relationship RelationshipType type = Context.getPersonService().getRelationshipType(1); Patient parent = Context.getPatientService().getPatient(2); Person child = Context.getPersonService().getPerson(6); Relationship rel = new Relationship(parent, child, type); Context.getPersonService().saveRelationship(rel); Assert.assertEquals(1, Context.getPersonService().getRelationships(parent, child, type).size()); return parent; };
@Override public Patient getPatient() { // preemptively create a relationship RelationshipType type = Context.getPersonService().getRelationshipType(1); Patient parent = Context.getPatientService().getPatient(2); Person child = Context.getPersonService().getPerson(6); Relationship rel = new Relationship(parent, child, type); Context.getPersonService().saveRelationship(rel); Assert.assertEquals(1, Context.getPersonService().getRelationships(parent, child, type).size()); return parent; };