Search in sources :

Example 26 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance 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 27 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class RegistrationSingleEventServiceTest method testDeleteEventShouldReturnReference.

@Test
@Disabled("luciano -> re-enable after delete has been implemented")
void testDeleteEventShouldReturnReference() {
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null, false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    importSummary = eventService.deleteEvent(tei.getEnrollments().get(0).getEvents().get(0).getEvent());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertNotNull(importSummary.getReference());
    assertEquals(tei.getEnrollments().get(0).getEvents().get(0).getEvent(), importSummary.getReference());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 28 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithEvents.

@Test
void testFetchTrackedEntityInstancesWithEvents() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), hasSize(5));
}
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)

Example 29 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEvents.

@Test
void testFetchTrackedEntityInstancesWithoutEvents() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(false);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), 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)

Example 30 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEnrollments.

@Test
void testFetchTrackedEntityInstancesWithoutEnrollments() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(false);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), 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

TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)61 Test (org.junit.jupiter.api.Test)57 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)50 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)37 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)34 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)29 Date (java.util.Date)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)26 ArrayList (java.util.ArrayList)25 List (java.util.List)25 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)25 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)24 Event (org.hisp.dhis.dxf2.events.event.Event)23 Program (org.hisp.dhis.program.Program)22 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Collectors (java.util.stream.Collectors)19 User (org.hisp.dhis.user.User)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)16 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)16