use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class QueryPlannerUtils method getLevelOrgUnitMap.
/**
* Creates a mapping between level and organisation unit for the given
* organisation units.
*
* @param orgUnits list of organisation units.
*/
public static ListMap<Integer, DimensionalItemObject> getLevelOrgUnitMap(List<DimensionalItemObject> orgUnits) {
ListMap<Integer, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject orgUnit : orgUnits) {
OrganisationUnit ou = (OrganisationUnit) orgUnit;
int level = ou.getLevel();
map.putValue(level, orgUnit);
}
return map;
}
use of org.hisp.dhis.common.DimensionalItemObject 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.common.DimensionalItemObject 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.common.DimensionalItemObject 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.common.DimensionalItemObject in project dhis2-core by dhis2.
the class PartitionUtils method getPeriodTypePeriodMap.
/**
* Creates a mapping between period type name and period for the given periods.
*/
public static ListMap<String, DimensionalItemObject> getPeriodTypePeriodMap(Collection<DimensionalItemObject> periods) {
ListMap<String, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject period : periods) {
String periodTypeName = ((Period) period).getPeriodType().getName();
map.putValue(periodTypeName, period);
}
return map;
}
Aggregations