Search in sources :

Example 1 with TrackedEntityProgramOwner

use of org.hisp.dhis.trackedentity.TrackedEntityProgramOwner in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method getTei.

private TrackedEntityInstance getTei(org.hisp.dhis.trackedentity.TrackedEntityInstance daoTrackedEntityInstance, Set<TrackedEntityAttribute> readableAttributes, TrackedEntityInstanceParams params, User user) {
    if (daoTrackedEntityInstance == null) {
        return null;
    }
    TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
    trackedEntityInstance.setTrackedEntityInstance(daoTrackedEntityInstance.getUid());
    trackedEntityInstance.setOrgUnit(daoTrackedEntityInstance.getOrganisationUnit().getUid());
    trackedEntityInstance.setTrackedEntityType(daoTrackedEntityInstance.getTrackedEntityType().getUid());
    trackedEntityInstance.setCreated(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getCreated()));
    trackedEntityInstance.setCreatedAtClient(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getCreatedAtClient()));
    trackedEntityInstance.setLastUpdated(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getLastUpdated()));
    trackedEntityInstance.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getLastUpdatedAtClient()));
    trackedEntityInstance.setInactive(Optional.ofNullable(daoTrackedEntityInstance.isInactive()).orElse(false));
    trackedEntityInstance.setGeometry(daoTrackedEntityInstance.getGeometry());
    trackedEntityInstance.setDeleted(daoTrackedEntityInstance.isDeleted());
    trackedEntityInstance.setPotentialDuplicate(daoTrackedEntityInstance.isPotentialDuplicate());
    trackedEntityInstance.setStoredBy(daoTrackedEntityInstance.getStoredBy());
    trackedEntityInstance.setCreatedByUserInfo(daoTrackedEntityInstance.getCreatedByUserInfo());
    trackedEntityInstance.setLastUpdatedByUserInfo(daoTrackedEntityInstance.getLastUpdatedByUserInfo());
    if (daoTrackedEntityInstance.getGeometry() != null) {
        Geometry geometry = daoTrackedEntityInstance.getGeometry();
        FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType());
        trackedEntityInstance.setFeatureType(featureType);
        trackedEntityInstance.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geometry));
    }
    if (params.isIncludeRelationships()) {
        for (RelationshipItem relationshipItem : daoTrackedEntityInstance.getRelationshipItems()) {
            org.hisp.dhis.relationship.Relationship daoRelationship = relationshipItem.getRelationship();
            if (trackerAccessManager.canRead(user, daoRelationship).isEmpty()) {
                Relationship relationship = relationshipService.getRelationship(relationshipItem.getRelationship(), RelationshipParams.FALSE, user);
                trackedEntityInstance.getRelationships().add(relationship);
            }
        }
    }
    if (params.isIncludeEnrollments()) {
        for (ProgramInstance programInstance : daoTrackedEntityInstance.getProgramInstances()) {
            if (trackerAccessManager.canRead(user, programInstance, false).isEmpty() && (params.isIncludeDeleted() || !programInstance.isDeleted())) {
                trackedEntityInstance.getEnrollments().add(enrollmentService.getEnrollment(user, programInstance, params, true));
            }
        }
    }
    if (params.isIncludeProgramOwners()) {
        for (TrackedEntityProgramOwner programOwner : daoTrackedEntityInstance.getProgramOwners()) {
            trackedEntityInstance.getProgramOwners().add(new ProgramOwner(programOwner));
        }
    }
    Set<TrackedEntityAttribute> readableAttributesCopy = filterOutSkipSyncAttributesIfApplies(params, trackedEntityInstance, readableAttributes);
    for (TrackedEntityAttributeValue attributeValue : daoTrackedEntityInstance.getTrackedEntityAttributeValues()) {
        if (readableAttributesCopy.contains(attributeValue.getAttribute())) {
            Attribute attribute = new Attribute();
            attribute.setCreated(DateUtils.getIso8601NoTz(attributeValue.getCreated()));
            attribute.setLastUpdated(DateUtils.getIso8601NoTz(attributeValue.getLastUpdated()));
            attribute.setDisplayName(attributeValue.getAttribute().getDisplayName());
            attribute.setAttribute(attributeValue.getAttribute().getUid());
            attribute.setValueType(attributeValue.getAttribute().getValueType());
            attribute.setCode(attributeValue.getAttribute().getCode());
            attribute.setValue(attributeValue.getValue());
            attribute.setStoredBy(attributeValue.getStoredBy());
            attribute.setSkipSynchronization(attributeValue.getAttribute().getSkipSynchronization());
            trackedEntityInstance.getAttributes().add(attribute);
        }
    }
    return trackedEntityInstance;
}
Also used : TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) FeatureType(org.hisp.dhis.organisationunit.FeatureType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Geometry(org.locationtech.jts.geom.Geometry) TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 2 with TrackedEntityProgramOwner

use of org.hisp.dhis.trackedentity.TrackedEntityProgramOwner in project dhis2-core by dhis2.

the class OwnershipTest method testProgramOwnerWhenEnrolled.

@Test
void testProgramOwnerWhenEnrolled() throws IOException {
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, teis.size());
    TrackedEntityInstance tei = teis.get(0);
    assertNotNull(tei.getProgramOwners());
    Set<TrackedEntityProgramOwner> tepos = tei.getProgramOwners();
    assertEquals(1, tepos.size());
    TrackedEntityProgramOwner tepo = tepos.iterator().next();
    assertNotNull(tepo.getEntityInstance());
    assertNotNull(tepo.getProgram());
    assertNotNull(tepo.getOrganisationUnit());
    assertEquals(enrollmentParams.getEnrollments().get(0).getProgram(), tepo.getProgram().getUid());
    assertEquals(enrollmentParams.getEnrollments().get(0).getOrgUnit(), tepo.getOrganisationUnit().getUid());
    assertEquals(enrollmentParams.getEnrollments().get(0).getTrackedEntity(), tepo.getEntityInstance().getUid());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Aggregations

TrackedEntityProgramOwner (org.hisp.dhis.trackedentity.TrackedEntityProgramOwner)2 FeatureType (org.hisp.dhis.organisationunit.FeatureType)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)1 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)1 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)1 TrackerTest (org.hisp.dhis.tracker.TrackerTest)1 Test (org.junit.jupiter.api.Test)1 Geometry (org.locationtech.jts.geom.Geometry)1