Search in sources :

Example 6 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class AbstractEventService method buildAnonymousEventsSearchParams.

private EventSearchParams buildAnonymousEventsSearchParams(Date lastSuccessTime) {
    EventSearchParams params = new EventSearchParams();
    params.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    params.setLastUpdatedStartDate(lastSuccessTime);
    return params;
}
Also used : EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams)

Example 7 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class EventController method getCsvEvents.

@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/csv", "application/csv+gzip", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
public void getCsvEvents(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false, defaultValue = "false") boolean skipHeader, IdSchemes idSchemes, HttpServletResponse response, HttpServletRequest request) throws IOException, WebMessageException {
    boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
    if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, null, null, null, includeDeleted);
    Events events = eventService.getEvents(params);
    OutputStream outputStream = response.getOutputStream();
    response.setContentType("application/csv");
    if (ContextUtils.isAcceptCsvGzip(request)) {
        response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
        outputStream = new GZIPOutputStream(outputStream);
        response.setContentType("application/csv+gzip");
    }
    if (!StringUtils.isEmpty(attachment)) {
        response.addHeader("Content-Disposition", "attachment; filename=" + attachment);
    }
    csvEventService.writeEvents(outputStream, events, !skipHeader);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Events(org.hisp.dhis.dxf2.events.event.Events) GZIPOutputStream(java.util.zip.GZIPOutputStream) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class RegistrationSingleEventServiceTest method testSavingMultipleEventsShouldOnlyUpdate.

@Test
@Ignore
public void testSavingMultipleEventsShouldOnlyUpdate() {
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    EventSearchParams params = new EventSearchParams();
    params.setProgram(programA);
    params.setOrgUnit(organisationUnitA);
    params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
    assertEquals(1, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(1, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(1, eventService.getEvents(params).getEvents().size());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Ignore(org.junit.Ignore) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class EventController method getEventsGrid.

// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "/query", method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Grid getEventsGrid(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
    if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, filter, dataElement, includeDeleted);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE);
    return eventService.getEventsGrid(params);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with EventSearchParams

use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.

the class EventController method getEventRows.

@RequestMapping(value = "/eventRows", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public EventRows getEventRows(@RequestParam(required = false) String program, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam Map<String, String> parameters, Model model) throws WebMessageException {
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, true);
    EventSearchParams params = eventService.getFromUrl(program, null, programStatus, null, orgUnit, ouMode, null, startDate, endDate, null, null, null, null, eventStatus, attributeOptionCombo, null, null, null, totalPages, skipPaging, getOrderParams(order), null, true, null, null, null, includeDeleted);
    return eventRowService.getEventRows(params);
}
Also used : EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)4 Event (org.hisp.dhis.dxf2.events.event.Event)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)3 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 Test (org.junit.Test)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 IntegrationTest (org.hisp.dhis.IntegrationTest)2 Events (org.hisp.dhis.dxf2.events.event.Events)2 EventRow (org.hisp.dhis.dxf2.events.report.EventRow)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Category (org.junit.experimental.categories.Category)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1