Search in sources :

Example 51 with ListGrid

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

the class GridRenderUtils method asGrid.

/**
 * Generates a grid according to the provided columns, rows and values.
 *
 * @param columns the columns.
 * @param rows the rows.
 * @param valueMap the values as a mapping between metadata key and value.
 * @return a grid.
 */
public static Grid asGrid(List<? extends DimensionalObject> columns, List<? extends DimensionalObject> rows, Map<String, Object> valueMap) {
    List<List<DimensionalItemObject>> columnItems = columns.stream().map(DimensionalObject::getItems).collect(Collectors.toList());
    List<List<DimensionalItemObject>> rowItems = rows.stream().map(DimensionalObject::getItems).collect(Collectors.toList());
    List<List<DimensionalItemObject>> gridColumns = CombinationGenerator.newInstance(columnItems).getCombinations();
    List<List<DimensionalItemObject>> gridRows = CombinationGenerator.newInstance(rowItems).getCombinations();
    Map<String, Object> internalValueMap = getSortedKeysMap(valueMap);
    Grid grid = new ListGrid();
    for (DimensionalObject object : rows) {
        grid.addHeader(new GridHeader(object.getDimension(), object.getDimensionDisplayName()));
    }
    for (List<DimensionalItemObject> column : gridColumns) {
        grid.addHeader(new GridHeader(getKey(column), getName(column)));
    }
    for (List<DimensionalItemObject> row : gridRows) {
        grid.addRow();
        for (DimensionalItemObject object : row) {
            grid.addValue(object.getDisplayName());
        }
        for (List<DimensionalItemObject> column : gridColumns) {
            String key = getKey(column, row);
            Object value = internalValueMap.get(key);
            grid.addValue(value);
        }
    }
    return grid;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) List(java.util.List) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader)

Example 52 with ListGrid

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

the class DefaultOrgUnitAnalyticsService method getOrgUnitDataNormalized.

private Grid getOrgUnitDataNormalized(OrgUnitQueryParams params) {
    Grid grid = new ListGrid();
    addHeaders(params, grid);
    addMetadata(params, grid);
    getOrgUnitDataMap(params).entrySet().forEach(entry -> {
        grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(entry.getValue());
    });
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 53 with ListGrid

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

the class PeriodOffsetUtilsTest method verifyGetPeriodOffsetRow.

@Test
void verifyGetPeriodOffsetRow() {
    // Given
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    int periodIndex = 2;
    grid.addRow();
    grid.addValue("de1");
    grid.addValue("ou2");
    grid.addValue("202001");
    grid.addValue(3);
    grid.addRow();
    grid.addValue("de1");
    grid.addValue("ou3");
    grid.addValue("202002");
    grid.addValue(5);
    DataElement dataElement = createDataElement(0);
    dataElement.setUid("de1");
    // When
    final List<Object> row1 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(0), periodIndex, 1);
    // Then
    assertThat(row1, is(notNullValue()));
    assertThat(row1, hasSize(4));
    assertThat(row1.get(periodIndex), is("201912"));
    // When
    final List<Object> row2 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(1), periodIndex, -1);
    // Then
    assertThat(row2, is(notNullValue()));
    assertThat(row2, hasSize(4));
    assertThat(row2.get(periodIndex), is("202003"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 54 with ListGrid

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

the class EventPredictionServiceTest method newGrid.

// -------------------------------------------------------------------------
// Local convenience methods
// -------------------------------------------------------------------------
/**
 * Make a data grid for MockAnalyticsService to return.
 *
 * @param dimensionItem Dimension item to be queried for
 * @param values (if any), starting with March 2017
 * @return the Grid, as would be returned by analytics
 */
private Grid newGrid(String dimensionItem, double... values) {
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID));
    int month = Integer.valueOf(testYear + "03");
    for (double value : values) {
        grid.addRow();
        grid.addValue(dimensionItem);
        grid.addValue(Integer.toString(month++));
        grid.addValue(orgUnitA.getUid());
        grid.addValue("HllvX50cXC0");
        grid.addValue(new Double(value));
    }
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 55 with ListGrid

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

the class DefaultVisualizationGridService method getVisualizationGridByUser.

@Override
@Transactional(readOnly = true)
public Grid getVisualizationGridByUser(final String uid, final Date relativePeriodDate, final String organisationUnitUid, final User user) {
    Visualization visualization = visualizationService.getVisualization(uid);
    final boolean hasPermission = visualization != null;
    if (hasPermission) {
        I18nFormat format = i18nManager.getI18nFormat();
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
        List<OrganisationUnit> atLevels = new ArrayList<>();
        List<OrganisationUnit> inGroups = new ArrayList<>();
        if (visualization.hasOrganisationUnitLevels()) {
            atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(visualization.getOrganisationUnitLevels(), visualization.getOrganisationUnits()));
        }
        if (visualization.hasItemOrganisationUnitGroups()) {
            inGroups.addAll(organisationUnitService.getOrganisationUnits(visualization.getItemOrganisationUnitGroups(), visualization.getOrganisationUnits()));
        }
        visualization.init(user, relativePeriodDate, organisationUnit, atLevels, inGroups, format);
        Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(visualization);
        Grid visualizationGrid = visualization.getGrid(new ListGrid(), valueMap, SHORTNAME, true);
        visualization.clearTransientState();
        return visualizationGrid;
    } else {
        return new ListGrid();
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)58 Grid (org.hisp.dhis.common.Grid)41 GridHeader (org.hisp.dhis.common.GridHeader)28 Test (org.junit.jupiter.api.Test)21 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)14 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)11 ArrayList (java.util.ArrayList)10 DimensionalObject (org.hisp.dhis.common.DimensionalObject)10 HashMap (java.util.HashMap)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 DataElement (org.hisp.dhis.dataelement.DataElement)8 List (java.util.List)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 Test (org.junit.Test)7 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5