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;
}
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;
}
Aggregations