use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class DhisConvenienceTest method createProgramIndicator.
public static ProgramIndicator createProgramIndicator(char uniqueCharacter, Program program, String expression, String filter) {
ProgramIndicator indicator = new ProgramIndicator();
indicator.setAutoFields();
indicator.setName("Indicator" + uniqueCharacter);
indicator.setShortName("IndicatorShort" + uniqueCharacter);
indicator.setCode("IndicatorCode" + uniqueCharacter);
indicator.setDescription("IndicatorDescription" + uniqueCharacter);
indicator.setProgram(program);
indicator.setExpression(expression);
indicator.setFilter(filter);
return indicator;
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetByDataDimensionType.
@Test
public void testGetByDataDimensionType() {
Program prA = createProgram('A');
DataElement deA = createDataElement('A', new DataElementCategoryCombo());
DataElement deB = createDataElement('B', new DataElementCategoryCombo());
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
use of org.hisp.dhis.program.ProgramIndicator 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.program.ProgramIndicator in project dhis2-core by dhis2.
the class EventQueryParams method fromDataQueryParams.
public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
EventQueryParams params = new EventQueryParams();
dataQueryParams.copyTo(params);
EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
ProgramIndicator programIndicator = (ProgramIndicator) object;
builder.addItemProgramIndicator(programIndicator);
}
return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsManager method getSelectColumns.
/**
* Returns the dynamic select columns. Dimensions come first and query items
* second. Program indicator expressions are converted to SQL expressions.
*/
private List<String> getSelectColumns(EventQueryParams params) {
List<String> columns = Lists.newArrayList();
for (DimensionalObject dimension : params.getDimensions()) {
columns.add(statementBuilder.columnQuote(dimension.getDimensionName()));
}
for (QueryItem queryItem : params.getItems()) {
if (queryItem.isProgramIndicator()) {
ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
String asClause = " as " + statementBuilder.columnQuote(in.getUid());
columns.add("(" + programIndicatorService.getAnalyticsSQl(in.getExpression(), in.getAnalyticsType(), params.getEarliestStartDate(), params.getLatestEndDate()) + ")" + asClause);
} else if (ValueType.COORDINATE == queryItem.getValueType()) {
String colName = statementBuilder.columnQuote(queryItem.getItemName());
String coordSql = "'[' || round(ST_X(" + colName + ")::numeric, 6) || ',' || round(ST_Y(" + colName + ")::numeric, 6) || ']' as " + colName;
columns.add(coordSql);
} else {
columns.add(statementBuilder.columnQuote(queryItem.getItemName()));
}
}
return columns;
}
Aggregations