use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class DefaultEventQueryPlanner method groupByPartition.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Group by partition.
*
* @param params the event query parameters.
* @param validPartitions the set of valid partitions.
* @return a list of {@link EventQueryParams}.
*/
private List<EventQueryParams> groupByPartition(EventQueryParams params, Set<String> validPartitions) {
String tableSuffix = PartitionUtils.SEP + params.getProgram().getUid();
if (params.hasEnrollmentProgramIndicatorDimension()) {
List<EventQueryParams> indicatorQueries = new ArrayList<>();
EventQueryParams query = new EventQueryParams.Builder(params).withPartitions(PartitionUtils.getPartitions(AnalyticsTableType.ENROLLMENT.getTableName(), tableSuffix, validPartitions)).build();
if (query.getPartitions().hasAny()) {
indicatorQueries.add(query);
}
return indicatorQueries;
} else if (params.hasStartEndDate()) {
List<EventQueryParams> queries = new ArrayList<>();
Period queryPeriod = new Period();
queryPeriod.setStartDate(params.getStartDate());
queryPeriod.setEndDate(params.getEndDate());
EventQueryParams query = new EventQueryParams.Builder(params).withPartitions(PartitionUtils.getPartitions(queryPeriod, AnalyticsTableType.EVENT.getTableName(), tableSuffix, validPartitions)).build();
if (query.getPartitions().hasAny()) {
queries.add(query);
}
return queries;
} else // Aggregate only
{
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableName(AnalyticsTableType.EVENT.getTableName()).withTableSuffix(tableSuffix).build();
return QueryPlannerUtils.convert(queryPlanner.groupByPartition(params, plannerParams));
}
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class DefaultEventQueryPlanner method groupByQueryItems.
/**
* Group by items if query items are to be collapsed in order to aggregate
* each item individually.
*
* @param params the event query parameters.
* @return a list of {@link EventQueryParams}.
*/
private List<EventQueryParams> groupByQueryItems(EventQueryParams params) {
List<EventQueryParams> queries = new ArrayList<>();
if (params.isAggregateData()) {
for (QueryItem item : params.getItemsAndItemFilters()) {
EventQueryParams.Builder query = new EventQueryParams.Builder(params).removeItems().removeItemProgramIndicators().withValue(item.getItem());
if (item.hasProgram()) {
query.withProgram(item.getProgram());
}
queries.add(query.build());
}
for (ProgramIndicator programIndicator : params.getItemProgramIndicators()) {
EventQueryParams query = new EventQueryParams.Builder(params).removeItems().removeItemProgramIndicators().withProgramIndicator(programIndicator).withProgram(programIndicator.getProgram()).build();
queries.add(query);
}
} else if (params.isCollapseDataDimensions() && !params.getItems().isEmpty()) {
for (QueryItem item : params.getItems()) {
EventQueryParams.Builder query = new EventQueryParams.Builder(params).removeItems().addItem(item);
if (item.hasProgram()) {
query.withProgram(item.getProgram());
}
queries.add(query.build());
}
} else {
queries.add(new EventQueryParams.Builder(params).build());
}
return queries;
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class DefaultEventDataQueryService method getFromUrl.
@Override
public EventQueryParams getFromUrl(String program, String stage, Date startDate, Date endDate, Set<String> dimension, Set<String> filter, String value, AggregationType aggregationType, boolean skipMeta, boolean skipData, boolean skipRounding, boolean completedOnly, boolean hierarchyMeta, boolean showHierarchy, SortOrder sortOrder, Integer limit, EventOutputType outputType, EventStatus eventStatus, ProgramStatus programStatus, boolean collapseDataDimensions, boolean aggregateData, DisplayProperty displayProperty, Date relativePeriodDate, String userOrgUnit, DhisApiVersion apiVersion) {
EventQueryParams query = getFromUrl(program, stage, startDate, endDate, dimension, filter, null, null, null, skipMeta, skipData, completedOnly, hierarchyMeta, false, eventStatus, programStatus, displayProperty, relativePeriodDate, userOrgUnit, null, null, null, apiVersion);
EventQueryParams params = new EventQueryParams.Builder(query).withValue(getValueDimension(value)).withAggregationType(aggregationType).withSkipRounding(skipRounding).withShowHierarchy(showHierarchy).withSortOrder(sortOrder).withLimit(limit).withOutputType(MoreObjects.firstNonNull(outputType, EventOutputType.EVENT)).withCollapseDataDimensions(collapseDataDimensions).withAggregateData(aggregateData).withProgramStatus(programStatus).build();
return params;
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class DefaultEventDataQueryService method getFromAnalyticalObject.
@Override
public EventQueryParams getFromAnalyticalObject(EventAnalyticalObject object) {
Assert.notNull(object, "Event analytical object cannot be null");
Assert.notNull(object.getProgram(), "Event analytical object must specify a program");
EventQueryParams.Builder params = new EventQueryParams.Builder();
I18nFormat format = i18nManager.getI18nFormat();
IdScheme idScheme = IdScheme.UID;
Date date = object.getRelativePeriodDate();
object.populateAnalyticalProperties();
for (DimensionalObject dimension : ListUtils.union(object.getColumns(), object.getRows())) {
DimensionalObject dimObj = dataQueryService.getDimension(dimension.getDimension(), getDimensionalItemIds(dimension.getItems()), date, null, format, true, false, idScheme);
if (dimObj != null) {
params.addDimension(dimObj);
} else {
params.addItem(getQueryItem(dimension.getDimension(), dimension.getFilter(), object.getProgram()));
}
}
for (DimensionalObject filter : object.getFilters()) {
DimensionalObject dimObj = dataQueryService.getDimension(filter.getDimension(), getDimensionalItemIds(filter.getItems()), date, null, format, true, false, idScheme);
if (dimObj != null) {
params.addFilter(dimObj);
} else {
params.addItemFilter(getQueryItem(filter.getDimension(), filter.getFilter(), object.getProgram()));
}
}
return params.withProgram(object.getProgram()).withProgramStage(object.getProgramStage()).withStartDate(object.getStartDate()).withEndDate(object.getEndDate()).withValue(object.getValue()).withOutputType(object.getOutputType()).build();
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetUidNameMapEventQuery.
@Test
public void testGetUidNameMapEventQuery() {
ProgramStage psA = createProgramStage('A', 0);
ProgramStage psB = createProgramStage('B', 0);
Program prA = createProgram('A');
prA.getProgramStages().add(psA);
prA.getProgramStages().add(psB);
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('A');
OrganisationUnit ouA = createOrganisationUnit('A');
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addItem(new QueryItem(deA)).addItem(new QueryItem(deB)).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA))).withDisplayProperty(DisplayProperty.NAME).build();
Map<String, String> map = AnalyticsUtils.getUidNameMap(params);
assertEquals(psA.getName(), map.get(psA.getUid()));
assertEquals(psB.getName(), map.get(psB.getUid()));
assertEquals(prA.getName(), map.get(prA.getUid()));
assertEquals(deA.getName(), map.get(deA.getUid()));
assertEquals(deB.getName(), map.get(deB.getUid()));
assertEquals(ouA.getName(), map.get(ouA.getUid()));
}
Aggregations