Search in sources :

Example 11 with RelationshipItem

use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.

the class RelationshipStoreTest method setUpTest.

@Override
public void setUpTest() {
    relationshipType = createRelationshipType('A');
    relationshipTypeService.addRelationshipType(relationshipType);
    organisationUnit = createOrganisationUnit("testOU");
    organisationUnitService.addOrganisationUnit(organisationUnit);
    trackedEntityInstanceA = createTrackedEntityInstance(organisationUnit);
    trackedEntityInstanceB = createTrackedEntityInstance(organisationUnit);
    trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstanceA);
    trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstanceB);
    relationship = new Relationship();
    RelationshipItem relationshipItemFrom = new RelationshipItem();
    RelationshipItem relationshipItemTo = new RelationshipItem();
    relationshipItemFrom.setTrackedEntityInstance(trackedEntityInstanceA);
    relationshipItemTo.setTrackedEntityInstance(trackedEntityInstanceB);
    relationship.setRelationshipType(relationshipType);
    relationship.setFrom(relationshipItemFrom);
    relationship.setTo(relationshipItemTo);
    relationship.setKey(RelationshipUtils.generateRelationshipKey(relationship));
    relationship.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(relationship));
    relationshipService.addRelationship(relationship);
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 12 with RelationshipItem

use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.

the class DhisConvenienceTest method createTeiToTeiRelationship.

public static Relationship createTeiToTeiRelationship(TrackedEntityInstance from, TrackedEntityInstance to, RelationshipType relationshipType) {
    Relationship relationship = new Relationship();
    RelationshipItem _from = new RelationshipItem();
    RelationshipItem _to = new RelationshipItem();
    _from.setTrackedEntityInstance(from);
    _to.setTrackedEntityInstance(to);
    relationship.setRelationshipType(relationshipType);
    relationship.setFrom(_from);
    relationship.setTo(_to);
    relationship.setKey(RelationshipUtils.generateRelationshipKey(relationship));
    relationship.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(relationship));
    relationship.setAutoFields();
    return relationship;
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 13 with RelationshipItem

use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method relationship.

private Relationship relationship(RelationshipType type, ProgramStageInstance from, TrackedEntityInstance to) {
    Relationship r = new Relationship();
    RelationshipItem rItem1 = new RelationshipItem();
    rItem1.setProgramStageInstance(from);
    RelationshipItem rItem2 = new RelationshipItem();
    rItem2.setTrackedEntityInstance(to);
    r.setFrom(rItem1);
    r.setTo(rItem2);
    r.setRelationshipType(type);
    r.setKey(type.getUid());
    r.setInvertedKey(type.getUid());
    r.setAutoFields();
    manager.save(r);
    return r;
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 14 with RelationshipItem

use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method relationship.

private Relationship relationship(RelationshipType type, ProgramInstance from, TrackedEntityInstance to) {
    Relationship r = new Relationship();
    RelationshipItem rItem1 = new RelationshipItem();
    rItem1.setProgramInstance(from);
    RelationshipItem rItem2 = new RelationshipItem();
    rItem2.setTrackedEntityInstance(to);
    r.setFrom(rItem1);
    r.setTo(rItem2);
    r.setRelationshipType(type);
    r.setKey(type.getUid());
    r.setInvertedKey(type.getUid());
    r.setAutoFields();
    manager.save(r);
    return r;
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 15 with RelationshipItem

use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.

the class TrackerTest method persistRelationship.

public Relationship persistRelationship(TrackedEntityInstance tei, ProgramStageInstance psi) {
    RelationshipItem from = new RelationshipItem();
    from.setTrackedEntityInstance(tei);
    RelationshipItem to = new RelationshipItem();
    to.setProgramStageInstance(psi);
    return _persistRelationship(from, to);
}
Also used : RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Aggregations

RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)30 Relationship (org.hisp.dhis.relationship.Relationship)16 Test (org.junit.jupiter.api.Test)11 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 RelationshipType (org.hisp.dhis.relationship.RelationshipType)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 ArrayList (java.util.ArrayList)5 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Date (java.util.Date)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CodeGenerator (org.hisp.dhis.common.CodeGenerator)2 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 ProgramInstanceService (org.hisp.dhis.program.ProgramInstanceService)2 RelationshipService (org.hisp.dhis.relationship.RelationshipService)2