use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getCollapsedDataItemValue.
/**
* Returns an item value for the given query, query item and value. Assumes that
* data dimensions are collapsed for the given query. Returns the short name
* of the given query item followed by the item value. If the given query item
* has a legend set, the item value is treated as an id and substituted with
* the matching legend name. If the given query item has an option set, the
* item value is treated as a code and substituted with the matching option
* name.
*
* @param params the {@link EventQueryParams}..
* @param item the {@link QueryItem}.
* @param itemValue the item value.
*/
private String getCollapsedDataItemValue(EventQueryParams params, QueryItem item, String itemValue) {
String value = item.getItem().getDisplayShortName() + ITEM_NAME_SEP;
Legend legend = null;
Option option = null;
if (item.hasLegendSet() && (legend = item.getLegendSet().getLegendByUid(itemValue)) != null) {
return value + legend.getDisplayName();
} else if (item.hasOptionSet() && (option = item.getOptionSet().getOptionByCode(itemValue)) != null) {
return value + option.getDisplayName();
} else {
itemValue = StringUtils.defaultString(itemValue, NA);
return value + itemValue;
}
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class TrackedEntityAttributeServiceTest method successWhenTeaOptionValueIsValid.
@Test
void successWhenTeaOptionValueIsValid() {
tea.setUid("uid");
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(null, option, option1));
tea.setOptionSet(optionSet);
assertNull(trackedEntityAttributeService.validateValueType(tea, "CODE"));
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DefaultCsvImportService method setOptionSetsFromCsv.
/**
* Option set format:
* <p>
* <ul>
* <li>option set name</li>
* <li>option set uid</li>
* <li>option set code</li>
* <li>option name</li>
* <li>option uid</li>
* <li>option code</li>
* </ul>
*/
private void setOptionSetsFromCsv(CsvReader reader, Metadata metadata) throws IOException {
ListMap<String, Option> nameOptionMap = new ListMap<>();
Map<String, OptionSet> nameOptionSetMap = new HashMap<>();
List<Option> options = new ArrayList<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
OptionSet optionSet = new OptionSet();
setIdentifiableObject(optionSet, values);
optionSet.setAutoFields();
optionSet.setValueType(ValueType.TEXT);
Option option = new Option();
option.setName(getSafe(values, 3, 230));
option.setUid(getSafe(values, 4, CodeGenerator.generateUid(), 11));
option.setCode(getSafe(values, 5, 50));
option.setAutoFields();
if (optionSet.getName() == null || option.getCode() == null) {
continue;
}
nameOptionSetMap.put(optionSet.getName(), optionSet);
nameOptionMap.putValue(optionSet.getName(), option);
options.add(option);
}
}
for (Entry<String, OptionSet> optionSetEntry : nameOptionSetMap.entrySet()) {
optionSetEntry.getValue().setOptions(new ArrayList<>(nameOptionMap.get(optionSetEntry.getKey())));
}
metadata.setOptions(options);
metadata.setOptionSets(new ArrayList<>(nameOptionSetMap.values()));
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DefaultCsvImportService method setOptionGroupSetFromCsv.
/**
* Option group set format:
* <p>
* <ul>
* <li>option group set name</li>
* <li>option group set uid</li>
* <li>option group set code</li>
* <li>option group set description</li>
* <li>data dimension</li>
* <li>option set uid</li>
* <li>option set code</li>
* </ul>
*/
private List<OptionGroupSet> setOptionGroupSetFromCsv(CsvReader reader) throws IOException {
List<OptionGroupSet> optionGroupSets = new ArrayList<>();
Map<String, OptionSet> mapOptionSet = new HashMap<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
OptionGroupSet optionGroupSet = new OptionGroupSet();
optionGroupSet.setAutoFields();
setIdentifiableObject(optionGroupSet, values);
optionGroupSet.setDescription(getSafe(values, 4));
optionGroupSet.setDataDimension(// boolean
Boolean.parseBoolean(getSafe(values, 3, Boolean.FALSE.toString(), 40)));
OptionSet optionSet = new OptionSet();
optionSet.setUid(getSafe(values, 5, 11));
optionSet.setCode(getSafe(values, 6, 50));
if (optionSet.getUid() == null && optionSet.getCode() == null) {
continue;
}
OptionSet persistedOptionSet = optionSet.getUid() != null ? mapOptionSet.computeIfAbsent(optionSet.getUid(), key -> optionService.getOptionSet(optionSet.getUid())) : mapOptionSet.computeIfAbsent(optionSet.getCode(), key -> optionService.getOptionSetByCode(optionSet.getCode()));
if (persistedOptionSet == null) {
continue;
}
optionGroupSet.setOptionSet(optionSet);
optionGroupSets.add(optionGroupSet);
}
}
return optionGroupSets;
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class VersionedObjectObjectBundleHook method postCreate.
@Override
public void postCreate(IdentifiableObject persistedObject, ObjectBundle bundle) {
VersionedObject versionedObject = null;
if (persistedObject instanceof Section) {
versionedObject = ((Section) persistedObject).getDataSet();
} else if (persistedObject instanceof Option) {
versionedObject = ((Option) persistedObject).getOptionSet();
}
if (versionedObject != null) {
versionedObject.increaseVersion();
sessionFactory.getCurrentSession().save(versionedObject);
}
}
Aggregations