Search in sources :

Example 1 with ListGrid

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;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ListGrid

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) ArrayList(java.util.ArrayList) ReportTable(org.hisp.dhis.reporttable.ReportTable) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 3 with ListGrid

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) List(java.util.List) ValidationResult(org.hisp.dhis.validation.ValidationResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 4 with ListGrid

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;
}
Also used : DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 5 with ListGrid

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());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)58 Grid (org.hisp.dhis.common.Grid)41 GridHeader (org.hisp.dhis.common.GridHeader)28 Test (org.junit.jupiter.api.Test)21 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)14 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)11 ArrayList (java.util.ArrayList)10 DimensionalObject (org.hisp.dhis.common.DimensionalObject)10 HashMap (java.util.HashMap)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 DataElement (org.hisp.dhis.dataelement.DataElement)8 List (java.util.List)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 Test (org.junit.Test)7 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5