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 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;
}
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);
}
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));
}
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());
}
Aggregations