Search in sources :

Example 11 with RelationshipType

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

the class DefaultTrackedEntityInstanceService method createTrackedEntityInstance.

@Override
public int createTrackedEntityInstance(TrackedEntityInstance instance, String representativeId, Integer relationshipTypeId, Set<TrackedEntityAttributeValue> attributeValues) {
    int id = addTrackedEntityInstance(instance);
    for (TrackedEntityAttributeValue pav : attributeValues) {
        attributeValueService.addTrackedEntityAttributeValue(pav);
        instance.getTrackedEntityAttributeValues().add(pav);
    }
    if (representativeId != null) {
        TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid(representativeId);
        if (representative != null) {
            instance.setRepresentative(representative);
            Relationship rel = new Relationship();
            rel.setEntityInstanceA(representative);
            rel.setEntityInstanceB(instance);
            if (relationshipTypeId != null) {
                RelationshipType relType = relationshipTypeService.getRelationshipType(relationshipTypeId);
                if (relType != null) {
                    rel.setRelationshipType(relType);
                    relationshipService.addRelationship(rel);
                }
            }
        }
    }
    // Update associations
    updateTrackedEntityInstance(instance);
    return id;
}
Also used : TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Aggregations

RelationshipType (org.hisp.dhis.relationship.RelationshipType)11 Relationship (org.hisp.dhis.relationship.Relationship)4 ArrayList (java.util.ArrayList)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 HashSet (java.util.HashSet)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Program (org.hisp.dhis.program.Program)2 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)2 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 Test (org.junit.Test)2 Date (java.util.Date)1 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)1 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1