Search in sources :

Example 1 with EventDataValueAggregator

use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.

the class FilteringOutUndeclaredDataElementsProcessorTest method testNotLinkedDataElementsAreRemovedFromEvent.

@Test
void testNotLinkedDataElementsAreRemovedFromEvent() {
    Event event = new Event();
    event.setProgramStage(PROGRAMSTAGE);
    HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
    event.setDataValues(dataValues);
    WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
    preProcessor.process(event, ctx);
    Set<String> allowedDataValues = ctx.getProgramStage(ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme(), PROGRAMSTAGE).getDataElements().stream().map(BaseIdentifiableObject::getUid).collect(Collectors.toSet());
    Set<String> filteredEventDataValues = ctx.getEventDataValueMap().values().stream().flatMap(Collection::stream).map(EventDataValue::getDataElement).collect(Collectors.toSet());
    assertTrue(allowedDataValues.containsAll(filteredEventDataValues));
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) EventDataValueAggregator(org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator) Event(org.hisp.dhis.dxf2.events.event.Event) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test)

Example 2 with EventDataValueAggregator

use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.

the class FilteredDataValueCheckTest method testNotLinkedDataElementsAreReported.

@Test
void testNotLinkedDataElementsAreReported() {
    Event event = new Event();
    event.setProgramStage(PROGRAMSTAGE);
    HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
    event.setDataValues(dataValues);
    WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
    ImportSummary importSummary = dataValueCheck.check(new ImmutableEvent(event), ctx);
    assertEquals(ImportStatus.WARNING, importSummary.getStatus());
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventDataValueAggregator(org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator) Event(org.hisp.dhis.dxf2.events.event.Event) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test)

Example 3 with EventDataValueAggregator

use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.

the class WorkContextLoader method load.

@Transactional(readOnly = true)
public WorkContext load(ImportOptions importOptions, List<Event> events) {
    sessionFactory.getCurrentSession().flush();
    ImportOptions localImportOptions = importOptions;
    // API allows a null Import Options
    if (localImportOptions == null) {
        localImportOptions = ImportOptions.getDefaultImportOptions();
    }
    initializeUser(localImportOptions);
    // Make sure all events have the 'uid' field populated
    events = uidGen.assignUidToEvents(events);
    final Map<String, ProgramStageInstance> programStageInstanceMap = programStageInstanceSupplier.get(localImportOptions, events);
    final Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = trackedEntityInstanceSupplier.get(localImportOptions, events);
    final Map<String, OrganisationUnit> orgUniMap = organisationUnitSupplier.get(localImportOptions, events);
    return WorkContext.builder().importOptions(localImportOptions).programsMap(programSupplier.get(localImportOptions, events)).programStageInstanceMap(programStageInstanceMap).organisationUnitMap(orgUniMap).trackedEntityInstanceMap(teiMap).programInstanceMap(programInstanceSupplier.get(localImportOptions, teiMap, events)).categoryOptionComboMap(categoryOptionComboSupplier.get(localImportOptions, events)).dataElementMap(dataElementSupplier.get(localImportOptions, events)).notesMap(noteSupplier.get(localImportOptions, events)).assignedUserMap(assignedUserSupplier.get(localImportOptions, events)).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(events, programStageInstanceMap, localImportOptions)).programWithOrgUnitsMap(programOrgUnitSupplier.get(localImportOptions, events, orgUniMap)).serviceDelegator(serviceDelegatorSupplier.get()).build();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Pair(org.apache.commons.lang3.tuple.Pair) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DataValue (org.hisp.dhis.dxf2.events.event.DataValue)2 Event (org.hisp.dhis.dxf2.events.event.Event)2 EventDataValueAggregator (org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator)2 WorkContext (org.hisp.dhis.dxf2.events.importer.context.WorkContext)2 Test (org.junit.jupiter.api.Test)2 Collection (java.util.Collection)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)1 Transactional (org.springframework.transaction.annotation.Transactional)1