Search in sources :

Example 26 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithSingleQuoteInAttributeSearchInput.

@Test
void testFetchTrackedEntityInstancesWithSingleQuoteInAttributeSearchInput() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.addFilter(new QueryItem(createTrackedEntityAttribute('A'), QueryOperator.EQ, "M'M", ValueType.TEXT, AggregationType.NONE, null));
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(0));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) 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 27 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesAndEnrollments.

@Test
void testFetchTrackedEntityInstancesAndEnrollments() {
    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(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));
}
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 28 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstances.

@Test
void testFetchTrackedEntityInstances() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
    // Check further for explicit uid in param
    queryParams.getTrackedEntityInstanceUids().addAll(trackedEntityInstances.stream().limit(2).map(TrackedEntityInstance::getTrackedEntityInstance).collect(Collectors.toSet()));
    final List<TrackedEntityInstance> limitedTTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTTrackedEntityInstances, hasSize(2));
}
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 TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Tei.

@Test
void testTrackedEntityInstanceRelationshipsTei2Tei() {
    final String[] teiUid = new String[2];
    doInTransaction(() -> {
        org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
        org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstance();
        this.persistRelationship(t1, t2);
        teiUid[0] = t1.getUid();
        teiUid[1] = t2.getUid();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeRelationships(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances.get(0).getRelationships(), hasSize(1));
    final Relationship relationship = trackedEntityInstances.get(0).getRelationships().get(0);
    assertThat(relationship.getFrom().getTrackedEntityInstance().getTrackedEntityInstance(), is(teiUid[0]));
    assertThat(relationship.getTo().getTrackedEntityInstance().getTrackedEntityInstance(), is(teiUid[1]));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) 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 TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceProgramOwners.

@Test
void testTrackedEntityInstanceProgramOwners() {
    doInTransaction(() -> {
        final org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = persistTrackedEntityInstance();
        programOwnerService.createOrUpdateTrackedEntityProgramOwner(trackedEntityInstance, programA, organisationUnitA);
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeProgramOwners(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances.get(0).getProgramOwners(), hasSize(1));
    ProgramOwner programOwner = trackedEntityInstances.get(0).getProgramOwners().get(0);
    assertThat(programOwner.getProgram(), is(programA.getUid()));
    assertThat(programOwner.getOwnerOrgUnit(), is(organisationUnitA.getUid()));
    assertThat(programOwner.getTrackedEntityInstance(), is(trackedEntityInstances.get(0).getTrackedEntityInstance()));
}
Also used : ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) 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

TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)30 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)26 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)24 Test (org.junit.jupiter.api.Test)24 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)8 Date (java.util.Date)7 List (java.util.List)6 Event (org.hisp.dhis.dxf2.events.event.Event)6 ProgramOwner (org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner)6 Collectors (java.util.stream.Collectors)5 Relationship (org.hisp.dhis.dxf2.events.trackedentity.Relationship)5 User (org.hisp.dhis.user.User)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Set (java.util.Set)4 QueryItem (org.hisp.dhis.common.QueryItem)4 TrackedEntityInstanceService (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Sets (com.google.common.collect.Sets)3