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