use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeAllAttributesInProtectedProgramNoAccess.
@Test
void testTrackedEntityInstanceIncludeAllAttributesInProtectedProgramNoAccess() {
populatePrerequisites(true);
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);
assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "C");
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeSpecificOpenProgram.
@Test
void testTrackedEntityInstanceIncludeSpecificOpenProgram() {
populatePrerequisites(false);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setProgram(programA);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "C");
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnNoProgramInstanceByActiveProgramAndTei.
@Test
void failOnNoProgramInstanceByActiveProgramAndTei() {
// Data preparation
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
event.setProgram(program.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Tracked entity instance: " + tei.getUid() + " is not enrolled in program: " + program.getUid());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ProgramInstanceRepeatableStageCheckTest method failOnNonRepeatableStageAndExistingEvents.
@Test
void failOnNonRepeatableStageAndExistingEvents() {
// Data preparation
Program program = createProgram('P');
TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
event.setProgramStage(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setTrackedEntityInstance(tei.getUid());
ProgramStage programStage = createProgramStage('A', program);
programStage.setRepeatable(false);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
ProgramInstance programInstance = new ProgramInstance();
programInstanceMap.put(event.getUid(), programInstance);
Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), teiPair);
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
when(workContext.getProgramsMap()).thenReturn(programMap);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(true);
// Method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Program stage is not repeatable and an event already exists");
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnMultipleProgramInstance.
@Test
void failOnMultipleProgramInstance() {
// Data preparation
Program programNoReg = createProgram('P');
programNoReg.setProgramType(ProgramType.WITHOUT_REGISTRATION);
Map<String, Program> programMap = new HashMap<>();
programMap.put(programNoReg.getUid(), programNoReg);
when(workContext.getProgramsMap()).thenReturn(programMap);
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), Pair.of(tei, true));
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
ProgramInstance programInstance1 = new ProgramInstance();
ProgramInstance programInstance2 = new ProgramInstance();
when(this.programInstanceStore.get(programNoReg, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
event.setProgram(programNoReg.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Multiple active program instances exists for program: " + programNoReg.getUid());
}
Aggregations