Search in sources :

Example 36 with Relationship

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]));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 37 with Relationship

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;
}
Also used : Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) Event(org.hisp.dhis.dxf2.events.event.Event) RelationshipItem(org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem)

Example 38 with 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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Relationship (org.hisp.dhis.dxf2.events.trackedentity.Relationship)30 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)14 ArrayList (java.util.ArrayList)11 Transactional (org.springframework.transaction.annotation.Transactional)10 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)9 Test (org.junit.jupiter.api.Test)9 List (java.util.List)8 RelationshipType (org.hisp.dhis.relationship.RelationshipType)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 Optional (java.util.Optional)5 Set (java.util.Set)5 Event (org.hisp.dhis.dxf2.events.event.Event)5 Lists (com.google.common.collect.Lists)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 CurrentUserService (org.hisp.dhis.user.CurrentUserService)4