Search in sources :

Example 31 with ImmutableEvent

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

the class TrackedEntityInstanceCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    Program program = ctx.getProgramsMap().get(event.getProgram());
    final Optional<TrackedEntityInstance> trackedEntityInstance = ctx.getTrackedEntityInstance(event.getUid());
    if (program.isRegistration() && !trackedEntityInstance.isPresent()) {
        return new ImportSummary(ImportStatus.ERROR, "Event.trackedEntityInstance does not point to a valid tracked entity instance: " + event.getTrackedEntityInstance()).setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 32 with ImmutableEvent

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

the class EventBaseCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    ImportSummary importSummary = new ImportSummary();
    List<String> errors = validate(event, ctx);
    if (!errors.isEmpty()) {
        importSummary.setStatus(ERROR);
        importSummary.setReference(event.getEvent());
        errors.forEach(error -> importSummary.addConflict("Event", error));
        importSummary.incrementIgnored();
    }
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 33 with ImmutableEvent

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

the class FilteredDataValueCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    final Set<String> eventDataValuesUids = Optional.ofNullable(event).map(ImmutableEvent::getDataValues).orElse(Collections.emptySet()).stream().map(DataValue::getDataElement).collect(Collectors.toSet());
    final ImportSummary importSummary = new ImportSummary();
    if (!eventDataValuesUids.isEmpty() && Objects.nonNull(event) && StringUtils.isNotBlank(event.getProgramStage())) {
        Set<String> filteredEventDataValuesUids = getFilteredDataValues(event.getDataValues(), getDataElementUidsFromProgramStage(event.getProgramStage(), ctx)).stream().map(DataValue::getDataElement).collect(Collectors.toSet());
        Set<String> ignoredDataValues = eventDataValuesUids.stream().filter(uid -> !filteredEventDataValuesUids.contains(uid)).collect(Collectors.toSet());
        if (!ignoredDataValues.isEmpty()) {
            importSummary.setStatus(ImportStatus.WARNING);
            importSummary.setReference(event.getUid());
            importSummary.setDescription("Data Values " + ignoredDataValues.stream().collect(Collectors.joining(",", "[", "]")) + " ignored because " + "not defined in program stage " + event.getProgramStage());
            importSummary.incrementImported();
        }
    }
    return importSummary;
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) Set(java.util.Set) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Objects(java.util.Objects) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Component(org.springframework.stereotype.Component) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) FilteringOutUndeclaredDataElementsProcessor.getDataElementUidsFromProgramStage(org.hisp.dhis.dxf2.events.importer.shared.preprocess.FilteringOutUndeclaredDataElementsProcessor.getDataElementUidsFromProgramStage) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Checker(org.hisp.dhis.dxf2.events.importer.Checker) Optional(java.util.Optional) Collections(java.util.Collections) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) FilteringOutUndeclaredDataElementsProcessor.getFilteredDataValues(org.hisp.dhis.dxf2.events.importer.shared.preprocess.FilteringOutUndeclaredDataElementsProcessor.getFilteredDataValues) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)

Example 34 with ImmutableEvent

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

the class ProgramOrgUnitCheckTest method failWhenProgramHasNoOrgUnitMatchingEventOrgUnit.

@Test
void failWhenProgramHasNoOrgUnitMatchingEventOrgUnit() {
    // assign a UID to the event's org unit
    event.setOrgUnit(CodeGenerator.generateUid());
    // Prepare data
    Program program = createProgram('P');
    program.setId(1);
    OrganisationUnit ou = new OrganisationUnit();
    ou.setId(1);
    ou.setUid(event.getOrgUnit());
    when(workContext.getOrganisationUnitMap()).thenReturn(ImmutableMap.of(event.getUid(), ou));
    when(workContext.getProgramWithOrgUnitsMap()).thenReturn(new HashMap<>());
    ProgramInstance pi = new ProgramInstance();
    pi.setProgram(program);
    Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
    programInstanceMap.put(event.getUid(), pi);
    when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
    // method under test
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Program is not assigned to this Organisation Unit: " + event.getOrgUnit());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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) 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 35 with ImmutableEvent

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

the class DataValueCheckTest method verifyValidationFailOnMissingDataElement.

@Test
void verifyValidationFailOnMissingDataElement() {
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
    addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"), createEventDataValue("iDontExist", "2"));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    DataValue dv2 = createDataValue("iDontExist", "2");
    event.setDataValues(Sets.newHashSet(dv1, dv2));
    final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
    assertHasError(summary, event, null);
    assertHasConflict(summary, "iDontExist is not a valid data element", "dataElement");
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

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