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