Search in sources :

Example 41 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenProgramStageInstanceHasNoExecDateAndProgramHasPeriodType.

@Test
void failWhenProgramStageInstanceHasNoExecDateAndProgramHasPeriodType() {
    // Given
    // Prepare program
    Program program = createProgram('P');
    program.setCompleteEventsExpiryDays(3);
    program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString("202001"));
    program.setExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare program stage instance
    Map<String, ProgramStageInstance> psiMap = new HashMap<>();
    ProgramStageInstance psi = new ProgramStageInstance();
    psi.setCompletedDate(getTodayPlusDays(5));
    psi.setUid(event.getUid());
    psiMap.put(event.getUid(), psi);
    when(workContext.getProgramStageInstanceMap()).thenReturn(psiMap);
    // Prepare event
    event.setProgram(program.getUid());
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "Event needs to have event date");
}
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) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) 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 42 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenEventHasNoCompletedDateAndProgramHasExpiryDays.

@Test
void failWhenEventHasNoCompletedDateAndProgramHasExpiryDays() {
    // Given
    // Prepare program
    Program program = createProgram('P');
    program.setCompleteEventsExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare event
    event.setProgram(program.getUid());
    event.setStatus(EventStatus.COMPLETED);
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "Event needs to have completed date");
}
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) 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 43 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramInstanceCheckTest method failOnMultipleProgramInstanceByActiveProgramAndTei.

@Test
void failOnMultipleProgramInstanceByActiveProgramAndTei() {
    // 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));
    ProgramInstance programInstance1 = new ProgramInstance();
    ProgramInstance programInstance2 = new ProgramInstance();
    when(this.programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
    event.setProgram(program.getUid());
    // 
    // Method under test
    // 
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Tracked entity instance: " + tei.getUid() + " has multiple active enrollments in program: " + program.getUid());
}
Also used : 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) 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 44 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramStageInstanceBasicCheckTest method failOnDeletedProgramStageInstance.

@Test
void failOnDeletedProgramStageInstance() {
    Map<String, ProgramStageInstance> programStageInstanceMap = new HashMap<>();
    ProgramStageInstance psi = new ProgramStageInstance();
    psi.setDeleted(true);
    programStageInstanceMap.put(event.getEvent(), psi);
    when(workContext.getProgramStageInstanceMap()).thenReturn(programStageInstanceMap);
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.");
}
Also used : HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) 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 45 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramStageInstanceBasicCheckTest method failOnMissingProgramStageInstance.

@Test
void failOnMissingProgramStageInstance() {
    when(workContext.getProgramStageInstanceMap()).thenReturn(new HashMap<>());
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Event ID " + event.getEvent() + " doesn't point to valid event");
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) 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

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)49 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)38 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)34 Program (org.hisp.dhis.program.Program)18 HashMap (java.util.HashMap)17 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)13 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)11 ProgramInstance (org.hisp.dhis.program.ProgramInstance)10 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 ProgramStage (org.hisp.dhis.program.ProgramStage)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)5 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)5 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)5 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 EventTestUtils.createDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue)5 EventTestUtils.createEventDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue)5