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());
}
}
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());
}
}
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());
}
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;
}
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());
}
}
Aggregations