use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class EventGeometryCheckTest method allowEventWithNoGeometry.
@Test
void allowEventWithNoGeometry() {
ProgramStage programStage = createProgramStage();
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(importSummary);
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class ExpirationDaysCheckTest method failWhenProgramStageInstanceCompletedDateFallsAfterCurrentDay.
@Test
void failWhenProgramStageInstanceCompletedDateFallsAfterCurrentDay() {
// 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 program stage instance
Map<String, ProgramStageInstance> psiMap = new HashMap<>();
ProgramStageInstance psi = new ProgramStageInstance();
psi.setStatus(EventStatus.COMPLETED);
psi.setCompletedDate(getTodayMinusDays(5));
psi.setUid(event.getUid());
psiMap.put(event.getUid(), psi);
when(workContext.getProgramStageInstanceMap()).thenReturn(psiMap);
// Prepare event
event.setProgram(program.getUid());
event.setStatus(EventStatus.COMPLETED);
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, "The event's completeness date has expired. Not possible to make changes to this event");
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext 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");
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext 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");
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext 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());
}
Aggregations