Search in sources :

Example 56 with TrackedEntityInstance

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");
}
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 57 with TrackedEntityInstance

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");
}
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 58 with TrackedEntityInstance

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 59 with TrackedEntityInstance

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");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) Pair(org.apache.commons.lang3.tuple.Pair) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 60 with TrackedEntityInstance

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());
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

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