Search in sources :

Example 36 with DimensionalObject

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;
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 37 with DimensionalObject

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);
    }
}
Also used : DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 38 with DimensionalObject

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;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 39 with DimensionalObject

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;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 40 with DimensionalObject

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());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DimensionalObject (org.hisp.dhis.common.DimensionalObject)44 ArrayList (java.util.ArrayList)14 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)13 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 Test (org.junit.Test)8 List (java.util.List)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 Grid (org.hisp.dhis.common.Grid)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 Period (org.hisp.dhis.period.Period)5 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 Calendar (org.hisp.dhis.calendar.Calendar)4 User (org.hisp.dhis.user.User)4 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Indicator (org.hisp.dhis.indicator.Indicator)3 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)3 ListGrid (org.hisp.dhis.system.grid.ListGrid)3