use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testPlanAggregateQueryC.
@Test
public void testPlanAggregateQueryC() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA, ouB)).build();
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
assertEquals(2, queries.size());
assertEquals(ouA, queries.get(0).getOrganisationUnits().get(0));
assertEquals(ouB, queries.get(1).getOrganisationUnits().get(0));
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testPlanAggregateQueryA.
@Test
public void testPlanAggregateQueryA() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
assertEquals(1, queries.size());
EventQueryParams query = queries.get(0);
assertEquals(new DateTime(2010, 6, 1, 0, 0).toDate(), query.getStartDate());
assertEquals(new DateTime(2012, 3, 20, 0, 0).toDate(), query.getEndDate());
Partitions partitions = query.getPartitions();
assertEquals(3, partitions.getPartitions().size());
assertEquals("analytics_event_2010_programuida", partitions.getPartitions().get(0));
assertEquals("analytics_event_2011_programuida", partitions.getPartitions().get(1));
assertEquals("analytics_event_2012_programuida", partitions.getPartitions().get(2));
}
use of org.hisp.dhis.analytics.event.EventQueryParams 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);
}
}
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, OrganisationUnitSelectionMode ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean skipData, boolean completedOnly, boolean hierarchyMeta, boolean coordinatesOnly, EventStatus eventStatus, ProgramStatus programStatus, DisplayProperty displayProperty, Date relativePeriodDate, String userOrgUnit, String coordinateField, Integer page, Integer pageSize, DhisApiVersion apiVersion) {
I18nFormat format = i18nManager.getI18nFormat();
EventQueryParams.Builder params = new EventQueryParams.Builder();
IdScheme idScheme = IdScheme.UID;
List<OrganisationUnit> userOrgUnits = dataQueryService.getUserOrgUnits(null, userOrgUnit);
Program pr = programService.getProgram(program);
if (pr == null) {
throw new IllegalQueryException("Program does not exist: " + program);
}
ProgramStage ps = programStageService.getProgramStage(stage);
if (StringUtils.isNotEmpty(stage) && ps == null) {
throw new IllegalQueryException("Program stage is specified but does not exist: " + stage);
}
if (dimension != null) {
for (String dim : dimension) {
String dimensionId = getDimensionFromParam(dim);
List<String> items = getDimensionItemsFromParam(dim);
DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
if (dimObj != null) {
params.addDimension(dimObj);
} else {
params.addItem(getQueryItem(dim, pr));
}
}
}
if (filter != null) {
for (String dim : filter) {
String dimensionId = getDimensionFromParam(dim);
List<String> items = getDimensionItemsFromParam(dim);
DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
if (dimObj != null) {
params.addFilter(dimObj);
} else {
params.addItemFilter(getQueryItem(dim, pr));
}
}
}
if (asc != null) {
for (String sort : asc) {
params.addAscSortItem(getSortItem(sort, pr));
}
}
if (desc != null) {
for (String sort : desc) {
params.addDescSortItem(getSortItem(sort, pr));
}
}
return params.withProgram(pr).withProgramStage(ps).withStartDate(startDate).withEndDate(endDate).withOrganisationUnitMode(ouMode).withSkipMeta(skipMeta).withSkipData(skipData).withCompletedOnly(completedOnly).withHierarchyMeta(hierarchyMeta).withCoordinatesOnly(coordinatesOnly).withEventStatus(eventStatus).withDisplayProperty(displayProperty).withCoordinateField(getCoordinateField(coordinateField)).withPage(page).withPageSize(pageSize).withProgramStatus(programStatus).withApiVersion(apiVersion).build();
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class DefaultEventQueryPlanner method planAggregateQuery.
// TODO use list of functional groupers and single loop
@Override
public List<EventQueryParams> planAggregateQuery(EventQueryParams params) {
Set<String> validPartitions = partitionManager.getEventAnalyticsPartitions();
List<EventQueryParams> queries = new ArrayList<>();
List<EventQueryParams> groupedByQueryItems = groupByQueryItems(params);
for (EventQueryParams byQueryItem : groupedByQueryItems) {
List<EventQueryParams> groupedByPartition = groupByPartition(byQueryItem, validPartitions);
for (EventQueryParams byPartition : groupedByPartition) {
List<EventQueryParams> groupedByOrgUnitLevel = QueryPlannerUtils.convert(queryPlanner.groupByOrgUnitLevel(byPartition));
for (EventQueryParams byOrgUnitLevel : groupedByOrgUnitLevel) {
queries.addAll(QueryPlannerUtils.convert(queryPlanner.groupByPeriodType(byOrgUnitLevel)));
}
}
}
return queries;
}
Aggregations