use of org.hisp.dhis.system.grid.ListGrid 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.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultReportTableService method getReportTableGridByUser.
@Override
public Grid getReportTableGridByUser(String uid, Date reportingPeriod, String organisationUnitUid, User user) {
I18nFormat format = i18nManager.getI18nFormat();
ReportTable reportTable = getReportTable(uid);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
List<OrganisationUnit> atLevels = new ArrayList<>();
List<OrganisationUnit> inGroups = new ArrayList<>();
if (reportTable.hasOrganisationUnitLevels()) {
atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(reportTable.getOrganisationUnitLevels(), reportTable.getOrganisationUnits()));
}
if (reportTable.hasItemOrganisationUnitGroups()) {
inGroups.addAll(organisationUnitService.getOrganisationUnits(reportTable.getItemOrganisationUnitGroups(), reportTable.getOrganisationUnits()));
}
reportTable.init(user, reportingPeriod, organisationUnit, atLevels, inGroups, format);
Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(reportTable);
Grid reportTableGrid = reportTable.getGrid(new ListGrid(), valueMap, DisplayProperty.SHORTNAME, true);
reportTable.clearTransientState();
return reportTableGrid;
}
use of org.hisp.dhis.system.grid.ListGrid 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.system.grid.ListGrid 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.system.grid.ListGrid in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetDataValueSetFromGridWithDuplicates.
@Test
public void testGetDataValueSetFromGridWithDuplicates() {
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peA", null, null, 1d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peB", null, null, 2d));
// Duplicate
grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peB", null, null, 2d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peA", null, null, 3d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peB", null, null, 4d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peA", null, null, 5d));
// Duplicate
grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peA", null, null, 5d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peB", null, null, 6d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peA", null, null, 7d));
// Duplicate
grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peA", null, null, 7d));
grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peB", null, null, 8d));
DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().withDuplicatesOnly(true).build(), grid);
assertNotNull(dvs);
assertNotNull(dvs.getDataValues());
assertEquals(3, dvs.getDataValues().size());
}
Aggregations