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