Search in sources :

Example 6 with Relationship

use of org.hisp.dhis.relationship.Relationship 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

Relationship (org.hisp.dhis.relationship.Relationship)6 RelationshipType (org.hisp.dhis.relationship.RelationshipType)4 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 ArrayList (java.util.ArrayList)1 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)1 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)1 OptionSet (org.hisp.dhis.api.mobile.model.OptionSet)1 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)1 TrackedEntityAttributeValueSortOrderComparator (org.hisp.dhis.api.mobile.model.comparator.TrackedEntityAttributeValueSortOrderComparator)1 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)1 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)1