Search in sources :

Example 6 with GridHeader

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;
}
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 7 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class DefaultTrackedEntityInstanceService method getTrackedEntityInstancesGrid.

// TODO lower index on attribute value?
@Override
public Grid getTrackedEntityInstancesGrid(TrackedEntityInstanceQueryParams params) {
    decideAccess(params);
    validate(params);
    handleAttributes(params);
    params.setUser(currentUserService.getCurrentUser());
    // ---------------------------------------------------------------------
    // Conform parameters
    // ---------------------------------------------------------------------
    params.conform();
    // ---------------------------------------------------------------------
    // Grid headers
    // ---------------------------------------------------------------------
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(TRACKED_ENTITY_INSTANCE_ID, "Instance"));
    grid.addHeader(new GridHeader(CREATED_ID, "Created"));
    grid.addHeader(new GridHeader(LAST_UPDATED_ID, "Last updated"));
    grid.addHeader(new GridHeader(ORG_UNIT_ID, "Organisation unit"));
    grid.addHeader(new GridHeader(ORG_UNIT_NAME, "Organisation unit name"));
    grid.addHeader(new GridHeader(TRACKED_ENTITY_ID, "Tracked entity"));
    grid.addHeader(new GridHeader(INACTIVE_ID, "Inactive"));
    if (params.isIncludeDeleted()) {
        grid.addHeader(new GridHeader(DELETED, "Deleted", ValueType.BOOLEAN, "boolean", false, false));
    }
    for (QueryItem item : params.getAttributes()) {
        grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
    }
    List<Map<String, String>> entities = trackedEntityInstanceStore.getTrackedEntityInstancesGrid(params);
    // ---------------------------------------------------------------------
    // Grid rows
    // ---------------------------------------------------------------------
    Set<String> tes = new HashSet<>();
    for (Map<String, String> entity : entities) {
        grid.addRow();
        grid.addValue(entity.get(TRACKED_ENTITY_INSTANCE_ID));
        grid.addValue(entity.get(CREATED_ID));
        grid.addValue(entity.get(LAST_UPDATED_ID));
        grid.addValue(entity.get(ORG_UNIT_ID));
        grid.addValue(entity.get(ORG_UNIT_NAME));
        grid.addValue(entity.get(TRACKED_ENTITY_ID));
        grid.addValue(entity.get(INACTIVE_ID));
        if (params.isIncludeDeleted()) {
            grid.addValue(entity.get(DELETED));
        }
        tes.add(entity.get(TRACKED_ENTITY_ID));
        for (QueryItem item : params.getAttributes()) {
            grid.addValue(entity.get(item.getItemId()));
        }
    }
    Map<String, Object> metaData = new HashMap<>();
    if (params.isPaging()) {
        int count = 0;
        if (params.isTotalPages()) {
            count = trackedEntityInstanceStore.getTrackedEntityInstanceCount(params);
        }
        Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
        metaData.put(PAGER_META_KEY, pager);
    }
    if (!params.isSkipMeta()) {
        Map<String, String> names = new HashMap<>();
        for (String te : tes) {
            TrackedEntity entity = trackedEntityService.getTrackedEntity(te);
            names.put(te, entity != null ? entity.getDisplayName() : null);
        }
        metaData.put(META_DATA_NAMES_KEY, names);
    }
    grid.setMetaData(metaData);
    return grid;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) HashMap(java.util.HashMap) 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) Pager(org.hisp.dhis.common.Pager) DimensionalObject(org.hisp.dhis.common.DimensionalObject) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class GridTest method setUp.

@Before
public void setUp() {
    gridA = new ListGrid();
    gridB = new ListGrid();
    headerA = new GridHeader("ColA", "colA", ValueType.TEXT, String.class.getName(), false, true);
    headerB = new GridHeader("ColB", "colB", ValueType.TEXT, String.class.getName(), false, true);
    headerC = new GridHeader("ColC", "colC", ValueType.TEXT, String.class.getName(), true, false);
    gridA.addHeader(headerA);
    gridA.addHeader(headerB);
    gridA.addHeader(headerC);
    gridA.addRow();
    gridA.addValue(11);
    gridA.addValue(12);
    gridA.addValue(13);
    gridA.addRow();
    gridA.addValue(21);
    gridA.addValue(22);
    gridA.addValue(23);
    gridA.addRow();
    gridA.addValue(31);
    gridA.addValue(32);
    gridA.addValue(33);
    gridA.addRow();
    gridA.addValue(41);
    gridA.addValue(42);
    gridA.addValue(43);
    gridB.addRow();
    gridB.addValue(11);
    gridB.addValue(12);
    gridB.addValue(13);
}
Also used : GridHeader(org.hisp.dhis.common.GridHeader) Before(org.junit.Before)

Example 9 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class GridTest method testAddHeaders.

@Test
public void testAddHeaders() {
    Grid grid = new ListGrid();
    GridHeader headerA = new GridHeader("DataElementA", "Data element A");
    GridHeader headerB = new GridHeader("DataElementB", "Data element B");
    GridHeader headerC = new GridHeader("DataElementC", "Data element C");
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    assertEquals(2, grid.getHeaders().size());
    assertEquals(headerA, grid.getHeaders().get(0));
    assertEquals(headerB, grid.getHeaders().get(1));
    grid.addHeader(1, headerC);
    assertEquals(3, grid.getHeaders().size());
    assertEquals(headerA, grid.getHeaders().get(0));
    assertEquals(headerC, grid.getHeaders().get(1));
    assertEquals(headerB, grid.getHeaders().get(2));
}
Also used : Grid(org.hisp.dhis.common.Grid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.Test)

Example 10 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class GridTest method testRemoveEmptyColumns.

@Test
public void testRemoveEmptyColumns() {
    Grid grid = new ListGrid().addHeader(new GridHeader("H1")).addHeader(new GridHeader("H2")).addHeader(new GridHeader("H3")).addHeader(new GridHeader("H4")).addRow().addValuesVar("A1", null, "A3", null).addRow().addValuesVar("B1", null, "B3", null).addRow().addValuesVar(null, null, "C3", null).addRow().addValuesVar("D1", null, null, null);
    assertEquals(4, grid.getHeaders().size());
    assertEquals(4, grid.getWidth());
    grid.removeEmptyColumns();
    assertEquals(2, grid.getWidth());
}
Also used : Grid(org.hisp.dhis.common.Grid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.Test)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)27 Grid (org.hisp.dhis.common.Grid)14 ArrayList (java.util.ArrayList)9 ListGrid (org.hisp.dhis.system.grid.ListGrid)9 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 QueryItem (org.hisp.dhis.common.QueryItem)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)2 MetadataObject (org.hisp.dhis.common.MetadataObject)2 Pager (org.hisp.dhis.common.Pager)2 Period (org.hisp.dhis.period.Period)2 CsvWriter (com.csvreader.CsvWriter)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1