use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.
the class AnalyticsUtils method getDimensionalItemObjectMap.
/**
* Returns a mapping between dimension item identifiers and dimensional
* item object for the given query.
*
* @param params the data query parameters.
* @return a mapping between identifiers and names.
*/
public static Map<String, DimensionalItemObject> getDimensionalItemObjectMap(DataQueryParams params) {
List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
Map<String, DimensionalItemObject> map = new HashMap<>();
for (DimensionalObject dimension : dimensions) {
dimension.getItems().stream().forEach(i -> map.put(i.getDimensionItem(), i));
}
return map;
}
use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.
the class DataQueryParams method setDataDimensionOptions.
/**
* Sets the given list of data dimension options. Replaces existing options
* of the given data dimension type.
*
* @param itemType the data dimension type, or all types if null.
* @param options the data dimension options.
*/
private void setDataDimensionOptions(@Nullable DataDimensionItemType itemType, List<? extends DimensionalItemObject> options) {
List<DimensionalItemObject> existing = getDimensionOptions(DATA_X_DIM_ID);
if (itemType != null) {
existing = AnalyticsUtils.getByDataDimensionItemType(itemType, existing);
}
DimensionalObject dimension = getDimension(DATA_X_DIM_ID);
if (dimension == null) {
dimension = new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, options);
addDimension(dimension);
} else {
dimension.getItems().removeAll(existing);
dimension.getItems().addAll(options);
}
}
use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.
the class JdbcRawAnalyticsManager method getRawDataValues.
// -------------------------------------------------------------------------
// RawAnalyticsManager implementation
// -------------------------------------------------------------------------
@Override
public Grid getRawDataValues(DataQueryParams params, Grid grid) {
List<DimensionalObject> dimensions = params.getDimensions();
String sql = getStatement(params);
log.debug("Get raw data SQL: " + sql);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while (rowSet.next()) {
grid.addRow();
for (DimensionalObject dim : dimensions) {
grid.addValue(rowSet.getString(dim.getDimensionName()));
}
grid.addValue(rowSet.getDouble("value"));
}
return grid;
}
use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByOrgUnitLevel.
@Override
public List<DataQueryParams> groupByOrgUnitLevel(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getOrganisationUnits().isEmpty()) {
ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getOrganisationUnits());
for (Integer level : levelOrgUnitMap.keySet()) {
DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, LEVEL_PREFIX + level, levelOrgUnitMap.get(level)).build();
queries.add(query);
}
} else if (!params.getFilterOrganisationUnits().isEmpty()) {
ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getFilterOrganisationUnits());
DimensionalObject filter = params.getFilter(ORGUNIT_DIM_ID);
DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(ORGUNIT_DIM_ID);
for (Integer level : levelOrgUnitMap.keySet()) {
query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), LEVEL_PREFIX + level, filter.getDisplayName(), levelOrgUnitMap.get(level)));
}
queries.add(query.build());
} else {
queries.add(DataQueryParams.newBuilder(params).build());
return queries;
}
if (queries.size() > 1) {
log.debug(String.format("Split on org unit level: %d", queries.size()));
}
return queries;
}
use of org.hisp.dhis.common.DimensionalObject in project dhis2-core by dhis2.
the class DataQueryGroupsTest method getQueryA.
@Test
public void getQueryA() {
DimensionalObject dimA = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB));
DimensionalObject dimB = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB, ouC));
DimensionalObject dimC = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, getList(createPeriod("2000Q1")));
DataQueryParams paramsA = DataQueryParams.newBuilder().addDimension(dimA).addDimension(dimB).addFilter(dimC).build();
assertNotNull(paramsA.getDimension(DimensionalObject.DATA_X_DIM_ID));
assertNotNull(paramsA.getDimension(DimensionalObject.ORGUNIT_DIM_ID));
assertNotNull(paramsA.getFilter(DimensionalObject.PERIOD_DIM_ID));
assertEquals(2, paramsA.getDimension(DimensionalObject.DATA_X_DIM_ID).getItems().size());
assertEquals(3, paramsA.getDimension(DimensionalObject.ORGUNIT_DIM_ID).getItems().size());
assertEquals(1, paramsA.getFilter(DimensionalObject.PERIOD_DIM_ID).getItems().size());
}
Aggregations