Search in sources :

Example 11 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultAnalyticsService method getRawDataGrid.

/**
     * Returns headers, raw data and meta data as a grid.
     * 
     * @param params the {@link DataQueryParams}.
     * @return a grid.
     */
private Grid getRawDataGrid(DataQueryParams params) {
    Grid grid = new ListGrid();
    addHeaders(params, grid);
    addRawData(params, grid);
    addMetaData(params, grid);
    applyIdScheme(params, grid);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 12 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultAnalyticsService method getAggregatedDataValueGridInternal.

// -------------------------------------------------------------------------
// Private business logic methods
// -------------------------------------------------------------------------
/**
     * Returns a grid with aggregated data.
     *
     * @param params the {@link DataQueryParams}.
     * @return a grid with aggregated data.
     */
private Grid getAggregatedDataValueGridInternal(DataQueryParams params) {
    params = preHandleQuery(params);
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    Grid grid = new ListGrid();
    addHeaders(params, grid);
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    addIndicatorValues(params, grid);
    addDataElementValues(params, grid);
    addDataElementOperandValues(params, grid);
    addReportingRates(params, grid);
    addProgramDataElementAttributeIndicatorValues(params, grid);
    addDynamicDimensionValues(params, grid);
    // ---------------------------------------------------------------------
    // Meta-data
    // ---------------------------------------------------------------------
    addMetaData(params, grid);
    handleDataValueSet(params, grid);
    applyIdScheme(params, grid);
    postHandleGrid(params, grid);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 13 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultSqlViewService method getSqlViewGrid.

@Override
public Grid getSqlViewGrid(SqlView sqlView, Map<String, String> criteria, Map<String, String> variables, List<String> filters, List<String> fields) {
    validateSqlView(sqlView, criteria, variables);
    Grid grid = new ListGrid();
    grid.setTitle(sqlView.getName());
    grid.setSubtitle(sqlView.getDescription());
    validateSqlView(sqlView, criteria, variables);
    String sql = sqlView.isQuery() ? getSqlForQuery(grid, sqlView, criteria, variables, filters, fields) : getSqlForView(grid, sqlView, criteria, filters, fields);
    sqlViewStore.populateSqlViewGrid(grid, sql);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 14 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultEventAnalyticsService method getEventClusters.

@Override
public Grid getEventClusters(EventQueryParams params) {
    if (!databaseInfo.isSpatialSupport()) {
        throw new IllegalQueryException("Spatial database support is not enabled");
    }
    params = new EventQueryParams.Builder(params).withGeometryOnly(true).withStartEndDatesForPeriods().build();
    securityManager.decideAccess(params);
    queryPlanner.validate(params);
    Grid grid = new ListGrid();
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    grid.addHeader(new GridHeader(ITEM_COUNT, NAME_COUNT, ValueType.NUMBER, Long.class.getName(), false, false)).addHeader(new GridHeader(ITEM_CENTER, NAME_CENTER, ValueType.TEXT, String.class.getName(), false, false)).addHeader(new GridHeader(ITEM_EXTENT, NAME_EXTENT, ValueType.TEXT, String.class.getName(), false, false)).addHeader(new GridHeader(ITEM_POINTS, NAME_POINTS, ValueType.TEXT, String.class.getName(), false, false));
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    params = queryPlanner.planEventQuery(params);
    eventAnalyticsManager.getEventClusters(params, grid, queryPlanner.getMaxLimit());
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 15 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultEventAnalyticsService method getAggregatedEventData.

// -------------------------------------------------------------------------
// EventAnalyticsService implementation
// -------------------------------------------------------------------------
// TODO use [longitude/latitude] format for event points
// TODO order event analytics tables on execution date to avoid default sort
// TODO sorting in queries
@Override
public Grid getAggregatedEventData(EventQueryParams params) {
    securityManager.decideAccess(params);
    queryPlanner.validate(params);
    // Not supported as items for aggregate
    params.removeProgramIndicatorItems();
    Grid grid = new ListGrid();
    int maxLimit = queryPlanner.getMaxLimit();
    if (!params.isSkipData()) {
        if (params.isCollapseDataDimensions() || params.isAggregateData()) {
            grid.addHeader(new GridHeader(DimensionalObject.DATA_COLLAPSED_DIM_ID, DataQueryParams.DISPLAY_NAME_DATA_X, ValueType.TEXT, String.class.getName(), false, true));
        } else {
            for (QueryItem item : params.getItems()) {
                String legendSet = item.hasLegendSet() ? item.getLegendSet().getUid() : null;
                grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName(), item.getValueType(), item.getTypeAsString(), false, true, item.getOptionSetUid(), legendSet));
            }
        }
        for (DimensionalObject dimension : params.getDimensions()) {
            grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDisplayName(), ValueType.TEXT, String.class.getName(), false, true));
        }
        grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
        if (params.isIncludeNumDen()) {
            grid.addHeader(new GridHeader(NUMERATOR_ID, NUMERATOR_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false)).addHeader(new GridHeader(DENOMINATOR_ID, DENOMINATOR_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false)).addHeader(new GridHeader(FACTOR_ID, FACTOR_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
        }
        // -----------------------------------------------------------------
        // Data
        // -----------------------------------------------------------------
        Timer timer = new Timer().start().disablePrint();
        List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
        timer.getSplitTime("Planned event query, got partitions: " + params.getPartitions());
        for (EventQueryParams query : queries) {
            if (query.hasEnrollmentProgramIndicatorDimension()) {
                enrollmentAnalyticsManager.getAggregatedEventData(query, grid, maxLimit);
            } else {
                eventAnalyticsManager.getAggregatedEventData(query, grid, maxLimit);
            }
        }
        timer.getTime("Got aggregated events");
        if (maxLimit > 0 && grid.getHeight() > maxLimit) {
            throw new IllegalQueryException("Number of rows produced by query is larger than the max limit: " + maxLimit);
        }
        if (params.hasSortOrder() && grid.getHeight() > 0) {
            grid.sortGrid(1, params.getSortOrderAsInt());
        }
        if (params.hasLimit() && grid.getHeight() > params.getLimit()) {
            grid.limitGrid(params.getLimit());
        }
    }
    // ---------------------------------------------------------------------
    // Meta-data
    // ---------------------------------------------------------------------
    addMetadata(params, grid);
    return grid;
}
Also used : Timer(org.hisp.dhis.util.Timer) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)24 Grid (org.hisp.dhis.common.Grid)16 GridHeader (org.hisp.dhis.common.GridHeader)9 DimensionalObject (org.hisp.dhis.common.DimensionalObject)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)5 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 List (java.util.List)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DisplayProperty (org.hisp.dhis.common.DisplayProperty)2 Pager (org.hisp.dhis.common.Pager)2 QueryItem (org.hisp.dhis.common.QueryItem)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)2