Search in sources :

Example 31 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlA.

@Test
public void testGetFromUrlA() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getUid() + ";" + deB.getUid() + ";" + deC.getUid() + ";" + deD.getUid());
    dimensionParams.add("pe:2012;2012S1;2012S2");
    dimensionParams.add(ouGroupSetA.getUid() + ":" + ouGroupA.getUid() + ";" + ouGroupB.getUid() + ";" + ouGroupC.getUid());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getUid() + ";" + ouB.getUid() + ";" + ouC.getUid() + ";" + ouD.getUid() + ";" + ouE.getUid());
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, filterParams, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, false, null);
    assertEquals(4, params.getDataElements().size());
    assertEquals(3, params.getPeriods().size());
    assertEquals(5, params.getFilterOrganisationUnits().size());
    assertEquals(3, params.getDimensionOptions(ouGroupSetA.getUid()).size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlOrgUnitLevel.

@Test
public void testGetFromUrlOrgUnitLevel() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:LEVEL-2");
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem());
    dimensionParams.add("pe:2011;2012");
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, null, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, false, null);
    assertEquals(2, params.getOrganisationUnits().size());
    assertEquals(2, params.getDataElements().size());
    assertEquals(2, params.getPeriods().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 33 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromAnalyticalObjectB.

@Test
public void testGetFromAnalyticalObjectB() {
    Chart chart = new Chart();
    chart.setSeries(DimensionalObject.DATA_X_DIM_ID);
    chart.setCategory(ouGroupSetA.getUid());
    chart.getFilterDimensions().add(DimensionalObject.PERIOD_DIM_ID);
    chart.addDataDimensionItem(deA);
    chart.addDataDimensionItem(deB);
    chart.addDataDimensionItem(deC);
    OrganisationUnitGroupSetDimension ouGroupSetDim = new OrganisationUnitGroupSetDimension();
    ouGroupSetDim.setDimension(ouGroupSetA);
    ouGroupSetDim.setItems(Lists.newArrayList(ouGroupA, ouGroupB, ouGroupC));
    chart.getOrganisationUnitGroupSetDimensions().add(ouGroupSetDim);
    chart.getPeriods().add(PeriodType.getPeriodFromIsoString("2012"));
    DataQueryParams params = dataQueryService.getFromAnalyticalObject(chart);
    assertNotNull(params);
    assertEquals(3, params.getDataElements().size());
    assertEquals(1, params.getFilterPeriods().size());
    assertEquals(2, params.getDimensions().size());
    assertEquals(1, params.getFilters().size());
    assertEquals(3, params.getDimensionOptions(ouGroupSetA.getUid()).size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 34 with DataQueryParams

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

the class DefaultAnalyticsService method addDataElementOperandValues.

/**
     * Adds data element operand values to the given grid.
     * 
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     * @param totalType the operand {@link DataElementOperand.TotalType}.
     */
private void addDataElementOperandValues(DataQueryParams params, Grid grid, DataElementOperand.TotalType totalType) {
    List<DataElementOperand> operands = asTypedList(params.getDataElementOperands());
    operands = operands.stream().filter(o -> totalType.equals(o.getTotalType())).collect(Collectors.toList());
    if (operands.isEmpty()) {
        return;
    }
    List<DimensionalItemObject> dataElements = Lists.newArrayList(DimensionalObjectUtils.getDataElements(operands));
    List<DimensionalItemObject> categoryOptionCombos = Lists.newArrayList(DimensionalObjectUtils.getCategoryOptionCombos(operands));
    List<DimensionalItemObject> attributeOptionCobos = Lists.newArrayList(DimensionalObjectUtils.getAttributeOptionCombos(operands));
    //TODO check if data was dim or filter
    DataQueryParams.Builder builder = DataQueryParams.newBuilder(params).removeDimension(DATA_X_DIM_ID).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, dataElements));
    if (totalType.isCategoryOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, categoryOptionCombos));
    }
    if (totalType.isAttributeOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(ATTRIBUTEOPTIONCOMBO_DIM_ID, DimensionType.ATTRIBUTE_OPTION_COMBO, attributeOptionCobos));
    }
    DataQueryParams operandParams = builder.build();
    Map<String, Object> aggregatedDataMap = getAggregatedDataValueMapObjectTyped(operandParams);
    aggregatedDataMap = AnalyticsUtils.convertDxToOperand(aggregatedDataMap, totalType);
    for (Map.Entry<String, Object> entry : aggregatedDataMap.entrySet()) {
        Object value = AnalyticsUtils.getRoundedValueObject(operandParams, entry.getValue());
        grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(value);
        if (params.isIncludeNumDen()) {
            grid.addNullValues(3);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) HashMap(java.util.HashMap) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)

Example 35 with DataQueryParams

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

the class DefaultAnalyticsService method addProgramDataElementAttributeIndicatorValues.

/**
     * Adds program data element values to the given grid based on the given data
     * query parameters.
     *
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     */
private void addProgramDataElementAttributeIndicatorValues(DataQueryParams params, Grid grid) {
    if ((!params.getAllProgramDataElementsAndAttributes().isEmpty() || !params.getProgramIndicators().isEmpty()) && !params.isSkipData()) {
        DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimensions(PROGRAM_DATA_ELEMENT, PROGRAM_ATTRIBUTE, PROGRAM_INDICATOR).build();
        EventQueryParams eventQueryParams = new EventQueryParams.Builder(EventQueryParams.fromDataQueryParams(dataSourceParams)).withSkipMeta(true).build();
        Grid eventGrid = eventAnalyticsService.getAggregatedEventData(eventQueryParams);
        grid.addRows(eventGrid);
    }
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid)

Aggregations

DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)81 Test (org.junit.Test)52 DhisSpringTest (org.hisp.dhis.DhisSpringTest)51 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)24 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)22 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)17 ArrayList (java.util.ArrayList)16 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 HashSet (java.util.HashSet)14 LinkedHashSet (java.util.LinkedHashSet)13 HashMap (java.util.HashMap)7 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 List (java.util.List)6 Map (java.util.Map)6 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)6 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)5 Grid (org.hisp.dhis.common.Grid)5