use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsManager method getAggregatedEventData.
private void getAggregatedEventData(Grid grid, EventQueryParams params, String sql) {
log.debug("Analytics event aggregate SQL: " + sql);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while (rowSet.next()) {
grid.addRow();
if (params.isAggregateData()) {
if (params.hasValueDimension()) {
String itemId = params.getProgram().getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + params.getValue().getUid();
grid.addValue(itemId);
} else if (params.hasProgramIndicatorDimension()) {
grid.addValue(params.getProgramIndicator().getUid());
}
} else {
for (QueryItem queryItem : params.getItems()) {
String itemValue = rowSet.getString(queryItem.getItemName());
String gridValue = params.isCollapseDataDimensions() ? getCollapsedDataItemValue(params, queryItem, itemValue) : itemValue;
grid.addValue(gridValue);
}
}
for (DimensionalObject dimension : params.getDimensions()) {
String dimensionValue = rowSet.getString(dimension.getDimensionName());
grid.addValue(dimensionValue);
}
if (params.hasValueDimension()) {
double value = rowSet.getDouble("value");
grid.addValue(params.isSkipRounding() ? value : getRounded(value));
} else if (params.hasProgramIndicatorDimension()) {
double value = rowSet.getDouble("value");
ProgramIndicator indicator = params.getProgramIndicator();
grid.addValue(AnalyticsUtils.getRoundedValue(params, indicator.getDecimals(), value));
} else {
int value = rowSet.getInt("value");
grid.addValue(value);
}
if (params.isIncludeNumDen()) {
grid.addNullValues(3);
}
}
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getPartitionSelectColumns.
/**
* Returns the dynamic select columns. Dimensions come first and query items
* second. Program indicator expressions are exploded into attributes and
* data element identifiers.
*
* @param params the {@link EventQueryParams}.
*/
private List<String> getPartitionSelectColumns(EventQueryParams params) {
List<String> columns = Lists.newArrayList();
for (DimensionalObject dimension : params.getDimensions()) {
columns.add(dimension.getDimensionName());
}
for (QueryItem queryItem : params.getItems()) {
if (queryItem.isProgramIndicator()) {
ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
Set<String> uids = ProgramIndicator.getDataElementAndAttributeIdentifiers(in.getExpression(), in.getAnalyticsType());
columns.addAll(uids);
} else {
columns.add(queryItem.getItemName());
}
}
return columns;
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getAggregatedEventData.
private void getAggregatedEventData(Grid grid, EventQueryParams params, String sql) {
log.debug(String.format("Analytics event aggregate SQL: %s", sql));
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while (rowSet.next()) {
grid.addRow();
if (params.isAggregateData()) {
if (params.hasValueDimension()) {
String itemId = params.getProgram().getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + params.getValue().getUid();
grid.addValue(itemId);
} else if (params.hasProgramIndicatorDimension()) {
grid.addValue(params.getProgramIndicator().getUid());
}
} else {
for (QueryItem queryItem : params.getItems()) {
String itemValue = rowSet.getString(queryItem.getItemName());
String gridValue = params.isCollapseDataDimensions() ? getCollapsedDataItemValue(params, queryItem, itemValue) : itemValue;
grid.addValue(gridValue);
}
}
for (DimensionalObject dimension : params.getDimensions()) {
String dimensionValue = rowSet.getString(dimension.getDimensionName());
grid.addValue(dimensionValue);
}
if (params.hasValueDimension()) {
double value = rowSet.getDouble("value");
grid.addValue(params.isSkipRounding() ? value : getRounded(value));
} else if (params.hasProgramIndicatorDimension()) {
double value = rowSet.getDouble("value");
ProgramIndicator indicator = params.getProgramIndicator();
grid.addValue(AnalyticsUtils.getRoundedValue(params, indicator.getDecimals(), value));
} else {
int value = rowSet.getInt("value");
grid.addValue(value);
}
if (params.isIncludeNumDen()) {
grid.addNullValues(3);
}
}
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getSelectColumns.
/**
* Returns the dynamic select columns. Dimensions come first and query items
* second. Program indicator expressions are converted to SQL expressions.
*
* @param params the {@link EventQueryParams}.
*/
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, " + COORD_DEC + ") ||" + "',' || round(ST_Y(" + colName + ")::numeric, " + COORD_DEC + ") || ']' as " + colName;
columns.add(coordSql);
} else {
columns.add(statementBuilder.columnQuote(queryItem.getItemName()));
}
}
return columns;
}
use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.
the class DefaultDimensionService method getDimensionType.
@Override
public DimensionType getDimensionType(String uid) {
DataElementCategory cat = idObjectManager.get(DataElementCategory.class, uid);
if (cat != null) {
return DimensionType.CATEGORY;
}
DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
if (degs != null) {
return DimensionType.DATA_ELEMENT_GROUP_SET;
}
OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
if (ougs != null) {
return DimensionType.ORGANISATION_UNIT_GROUP_SET;
}
CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
if (cogs != null) {
return DimensionType.CATEGORY_OPTION_GROUP_SET;
}
TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
if (tea != null) {
return DimensionType.PROGRAM_ATTRIBUTE;
}
DataElement pde = idObjectManager.get(DataElement.class, uid);
if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
return DimensionType.PROGRAM_DATA_ELEMENT;
}
ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
if (pin != null) {
return DimensionType.PROGRAM_INDICATOR;
}
final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
return dimObjectTypeMap.get(uid);
}
Aggregations