use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultAnalyticsService method addReportingRates.
/**
* Adds reporting rates to the given grid based on the given data query
* parameters.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
*/
private void addReportingRates(DataQueryParams params, Grid grid) {
if (!params.getReportingRates().isEmpty() && !params.isSkipData()) {
for (ReportingRateMetric metric : ReportingRateMetric.values()) {
DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimensionReportingRates(metric).ignoreDataApproval().withAggregationType(AggregationType.COUNT).withTimely((REPORTING_RATE_ON_TIME == metric || ACTUAL_REPORTS_ON_TIME == metric)).build();
addReportingRates(dataSourceParams, grid, metric);
}
}
}
use of org.hisp.dhis.analytics.DataQueryParams 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.getDisplayName(), levelOrgUnitMap.get(level)));
}
queries.add(query.build());
} else {
queries.add(DataQueryParams.newBuilder(params).build());
return queries;
}
if (queries.size() > 1) {
log.debug(String.format("Split on org unit level: %d", queries.size()));
}
return queries;
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByDataType.
/**
* Groups queries by their data type.
*
* @param params the data query parameters.
* @return a list of {@link DataQueryParams}.
*/
private List<DataQueryParams> groupByDataType(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getDataElements().isEmpty()) {
ListMap<DataType, DimensionalItemObject> dataTypeDataElementMap = QueryPlannerUtils.getDataTypeDataElementMap(params.getDataElements());
for (DataType dataType : dataTypeDataElementMap.keySet()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(dataTypeDataElementMap.get(dataType)).withDataType(dataType).build();
queries.add(query);
}
} else {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataType(DataType.NUMERIC).build();
queries.add(query);
}
if (queries.size() > 1) {
log.debug(String.format("Split on data type: %d", queries.size()));
}
return queries;
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class AnalyticsManagerTest method testReplaceDataPeriodsWithAggregationPeriods.
@Test
public void testReplaceDataPeriodsWithAggregationPeriods() {
Period y2012 = createPeriod("2012");
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2012)).withOrganisationUnits(getList(createOrganisationUnit('A'))).withDataPeriodType(new YearlyPeriodType()).withAggregationType(AggregationType.AVERAGE_SUM_INT_DISAGGREGATION).build();
Map<String, Object> dataValueMap = new HashMap<>();
dataValueMap.put(BASE_UID + "A-2012-" + BASE_UID + "A", 1d);
dataValueMap.put(BASE_UID + "B-2012-" + BASE_UID + "A", 1d);
ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q1"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q2"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q3"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q4"));
analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
assertEquals(8, dataValueMap.size());
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q4-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q4-" + BASE_UID + "A"));
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DataQueryServiceTest method testGetFromUrlUserOrgUnit.
@Test
public void testGetFromUrlUserOrgUnit() {
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add("ou:" + OrganisationUnit.KEY_USER_ORGUNIT);
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(1, params.getOrganisationUnits().size());
assertEquals(2, params.getDataElements().size());
assertEquals(2, params.getPeriods().size());
}
Aggregations