Search in sources :

Example 21 with ListGrid

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) Pager(org.hisp.dhis.common.Pager) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Map(java.util.Map) HashMap(java.util.HashMap) CachingMap(org.hisp.dhis.commons.collection.CachingMap)

Example 22 with ListGrid

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;
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) HashMap(java.util.HashMap) DataValue(org.hisp.dhis.datavalue.DataValue) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Section(org.hisp.dhis.dataset.Section) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) GridValue(org.hisp.dhis.common.GridValue) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 23 with ListGrid

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);
}
Also used : Field(java.lang.reflect.Field) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) GridHeader(org.hisp.dhis.common.GridHeader)

Example 24 with ListGrid

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

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)24 Grid (org.hisp.dhis.common.Grid)16 GridHeader (org.hisp.dhis.common.GridHeader)9 DimensionalObject (org.hisp.dhis.common.DimensionalObject)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)5 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 List (java.util.List)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DisplayProperty (org.hisp.dhis.common.DisplayProperty)2 Pager (org.hisp.dhis.common.Pager)2 QueryItem (org.hisp.dhis.common.QueryItem)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)2