use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class DefaultOrgUnitDistributionService method getOrganisationUnitDistribution.
@Override
@Transactional
public Grid getOrganisationUnitDistribution(OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit, boolean organisationUnitOnly) {
Grid grid = new ListGrid();
grid.setTitle(groupSet.getName() + TITLE_SEP + organisationUnit.getName());
List<OrganisationUnit> units = organisationUnitOnly ? Arrays.asList(organisationUnit) : new ArrayList<>(organisationUnit.getChildren());
List<OrganisationUnitGroup> groups = new ArrayList<>(groupSet.getOrganisationUnitGroups());
Collections.sort(units);
Collections.sort(groups);
if (!organisationUnitOnly) {
// Add parent itself to the end to get the total
units.add(organisationUnit);
}
grid.addHeader(new GridHeader(FIRST_COLUMN_TEXT, FIRST_COLUMN_TEXT, ValueType.TEXT, String.class.getName(), false, true));
for (OrganisationUnitGroup group : groups) {
grid.addHeader(new GridHeader(group.getName(), false, false));
}
grid.addHeader(new GridHeader(HEADER_TOTAL, false, false));
for (OrganisationUnit unit : units) {
grid.addRow();
grid.addValue(unit.getName());
int totalGroup = 0;
Set<OrganisationUnit> subTree = new HashSet<>(organisationUnitService.getOrganisationUnitWithChildren(unit.getId()));
for (OrganisationUnitGroup group : groups) {
Set<OrganisationUnit> result = Sets.intersection(subTree, group.getMembers());
int count = result != null ? result.size() : 0;
grid.addValue(count);
totalGroup += count;
}
grid.addValue(totalGroup);
}
return grid;
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class ExportValidationResultAction method generateGrid.
@SuppressWarnings("unchecked")
private Grid generateGrid() {
List<ValidationResult> results = (List<ValidationResult>) SessionUtils.getSessionVar(KEY_VALIDATIONRESULT);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Grid grid = new ListGrid();
grid.setTitle(i18n.getString("data_quality_report"));
if (organisationUnit != null) {
grid.setSubtitle(organisationUnit.getName());
}
grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
grid.addHeader(new GridHeader(i18n.getString("validation_rule"), false, true));
grid.addHeader(new GridHeader(i18n.getString("importance"), false, true));
grid.addHeader(new GridHeader(i18n.getString("left_side_description"), false, true));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("operator"), false, false));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("right_side_description"), false, true));
for (ValidationResult validationResult : results) {
OrganisationUnit unit = validationResult.getOrganisationUnit();
Period period = validationResult.getPeriod();
grid.addRow();
grid.addValue(unit.getName());
grid.addValue(format.formatPeriod(period));
grid.addValue(validationResult.getValidationRule().getName());
grid.addValue(i18n.getString(validationResult.getValidationRule().getImportance().toString().toLowerCase()));
//TODO lazy prone
grid.addValue(validationResult.getValidationRule().getLeftSide().getDescription());
grid.addValue(String.valueOf(validationResult.getLeftsideValue()));
grid.addValue(i18n.getString(validationResult.getValidationRule().getOperator().toString()));
grid.addValue(String.valueOf(validationResult.getRightsideValue()));
grid.addValue(validationResult.getValidationRule().getRightSide().getDescription());
}
return grid;
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GetDataCompletenessAction method getGrid.
private Grid getGrid(List<DataSetCompletenessResult> mainResults, List<DataSetCompletenessResult> footerResults, OrganisationUnit unit, DataSet dataSet, Period period) {
String title = (unit != null ? unit.getName() : EMPTY) + (dataSet != null ? TITLE_SEP + dataSet.getName() : EMPTY) + (period != null ? TITLE_SEP + format.formatPeriod(period) : EMPTY);
Grid grid = new ListGrid().setTitle(title);
grid.addHeader(new GridHeader(i18n.getString("name"), false, true));
grid.addHeader(new GridHeader(i18n.getString("actual_reports"), false, false));
grid.addHeader(new GridHeader(i18n.getString("expected_reports"), false, false));
grid.addHeader(new GridHeader(i18n.getString("percent"), false, false));
grid.addHeader(new GridHeader(i18n.getString("reports_on_time"), false, false));
grid.addHeader(new GridHeader(i18n.getString("percent_on_time"), false, false));
for (DataSetCompletenessResult result : mainResults) {
addRow(grid, result);
}
if (grid.getWidth() >= 4) {
grid.sortGrid(4, 1);
}
for (DataSetCompletenessResult result : footerResults) {
addRow(grid, result);
}
return grid;
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class AnalyticsUtils method handleGridForDataValueSet.
/**
* Prepares the given grid to be converted to a data value set.
*
* <ul>
* <li>Converts data values from double to integer based on the associated
* data item if required.</li>
* <li>Adds a category option combo and a attribute option combo column to
* the grid based on the aggregated export properties of the associated data
* item.</li>
* <li>For data element operand data items, the operand identifier is split
* and the data element identifier is used for the data dimension column and
* the category option combo identifier is used for the category option
* combo column.</li>
* </ul>
*
* @param params the data query parameters.
* @param grid the grid.
*/
public static void handleGridForDataValueSet(DataQueryParams params, Grid grid) {
Map<String, DimensionalItemObject> dimItemObjectMap = AnalyticsUtils.getDimensionalItemObjectMap(params);
List<Object> cocCol = Lists.newArrayList();
List<Object> aocCol = Lists.newArrayList();
int dxInx = grid.getIndexOfHeader(DATA_X_DIM_ID);
int vlInx = grid.getHeaderWidth() - 1;
Assert.isTrue(dxInx >= 0, "Data dimension index must be greater than or equal to zero");
Assert.isTrue(vlInx >= 0, "Value index must be greater than or equal to zero");
for (List<Object> row : grid.getRows()) {
String dx = String.valueOf(row.get(dxInx));
Assert.notNull(dx, "Data dimension item cannot be null");
DimensionalItemObject item = dimItemObjectMap.get(dx);
Assert.notNull(item, "Dimensional item cannot be null");
Object value = AnalyticsUtils.getIntegerOrValue(row.get(vlInx), item);
row.set(vlInx, value);
String coc = null, aoc = null;
if (DataDimensionalItemObject.class.isAssignableFrom(item.getClass())) {
DataDimensionalItemObject dataItem = (DataDimensionalItemObject) item;
coc = dataItem.getAggregateExportCategoryOptionCombo();
aoc = dataItem.getAggregateExportAttributeOptionCombo();
} else if (DataElementOperand.class.isAssignableFrom(item.getClass())) {
row.set(dxInx, DimensionalObjectUtils.getFirstIdentifer(dx));
coc = DimensionalObjectUtils.getSecondIdentifer(dx);
}
cocCol.add(coc);
aocCol.add(aoc);
}
grid.addHeader(vlInx, new GridHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTEOPTIONCOMBO_DIM_ID, ValueType.TEXT, false, true)).addHeader(vlInx, new GridHeader(CATEGORYOPTIONCOMBO_DIM_ID, CATEGORYOPTIONCOMBO_DIM_ID, ValueType.TEXT, false, true)).addColumn(vlInx, aocCol).addColumn(vlInx, cocCol);
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class Visualization method getGrid.
/**
* Generates a grid for this visualization 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(final Grid grid, Map<String, Object> valueMap, final DisplayProperty displayProperty, final boolean reportParamColumns) {
valueMap = getSortedKeysMap(valueMap);
if (name != null) {
grid.setTitle(name);
grid.setSubtitle(gridTitle);
} else {
grid.setTitle(gridTitle);
}
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
final Map<String, String> metaData = getMetaData();
metaData.putAll(PRETTY_NAMES);
for (String dimension : rowDimensions) {
final String dimensionId = getDimensionIdentifierFor(dimension, getDimensionDescriptors());
final String name = defaultIfEmpty(metaData.get(dimensionId), dimensionId);
final String col = defaultIfEmpty(COLUMN_NAMES.get(dimensionId), dimensionId);
grid.addHeader(new GridHeader(name + " ID", col + "id", TEXT, true, true));
grid.addHeader(new GridHeader(name, col + "name", TEXT, false, true));
grid.addHeader(new GridHeader(name + " code", col + "code", TEXT, true, true));
grid.addHeader(new GridHeader(name + " description", col + "description", TEXT, true, true));
}
if (reportParamColumns) {
grid.addHeader(new GridHeader("Reporting month", REPORTING_MONTH_COLUMN_NAME, TEXT, true, true));
grid.addHeader(new GridHeader("Organisation unit parameter", PARAM_ORGANISATIONUNIT_COLUMN_NAME, TEXT, true, true));
grid.addHeader(new GridHeader("Organisation unit is parent", ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME, TEXT, true, true));
}
final int startColumnIndex = grid.getHeaders().size();
final int numberOfColumns = getGridColumns().size();
for (List<DimensionalItemObject> column : gridColumns) {
grid.addHeader(new GridHeader(getColumnName(column), getPrettyColumnName(column, displayProperty), NUMBER, 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(visualizationPeriodName);
grid.addValue(getParentOrganisationUnitName());
grid.addValue(isCurrentParent(row) ? "Yes" : "No");
}
// -----------------------------------------------------------------
// Row data values
// -----------------------------------------------------------------
boolean hasValue = false;
for (List<DimensionalItemObject> column : gridColumns) {
final String key = DimensionalObjectUtils.getKey(column, row);
final 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 (cumulativeValues) {
grid.addCumulativesToGrid(startColumnIndex, numberOfColumns);
}
if (sortOrder != NONE) {
grid.sortGrid(grid.getWidth(), sortOrder);
}
if (topLimit > 0) {
grid.limitGrid(topLimit);
}
if (showHierarchy && rowDimensions.contains(ORGUNIT_DIM_ID) && grid.hasInternalMetaDataKey(ORG_UNIT_ANCESTORS.getKey())) {
final int ouIdColumnIndex = rowDimensions.indexOf(ORGUNIT_DIM_ID) * 4;
addHierarchyColumns(grid, ouIdColumnIndex);
}
return grid;
}
Aggregations