Search in sources :

Example 26 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EventQueryParams method fromDataQueryParams.

public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
    EventQueryParams params = new EventQueryParams();
    dataQueryParams.copyTo(params);
    EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
    for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
        ProgramIndicator programIndicator = (ProgramIndicator) object;
        builder.addItemProgramIndicator(programIndicator);
    }
    return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 27 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class QueryPlannerUtils method getAggregationTypeDataElementMap.

/**
     * Creates a mapping between the aggregation type and data element for the
     * given data elements and period type.
     * 
     * @param params the data query parameters.
     */
public static ListMap<AggregationType, DimensionalItemObject> getAggregationTypeDataElementMap(DataQueryParams params) {
    List<DimensionalItemObject> dataElements = params.getDataElements();
    PeriodType aggregationPeriodType = PeriodType.getPeriodTypeByName(params.getPeriodType());
    ListMap<AggregationType, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject element : dataElements) {
        DataElement de = (DataElement) element;
        AggregationType type = ObjectUtils.firstNonNull(params.getAggregationType(), de.getAggregationType());
        AggregationType aggregationType = getAggregationType(de.getValueType(), type, aggregationPeriodType, de.getPeriodType());
        map.putValue(aggregationType, de);
    }
    return map;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) AggregationType(org.hisp.dhis.analytics.AggregationType) ListMap(org.hisp.dhis.common.ListMap)

Example 28 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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 29 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EventQueryParams method getOrganisationUnitChildren.

public Set<OrganisationUnit> getOrganisationUnitChildren() {
    Set<OrganisationUnit> children = new HashSet<>();
    for (DimensionalItemObject object : getDimensionOrFilterItems(DimensionalObject.ORGUNIT_DIM_ID)) {
        OrganisationUnit unit = (OrganisationUnit) object;
        children.addAll(unit.getChildren());
    }
    return children;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashSet(java.util.HashSet)

Example 30 with DimensionalItemObject

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

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)55 ArrayList (java.util.ArrayList)15 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 Test (org.junit.Test)12 Period (org.hisp.dhis.period.Period)11 ListMap (org.hisp.dhis.common.ListMap)10 DataElement (org.hisp.dhis.dataelement.DataElement)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)7 HashMap (java.util.HashMap)6 List (java.util.List)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 PeriodType (org.hisp.dhis.period.PeriodType)6 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)5 Matcher (java.util.regex.Matcher)4 Grid (org.hisp.dhis.common.Grid)4 HashSet (java.util.HashSet)3