for (Relationship rel : relationships) { Person from = rel.getPersonA(); Person to = rel.getPersonB();
/** * generate a relationship hash for use in mergePatients; follows the convention: * [relationshipType][A|B][relativeId] * * @param rel relationship under consideration * @param primary the focus of the hash * @return hash depicting relevant information to avoid duplicates */ private String relationshipHash(Relationship rel, Person primary) { boolean isA = rel.getPersonA().equals(primary); return rel.getRelationshipType().getRelationshipTypeId().toString() + (isA ? "A" : "B") + (isA ? rel.getPersonB().getPersonId().toString() : rel.getPersonA().getPersonId().toString()); }
/** * @see org.openmrs.api.PersonService#saveRelationship(org.openmrs.Relationship) */ @Override public Relationship saveRelationship(Relationship relationship) throws APIException { if (relationship.getPersonA().equals(relationship.getPersonB())) { throw new APIException("Person.cannot.same", (Object[]) null); } return dao.saveRelationship(relationship); }
boolean personAisPreferred = rel.getPersonA().equals(preferred); boolean personAisNotPreferred = rel.getPersonA().equals(notPreferred); boolean personBisPreferred = rel.getPersonB().equals(preferred); boolean personBisNotPreferred = rel.getPersonB().equals(notPreferred); String relHash = relationshipHash(rel, notPreferred);
/** * The purpose of this method is to allow subclasses of Relationship to delegate a portion of * their copy() method back to the superclass, in case the base class implementation changes. * * @param target a Relationship that will have the state of <code>this</code> copied into it * @return the Relationship that was passed in, with state copied into it */ protected Relationship copyHelper(Relationship target) { target.personA = getPersonA(); target.relationshipType = getRelationshipType(); target.personB = getPersonB(); target.setCreator(getCreator()); target.setDateCreated(getDateCreated()); target.setVoided(getVoided()); target.setVoidedBy(getVoidedBy()); target.setDateVoided(getDateVoided()); target.setVoidReason(getVoidReason()); return target; }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditCreatedRelationships() throws Exception { //create relationships and retrieve preferred and notPreferredPatient patient executeDataSet(PATIENT_RELATIONSHIPS_XML); Patient preferred = patientService.getPatient(7); Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); //merge the two patients and retrieve the audit object PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); //find the UUID of the created relationship as a result of the merge //note: since patient 2 is related to patient 1. patient 7 should now be related to patient 1 String createdRelationshipUuid = null; List<Relationship> relationships = personService.getRelationshipsByPerson(preferred); for (Relationship r : relationships) { if (r.getPersonB().getId().equals(1) || r.getPersonA().getId().equals(1)) { createdRelationshipUuid = r.getUuid(); } } Assert.assertNotNull("expected relationship was not found for the preferred patient after the merge", createdRelationshipUuid); Assert.assertTrue("relationship creation not audited", isValueInList(createdRelationshipUuid, audit.getPersonMergeLogData().getCreatedRelationships())); }
String s = r.getPersonB().getGivenName()+" "+r.getPersonB().getFamilyName(); sb.append(s); val.append(s); if(r.getPersonB().equals(context.getExistingPatient()))
relMap.put(rel.getRelationshipType().getbIsToA(), list); list.add(rel.getPersonB()); } else { List<Person> list = relMap.get(rel.getRelationshipType().getaIsToB());
/** * @param relationship * @return relationship type and start date */ @PropertyGetter("display") public String getDisplayString(Relationship relationship) { String relType = relationship.getRelationshipType() == null ? "NULL" : relationship.getRelationshipType() .getaIsToB(); return relationship.getPersonA().getGivenName() + " is the " + relType + " of " + relationship.getPersonB().getGivenName(); }
if (er.getPersonB().equals(relatedPerson)) { create = false; else if (er.getPersonB().equals(session.getSubmissionActions().getCurrentPerson()) && replace) { session.getSubmissionActions().getRelationshipsToVoid().add(er);