Search in sources :

Example 6 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventImportTest method testVerifyEventUncompleteSetsCompletedDateToNull.

@Test
void testVerifyEventUncompleteSetsCompletedDateToNull() throws IOException {
    // CREATE A NEW EVENT
    InputStream is = createEventJsonInputStream(programB.getUid(), programStageB.getUid(), organisationUnitB.getUid(), null, dataElementB, "10");
    ImportSummaries importSummaries = eventService.addEventsJson(is, null);
    String uid = importSummaries.getImportSummaries().get(0).getReference();
    assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
    // FETCH NEWLY CREATED EVENT
    ProgramStageInstance psi = programStageInstanceService.getProgramStageInstance(uid);
    // UPDATE EVENT (no actual changes, except for empty data value and
    // status
    // change)
    Event event = new Event();
    event.setEvent(uid);
    event.setProgram(programB.getUid());
    event.setStatus(EventStatus.ACTIVE);
    assertEquals(ImportStatus.SUCCESS, eventService.updateEvent(event, false, ImportOptions.getDefaultImportOptions(), false).getStatus());
    cleanSession();
    ProgramStageInstance psi2 = programStageInstanceService.getProgramStageInstance(uid);
    assertThat(psi.getLastUpdated(), DateMatchers.before(psi2.getLastUpdated()));
    assertThat(psi.getCreated(), is(psi2.getCreated()));
    assertThat(psi.getProgramInstance().getUid(), is(psi2.getProgramInstance().getUid()));
    assertThat(psi.getProgramStage().getUid(), is(psi2.getProgramStage().getUid()));
    assertThat(psi.getOrganisationUnit().getUid(), is(psi2.getOrganisationUnit().getUid()));
    assertThat(psi.getAttributeOptionCombo().getUid(), is(psi2.getAttributeOptionCombo().getUid()));
    assertThat(psi2.getStatus(), is(EventStatus.ACTIVE));
    assertThat(psi.getExecutionDate(), is(psi2.getExecutionDate()));
    assertThat(psi2.getCompletedDate(), is(nullValue()));
    assertThat(psi.getCompletedBy(), is(psi2.getCompletedBy()));
    assertThat(psi.isDeleted(), is(psi2.isDeleted()));
    assertThat(psi.getEventDataValues().size(), is(1));
    assertThat(psi2.getEventDataValues().size(), is(0));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventController method queryEventsXml.

@GetMapping(value = "/query", produces = ContextUtils.CONTENT_TYPE_XML)
public void queryEventsXml(@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) AssignedUserSelectionMode assignedUserMode, @RequestParam(required = false) String assignedUser, @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) Boolean paging, @RequestParam(required = false) List<OrderCriteria> 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(required = false, defaultValue = "false") boolean includeAllDataElements, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, false);
    if (attributeOptionCombo == null) {
        throw new WebMessageException(conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
    Set<String> assignedUserIds = TextUtils.splitToArray(assignedUser, TextUtils.SEMICOLON);
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    skipPaging = PagerUtils.isSkipPaging(skipPaging, paging);
    EventSearchParams params = requestToSearchParamsMapper.map(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, null, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, false, assignedUserMode, assignedUserIds, filter, dataElement, includeAllDataElements, includeDeleted);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE);
    Grid grid = eventService.getEventsGrid(params);
    GridUtils.toXml(grid, response.getOutputStream());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Grid(org.hisp.dhis.common.Grid) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventController method getEvents.

// -------------------------------------------------------------------------
// Object Read
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEvents(EventCriteria eventCriteria, @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request) {
    WebOptions options = new WebOptions(parameters);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("event,uid,program,programType,status,assignedUser,orgUnit,orgUnitName,eventDate,orgUnit,orgUnitName,created,lastUpdated,followup");
    }
    EventSearchParams params = requestToSearchParamsMapper.map(eventCriteria);
    setParamBasedOnFieldParameters(params, fields);
    Events events = eventService.getEvents(params);
    if (hasHref(fields, eventCriteria.getSkipEventId())) {
        events.getEvents().forEach(e -> e.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + e.getEvent()));
    }
    if (!eventCriteria.isSkipMeta() && params.getProgram() != null) {
        events.setMetaData(getMetaData(params.getProgram()));
    }
    model.addAttribute("model", events);
    model.addAttribute("viewClass", options.getViewClass("detailed"));
    RootNode rootNode = NodeUtils.createMetadata();
    addPager(params, events, rootNode);
    if (!StringUtils.isEmpty(eventCriteria.getAttachment())) {
        response.addHeader(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + eventCriteria.getAttachment());
        response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(Event.class, new FieldFilterParams(events.getEvents(), fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Events(org.hisp.dhis.dxf2.events.event.Events) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Event(org.hisp.dhis.dxf2.events.event.Event) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventController method queryEventsJson.

// -------------------------------------------------------------------------
// Read
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Query Read
// -------------------------------------------------------------------------
@GetMapping(value = "/query", produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@ResponseBody
public Grid queryEventsJson(@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) AssignedUserSelectionMode assignedUserMode, @RequestParam(required = false) String assignedUser, @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) Boolean paging, @RequestParam(required = false) List<OrderCriteria> 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(required = false, defaultValue = "false") boolean includeAllDataElements, @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.add("*");
        fields.add("dataValues");
    }
    CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, false);
    if (attributeOptionCombo == null) {
        throw new WebMessageException(conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
    Set<String> assignedUserIds = TextUtils.splitToArray(assignedUser, TextUtils.SEMICOLON);
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    skipPaging = PagerUtils.isSkipPaging(skipPaging, paging);
    EventSearchParams params = requestToSearchParamsMapper.map(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, null, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, false, assignedUserMode, assignedUserIds, filter, dataElement, includeAllDataElements, 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) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithEventFilters.

@Test
void testFetchTrackedEntityInstancesWithEventFilters() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setProgram(programA);
    queryParams.setEventStatus(EventStatus.COMPLETED);
    queryParams.setEventStartDate(Date.from(Instant.now().minus(10, ChronoUnit.DAYS)));
    queryParams.setEventEndDate(Date.from(Instant.now().plus(10, ChronoUnit.DAYS)));
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    // Update status to active
    queryParams.setEventStatus(EventStatus.ACTIVE);
    final List<TrackedEntityInstance> limitedTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTrackedEntityInstances, hasSize(0));
    // Update status to overdue
    queryParams.setEventStatus(EventStatus.OVERDUE);
    final List<TrackedEntityInstance> limitedTrackedEntityInstances2 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTrackedEntityInstances2, hasSize(0));
    // Update status to schedule
    queryParams.setEventStatus(EventStatus.SCHEDULE);
    final List<TrackedEntityInstance> limitedTrackedEntityInstances3 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTrackedEntityInstances3, hasSize(0));
    // Update status to schedule
    queryParams.setEventStatus(EventStatus.SKIPPED);
    final List<TrackedEntityInstance> limitedTrackedEntityInstances4 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTrackedEntityInstances4, hasSize(0));
    // Update status to visited
    queryParams.setEventStatus(EventStatus.VISITED);
    final List<TrackedEntityInstance> limitedTrackedEntityInstances5 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTrackedEntityInstances5, hasSize(0));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Aggregations

Test (org.junit.jupiter.api.Test)28 User (org.hisp.dhis.user.User)20 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)16 Event (org.hisp.dhis.dxf2.events.event.Event)14 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Period (org.hisp.dhis.period.Period)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5