Search in sources :

Example 6 with RelationshipItem

use of org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem in project dhis2-core by dhis2.

the class RelationshipRowCallbackHandler method createItem.

/**
 * The SQL query that generates the ResultSet used by this
 * {@see RowCallbackHandler} fetches both sides of a relationship: since
 * each side can be a Tracked Entity Instance, a Program Instance or a
 * Program Stage Instance, the query adds an "hint" to the final result to
 * help this Handler to correctly associate the type to the left or right
 * side of the relationship. The "typeWithUid" variable contains the UID of
 * the object and a string representing the type. E.g.
 *
 * tei|dj3382832 psi|332983893
 *
 * This function parses the string and extract the type and the uid, in
 * order to instantiate the appropriate object and assign it to the
 * {@see RelationshipItem}
 *
 * @param typeWithUid a String containing the object type and the UID of the
 *        object, separated by | (pipe)
 * @return a {@see RelationshipItem}
 */
private RelationshipItem createItem(String typeWithUid) {
    if (StringUtils.isEmpty(typeWithUid)) {
        return new RelationshipItem();
    }
    RelationshipItem ri = new RelationshipItem();
    final String type = typeWithUid.split("\\|")[0];
    final String uid = typeWithUid.split("\\|")[1];
    switch(type) {
        case "tei":
            TrackedEntityInstance tei = new TrackedEntityInstance();
            tei.clear();
            tei.setTrackedEntityInstance(uid);
            ri.setTrackedEntityInstance(tei);
            break;
        case "pi":
            Enrollment pi = new Enrollment();
            pi.setEnrollment(uid);
            ri.setEnrollment(pi);
            break;
        case "psi":
            Event psi = new Event();
            psi.setEvent(uid);
            ri.setEvent(psi);
            break;
        default:
            log.warn("Expecting tei|psi|pi as type when fetching a relationship, got: " + type);
    }
    return ri;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) RelationshipItem(org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem)

Example 7 with RelationshipItem

use of org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem 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)

Aggregations

Relationship (org.hisp.dhis.dxf2.events.trackedentity.Relationship)4 RelationshipItem (org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem)4 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)3 Event (org.hisp.dhis.dxf2.events.event.Event)3 RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)3 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1