use of org.hisp.dhis.common.DimensionalItemObject 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.common.DimensionalItemObject in project dhis2-core by dhis2.
the class QueryPlannerUtils method getAggregationTypeDataElementMap.
/**
* Creates a mapping between the aggregation type and data element for the
* given data elements and period type.
*
* @param params the data query parameters.
*/
public static ListMap<AggregationType, DimensionalItemObject> getAggregationTypeDataElementMap(DataQueryParams params) {
List<DimensionalItemObject> dataElements = params.getDataElements();
PeriodType aggregationPeriodType = PeriodType.getPeriodTypeByName(params.getPeriodType());
ListMap<AggregationType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement de = (DataElement) element;
AggregationType type = ObjectUtils.firstNonNull(params.getAggregationType(), de.getAggregationType());
AggregationType aggregationType = getAggregationType(de.getValueType(), type, aggregationPeriodType, de.getPeriodType());
map.putValue(aggregationType, de);
}
return map;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class QueryPlannerUtils method getDataTypeDataElementMap.
/**
* Creates a mapping between data type and data element for the given data
* elements.
*
* @param dataElements list of data elements.
*/
public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap(List<DimensionalItemObject> dataElements) {
ListMap<DataType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement dataElement = (DataElement) element;
ValueType valueType = dataElement.getValueType();
// Both Text and Date types are recognized as TEXT
DataType dataType = (valueType.isText() || valueType.isDate()) ? DataType.TEXT : DataType.NUMERIC;
map.putValue(dataType, dataElement);
}
return map;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class EventQueryParams method getOrganisationUnitChildren.
public Set<OrganisationUnit> getOrganisationUnitChildren() {
Set<OrganisationUnit> children = new HashSet<>();
for (DimensionalItemObject object : getDimensionOrFilterItems(DimensionalObject.ORGUNIT_DIM_ID)) {
OrganisationUnit unit = (OrganisationUnit) object;
children.addAll(unit.getChildren());
}
return children;
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ReportTable method getGrid.
/**
* Generates a grid for this report table based on the given aggregate value
* map.
*
* @param grid the grid, should be empty and not null.
* @param valueMap the mapping of identifiers to aggregate values.
* @param displayProperty the display property to use for meta data.
* @param reportParamColumns whether to include report parameter columns.
* @return a grid.
*/
public Grid getGrid(Grid grid, Map<String, Object> valueMap, DisplayProperty displayProperty, boolean reportParamColumns) {
valueMap = new HashMap<>(valueMap);
sortKeys(valueMap);
if (name != null) {
grid.setTitle(name);
grid.setSubtitle(gridTitle);
} else {
grid.setTitle(gridTitle);
}
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Map<String, String> metaData = getMetaData();
metaData.putAll(DimensionalObject.PRETTY_NAMES);
for (String row : rowDimensions) {
String name = StringUtils.defaultIfEmpty(metaData.get(row), row);
String col = StringUtils.defaultIfEmpty(COLUMN_NAMES.get(row), row);
grid.addHeader(new GridHeader(name + " ID", col + "id", ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader(name, col + "name", ValueType.TEXT, String.class.getName(), false, true));
grid.addHeader(new GridHeader(name + " code", col + "code", ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader(name + " description", col + "description", ValueType.TEXT, String.class.getName(), true, true));
}
if (reportParamColumns) {
grid.addHeader(new GridHeader("Reporting month", REPORTING_MONTH_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader("Organisation unit parameter", PARAM_ORGANISATIONUNIT_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
grid.addHeader(new GridHeader("Organisation unit is parent", ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME, ValueType.TEXT, String.class.getName(), true, true));
}
final int startColumnIndex = grid.getHeaders().size();
final int numberOfColumns = getGridColumns().size();
for (List<DimensionalItemObject> column : gridColumns) {
grid.addHeader(new GridHeader(getPrettyColumnName(column, displayProperty), getColumnName(column), ValueType.NUMBER, Double.class.getName(), false, false));
}
for (List<DimensionalItemObject> row : gridRows) {
grid.addRow();
for (DimensionalItemObject object : row) {
grid.addValue(object.getDimensionItem());
grid.addValue(object.getDisplayProperty(displayProperty));
grid.addValue(object.getCode());
grid.addValue(object.getDisplayDescription());
}
if (reportParamColumns) {
grid.addValue(reportingPeriodName);
grid.addValue(getParentOrganisationUnitName());
grid.addValue(isCurrentParent(row) ? "Yes" : "No");
}
// -----------------------------------------------------------------
// Row data values
// -----------------------------------------------------------------
boolean hasValue = false;
for (List<DimensionalItemObject> column : gridColumns) {
String key = getIdentifier(column, row);
Object value = valueMap.get(key);
grid.addValue(value);
hasValue = hasValue || value != null;
}
if (hideEmptyRows && !hasValue) {
grid.removeCurrentWriteRow();
}
// TODO hide empty columns
}
if (hideEmptyColumns) {
grid.removeEmptyColumns();
}
if (regression) {
grid.addRegressionToGrid(startColumnIndex, numberOfColumns);
}
if (cumulative) {
grid.addCumulativesToGrid(startColumnIndex, numberOfColumns);
}
if (sortOrder != BaseAnalyticalObject.NONE) {
grid.sortGrid(grid.getWidth(), sortOrder);
}
if (topLimit > 0) {
grid.limitGrid(topLimit);
}
if (showHierarchy && rowDimensions.contains(ORGUNIT_DIM_ID) && grid.hasInternalMetaDataKey(AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS.getKey())) {
int ouIdColumnIndex = rowDimensions.indexOf(ORGUNIT_DIM_ID) * 4;
addHierarchyColumns(grid, ouIdColumnIndex);
}
return grid;
}
Aggregations