Search in sources :

Example 1 with SectionOrderComparator

use of org.hisp.dhis.dataset.comparator.SectionOrderComparator in project dhis2-core by dhis2.

the class LoadFormAction method getSectionForm.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getSectionForm(Collection<DataElement> dataElements, DataSet dataSet) {
    sections = new ArrayList<>(dataSet.getSections());
    Collections.sort(sections, new SectionOrderComparator());
    for (Section section : sections) {
        Set<Integer> categoryComboIds = new HashSet<>();
        for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
            categoryComboIds.add(categoryCombo.getId());
            sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
        }
        if (!categoryComboIds.isEmpty()) {
            sectionCombos.put(section.getId(), categoryComboIds);
        }
        for (DataElementOperand operand : section.getGreyedFields()) {
            if (operand != null && operand.getDataElement() != null && operand.getCategoryOptionCombo() != null) {
                greyedFields.put(operand.getDataElement().getUid() + ":" + operand.getCategoryOptionCombo().getUid(), true);
            }
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet)

Example 2 with SectionOrderComparator

use of org.hisp.dhis.dataset.comparator.SectionOrderComparator 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

DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)2 Section (org.hisp.dhis.dataset.Section)2 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Grid (org.hisp.dhis.common.Grid)1 GridHeader (org.hisp.dhis.common.GridHeader)1 GridValue (org.hisp.dhis.common.GridValue)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 ListGrid (org.hisp.dhis.system.grid.ListGrid)1