use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DefaultEventAnalyticsService method addEventReportDimensionalItems.
/**
* Adds dimensional items to the given list of objects. Send in a list of
* {@link EventAnalyticsDimensionalItem} and add properties from
* {@link ValueTypedDimensionalItemObject} parameter.
*
* @param eventDimensionalItemObject the
* {@link ValueTypedDimensionalItemObject} object to get properties
* from.
* @param objects the list of {@link EventAnalyticsDimensionalItem} objects.
* @param grid the {@link Grid} from the event analytics request.
* @param dimension the dimension identifier.
*/
@SuppressWarnings("unchecked")
private void addEventReportDimensionalItems(ValueTypedDimensionalItemObject eventDimensionalItemObject, List<EventAnalyticsDimensionalItem> objects, Grid grid, String dimension) {
Preconditions.checkNotNull(eventDimensionalItemObject, String.format("Data dimension '%s' is invalid", dimension));
String parentUid = eventDimensionalItemObject.getUid();
if (eventDimensionalItemObject.getValueType() == BOOLEAN) {
objects.add(new EventAnalyticsDimensionalItem(OPT_TRUE, parentUid));
objects.add(new EventAnalyticsDimensionalItem(OPT_FALSE, parentUid));
}
if (eventDimensionalItemObject.hasOptionSet()) {
for (Option option : eventDimensionalItemObject.getOptionSet().getOptions()) {
objects.add(new EventAnalyticsDimensionalItem(option, parentUid));
}
} else if (eventDimensionalItemObject.hasLegendSet()) {
List<String> legendOptions = (List<String>) ((Map<String, Object>) grid.getMetaData().get(DIMENSIONS.getKey())).get(dimension);
if (legendOptions.isEmpty()) {
List<Legend> legends = eventDimensionalItemObject.getLegendSet().getSortedLegends();
for (Legend legend : legends) {
for (int i = legend.getStartValue().intValue(); i < legend.getEndValue().intValue(); i++) {
objects.add(new EventAnalyticsDimensionalItem(new Option(String.valueOf(i), String.valueOf(i)), parentUid));
}
}
} else {
for (String legend : legendOptions) {
MetadataItem metadataItem = (MetadataItem) ((Map<String, Object>) grid.getMetaData().get(ITEMS.getKey())).get(legend);
objects.add(new EventAnalyticsDimensionalItem(new Option(metadataItem.getName(), legend), parentUid));
}
}
}
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method successValidationDataElementOptionValueIsValid.
@Test
void successValidationDataElementOptionValueIsValid() {
setUpIdentifiers();
DataValue validDataValue = dataValue("code");
DataValue nullDataValue = dataValue(null);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
DataElement dataElement = dataElement();
dataElement.setOptionSet(optionSet);
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
ProgramStage programStage = programStage(dataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue, nullDataValue)).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationDataElementOptionValueIsInValid.
@Test
void failValidationDataElementOptionValueIsInValid() {
setUpIdentifiers();
DataValue validDataValue = dataValue("value");
validDataValue.setDataElement(dataElementUid);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
DataElement dataElement = dataElement();
dataElement.setOptionSet(optionSet);
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
ProgramStage programStage = programStage(dataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertTrue(reporter.hasErrors());
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(1, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1125).count());
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class TrackedEntityAttributeValidationHookTest method getTrackedEntityAttributeWithOptionSet.
private TrackedEntityAttribute getTrackedEntityAttributeWithOptionSet() {
TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
trackedEntityAttribute.setUid("uid");
trackedEntityAttribute.setValueType(ValueType.TEXT);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
trackedEntityAttribute.setOptionSet(optionSet);
return trackedEntityAttribute;
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOptionSet.
public static OptionSet createOptionSet(char uniqueCharacter, Option... options) {
OptionSet optionSet = createOptionSet(uniqueCharacter);
for (Option option : options) {
optionSet.getOptions().add(option);
option.setOptionSet(optionSet);
}
return optionSet;
}
Aggregations