/** * @see org.openmrs.api.PersonService#unvoidRelationship(org.openmrs.Relationship) */ @Override public Relationship unvoidRelationship(Relationship relationship) throws APIException { relationship.setVoided(false); relationship.setVoidedBy(null); relationship.setDateVoided(null); relationship.setVoidReason(null); return Context.getPersonService().saveRelationship(relationship); }
personService.saveRelationship(rel); ++addedSoFar;
/** * @see org.openmrs.api.PersonService#voidRelationship(org.openmrs.Relationship, * java.lang.String) */ @Override public Relationship voidRelationship(Relationship relationship, String voidReason) throws APIException { if (relationship.getVoided()) { return relationship; } relationship.setVoided(true); if (relationship.getVoidedBy() == null) { relationship.setVoidedBy(Context.getAuthenticatedUser()); } if (voidReason != null) { relationship.setVoidReason(voidReason); } relationship.setDateVoided(new Date()); return Context.getPersonService().saveRelationship(relationship); }
/** * @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); }
r.setStartDate(df.parse("1980-01-01")); r.setEndDate(df.parse("2010-01-01")); personService.saveRelationship(r); rels.add(r); r.setStartDate(df.parse("1990-01-01")); r.setEndDate(df.parse("2010-01-01")); personService.saveRelationship(r); rels.add(r); r.setStartDate(df.parse("1980-01-01")); r.setEndDate(df.parse("1990-01-01")); personService.saveRelationship(r); rels.add(r); r.setRelationshipType(rt); r.setStartDate(df.parse("1980-01-01")); personService.saveRelationship(r); rels.add(r); r.setRelationshipType(rt); r.setStartDate(df.parse("1990-01-01")); personService.saveRelationship(r); rels.add(r); r.setRelationshipType(rt); r.setStartDate(df.parse("2010-01-01")); personService.saveRelationship(r); rels.add(r);
Context.getPersonService().saveRelationship(relation);
Relationship persisted = personService.saveRelationship(tmpRel); mergedData.addCreatedRelationship(persisted.getUuid());
/** * @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()); }
newRel.setPersonA(relative); newRel.setPersonB(patient); personService.saveRelationship(newRel);
sibling.setPersonB(p2); sibling.setRelationshipType(personService.getRelationshipType(4)); personService.saveRelationship(sibling); doctor.setPersonA(p2); doctor.setRelationshipType(personService.getRelationshipType(3)); personService.saveRelationship(doctor);
rel.setPersonA(relative); rel.setPersonB(patient); personService.saveRelationship(rel);
sibling.setPersonB(p2); sibling.setRelationshipType(personService.getRelationshipType(4)); personService.saveRelationship(sibling); 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()); }
/** * Voids the Mother-Child relationship * * @param childId Child's MOTECH Id * @return the voided Relationship of OpenMRS */ public Relationship voidRelationship(String childId) { Relationship relationship = getMotherRelationship(childId); relationship = personService.voidRelationship(relationship, REASON); return personService.saveRelationship(relationship); }
/** * Updates the Mother's MOTECH Id for the Child in the Relationship * * @param motherId updated MOTECH Id of the Mother * @param childId Child's MOTECH Id * @return updated OpenMRS Relationship */ public Relationship updateMotherRelationship(String motherId, String childId) { Relationship motherRelationship = getMotherRelationship(childId); Person updatedMother = personService.getPerson(Integer.valueOf(motherId)); motherRelationship.setPersonA(updatedMother); return personService.saveRelationship(motherRelationship); }
/** * 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; };
@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; };