Search in sources :

Example 6 with Category

use of org.hisp.dhis.category.Category 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 (Category 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 " + quote(category.getName()) + ", ";
        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 " + quote(category.getUid()) + ", ";
    }
    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 " + quote(groupSet.getName()) + ", ";
        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 " + quote(groupSet.getUid()) + ", ";
    }
    sql = TextUtils.removeLastComma(sql) + " ";
    sql += "from categoryoptioncombo coc ";
    return Optional.of(sql);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet)

Example 7 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class CategoryResourceTable method getCreateTempTableStatement.

@Override
public String getCreateTempTableStatement() {
    String statement = "create table " + getTempTableName() + " (" + "categoryoptioncomboid bigint not null, " + "categoryoptioncomboname varchar(255), ";
    UniqueNameContext nameContext = new UniqueNameContext();
    for (Category category : objects) {
        statement += quote(nameContext.uniqueName(category.getShortName())) + " varchar(230), ";
        statement += quote(category.getUid()) + " character(11), ";
    }
    for (CategoryOptionGroupSet groupSet : groupSets) {
        statement += quote(nameContext.uniqueName(groupSet.getShortName())) + " varchar(230), ";
        statement += quote(groupSet.getUid()) + " character(11), ";
    }
    statement += "primary key (categoryoptioncomboid))";
    return statement;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet)

Example 8 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultCategoryService method getCoDimensionConstraints.

@Override
@Transactional(readOnly = true)
public Set<CategoryOption> getCoDimensionConstraints(User user) {
    Set<CategoryOption> options = null;
    Set<Category> catConstraints = user.getCatDimensionConstraints();
    if (catConstraints != null && !catConstraints.isEmpty()) {
        options = new HashSet<>();
        for (Category category : catConstraints) {
            options.addAll(getCategoryOptions(category));
        }
    }
    return options;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryOption(org.hisp.dhis.category.CategoryOption) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultCsvImportService method categoriesFromCsv.

private List<Category> categoriesFromCsv(CsvReader reader) throws IOException {
    List<Category> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            Category object = new Category();
            setIdentifiableObject(object, values);
            object.setDescription(getSafe(values, 3, 255));
            object.setDataDimensionType(DataDimensionType.valueOf(getSafe(values, 4, DataDimensionType.DISAGGREGATION.toString(), 40)));
            object.setDataDimension(Boolean.parseBoolean(getSafe(values, 5, Boolean.FALSE.toString(), 40)));
            list.add(object);
        }
    }
    return list;
}
Also used : Category(org.hisp.dhis.category.Category) ArrayList(java.util.ArrayList)

Example 10 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultAdxDataService method convertAttributesToDxf.

private void convertAttributesToDxf(Map<String, String> attributes, String optionComboName, CategoryCombo catCombo, IdSchemes idSchemes) throws AdxException {
    log.debug("ADX attributes: " + attributes);
    if (catCombo.isDefault()) {
        return;
    }
    Map<String, Category> categoryMap = getCodeCategoryMap(catCombo, idSchemes.getCategoryIdScheme());
    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());
        }
    }
    CategoryOptionCombo catOptCombo = getCatOptComboFromAttributes(attributeOptions, catCombo, idSchemes);
    attributes.put(optionComboName, catOptCombo.getPropertyValue(idSchemes.getCategoryOptionComboIdScheme()));
    log.debug("DXF attributes: " + attributes);
}
Also used : Category(org.hisp.dhis.category.Category) HashMap(java.util.HashMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

Category (org.hisp.dhis.category.Category)61 CategoryOption (org.hisp.dhis.category.CategoryOption)25 CategoryCombo (org.hisp.dhis.category.CategoryCombo)22 Test (org.junit.jupiter.api.Test)21 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)13 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)13 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)12 DataElement (org.hisp.dhis.dataelement.DataElement)11 HashSet (java.util.HashSet)8 DataSet (org.hisp.dhis.dataset.DataSet)8 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)8 HashMap (java.util.HashMap)7 Date (java.util.Date)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 List (java.util.List)4 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Attribute (org.hisp.dhis.attribute.Attribute)4