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));
}
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());
}
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());
}
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;
}
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);
}
}
}
Aggregations