Search in sources :

Example 6 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class JdbcEnrollmentAnalyticsManager method getAggregatedEventData.

private void getAggregatedEventData(Grid grid, EventQueryParams params, String sql) {
    log.debug("Analytics event aggregate SQL: " + sql);
    SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
    while (rowSet.next()) {
        grid.addRow();
        if (params.isAggregateData()) {
            if (params.hasValueDimension()) {
                String itemId = params.getProgram().getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + params.getValue().getUid();
                grid.addValue(itemId);
            } else if (params.hasProgramIndicatorDimension()) {
                grid.addValue(params.getProgramIndicator().getUid());
            }
        } else {
            for (QueryItem queryItem : params.getItems()) {
                String itemValue = rowSet.getString(queryItem.getItemName());
                String gridValue = params.isCollapseDataDimensions() ? getCollapsedDataItemValue(params, queryItem, itemValue) : itemValue;
                grid.addValue(gridValue);
            }
        }
        for (DimensionalObject dimension : params.getDimensions()) {
            String dimensionValue = rowSet.getString(dimension.getDimensionName());
            grid.addValue(dimensionValue);
        }
        if (params.hasValueDimension()) {
            double value = rowSet.getDouble("value");
            grid.addValue(params.isSkipRounding() ? value : getRounded(value));
        } else if (params.hasProgramIndicatorDimension()) {
            double value = rowSet.getDouble("value");
            ProgramIndicator indicator = params.getProgramIndicator();
            grid.addValue(AnalyticsUtils.getRoundedValue(params, indicator.getDecimals(), value));
        } else {
            int value = rowSet.getInt("value");
            grid.addValue(value);
        }
        if (params.isIncludeNumDen()) {
            grid.addNullValues(3);
        }
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 7 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class JdbcEventAnalyticsManager method getPartitionSelectColumns.

/**
     * Returns the dynamic select columns. Dimensions come first and query items
     * second. Program indicator expressions are exploded into attributes and
     * data element identifiers.
     * 
     * @param params the {@link EventQueryParams}.
     */
private List<String> getPartitionSelectColumns(EventQueryParams params) {
    List<String> columns = Lists.newArrayList();
    for (DimensionalObject dimension : params.getDimensions()) {
        columns.add(dimension.getDimensionName());
    }
    for (QueryItem queryItem : params.getItems()) {
        if (queryItem.isProgramIndicator()) {
            ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
            Set<String> uids = ProgramIndicator.getDataElementAndAttributeIdentifiers(in.getExpression(), in.getAnalyticsType());
            columns.addAll(uids);
        } else {
            columns.add(queryItem.getItemName());
        }
    }
    return columns;
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 8 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class JdbcEventAnalyticsManager method getAggregatedEventData.

private void getAggregatedEventData(Grid grid, EventQueryParams params, String sql) {
    log.debug(String.format("Analytics event aggregate SQL: %s", sql));
    SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
    while (rowSet.next()) {
        grid.addRow();
        if (params.isAggregateData()) {
            if (params.hasValueDimension()) {
                String itemId = params.getProgram().getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + params.getValue().getUid();
                grid.addValue(itemId);
            } else if (params.hasProgramIndicatorDimension()) {
                grid.addValue(params.getProgramIndicator().getUid());
            }
        } else {
            for (QueryItem queryItem : params.getItems()) {
                String itemValue = rowSet.getString(queryItem.getItemName());
                String gridValue = params.isCollapseDataDimensions() ? getCollapsedDataItemValue(params, queryItem, itemValue) : itemValue;
                grid.addValue(gridValue);
            }
        }
        for (DimensionalObject dimension : params.getDimensions()) {
            String dimensionValue = rowSet.getString(dimension.getDimensionName());
            grid.addValue(dimensionValue);
        }
        if (params.hasValueDimension()) {
            double value = rowSet.getDouble("value");
            grid.addValue(params.isSkipRounding() ? value : getRounded(value));
        } else if (params.hasProgramIndicatorDimension()) {
            double value = rowSet.getDouble("value");
            ProgramIndicator indicator = params.getProgramIndicator();
            grid.addValue(AnalyticsUtils.getRoundedValue(params, indicator.getDecimals(), value));
        } else {
            int value = rowSet.getInt("value");
            grid.addValue(value);
        }
        if (params.isIncludeNumDen()) {
            grid.addNullValues(3);
        }
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 9 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class JdbcEventAnalyticsManager method getSelectColumns.

/**
     * Returns the dynamic select columns. Dimensions come first and query items
     * second. Program indicator expressions are converted to SQL expressions.
     * 
     * @param params the {@link EventQueryParams}.
     */
private List<String> getSelectColumns(EventQueryParams params) {
    List<String> columns = Lists.newArrayList();
    for (DimensionalObject dimension : params.getDimensions()) {
        columns.add(statementBuilder.columnQuote(dimension.getDimensionName()));
    }
    for (QueryItem queryItem : params.getItems()) {
        if (queryItem.isProgramIndicator()) {
            ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
            String asClause = " as " + statementBuilder.columnQuote(in.getUid());
            columns.add("(" + programIndicatorService.getAnalyticsSQl(in.getExpression(), in.getAnalyticsType(), params.getEarliestStartDate(), params.getLatestEndDate()) + ")" + asClause);
        } else if (ValueType.COORDINATE == queryItem.getValueType()) {
            String colName = statementBuilder.columnQuote(queryItem.getItemName());
            String coordSql = "'[' || round(ST_X(" + colName + ")::numeric, " + COORD_DEC + ") ||" + "',' || round(ST_Y(" + colName + ")::numeric, " + COORD_DEC + ") || ']' as " + colName;
            columns.add(coordSql);
        } else {
            columns.add(statementBuilder.columnQuote(queryItem.getItemName()));
        }
    }
    return columns;
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 10 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class DefaultDimensionService method getDimensionType.

@Override
public DimensionType getDimensionType(String uid) {
    DataElementCategory cat = idObjectManager.get(DataElementCategory.class, uid);
    if (cat != null) {
        return DimensionType.CATEGORY;
    }
    DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
    if (degs != null) {
        return DimensionType.DATA_ELEMENT_GROUP_SET;
    }
    OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
    if (ougs != null) {
        return DimensionType.ORGANISATION_UNIT_GROUP_SET;
    }
    CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
    if (cogs != null) {
        return DimensionType.CATEGORY_OPTION_GROUP_SET;
    }
    TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
    if (tea != null) {
        return DimensionType.PROGRAM_ATTRIBUTE;
    }
    DataElement pde = idObjectManager.get(DataElement.class, uid);
    if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
        return DimensionType.PROGRAM_DATA_ELEMENT;
    }
    ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
    if (pin != null) {
        return DimensionType.PROGRAM_INDICATOR;
    }
    final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
    dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
    dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
    dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
    return dimObjectTypeMap.get(uid);
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionType(org.hisp.dhis.common.DimensionType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 DataElement (org.hisp.dhis.dataelement.DataElement)6 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 ArrayList (java.util.ArrayList)3 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 QueryItem (org.hisp.dhis.common.QueryItem)2 Program (org.hisp.dhis.program.Program)2 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 DimensionType (org.hisp.dhis.common.DimensionType)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 MapMap (org.hisp.dhis.common.MapMap)1 SetMap (org.hisp.dhis.common.SetMap)1