Search in sources :

Example 71 with BaseDimensionalObject

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

the class DimensionServiceTest method testMergeAnalyticalEventObjectOrgUnitLevel.

@Test
void testMergeAnalyticalEventObjectOrgUnitLevel() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouLevel2, ouA)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(2, eventVisualization.getDataDimensionItems().size());
    assertEquals(1, eventVisualization.getPeriods().size());
    assertEquals(1, eventVisualization.getOrganisationUnits().size());
    assertEquals(Integer.valueOf(2), eventVisualization.getOrganisationUnitLevels().get(0));
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 72 with BaseDimensionalObject

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

the class DimensionServiceTest method testMergeAnalyticalEventObjectB.

@Test
void testMergeAnalyticalEventObjectB() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    BaseDimensionalObject deCDim = new BaseDimensionalObject(deC.getUid(), DimensionType.PROGRAM_DATA_ELEMENT, null, null, null, psA, "EQ:uidA");
    eventVisualization.getColumns().add(deCDim);
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(1, eventVisualization.getDataElementDimensions().size());
    assertEquals(2, eventVisualization.getPeriods().size());
    assertEquals(3, eventVisualization.getOrganisationUnits().size());
    TrackedEntityDataElementDimension teDeDim = eventVisualization.getDataElementDimensions().get(0);
    assertEquals(deC, teDeDim.getDataElement());
    assertEquals(psA, teDeDim.getProgramStage());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 73 with BaseDimensionalObject

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

the class DimensionServiceTest method testMergeAnalyticalEventObjectRelativePeriods.

@Test
void testMergeAnalyticalEventObjectRelativePeriods() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC, ouD, ouE)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peLast12Months)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(2, eventVisualization.getDataDimensionItems().size());
    assertEquals(0, eventVisualization.getPeriods().size());
    assertTrue(eventVisualization.getRelatives().isLast12Months());
    assertEquals(5, eventVisualization.getOrganisationUnits().size());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 74 with BaseDimensionalObject

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

the class DefaultQueryPlanner method groupByOrgUnitLevel.

@Override
public List<DataQueryParams> groupByOrgUnitLevel(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getOrganisationUnits());
        for (Integer level : levelOrgUnitMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, LEVEL_PREFIX + level, levelOrgUnitMap.get(level)).build();
            queries.add(query);
        }
    } else if (!params.getFilterOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getFilterOrganisationUnits());
        DimensionalObject filter = params.getFilter(ORGUNIT_DIM_ID);
        DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(ORGUNIT_DIM_ID);
        for (Integer level : levelOrgUnitMap.keySet()) {
            query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), LEVEL_PREFIX + level, filter.getDimensionDisplayName(), levelOrgUnitMap.get(level)));
        }
        queries.add(query.build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    logQuerySplit(queries, "organisation unit level");
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 75 with BaseDimensionalObject

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

the class DataHandler 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 TotalType}.
 */
private void addDataElementOperandValues(DataQueryParams params, Grid grid, 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 = newArrayList(getDataElements(operands));
    List<DimensionalItemObject> categoryOptionCombos = newArrayList(getCategoryOptionCombos(operands));
    List<DimensionalItemObject> attributeOptionCombos = newArrayList(getAttributeOptionCombos(operands));
    // TODO Check if data was dim or filter
    DataQueryParams.Builder builder = newBuilder(params).removeDimension(DATA_X_DIM_ID).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DATA_X, dataElements));
    if (totalType.isCategoryOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, CATEGORY_OPTION_COMBO, categoryOptionCombos));
    }
    if (totalType.isAttributeOptionCombo()) {
        builder.addDimension(new BaseDimensionalObject(ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTE_OPTION_COMBO, attributeOptionCombos));
    }
    DataQueryParams operandParams = builder.build();
    Map<String, Object> aggregatedDataMap = getAggregatedDataValueMapObjectTyped(operandParams);
    aggregatedDataMap = convertDxToOperand(aggregatedDataMap, totalType);
    for (Map.Entry<String, Object> entry : aggregatedDataMap.entrySet()) {
        Object value = getRoundedValueObject(operandParams, entry.getValue());
        grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(value);
        if (params.isIncludeNumDen()) {
            grid.addNullValues(NUMERATOR_DENOMINATOR_PROPERTIES_COUNT);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) EventQueryParams.fromDataQueryParams(org.hisp.dhis.analytics.event.EventQueryParams.fromDataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) AnalyticsUtils.getRoundedValueObject(org.hisp.dhis.analytics.util.AnalyticsUtils.getRoundedValueObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) Map(java.util.Map) DataQueryParams.getPermutationDimensionalItemValueMap(org.hisp.dhis.analytics.DataQueryParams.getPermutationDimensionalItemValueMap) DataQueryParams.getPermutationOrgUnitGroupCountMap(org.hisp.dhis.analytics.DataQueryParams.getPermutationOrgUnitGroupCountMap) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap) AnalyticsUtils.getDoubleMap(org.hisp.dhis.analytics.util.AnalyticsUtils.getDoubleMap) DimensionalObjectUtils.convertToDimItemValueMap(org.hisp.dhis.common.DimensionalObjectUtils.convertToDimItemValueMap) HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)108 Test (org.junit.jupiter.api.Test)77 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)69 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)31 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DimensionalObject (org.hisp.dhis.common.DimensionalObject)22 ArrayList (java.util.ArrayList)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)18 Grid (org.hisp.dhis.common.Grid)17 HashMap (java.util.HashMap)14 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)14 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 CategoryCombo (org.hisp.dhis.category.CategoryCombo)11 DataElement (org.hisp.dhis.dataelement.DataElement)11 Test (org.junit.Test)11 Map (java.util.Map)9 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)9 Period (org.hisp.dhis.period.Period)9 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)8 QueryItem (org.hisp.dhis.common.QueryItem)8