Search in sources :

Example 1 with DataType

use of org.hisp.dhis.analytics.DataType in project dhis2-core by dhis2.

the class QueryPlannerUtils method getDataTypeDataElementMap.

/**
     * Creates a mapping between data type and data element for the given data 
     * elements.
     * 
     * @param dataElements list of data elements.
     */
public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap(List<DimensionalItemObject> dataElements) {
    ListMap<DataType, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject element : dataElements) {
        DataElement dataElement = (DataElement) element;
        ValueType valueType = dataElement.getValueType();
        // Both Text and Date types are recognized as TEXT
        DataType dataType = (valueType.isText() || valueType.isDate()) ? DataType.TEXT : DataType.NUMERIC;
        map.putValue(dataType, dataElement);
    }
    return map;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ValueType(org.hisp.dhis.common.ValueType) DataType(org.hisp.dhis.analytics.DataType) ListMap(org.hisp.dhis.common.ListMap)

Example 2 with DataType

use of org.hisp.dhis.analytics.DataType in project dhis2-core by dhis2.

the class DefaultQueryPlanner method groupByDataType.

/**
     * Groups queries by their data type.
     * 
     * @param params the data query parameters.
     * @return a list of {@link DataQueryParams}.
     */
private List<DataQueryParams> groupByDataType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getDataElements().isEmpty()) {
        ListMap<DataType, DimensionalItemObject> dataTypeDataElementMap = QueryPlannerUtils.getDataTypeDataElementMap(params.getDataElements());
        for (DataType dataType : dataTypeDataElementMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(dataTypeDataElementMap.get(dataType)).withDataType(dataType).build();
            queries.add(query);
        }
    } else {
        DataQueryParams query = DataQueryParams.newBuilder(params).withDataType(DataType.NUMERIC).build();
        queries.add(query);
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on data type: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DataType(org.hisp.dhis.analytics.DataType)

Aggregations

DataType (org.hisp.dhis.analytics.DataType)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 ArrayList (java.util.ArrayList)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 ListMap (org.hisp.dhis.common.ListMap)1 ValueType (org.hisp.dhis.common.ValueType)1 DataElement (org.hisp.dhis.dataelement.DataElement)1