Search in sources :

Example 31 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo 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 32 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class ProgramDeletionHandler method deleteDataElementCategoryCombo.

@Override
public void deleteDataElementCategoryCombo(DataElementCategoryCombo categoryCombo) {
    DataElementCategoryCombo defaultCategoryCombo = categoryService.getDataElementCategoryComboByName(DEFAULT_CATEGORY_COMBO_NAME);
    Collection<Program> programs = idObjectManager.getAllNoAcl(Program.class);
    for (Program program : programs) {
        if (program != null && categoryCombo.equals(program.getCategoryCombo())) {
            program.setCategoryCombo(defaultCategoryCombo);
            idObjectManager.updateNoAcl(program);
        }
    }
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo)

Aggregations

DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)32 DataElement (org.hisp.dhis.dataelement.DataElement)14 DataSet (org.hisp.dhis.dataset.DataSet)12 ArrayList (java.util.ArrayList)11 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)10 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)8 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)8 Section (org.hisp.dhis.dataset.Section)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)5 List (java.util.List)4 Map (java.util.Map)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)3 OptionSet (org.hisp.dhis.option.OptionSet)3 Period (org.hisp.dhis.period.Period)3 Program (org.hisp.dhis.program.Program)3