use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationSuccessWhenTeiIsInPayload.
@Test
void verifyEnrollmentValidationSuccessWhenTeiIsInPayload() {
// given
Enrollment enrollment = validEnrollment();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
// when
when(ctx.getReference(TRACKED_ENTITY_UID)).thenReturn(Optional.of(new ReferenceTrackerEntity("", "")));
when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
validatorToTest.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEnrollmentWithNoteWithInvalidUidFails.
@Test
void verifyEnrollmentWithNoteWithInvalidUidFails() {
// given
Note note = Note.builder().note(INVALID_UID).build();
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1048, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEnrollmentValidationSuccess.
@Test
void verifyEnrollmentValidationSuccess() {
// given
Note note = Note.builder().note(CodeGenerator.generateUid()).build();
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleParamsConverter method convert.
/**
* Iterates over the collections of a dataBundle. If any objects in those
* collections have objects nested within them, they are extracted. For each
* object we process, we make sure all references are valid as well.
*
* @param dataBundle containing collections to check and update.
* @return a dataBundle with a flattened data structure, and valid uid
* references.
*/
@Override
public TrackerBundleParams convert(TrackerBundleParams dataBundle) {
Map<String, TrackedEntity> trackedEntityMap = new HashMap<>();
Map<String, Enrollment> enrollmentHashMap = new HashMap<>();
Map<String, Event> eventHashMap = new HashMap<>();
Map<String, Relationship> relationshipHashMap = new HashMap<>();
// Extract all enrollments and relationships, and set parent reference.
for (TrackedEntity te : dataBundle.getTrackedEntities()) {
updateTrackedEntityReferences(te);
trackedEntityMap.put(te.getTrackedEntity(), te);
extractEnrollments(te).forEach(enrollment -> enrollmentHashMap.put(enrollment.getEnrollment(), enrollment));
extractRelationships(te).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
}
// Set UID for all enrollments and notes
dataBundle.getEnrollments().stream().peek(enrollment -> updateEnrollmentReferences(enrollment, enrollment.getTrackedEntity())).forEach(enrollment -> enrollmentHashMap.put(enrollment.getEnrollment(), enrollment));
// Extract all events and relationships, and set parent references
for (Enrollment enrollment : enrollmentHashMap.values()) {
extractEvents(enrollment).forEach(event -> eventHashMap.put(event.getEvent(), event));
extractRelationships(enrollment).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
enrollment.setNotes(enrollment.getNotes().stream().filter(note -> !StringUtils.isEmpty(note.getValue())).peek(this::updateNoteReferences).collect(Collectors.toList()));
}
// Set UID for all events and notes
dataBundle.getEvents().stream().peek(event -> updateEventReferences(event, event.getEnrollment())).forEach(event -> eventHashMap.put(event.getEvent(), event));
// Extract all relationships
for (Event event : eventHashMap.values()) {
extractRelationships(event).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
event.setNotes(event.getNotes().stream().filter(note -> !StringUtils.isEmpty(note.getValue())).peek(this::updateNoteReferences).collect(Collectors.toList()));
}
// Set UID for all relationships
dataBundle.getRelationships().stream().peek(this::updateRelationshipReferences).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
return TrackerBundleParams.builder().trackedEntities(new ArrayList<>(trackedEntityMap.values())).enrollments(new ArrayList<>(enrollmentHashMap.values())).events(new ArrayList<>(eventHashMap.values())).relationships(new ArrayList<>(relationshipHashMap.values())).build();
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerEnrollmentsExportController method getInstances.
@GetMapping(produces = APPLICATION_JSON_VALUE)
PagingWrapper<Enrollment> getInstances(TrackerEnrollmentCriteria trackerEnrollmentCriteria) {
PagingWrapper<Enrollment> enrollmentPagingWrapper = new PagingWrapper<>();
List<org.hisp.dhis.dxf2.events.enrollment.Enrollment> enrollmentList;
if (trackerEnrollmentCriteria.getEnrollment() == null) {
ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(trackerEnrollmentCriteria);
Enrollments enrollments = enrollmentService.getEnrollments(params);
if (trackerEnrollmentCriteria.isPagingRequest()) {
enrollmentPagingWrapper = enrollmentPagingWrapper.withPager(PagingWrapper.Pager.fromLegacy(trackerEnrollmentCriteria, enrollments.getPager()));
}
enrollmentList = enrollments.getEnrollments();
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(trackerEnrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
enrollmentList = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentService::getEnrollment).collect(Collectors.toList()) : Collections.emptyList();
}
return enrollmentPagingWrapper.withInstances(ENROLLMENT_MAPPER.fromCollection(enrollmentList));
}
Aggregations