use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Tei.
@Test
void testTrackedEntityInstanceRelationshipsTei2Tei() {
final String[] teiUid = new String[2];
doInTransaction(() -> {
org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstance();
this.persistRelationship(t1, t2);
teiUid[0] = t1.getUid();
teiUid[1] = t2.getUid();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeRelationships(true);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances.get(0).getRelationships(), hasSize(1));
final Relationship relationship = trackedEntityInstances.get(0).getRelationships().get(0);
assertThat(relationship.getFrom().getTrackedEntityInstance().getTrackedEntityInstance(), is(teiUid[0]));
assertThat(relationship.getTo().getTrackedEntityInstance().getTrackedEntityInstance(), is(teiUid[1]));
}
use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.
the class HandleRelationshipsTrackedEntityInstanceServiceTest method createEventToTeiRelationship.
private Relationship createEventToTeiRelationship(char uniqueCharacter, RelationshipType relationshipType, TrackedEntityInstance trackedEntityInstance, ProgramStageInstance programStageInstance) {
RelationshipItem relationshipItemEvent = new RelationshipItem();
Event event = new Event();
event.setEvent(programStageInstance.getUid());
relationshipItemEvent.setEvent(event);
RelationshipItem relationshipItemTei = new RelationshipItem();
relationshipItemTei.setTrackedEntityInstance(trackedEntityInstance);
Relationship relationship = new Relationship();
relationship.setFrom(relationshipItemEvent);
relationship.setTo(relationshipItemTei);
relationship.setRelationshipType(relationshipType.getUid());
relationship.setRelationship("UID_" + uniqueCharacter);
relationship.setRelationshipName("Malaria case linked to person");
relationship.setBidirectional(relationshipType.isBidirectional());
return relationship;
}
use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.
the class HandleRelationshipsTrackedEntityInstanceServiceTest method testUpdateTeiWithBidirectionalRelationshipTeiToTei.
@Test
void testUpdateTeiWithBidirectionalRelationshipTeiToTei() {
TrackedEntityInstance trackedEntityInstanceFrom = trackedEntityInstanceService.getTrackedEntityInstance(this.trackedEntityInstanceA.getUid());
TrackedEntityInstance trackedEntityInstanceTo = trackedEntityInstanceService.getTrackedEntityInstance(this.trackedEntityInstanceB.getUid());
RelationshipType personToPersonRelationshipType = createPersonToPersonRelationshipType('A', programA, trackedEntityType, true);
relationshipTypeService.addRelationshipType(personToPersonRelationshipType);
Relationship relationship = createTeiToTeiRelationship('A', personToPersonRelationshipType, trackedEntityInstanceFrom, trackedEntityInstanceTo);
trackedEntityInstanceFrom.setRelationships(Lists.newArrayList(relationship));
ImportSummary importSummaryFrom = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstanceFrom, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummaryFrom.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummaryFrom.getRelationships().getStatus());
trackedEntityInstanceTo.setRelationships(Lists.newArrayList(relationship));
ImportSummary importSummaryTo = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstanceTo, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummaryTo.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummaryTo.getRelationships().getStatus());
}
Aggregations