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));
}
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));
}
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));
}
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]));
}
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()));
}
Aggregations