Search in sources :

Example 1 with GridValue

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

the class DefaultDataSetReportService method getSectionDataSetReport.

private List<Grid> getSectionDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
    I18nFormat format = i18nManager.getI18nFormat();
    I18n i18n = i18nManager.getI18n();
    List<Section> sections = new ArrayList<>(dataSet.getSections());
    sections.sort(new SectionOrderComparator());
    Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, periods, unit, filters);
    Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, periods, unit, filters);
    Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, periods, unit, filters);
    List<Grid> grids = new ArrayList<>();
    for (Section section : sections) {
        for (CategoryCombo categoryCombo : section.getCategoryCombos()) {
            Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + formatPeriods(periods, format));
            // -----------------------------------------------------------------
            // Grid headers
            // -----------------------------------------------------------------
            grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
            List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
            for (CategoryOptionCombo optionCombo : optionCombos) {
                grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
            }
            if (// Sub-total
            categoryCombo.doSubTotals() && !selectedUnitOnly) {
                for (CategoryOption 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
                grid.addValue(new GridValue(dataElement.getFormNameFallback()));
                for (// Values
                CategoryOptionCombo optionCombo : // Values
                optionCombos) {
                    Map<Object, Object> attributes = new HashMap<>();
                    attributes.put(ATTR_DE, dataElement.getUid());
                    attributes.put(ATTR_CO, optionCombo.getUid());
                    Object value;
                    if (selectedUnitOnly) {
                        value = getSelectedUnitValue(dataElement, periods, unit, optionCombo);
                    } else {
                        value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
                    }
                    grid.addValue(new GridValue(value, attributes));
                }
                if (// Sub-total
                categoryCombo.doSubTotals() && !selectedUnitOnly) {
                    for (CategoryOption 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 : HashMap(java.util.HashMap) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) I18nFormat(org.hisp.dhis.i18n.I18nFormat) 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) CategoryCombo(org.hisp.dhis.category.CategoryCombo) GridValue(org.hisp.dhis.common.GridValue) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) I18n(org.hisp.dhis.i18n.I18n)

Example 2 with GridValue

use of org.hisp.dhis.common.GridValue 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)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Grid (org.hisp.dhis.common.Grid)2 GridHeader (org.hisp.dhis.common.GridHeader)2 GridValue (org.hisp.dhis.common.GridValue)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Section (org.hisp.dhis.dataset.Section)2 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)2 ListGrid (org.hisp.dhis.system.grid.ListGrid)2 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 CategoryOption (org.hisp.dhis.category.CategoryOption)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 I18n (org.hisp.dhis.i18n.I18n)1 I18nFormat (org.hisp.dhis.i18n.I18nFormat)1