use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentController method getEnrollments.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEnrollments(EnrollmentCriteria enrollmentCriteria) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("enrollment,created,lastUpdated,trackedEntityType,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
}
RootNode rootNode = NodeUtils.createMetadata();
List<Enrollment> listEnrollments;
if (enrollmentCriteria.getEnrollment() == null) {
ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(TextUtils.splitToArray(enrollmentCriteria.getOu(), TextUtils.SEMICOLON), enrollmentCriteria.getOuMode(), enrollmentCriteria.getLastUpdated(), enrollmentCriteria.getLastUpdatedDuration(), enrollmentCriteria.getProgram(), enrollmentCriteria.getProgramStatus(), enrollmentCriteria.getProgramStartDate(), enrollmentCriteria.getProgramEndDate(), enrollmentCriteria.getTrackedEntityType(), enrollmentCriteria.getTrackedEntityInstance(), enrollmentCriteria.getFollowUp(), enrollmentCriteria.getPage(), enrollmentCriteria.getPageSize(), enrollmentCriteria.isTotalPages(), PagerUtils.isSkipPaging(enrollmentCriteria.getSkipPaging(), enrollmentCriteria.getPaging()), enrollmentCriteria.isIncludeDeleted(), enrollmentCriteria.getOrder());
Enrollments enrollments = enrollmentService.getEnrollments(params);
if (enrollments.getPager() != null) {
if (params.isTotalPages()) {
rootNode.addChild(NodeUtils.createPager(enrollments.getPager()));
} else {
rootNode.addChild(NodeUtils.createSlimPager((SlimPager) enrollments.getPager()));
}
}
listEnrollments = enrollments.getEnrollments();
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(enrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
listEnrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
}
rootNode.addChild(fieldFilterService.toCollectionNode(Enrollment.class, new FieldFilterParams(listEnrollments, fields)));
return rootNode;
}
use of org.hisp.dhis.dxf2.events.enrollment.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));
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerRelationshipCriteriaTest method getIdentifierParamThrowsIfEnrollmentAndEventAreSet.
@Test
void getIdentifierParamThrowsIfEnrollmentAndEventAreSet() {
TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
criteria.setEnrollment("Hq3Kc6HK4OZ");
criteria.setEvent("Hq3Kc6HK4OZ");
WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierParam);
assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerRelationshipCriteriaTest method getIdentifierNameThrowsIfNoParamsIsSet.
@Test
void getIdentifierNameThrowsIfNoParamsIsSet() {
TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierName);
assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
assertEquals("Missing required parameter 'trackedEntity', 'enrollment' or 'event'.", exception.getWebMessage().getMessage());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerRelationshipCriteriaTest method getIdentifierParamThrowsIfAllParamsAreSet.
@Test
void getIdentifierParamThrowsIfAllParamsAreSet() {
TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
criteria.setTrackedEntity("Hq3Kc6HK4OZ");
criteria.setTei("Hq3Kc6HK4OZ");
criteria.setEnrollment("Hq3Kc6HK4OZ");
criteria.setEvent("Hq3Kc6HK4OZ");
WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierParam);
assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Aggregations