Search in sources :

Example 6 with DataElementCategory

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

the class CategoryResourceTable method getPopulateTempTableStatement.

@Override
public Optional<String> getPopulateTempTableStatement() {
    String sql = "insert into " + getTempTableName() + " " + "select coc.categoryoptioncomboid as cocid, coc.name as cocname, ";
    for (DataElementCategory category : objects) {
        sql += "(" + "select co.name from categoryoptioncombos_categoryoptions cocco " + "inner join dataelementcategoryoption co on cocco.categoryoptionid = co.categoryoptionid " + "inner join categories_categoryoptions cco on co.categoryoptionid = cco.categoryoptionid " + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid " + "and cco.categoryid = " + category.getId() + " " + "limit 1) as " + columnQuote + category.getName() + columnQuote + ", ";
        sql += "(" + "select co.uid from categoryoptioncombos_categoryoptions cocco " + "inner join dataelementcategoryoption co on cocco.categoryoptionid = co.categoryoptionid " + "inner join categories_categoryoptions cco on co.categoryoptionid = cco.categoryoptionid " + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid " + "and cco.categoryid = " + category.getId() + " " + "limit 1) as " + columnQuote + category.getUid() + columnQuote + ", ";
    }
    for (CategoryOptionGroupSet groupSet : groupSets) {
        sql += "(" + "select cog.name from categoryoptioncombos_categoryoptions cocco " + "inner join categoryoptiongroupmembers cogm on cocco.categoryoptionid = cogm.categoryoptionid " + "inner join categoryoptiongroup cog on cogm.categoryoptiongroupid = cog.categoryoptiongroupid " + "inner join categoryoptiongroupsetmembers cogsm on cogm.categoryoptiongroupid = cogsm.categoryoptiongroupid " + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid " + "and cogsm.categoryoptiongroupsetid = " + groupSet.getId() + " " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
        sql += "(" + "select cog.uid from categoryoptioncombos_categoryoptions cocco " + "inner join categoryoptiongroupmembers cogm on cocco.categoryoptionid = cogm.categoryoptionid " + "inner join categoryoptiongroup cog on cogm.categoryoptiongroupid = cog.categoryoptiongroupid " + "inner join categoryoptiongroupsetmembers cogsm on cogm.categoryoptiongroupid = cogsm.categoryoptiongroupid " + "where coc.categoryoptioncomboid = cocco.categoryoptioncomboid " + "and cogsm.categoryoptiongroupsetid = " + groupSet.getId() + " " + "limit 1) as " + columnQuote + groupSet.getUid() + columnQuote + ", ";
    }
    sql = TextUtils.removeLastComma(sql) + " ";
    sql += "from categoryoptioncombo coc ";
    return Optional.of(sql);
}
Also used : DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet)

Example 7 with DataElementCategory

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

the class CategoryResourceTable method getCreateTempTableStatement.

@Override
public String getCreateTempTableStatement() {
    String statement = "create table " + getTempTableName() + " (" + "categoryoptioncomboid integer not null, " + "categoryoptioncomboname varchar(255), ";
    for (DataElementCategory category : objects) {
        statement += columnQuote + category.getName() + columnQuote + " varchar(230), ";
        statement += columnQuote + category.getUid() + columnQuote + " character(11), ";
    }
    for (CategoryOptionGroupSet groupSet : groupSets) {
        statement += columnQuote + groupSet.getName() + columnQuote + " varchar(230), ";
        statement += columnQuote + groupSet.getUid() + columnQuote + " character(11), ";
    }
    statement += "primary key (categoryoptioncomboid))";
    return statement;
}
Also used : DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet)

Example 8 with DataElementCategory

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

the class FormUtils method getCategoryCombo.

