Search in sources :

Example 1 with TrackedEntityProgramOwnerOrgUnit

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

the class ProgramOwnerSupplier method preheatAdd.

@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
    final Map<String, TrackedEntityInstance> preheatedTrackedEntities = preheat.getTrackedEntities().getOrDefault(TrackerIdScheme.UID, new HashMap<>());
    final Map<String, ProgramInstance> preheatedEnrollments = preheat.getEnrollments().getOrDefault(TrackerIdScheme.UID, new HashMap<>());
    Set<Long> teiIds = new HashSet<>();
    params.getEnrollments().stream().forEach(en -> {
        TrackedEntityInstance tei = preheatedTrackedEntities.get(en.getTrackedEntity());
        if (tei != null) {
            teiIds.add(tei.getId());
        }
    });
    params.getEvents().stream().forEach(ev -> {
        ProgramInstance pi = preheatedEnrollments.get(ev.getEnrollment());
        if (pi != null && pi.getEntityInstance() != null) {
            teiIds.add(pi.getEntityInstance().getId());
        }
    });
    List<TrackedEntityProgramOwnerOrgUnit> tepos = trackedEntityProgramOwnerStore.getTrackedEntityProgramOwnerOrgUnits(teiIds);
    tepos = tepos.stream().map(tepo -> new TrackedEntityProgramOwnerOrgUnit(tepo.getTrackedEntityInstanceId(), tepo.getProgramId(), OrganisationUnitMapper.INSTANCE.map(tepo.getOrganisationUnit()))).collect(Collectors.toList());
    preheat.addProgramOwners(tepos);
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) TrackedEntityProgramOwnerOrgUnit(org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerOrgUnit) HashSet(java.util.HashSet)

Example 2 with TrackedEntityProgramOwnerOrgUnit

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

the class TrackerPreheat method addProgramOwner.

public void addProgramOwner(String teiUid, String programUid, OrganisationUnit orgUnit) {
    if (!programOwner.containsKey(teiUid)) {
        programOwner.put(teiUid, new HashMap<>());
    }
    if (!programOwner.get(teiUid).containsKey(programUid)) {
        TrackedEntityProgramOwnerOrgUnit tepo = new TrackedEntityProgramOwnerOrgUnit(teiUid, programUid, orgUnit);
        programOwner.get(teiUid).put(programUid, tepo);
    }
}
Also used : TrackedEntityProgramOwnerOrgUnit(org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerOrgUnit)

Aggregations

TrackedEntityProgramOwnerOrgUnit (org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerOrgUnit)2 HashSet (java.util.HashSet)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1