use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerImportService method preHeat.
private TrackerBundle preHeat(TrackerImportParams params, TrackerTimingsStats opsTimer) {
TrackerBundle trackerBundle = opsTimer.exec(PREHEAT_OPS, () -> preheatBundle(params));
notifyOps(params, PREHEAT_OPS, opsTimer);
return trackerBundle;
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class AbstractTrackerDtoValidationHook method validate.
/**
* Delegating validate method, this delegates validation to the different
* implementing hooks.
*
* @param context validation context
*/
@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
TrackerBundle bundle = context.getBundle();
/*
* Validate the bundle, by passing each Tracker entities collection to
* the validation hooks. If a validation hook reports errors and has
* 'removeOnError=true' the Tracker entity under validation will be
* removed from the bundle.
*/
validateTrackerDtos(reporter, context, bundle.getTrackedEntities());
validateTrackerDtos(reporter, context, bundle.getEnrollments());
validateTrackerDtos(reporter, context, bundle.getEvents());
validateTrackerDtos(reporter, context, bundle.getRelationships());
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class AssignValueImplementer method addOrOverwriteAttribute.
private void addOrOverwriteAttribute(EnrollmentActionRule actionRule, TrackerBundle bundle) {
Enrollment enrollment = bundle.getEnrollment(actionRule.getEnrollment()).get();
Optional<TrackedEntity> trackedEntity = bundle.getTrackedEntity(enrollment.getTrackedEntity());
List<Attribute> attributes;
if (trackedEntity.isPresent()) {
attributes = trackedEntity.get().getAttributes();
Optional<Attribute> optionalAttribute = attributes.stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
if (optionalAttribute.isPresent()) {
optionalAttribute.get().setValue(actionRule.getData());
return;
}
}
attributes = enrollment.getAttributes();
Optional<Attribute> optionalAttribute = attributes.stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
if (optionalAttribute.isPresent()) {
optionalAttribute.get().setValue(actionRule.getData());
} else {
attributes.add(createAttribute(actionRule.getField(), actionRule.getData()));
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EventProgramPreProcessor method process.
@Override
public void process(TrackerBundle bundle) {
List<Event> eventsToPreprocess = bundle.getEvents().stream().filter(e -> Strings.isEmpty(e.getProgram()) || Strings.isEmpty(e.getProgramStage())).collect(Collectors.toList());
for (Event event : eventsToPreprocess) {
// Extract program from program stage
if (Strings.isNotEmpty(event.getProgramStage())) {
ProgramStage programStage = bundle.getPreheat().get(ProgramStage.class, event.getProgramStage());
if (Objects.nonNull(programStage)) {
// TODO remove if once metadata import is fixed
if (programStage.getProgram() == null) {
// a validation error for this edge case
return;
}
event.setProgram(programStage.getProgram().getUid());
bundle.getPreheat().put(TrackerIdentifier.UID, programStage.getProgram());
}
} else // If it is a program event, extract program stage from program
if (Strings.isNotEmpty(event.getProgram())) {
Program program = bundle.getPreheat().get(Program.class, event.getProgram());
if (Objects.nonNull(program) && program.isWithoutRegistration()) {
Optional<ProgramStage> programStage = program.getProgramStages().stream().findFirst();
if (programStage.isPresent()) {
event.setProgramStage(programStage.get().getUid());
bundle.getPreheat().put(TrackerIdentifier.UID, programStage.get());
}
}
}
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerProgramRuleService method getAttributes.
// Get all the attributes linked to enrollment from the payload and the DB,
// using the one from payload
// if they are present in both places
private List<TrackedEntityAttributeValue> getAttributes(Enrollment enrollment, TrackerBundle bundle) {
List<TrackedEntityAttributeValue> attributeValues = attributeValueTrackerConverterService.from(bundle.getPreheat(), enrollment.getAttributes());
TrackedEntityInstance trackedEntity = bundle.getPreheat().getTrackedEntity(bundle.getIdentifier(), enrollment.getTrackedEntity());
List<TrackedEntityAttributeValue> payloadAttributeValues = bundle.getTrackedEntity(enrollment.getTrackedEntity()).map(tei -> attributeValueTrackerConverterService.from(bundle.getPreheat(), tei.getAttributes())).orElse(Lists.newArrayList());
attributeValues.addAll(payloadAttributeValues);
if (trackedEntity != null) {
List<String> payloadAttributeValuesIds = payloadAttributeValues.stream().map(av -> av.getAttribute().getUid()).collect(Collectors.toList());
attributeValues.addAll(trackedEntity.getTrackedEntityAttributeValues().stream().filter(av -> !payloadAttributeValuesIds.contains(av.getAttribute().getUid())).collect(Collectors.toList()));
}
return attributeValues;
}
Aggregations