use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class AbstractEventService method getEventsGrid.
@Override
public Grid getEventsGrid(EventSearchParams params) {
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params);
// ---------------------------------------------------------------------
if (params.getDataElements().isEmpty() && params.getProgramStage() != null && params.getProgramStage().getProgramStageDataElements() != null) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
if (pde.getDisplayInReports()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
}
}
// ---------------------------------------------------------------------
// Grid headers
// ---------------------------------------------------------------------
Grid grid = new ListGrid();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addHeader(new GridHeader(col, col));
}
for (QueryItem item : params.getDataElements()) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
}
List<Map<String, String>> events = eventStore.getEventsGrid(params, organisationUnits);
for (Map<String, String> event : events) {
grid.addRow();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addValue(event.get(col));
}
for (QueryItem item : params.getDataElements()) {
grid.addValue(event.get(item.getItemId()));
}
}
Map<String, Object> metaData = new HashMap<>();
if (params.isPaging()) {
int count = 0;
if (params.isTotalPages()) {
count = eventStore.getEventCount(params, organisationUnits);
}
Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
metaData.put(PAGER_META_KEY, pager);
}
grid.setMetaData(metaData);
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getSectionDataSetReport.
@Override
public List<Grid> getSectionDataSetReport(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n) {
List<Section> sections = new ArrayList<>(dataSet.getSections());
Collections.sort(sections, new SectionOrderComparator());
Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, period, unit, dimensions);
Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, period, unit, dimensions);
Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, period, unit, dimensions);
List<Grid> grids = new ArrayList<>();
for (Section section : sections) {
for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + format.formatPeriod(period));
// -----------------------------------------------------------------
// Grid headers
// -----------------------------------------------------------------
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
for (DataElementCategoryOptionCombo optionCombo : optionCombos) {
grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
grid.addHeader(new GridHeader(categoryOption.getName(), false, false));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
grid.addHeader(new GridHeader(TOTAL_HEADER, false, false));
}
// -----------------------------------------------------------------
// Grid values
// -----------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(section.getDataElementsByCategoryCombo(categoryCombo));
FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
for (DataElement dataElement : dataElements) {
grid.addRow();
// Data element name
grid.addValue(new GridValue(dataElement.getFormNameFallback()));
for (// Values
DataElementCategoryOptionCombo optionCombo : // Values
optionCombos) {
Map<Object, Object> attributes = new HashMap<>();
attributes.put(ATTR_DE, dataElement.getUid());
attributes.put(ATTR_CO, optionCombo.getUid());
Object value = null;
if (selectedUnitOnly) {
DataValue dataValue = dataValueService.getDataValue(dataElement, period, unit, optionCombo);
value = dataValue != null && dataValue.getValue() != null ? Double.parseDouble(dataValue.getValue()) : null;
} else {
value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
}
grid.addValue(new GridValue(value, attributes));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
Object value = subTotalMap.get(dataElement.getUid() + SEPARATOR + categoryOption.getUid());
grid.addValue(new GridValue(value));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
Object value = totalMap.get(String.valueOf(dataElement.getUid()));
grid.addValue(new GridValue(value));
}
}
grids.add(grid);
}
}
return grids;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class AbstractGridView method renderMergedOutputModel.
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
Object object = model.get("model");
List<Grid> grids = new ArrayList<>();
if (WebMetadata.class.isAssignableFrom(object.getClass())) {
WebMetadata metadata = (WebMetadata) object;
Collection<Field> fields = ReflectionUtils.collectFields(WebMetadata.class, PredicateUtils.idObjectCollections);
for (Field field : fields) {
List<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod(field.getName(), metadata);
if (identifiableObjects == null || identifiableObjects.isEmpty()) {
continue;
}
Grid grid = new ListGrid();
grid.setTitle(identifiableObjects.get(0).getClass().getSimpleName() + "s");
boolean nameable = false;
grid.addHeader(new GridHeader("UID", false, false));
grid.addHeader(new GridHeader("Name", false, false));
if (NameableObject.class.isAssignableFrom(identifiableObjects.get(0).getClass())) {
grid.addHeader(new GridHeader("ShortName", false, false));
nameable = true;
}
grid.addHeader(new GridHeader("Code", false, false));
for (IdentifiableObject identifiableObject : identifiableObjects) {
grid.addRow();
grid.addValue(identifiableObject.getUid());
grid.addValue(identifiableObject.getName());
if (nameable) {
grid.addValue(((NameableObject) identifiableObject).getShortName());
}
grid.addValue(identifiableObject.getCode());
}
grids.add(grid);
}
} else {
IdentifiableObject identifiableObject = (IdentifiableObject) object;
Grid grid = new ListGrid();
grid.setTitle(identifiableObject.getClass().getSimpleName());
grid.addEmptyHeaders(2);
grid.addRow().addValue("UID").addValue(identifiableObject.getUid());
grid.addRow().addValue("Name").addValue(identifiableObject.getName());
if (NameableObject.class.isAssignableFrom(identifiableObject.getClass())) {
grid.addRow().addValue("ShortName").addValue(((NameableObject) identifiableObject).getShortName());
grid.addRow().addValue("Description").addValue(((NameableObject) identifiableObject).getDescription());
}
grid.addRow().addValue("Code").addValue(identifiableObject.getCode());
grids.add(grid);
}
renderGrids(grids, response);
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class ExportAnalysisResultAction method generateGrid.
@SuppressWarnings("unchecked")
private Grid generateGrid() {
List<DeflatedDataValue> results = (List<DeflatedDataValue>) SessionUtils.getSessionVar(GetAnalysisAction.KEY_ANALYSIS_DATA_VALUES);
Grid grid = new ListGrid();
grid.setTitle(i18n.getString("data_analysis_report"));
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
grid.addHeader(new GridHeader(i18n.getString("min"), false, false));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("max"), false, false));
for (DeflatedDataValue dataValue : results) {
Period period = dataValue.getPeriod();
grid.addRow();
grid.addValue(dataValue.getDataElementName());
grid.addValue(dataValue.getSourceName());
grid.addValue(format.formatPeriod(period));
grid.addValue(dataValue.getMin());
grid.addValue(dataValue.getValue());
grid.addValue(dataValue.getMax());
}
return grid;
}
Aggregations