private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
    if (dataset.hasCategoryCombo()) {
        DataElementCategoryCombo categoryCombo = dataset.getCategoryCombo();
        CategoryCombo catCombo = new CategoryCombo();
        catCombo.setId(categoryCombo.getUid());
        List<DataElementCategory> cats = categoryCombo.getCategories();
        if (cats != null && cats.size() > 0) {
            for (DataElementCategory cat : cats) {
                if (cat.getAccess() != null && !cat.getAccess().isRead()) {
                    continue;
                }
                Category c = new Category();
                c.setId(cat.getUid());
                c.setLabel(cat.getName());
                List<DataElementCategoryOption> options = cat.getCategoryOptions();
                if (options != null && options.size() > 0) {
                    for (DataElementCategoryOption option : options) {
                        if (option.getAccess() != null && !option.getAccess().isRead()) {
                            continue;
                        }
                        Option o = new Option();
                        o.setId(option.getUid());
                        o.setLabel(option.getDisplayName());
                        o.setStartDate(option.getStartDate());
                        o.setEndDate(option.getEndDate());
                        Set<OrganisationUnit> catOptionOUs = option.getOrganisationUnits();
                        if (userOrganisationUnits == null || userOrganisationUnits.isEmpty() || catOptionOUs == null || catOptionOUs.isEmpty()) {
                            c.getOptions().add(o);
                        } else if (userOrganisationUnits != null && catOptionOUs != null && !Collections.disjoint(userOrganisationUnits, catOptionOUs)) {
                            HashSet<OrganisationUnit> organisationUnits = new HashSet<>();
                            catOptionOUs.stream().filter(ou -> userOrganisationUnits.contains(ou)).forEach(ou -> {
                                organisationUnits.add(ou);
                                organisationUnits.addAll(getChildren(ou, new HashSet<>()));
                            });
                            o.setOrganisationUnits(organisationUnits);
                            c.getOptions().add(o);
                        }
                    }
                }
                catCombo.getCategories().add(c);
            }
        }
        return catCombo;
    }
    return null;
}
Also used : SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Category(org.hisp.dhis.webapi.webdomain.form.Category) ValueType(org.hisp.dhis.common.ValueType) DataSet(org.hisp.dhis.dataset.DataSet) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) HashMap(java.util.HashMap) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) HashSet(java.util.HashSet) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) Map(java.util.Map) Field(org.hisp.dhis.webapi.webdomain.form.Field) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Option(org.hisp.dhis.webapi.webdomain.form.Option) Collection(java.util.Collection) Set(java.util.Set) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) NameableObjectUtils(org.hisp.dhis.common.NameableObjectUtils) ProgramStage(org.hisp.dhis.program.ProgramStage) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) DataValue(org.hisp.dhis.datavalue.DataValue) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) Collections(java.util.Collections) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Category(org.hisp.dhis.webapi.webdomain.form.Category) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.webapi.webdomain.form.Option) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Example 9 with DataElementCategory

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

the class DefaultAdxDataService method convertAttributesToDxf.

private void convertAttributesToDxf(Map<String, String> attributes, String optionComboName, DataElementCategoryCombo catCombo, IdentifiableProperty scheme) throws AdxException {
    log.debug("ADX attributes: " + attributes);
    if (catCombo.isDefault()) {
        return;
    }
    Map<String, DataElementCategory> categoryMap = getCodeCategoryMap(catCombo);
    Map<String, String> attributeOptions = new HashMap<>();
    for (String category : categoryMap.keySet()) {
        if (attributes.containsKey(category)) {
            attributeOptions.put(category, attributes.get(category));
            attributes.remove(category);
        } else {
            throw new AdxException("Category combo " + catCombo.getName() + " must have " + categoryMap.get(category).getName());
        }
    }
    DataElementCategoryOptionCombo catOptCombo = getCatOptComboFromAttributes(attributeOptions, catCombo, scheme);
    attributes.put(optionComboName, catOptCombo.getUid());
    log.debug("DXF attributes: " + attributes);
}
Also used : HashMap(java.util.HashMap) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 10 with DataElementCategory

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

the class AnalyticsDataSetReportStore method getAggregatedSubTotals.

@Override
public Map<String, Object> getAggregatedSubTotals(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions) {
    Map<String, Object> dataMap = new HashMap<>();
    for (Section section : dataSet.getSections()) {
        List<DataElement> dataElements = new ArrayList<>(section.getDataElements());
        Set<DataElementCategory> categories = new HashSet<>();
        for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
            categories.addAll(categoryCombo.getCategories());
        }
        FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
        if (dataElements.isEmpty() || categories == null || categories.isEmpty()) {
            continue;
        }
        for (DataElementCategory category : categories) {
            if (category.isDefault()) {
                // No need for sub-total for default
                continue;
            }
            if (!category.isDataDimension()) {
                log.warn("Could not get sub-total for category: " + category.getUid() + " for data set report: " + dataSet + ", not a data dimension");
                continue;
            }
            DataQueryParams.Builder params = DataQueryParams.newBuilder().withDataElements(dataElements).withPeriod(period).withOrganisationUnit(unit).withCategory(category);
            if (dimensions != null) {
                params.addFilters(dataQueryService.getDimensionalObjects(dimensions, null, null, null, false, IdScheme.UID));
            }
            Map<String, Object> map = analyticsService.getAggregatedDataValueMapping(params.build());
            for (Entry<String, Object> entry : map.entrySet()) {
                String[] split = entry.getKey().split(SEPARATOR);
                dataMap.put(split[0] + SEPARATOR + split[3], entry.getValue());
            }
        }
    }
    return dataMap;
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet)

Aggregations

DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)29 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)12 HashMap (java.util.HashMap)8 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)8 HashSet (java.util.HashSet)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)7 ArrayList (java.util.ArrayList)6 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Test (org.junit.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 User (org.hisp.dhis.user.User)5 DataSet (org.hisp.dhis.dataset.DataSet)4 Section (org.hisp.dhis.dataset.Section)4 List (java.util.List)3 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)3 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)3 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3