use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultExpressionService method getDimensionalItemObjectsInExpression.
@Override
public Set<DimensionalItemObject> getDimensionalItemObjectsInExpression(String expression) {
Set<DimensionalItemObject> dimensionItems = Sets.newHashSet();
if (expression == null || expression.isEmpty()) {
return dimensionItems;
}
Matcher matcher = VARIABLE_PATTERN.matcher(expression);
while (matcher.find()) {
String dimensionItem = matcher.group(GROUP_ID);
DimensionalItemObject dimensionItemObject = dimensionService.getDataDimensionalItemObject(dimensionItem);
if (dimensionItemObject != null) {
dimensionItems.add(dimensionItemObject);
}
}
return dimensionItems;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DimensionController method getItems.
@SuppressWarnings("unchecked")
@RequestMapping(value = "/{uid}/items", method = RequestMethod.GET)
@ResponseBody
public RootNode getItems(@PathVariable String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, HttpServletResponse response) throws QueryParserException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
if (fields.isEmpty()) {
fields.addAll(Preset.defaultPreset().getFields());
}
List<DimensionalItemObject> items = dimensionService.getCanReadDimensionItems(uid);
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>());
query.setObjects(items);
query.setDefaultOrder();
items = (List<DimensionalItemObject>) queryService.query(query);
RootNode rootNode = NodeUtils.createMetadata();
CollectionNode collectionNode = rootNode.addChild(fieldFilterService.filter(getEntityClass(), items, fields));
collectionNode.setName("items");
for (Node node : collectionNode.getChildren()) {
((AbstractNode) node).setName("item");
}
return rootNode;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultValidationService method getValidationContext.
/**
* Returns a new Builder with basic configuration based on the input parameters.
*
* @param orgUnits organisation units to include in analysis.
* @param periods periods to include in analysis.
* @param validationRules rules to include in analysis.
* @return Builder with basic configuration based on input.
*/
private ValidationRunContext.Builder getValidationContext(List<OrganisationUnit> orgUnits, Collection<Period> periods, Collection<ValidationRule> validationRules) {
User currentUser = currentUserService.getCurrentUser();
Map<PeriodType, PeriodTypeExtended> periodTypeExtendedMap = new HashMap<>();
addPeriodsToContext(periodTypeExtendedMap, periods);
Map<String, DimensionalItemObject> dimensionItemMap = addRulesToContext(periodTypeExtendedMap, validationRules);
removeAnyUnneededPeriodTypes(periodTypeExtendedMap);
addOrgUnitsToContext(periodTypeExtendedMap, orgUnits);
ValidationRunContext.Builder builder = ValidationRunContext.newBuilder().withPeriodTypeExtendedMap(periodTypeExtendedMap).withOrgUnits(orgUnits).withEventItems(getEventItems(dimensionItemMap)).withConstantMap(constantService.getConstantMap());
if (currentUser != null) {
builder.withCoDimensionConstraints(categoryService.getCoDimensionConstraints(currentUser.getUserCredentials())).withCogDimensionConstraints(categoryService.getCogDimensionConstraints(currentUser.getUserCredentials()));
}
return builder;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getAggregatedDataValueMap.
/**
* Returns a mapping between dimension items and values for the given data
* query and list of indicators. The dimensional items part of the indicator
* numerators and denominators are used as dimensional item for the aggregated
* values being retrieved.
*
* @param params the {@link DataQueryParams}.
* @param indicators the list of indicators.
* @return a dimensional items to aggregate values map.
*/
private Map<String, Double> getAggregatedDataValueMap(DataQueryParams params, List<Indicator> indicators) {
List<DimensionalItemObject> items = Lists.newArrayList(expressionService.getDimensionalItemObjectsInIndicators(indicators));
items = DimensionalObjectUtils.replaceOperandTotalsWithDataElements(items);
DimensionalObject dimension = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, items);
DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).replaceDimension(dimension).withIncludeNumDen(false).withSkipHeaders(true).withSkipMeta(true).build();
Grid grid = getAggregatedDataValueGridInternal(dataSourceParams);
return grid.getAsMap(grid.getWidth() - 1, DimensionalObject.DIMENSION_SEP);
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getAggregatedDataValuesTableLayout.
/**
* Returns a Grid with aggregated data in table layout.
*
* @param params the {@link DataQueryParams}.
* @param columns the column dimensions.
* @param rows the row dimensions.
* @return a Grid with aggregated data in table layout.
*/
private Grid getAggregatedDataValuesTableLayout(DataQueryParams params, List<String> columns, List<String> rows) {
params.setOutputIdScheme(null);
Grid grid = getAggregatedDataValues(params);
ListUtils.removeEmptys(columns);
ListUtils.removeEmptys(rows);
queryPlanner.validateTableLayout(params, columns, rows);
ReportTable reportTable = new ReportTable();
List<DimensionalItemObject[]> tableColumns = new ArrayList<>();
List<DimensionalItemObject[]> tableRows = new ArrayList<>();
if (columns != null) {
for (String dimension : columns) {
reportTable.getColumnDimensions().add(dimension);
tableColumns.add(params.getDimensionItemArrayExplodeCoc(dimension));
}
}
if (rows != null) {
for (String dimension : rows) {
reportTable.getRowDimensions().add(dimension);
tableRows.add(params.getDimensionItemArrayExplodeCoc(dimension));
}
}
reportTable.setGridTitle(IdentifiableObjectUtils.join(params.getFilterItems())).setGridColumns(new CombinationGenerator<>(tableColumns.toArray(IRT2D)).getCombinations()).setGridRows(new CombinationGenerator<>(tableRows.toArray(IRT2D)).getCombinations());
addListIfEmpty(reportTable.getGridColumns());
addListIfEmpty(reportTable.getGridRows());
reportTable.setHideEmptyRows(params.isHideEmptyRows());
reportTable.setHideEmptyColumns(params.isHideEmptyColumns());
reportTable.setShowHierarchy(params.isShowHierarchy());
Map<String, Object> valueMap = AnalyticsUtils.getAggregatedDataValueMapping(grid);
return reportTable.getGrid(new ListGrid(grid.getMetaData(), grid.getInternalMetaData()), valueMap, params.getDisplayProperty(), false);
}
Aggregations