Search in sources :

Example 1 with TrackerIdentifier

use of org.hisp.dhis.tracker.TrackerIdentifier in project dhis2-core by dhis2.

the class TrackerPreheatIdentifiersTest method testOrgUnitIdentifiers.

@Test
void testOrgUnitIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("PlKwabX2xRW", "COU1", "Country");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setOrgUnit(pair.getLeft());
        TrackerImportParams params = buildParams(event, builder().orgUnitIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, OrganisationUnit.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 2 with TrackerIdentifier

use of org.hisp.dhis.tracker.TrackerIdentifier in project dhis2-core by dhis2.

the class TrackerPreheatIdentifiersTest method testCategoryOptionIdentifiers.

@Test
void testCategoryOptionIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("XXXrKDKCefk", "COA", "COAname");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setAttributeCategoryOptions(pair.getLeft());
        TrackerImportParams params = buildParams(event, builder().categoryOptionIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, CategoryOption.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 3 with TrackerIdentifier

use of org.hisp.dhis.tracker.TrackerIdentifier in project dhis2-core by dhis2.

the class AbstractSchemaStrategy method add.

@Override
public void add(TrackerImportParams params, List<List<String>> splitList, TrackerPreheat preheat) {
    TrackerIdentifier identifier = params.getIdentifiers().getByClass(getSchemaClass());
    Schema schema = schemaService.getDynamicSchema(getSchemaClass());
    queryForIdentifiableObjects(preheat, schema, identifier, splitList, mapper());
}
Also used : TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Schema(org.hisp.dhis.schema.Schema)

Example 4 with TrackerIdentifier

use of org.hisp.dhis.tracker.TrackerIdentifier in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHook method resolveAttributeOptionCombo.

private CategoryOptionCombo resolveAttributeOptionCombo(ValidationErrorReporter reporter, Event event, Program program) {
    TrackerPreheat preheat = reporter.getValidationContext().getBundle().getPreheat();
    CategoryOptionCombo aoc;
    if (hasNoAttributeOptionComboSet(event) && program.getCategoryCombo().isDefault()) {
        aoc = preheat.getDefault(CategoryOptionCombo.class);
    } else if (hasNoAttributeOptionComboSet(event) && hasAttributeCategoryOptionsSet(event)) {
        aoc = fetchAttributeOptionCombo(reporter, event, program);
        if (aoc != null) {
            // TODO validation hooks should not need to mutate the payload.
            // This
            // should be moved to a pre-processor.
            event.setAttributeOptionCombo(reporter.getValidationContext().getIdentifiers().getCategoryOptionComboIdScheme().getIdentifier(aoc));
            // TODO validation hooks should not need to populate the
            // preheat. Move this to the preheat.
            // We need the AOC in the preheat so we can allow users not to
            // send it. We need to set it on the
            // ProgramStageInstance before persisting.
            TrackerIdentifier identifier = preheat.getIdentifiers().getCategoryOptionComboIdScheme();
            preheat.put(identifier, aoc);
        }
    } else {
        // Note: there is a potential case when there are multiple AOCs in
        // the default CC
        // this should not happen, but it's technically possible. In this
        // case with event.AOC provided,
        // stick to the given AOC in the payload instead of
        // preheat.getDefault( CategoryOptionCombo.class )
        aoc = preheat.getCategoryOptionCombo(event.getAttributeOptionCombo());
    }
    return aoc;
}
Also used : TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 5 with TrackerIdentifier

use of org.hisp.dhis.tracker.TrackerIdentifier in project dhis2-core by dhis2.

the class TrackerPreheatIdentifiersTest method testDataElementIdentifiers.

@Test
void testDataElementIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("DSKTW8qFP0z", "DEAGE", "DE Age");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setProgramStage("NpsdDv6kKSO");
        DataValue dv1 = new DataValue();
        dv1.setDataElement(pair.getLeft());
        dv1.setValue("val1");
        event.setDataValues(Collections.singleton(dv1));
        TrackerImportParams params = buildParams(event, builder().dataElementIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, DataElement.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Aggregations

TrackerIdentifier (org.hisp.dhis.tracker.TrackerIdentifier)7 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Pair (org.apache.commons.lang3.tuple.Pair)5 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)5 TrackerTest (org.hisp.dhis.tracker.TrackerTest)5 Event (org.hisp.dhis.tracker.domain.Event)5 Test (org.junit.jupiter.api.Test)5 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 Schema (org.hisp.dhis.schema.Schema)1 DataValue (org.hisp.dhis.tracker.domain.DataValue)1 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)1