Search in sources :

Example 81 with Enrollment

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;
}
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)

Example 82 with Enrollment

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));
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 83 with Enrollment

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());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 84 with Enrollment

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());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 85 with Enrollment

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());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)46 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)44 Test (org.junit.jupiter.api.Test)35 Event (org.hisp.dhis.dxf2.events.event.Event)31 Date (java.util.Date)28 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)23 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 ArrayList (java.util.ArrayList)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)18 ProgramInstance (org.hisp.dhis.program.ProgramInstance)18 List (java.util.List)17 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)17 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)14 Program (org.hisp.dhis.program.Program)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Map (java.util.Map)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Lists (com.google.common.collect.Lists)11