use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class DefaultTrackerObjectsDeletionService method deleteEnrollments.
@Override
public TrackerTypeReport deleteEnrollments(TrackerBundle bundle) {
TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.ENROLLMENT);
List<Enrollment> enrollments = bundle.getEnrollments();
for (int idx = 0; idx < enrollments.size(); idx++) {
String uid = enrollments.get(idx).getEnrollment();
TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.ENROLLMENT, uid, idx);
ProgramInstance programInstance = programInstanceService.getProgramInstance(uid);
List<Event> events = eventTrackerConverterService.to(Lists.newArrayList(programInstance.getProgramStageInstances().stream().filter(psi -> !psi.isDeleted()).collect(Collectors.toList())));
TrackerBundle trackerBundle = TrackerBundle.builder().events(events).user(bundle.getUser()).build();
deleteEvents(trackerBundle);
TrackedEntityInstance tei = programInstance.getEntityInstance();
tei.getProgramInstances().remove(programInstance);
programInstanceService.deleteProgramInstance(programInstance);
teiService.updateTrackedEntityInstance(tei);
typeReport.getStats().incDeleted();
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class StrategyPreProcessor method preProcessEvents.
public void preProcessEvents(TrackerBundle bundle) {
for (Event event : bundle.getEvents()) {
TrackerImportStrategy importStrategy = bundle.getImportStrategy();
ProgramStageInstance existingPsi = bundle.getPreheat().getEvent(TrackerIdScheme.UID, event.getEvent());
if (importStrategy.isCreateAndUpdate()) {
if (existingPsi == null) {
bundle.setStrategy(event, TrackerImportStrategy.CREATE);
} else {
bundle.setStrategy(event, TrackerImportStrategy.UPDATE);
}
} else {
bundle.setStrategy(event, importStrategy);
}
}
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate.
@Test
void failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate() {
setUpIdentifiers();
DataElement validDataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, true);
programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue validDataValue = dataValue();
validDataValue.setValue(null);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete.
@Test
void failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete() {
setUpIdentifiers();
DataElement validDataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, true);
programStage.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue validDataValue = dataValue();
validDataValue.setValue(null);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenUpdatedAtIsNull.
@Test
void failValidationWhenUpdatedAtIsNull() {
setUpIdentifiers();
DataElement dataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
ProgramStage programStage = programStage(dataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue validDataValue = dataValue();
validDataValue.setUpdatedAt(null);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
Aggregations