use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class ORUR01HandlerTest method processNK1_shouldCreateARelationshipFromANK1Segment.
/**
* @see ORUR01Handler#processNK1(Patient,NK1)
*/
@Test
public void processNK1_shouldCreateARelationshipFromANK1Segment() throws Exception {
PersonService personService = Context.getPersonService();
// the patient that is the focus of
Patient patient = new Patient(3);
// this hl7 message
// the patient that is related to
Patient relative = new Patient(2);
// patientA
// process a message with a single NK1 segment
// defines relative as patient's Parent
String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
ORUR01Handler oruHandler = new ORUR01Handler();
Message hl7message = parser.parse(hl7String);
ORU_R01 oru = (ORU_R01) hl7message;
List<NK1> nk1List = oruHandler.getNK1List(oru);
for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1);
// verify relationship was created
List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3));
Assert.assertTrue("new relationship was not created", !rels.isEmpty() && rels.size() == 1);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class ORUR01HandlerTest method processNK1_shouldCreateAPersonIfTheRelativeIsNotFound.
/**
* @see ORUR01Handler#processNK1(Patient,NK1)
*/
@Test
public void processNK1_shouldCreateAPersonIfTheRelativeIsNotFound() throws Exception {
// process a message with an invalid relative identifier
PersonService personService = Context.getPersonService();
// the patient that is the focus of
Patient patient = new Patient(3);
// this hl7 message
String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220029^^^UUID^v4\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
ORUR01Handler oruHandler = new ORUR01Handler();
Message hl7message = parser.parse(hl7String);
ORU_R01 oru = (ORU_R01) hl7message;
List<NK1> nk1List = oruHandler.getNK1List(oru);
for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1);
// find the relative in the database
Person relative = personService.getPersonByUuid("2178037d-f86b-4f12-8d8b-be3ebc220029");
Assert.assertNotNull("a new person was not created", relative);
// see if the relative made it into the relationship properly
List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3));
Assert.assertTrue("new relationship was not created", !rels.isEmpty() && rels.size() == 1);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldNotCreateDuplicateRelationships.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldNotCreateDuplicateRelationships() throws Exception {
executeDataSet(PATIENT_RELATIONSHIPS_XML);
Patient preferred = patientService.getPatient(999);
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
// expected relationships before merge:
// * 2->1 (type 2)
// * 999->2 (type 5)
// * 999->1 (type 2)
// * 7->999 (type 4)
// * 502->2 (type 1)
// * 7->2 (type 1)
patientService.mergePatients(preferred, notPreferred);
// expected relationships after merge:
// * 999->1 (type 2)
// * 7->999 (type 4)
// * 502->999 (type 1)
// * 7->999 (type 1)
// check for a relationship that should not be duplicated: 2->1 and
// 999->1
List<Relationship> rels = personService.getRelationships(preferred, new Person(1), new RelationshipType(2));
assertEquals("duplicate relationships were not removed", 1, rels.size());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedRelationships.
/**
* @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()));
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldVoidAllRelationshipsForNonPreferredPatient.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldVoidAllRelationshipsForNonPreferredPatient() throws Exception {
executeDataSet(PATIENT_RELATIONSHIPS_XML);
Patient preferred = patientService.getPatient(999);
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
patientService.mergePatients(preferred, notPreferred);
List<Relationship> rels = personService.getRelationshipsByPerson(notPreferred);
assertTrue("there should not be any relationships for non preferred", rels.isEmpty());
}
Aggregations