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