use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ReportTable method getGrid.
/**
* Generates a grid for this report table based on the given aggregate value
* map.
*
* @param grid the grid, should be empty and not null.
* @param valueMap the mapping of identifiers to aggregate values.
* @param displayProperty the display property to use for meta data.
* @param reportParamColumns whether to include report parameter columns.
* @return a grid.
*/
public Grid getGrid(Grid grid, Map<String, Object> valueMap, DisplayProperty displayProperty, boolean reportParamColumns) {
valueMap = new HashMap<>(valueMap);
sortKeys(valueMap);
if (name != null) {
grid.setTitle(name);
grid.setSubtitle(gridTitle);
} else {
grid.setTitle(gridTitle);
}
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Map<String, String> metaData = getMetaData();
metaData.putAll(DimensionalObject.PRETTY_NAMES);
for (String row : rowDimensions) {
String name = StringUtils.defaultIfEmpty(metaData.get(row), row);
String col = StringUtils.defaultIfEmpty(COLUMN_NAMES.get(row), row);
grid.addHeader(new GridHeader(name + " ID", col + "id", ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader(name, col + "name", ValueType.TEXT, String.class.getName(), false, true));
grid.addHeader(new GridHeader(name + " code", col + "code", ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader(name + " description", col + "description", ValueType.TEXT, String.class.getName(), true, true));
}
if (reportParamColumns) {
grid.addHeader(new GridHeader("Reporting month", REPORTING_MONTH_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader("Organisation unit parameter", PARAM_ORGANISATIONUNIT_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader("Organisation unit is parent", ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
}
final int startColumnIndex = grid.getHeaders().size();
final int numberOfColumns = getGridColumns().size();
for (List<DimensionalItemObject> column : gridColumns) {
grid.addHeader(new GridHeader(getPrettyColumnName(column, displayProperty), getColumnName(column), ValueType.NUMBER, Double.class.getName(), false, false));
}
for (List<DimensionalItemObject> row : gridRows) {
grid.addRow();
for (DimensionalItemObject object : row) {
grid.addValue(object.getDimensionItem());
grid.addValue(object.getDisplayProperty(displayProperty));
grid.addValue(object.getCode());
grid.addValue(object.getDisplayDescription());
}
if (reportParamColumns) {
grid.addValue(reportingPeriodName);
grid.addValue(getParentOrganisationUnitName());
grid.addValue(isCurrentParent(row) ? "Yes" : "No");
}
// -----------------------------------------------------------------
// Row data values
// -----------------------------------------------------------------
boolean hasValue = false;
for (List<DimensionalItemObject> column : gridColumns) {
String key = getIdentifier(column, row);
Object value = valueMap.get(key);
grid.addValue(value);
hasValue = hasValue || value != null;
}
if (hideEmptyRows && !hasValue) {
grid.removeCurrentWriteRow();
}
// TODO hide empty columns
}
if (hideEmptyColumns) {
grid.removeEmptyColumns();
}
if (regression) {
grid.addRegressionToGrid(startColumnIndex, numberOfColumns);
}
if (cumulative) {
grid.addCumulativesToGrid(startColumnIndex, numberOfColumns);
}
if (sortOrder != BaseAnalyticalObject.NONE) {
grid.sortGrid(grid.getWidth(), sortOrder);
}
if (topLimit > 0) {
grid.limitGrid(topLimit);
}
if (showHierarchy && rowDimensions.contains(ORGUNIT_DIM_ID) && grid.hasInternalMetaDataKey(AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS.getKey())) {
int ouIdColumnIndex = rowDimensions.indexOf(ORGUNIT_DIM_ID) * 4;
addHierarchyColumns(grid, ouIdColumnIndex);
}
return grid;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultAnalyticsService method addIndicatorValues.
/**
* Adds indicator values to the given grid based on the given data query
* parameters.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
*/
private void addIndicatorValues(DataQueryParams params, Grid grid) {
if (!params.getIndicators().isEmpty() && !params.isSkipData()) {
DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimension(DataDimensionItemType.INDICATOR).withIncludeNumDen(false).build();
List<Indicator> indicators = asTypedList(dataSourceParams.getIndicators());
Period filterPeriod = dataSourceParams.getFilterPeriod();
Map<String, Double> constantMap = constantService.getConstantMap();
// -----------------------------------------------------------------
// Get indicator values
// -----------------------------------------------------------------
Map<String, Map<String, Integer>> permutationOrgUnitTargetMap = getOrgUnitTargetMap(dataSourceParams, indicators);
List<List<DimensionItem>> dimensionItemPermutations = dataSourceParams.getDimensionItemPermutations();
Map<String, Map<DimensionalItemObject, Double>> permutationDimensionItemValueMap = getPermutationDimensionItemValueMap(dataSourceParams);
for (Indicator indicator : indicators) {
for (List<DimensionItem> dimensionItems : dimensionItemPermutations) {
String permKey = DimensionItem.asItemKey(dimensionItems);
Map<DimensionalItemObject, Double> valueMap = permutationDimensionItemValueMap.get(permKey);
if (valueMap == null) {
continue;
}
Period period = filterPeriod != null ? filterPeriod : (Period) DimensionItem.getPeriodItem(dimensionItems);
OrganisationUnit unit = (OrganisationUnit) DimensionItem.getOrganisationUnitItem(dimensionItems);
String ou = unit != null ? unit.getUid() : null;
Map<String, Integer> orgUnitCountMap = permutationOrgUnitTargetMap != null ? permutationOrgUnitTargetMap.get(ou) : null;
IndicatorValue value = expressionService.getIndicatorValueObject(indicator, period, valueMap, constantMap, orgUnitCountMap);
if (value != null) {
List<DimensionItem> row = new ArrayList<>(dimensionItems);
row.add(DX_INDEX, new DimensionItem(DATA_X_DIM_ID, indicator));
grid.addRow().addValues(DimensionItem.getItemIdentifiers(row)).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getValue()));
if (params.isIncludeNumDen()) {
grid.addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getNumeratorValue())).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getDenominatorValue())).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getFactorAnnualizedValue()));
}
}
}
}
}
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class QueryPlannerUtils method getPeriodTypeDataElementMap.
/**
* Creates a mapping between the period type and the data element for the
* given data elements.
*
* @param dataElements list of data elements.
*/
public static ListMap<PeriodType, DimensionalItemObject> getPeriodTypeDataElementMap(Collection<DimensionalItemObject> dataElements) {
ListMap<PeriodType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement dataElement = (DataElement) element;
map.putValue(dataElement.getPeriodType(), element);
}
return map;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class QueryPlannerUtils method getDaysPeriodMap.
/**
* Creates a mapping between the number of days in the period interval and period
* for the given periods.
*
* @param periods
*/
public static ListMap<Integer, DimensionalItemObject> getDaysPeriodMap(List<DimensionalItemObject> periods) {
ListMap<Integer, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject period : periods) {
Period pe = (Period) period;
int days = pe.getDaysInPeriod();
map.putValue(days, pe);
}
return map;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByDataPeriodType.
/**
* Groups the given query in sub queries based on the period type of its
* data elements. Sets the data period type on each query. This only applies
* if the aggregation type of the query involves disaggregation.
*
* @param params the data query parameters.
* @return a list of {@link DataQueryParams}.
*/
private List<DataQueryParams> groupByDataPeriodType(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (params.getDataElements().isEmpty() || !params.isDisaggregation()) {
queries.add(DataQueryParams.newBuilder(params).build());
return queries;
}
ListMap<PeriodType, DimensionalItemObject> periodTypeDataElementMap = QueryPlannerUtils.getPeriodTypeDataElementMap(params.getDataElements());
for (PeriodType periodType : periodTypeDataElementMap.keySet()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(periodTypeDataElementMap.get(periodType)).withDataPeriodType(periodType).build();
queries.add(query);
}
if (queries.size() > 1) {
log.debug(String.format("Split on data period type: %d", queries.size()));
}
return queries;
}
Aggregations