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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations