Search in sources :

Example 21 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ProgramOrgUnitsSupplier method preheatAdd.

@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
    // fetch all existing Org Units from payload
    final List<Long> orgUnitIds = preheat.getMap().getOrDefault(OrganisationUnit.class, Collections.emptyMap()).values().stream().map(IdentifiableObject::getId).distinct().collect(Collectors.toList());
    if (orgUnitIds.isEmpty()) {
        return;
    }
    final String sql = "SELECT p.uid AS programuid, ou.uid AS organisationunituid " + "FROM program_organisationunits po " + "JOIN program p ON po.programid=p.programid " + "JOIN organisationunit ou ON po.organisationunitid=ou.organisationunitid " + "WHERE po.organisationunitid IN ( :ids )";
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", orgUnitIds);
    preheat.setProgramWithOrgUnitsMap(jdbcTemplate.query(sql, parameters, rs -> {
        Map<String, List<String>> map = new HashMap<>();
        while (rs.next()) {
            final String pid = rs.getString("programuid");
            final String ouid = rs.getString("organisationunituid");
            if (map.containsKey(pid)) {
                map.get(pid).add(ouid);
            } else {
                List<String> ouids = new ArrayList<>();
                ouids.add(ouid);
                map.put(pid, ouids);
            }
        }
        return map;
    }));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) java.util(java.util) Component(org.springframework.stereotype.Component) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Collectors(java.util.stream.Collectors) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 22 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class ProgramStageInstanceProgramStageMapSupplier method preheatAdd.

@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
    if (params.getEvents().size() == 0) {
        return;
    }
    List<String> notRepeatableProgramStageUids = params.getEvents().stream().map(Event::getProgramStage).filter(Objects::nonNull).map(ps -> (ProgramStage) preheat.get(ProgramStage.class, ps)).filter(Objects::nonNull).filter(ps -> !ps.getRepeatable()).map(ProgramStage::getUid).distinct().collect(Collectors.toList());
    List<String> programInstanceUids = params.getEvents().stream().map(Event::getEnrollment).filter(Objects::nonNull).distinct().collect(Collectors.toList());
    if (!notRepeatableProgramStageUids.isEmpty() && !programInstanceUids.isEmpty()) {
        List<Pair<String, String>> programStageWithEvents = new ArrayList<>();
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        parameters.addValue("programStageUids", notRepeatableProgramStageUids);
        parameters.addValue("programInstanceUids", programInstanceUids);
        jdbcTemplate.query(SQL, parameters, rs -> {
            programStageWithEvents.add(Pair.of(rs.getString(PS_UID), rs.getString(PI_UID)));
        });
        preheat.setProgramStageWithEvents(programStageWithEvents);
    }
}
Also used : Objects(java.util.Objects) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Collectors(java.util.stream.Collectors) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Objects(java.util.Objects) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) Pair(org.apache.commons.lang3.tuple.Pair)

Example 23 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHook method validateCategoryOptionsExist.

private boolean validateCategoryOptionsExist(ValidationErrorReporter reporter, Event event) {
    if (hasNoAttributeCategoryOptionsSet(event)) {
        return true;
    }
    boolean allCOsExist = true;
    Set<String> categoryOptions = parseCategoryOptions(event);
    TrackerPreheat preheat = reporter.getValidationContext().getBundle().getPreheat();
    for (String id : categoryOptions) {
        if (preheat.getCategoryOption(id) == null) {
            reporter.addError(event, E1116, id);
            allCOsExist = false;
        }
    }
    return allCOsExist;
}
Also used : TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat)

Example 24 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class AssignValueImplementer method isTheSameValue.

private boolean isTheSameValue(EventActionRule actionRule, TrackerPreheat preheat) {
    DataElement dataElement = preheat.get(DataElement.class, actionRule.getField());
    String dataValue = actionRule.getValue();
    Optional<DataValue> optionalDataValue = actionRule.getDataValues().stream().filter(dv -> dv.getDataElement().equals(actionRule.getField())).findAny();
    if (optionalDataValue.isPresent()) {
        return areEquals(dataValue, optionalDataValue.get().getValue(), dataElement.getValueType());
    }
    return false;
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Map(java.util.Map) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) EventActionRule(org.hisp.dhis.tracker.programrule.EventActionRule) EnrollmentActionRule(org.hisp.dhis.tracker.programrule.EnrollmentActionRule) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Sets(com.google.common.collect.Sets) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) IssueType(org.hisp.dhis.tracker.programrule.IssueType) SettingKey(org.hisp.dhis.setting.SettingKey) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue)

Example 25 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class NotesConverterServiceTest method setUp.

@BeforeEach
void setUp() {
    this.notesConverterService = new NotesConverterService();
    User user = createUser('A');
    this.preheat = new TrackerPreheat();
    preheat.setUser(user);
}
Also used : User(org.hisp.dhis.user.User) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)33 Test (org.junit.jupiter.api.Test)17 List (java.util.List)11 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)10 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)10 Event (org.hisp.dhis.tracker.domain.Event)9 Collectors (java.util.stream.Collectors)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Optional (java.util.Optional)6 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)6 ProgramStage (org.hisp.dhis.program.ProgramStage)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 Component (org.springframework.stereotype.Component)5 Lists (com.google.common.collect.Lists)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)4 Program (org.hisp.dhis.program.Program)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4