Search in sources :

Example 1 with SlimPager

use of org.hisp.dhis.common.SlimPager 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;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) ContextService(org.hisp.dhis.webapi.service.ContextService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) EnrollmentCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EnrollmentCriteria) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENROLLMENT_IMPORT(org.hisp.dhis.scheduling.JobType.ENROLLMENT_IMPORT) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) EnrollmentCriteriaMapper(org.hisp.dhis.webapi.controller.event.mapper.EnrollmentCriteriaMapper) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) IOException(java.io.IOException) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) HttpStatus(org.springframework.http.HttpStatus) CurrentUserService(org.hisp.dhis.user.CurrentUserService) InputStream(java.io.InputStream) TextUtils(org.hisp.dhis.commons.util.TextUtils) RootNode(org.hisp.dhis.node.types.RootNode) SlimPager(org.hisp.dhis.common.SlimPager) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AsyncTaskExecutor (org.hisp.dhis.common.AsyncTaskExecutor)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 PagerUtils (org.hisp.dhis.common.PagerUtils)1 SlimPager (org.hisp.dhis.common.SlimPager)1 StreamUtils (org.hisp.dhis.commons.util.StreamUtils)1 TextUtils (org.hisp.dhis.commons.util.TextUtils)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)1 EnrollmentService (org.hisp.dhis.dxf2.events.enrollment.EnrollmentService)1 Enrollments (org.hisp.dhis.dxf2.events.enrollment.Enrollments)1 ImportEnrollmentsTask (org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask)1 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1