Search in sources :

Example 1 with DataElementGroupSet

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

the class JdbcAnalyticsTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<DataElementGroupSet> dataElementGroupSets = idObjectManager.getDataDimensionsNoAcl(DataElementGroupSet.class);
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<CategoryOptionGroupSet> disaggregationCategoryOptionGroupSets = categoryService.getDisaggregationCategoryOptionGroupSetsNoAcl();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<DataElementCategory> disaggregationCategories = categoryService.getDisaggregationDataDimensionCategoriesNoAcl();
    List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    for (DataElementGroupSet groupSet : dataElementGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "degs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : disaggregationCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "dcs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (DataElementCategory category : disaggregationCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "dcs." + quote(category.getUid()), category.getCreated()));
    }
    for (DataElementCategory category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
    for (PeriodType periodType : periodTypes) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, "character varying(15)", "ps." + column));
    }
    AnalyticsTableColumn de = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "de.uid");
    AnalyticsTableColumn co = new AnalyticsTableColumn(quote("co"), "character(11) not null", "co.uid");
    AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
    AnalyticsTableColumn startDate = new AnalyticsTableColumn(quote("pestartdate"), "timestamp", "pe.startdate");
    AnalyticsTableColumn endDate = new AnalyticsTableColumn(quote("peenddate"), "timestamp", "pe.enddate");
    AnalyticsTableColumn pe = new AnalyticsTableColumn(quote("pe"), "character varying(15) not null", "ps.iso");
    AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
    AnalyticsTableColumn level = new AnalyticsTableColumn(quote("level"), "integer", "ous.level");
    columns.addAll(Lists.newArrayList(de, co, ao, startDate, endDate, pe, ou, level));
    if (isApprovalEnabled(table)) {
        String col = "coalesce(des.datasetapprovallevel, aon.approvallevel, da.minlevel, " + APPROVAL_LEVEL_UNAPPROVED + ") as approvallevel ";
        columns.add(new AnalyticsTableColumn(quote("approvallevel"), "integer", col));
    } else {
        String col = DataApprovalLevelService.APPROVAL_LEVEL_HIGHEST + " as approvallevel";
        columns.add(new AnalyticsTableColumn(quote("approvallevel"), "integer", col));
    }
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 2 with DataElementGroupSet

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

the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.

@Override
public void executeInTransaction() {
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
        dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addDataElementGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
        dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
        dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addCategoryOptionGroupSetDimension(dimension);
    };
    try {
        upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
    } catch (Exception ex) {
        log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
        return;
    }
}
Also used : AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) Autowired(org.springframework.beans.factory.annotation.Autowired) EventReport(org.hisp.dhis.eventreport.EventReport) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) EventChart(org.hisp.dhis.eventchart.EventChart) ReportTable(org.hisp.dhis.reporttable.ReportTable) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) BiConsumer(java.util.function.BiConsumer) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) Chart(org.hisp.dhis.chart.Chart) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) TransactionContextStartupRoutine(org.hisp.dhis.system.startup.TransactionContextStartupRoutine) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) List(java.util.List) DimensionalObject(org.hisp.dhis.common.DimensionalObject) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TextUtils(org.hisp.dhis.commons.util.TextUtils) Assert(org.springframework.util.Assert) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject)

Example 3 with DataElementGroupSet

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

the class JdbcAnalyticsTableManager method getDimensionColumns.

private List<AnalyticsTableColumn> getDimensionColumns(Integer year) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    String idColAlias = "(de.uid || '-' || ps.iso || '-' || ou.uid || '-' || co.uid || '-' || ao.uid) as id ";
    columns.add(new AnalyticsTableColumn(quote("id"), ColumnDataType.TEXT, idColAlias));
    List<DataElementGroupSet> dataElementGroupSets = idObjectManager.getDataDimensionsNoAcl(DataElementGroupSet.class);
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<CategoryOptionGroupSet> disaggregationCategoryOptionGroupSets = categoryService.getDisaggregationCategoryOptionGroupSetsNoAcl();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<Category> disaggregationCategories = categoryService.getDisaggregationDataDimensionCategoriesNoAcl();
    List<Category> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    for (DataElementGroupSet groupSet : dataElementGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "degs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "ougs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : disaggregationCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "dcs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "acs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (Category category : disaggregationCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "dcs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    for (Category category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, CHARACTER_11, "ous." + column).withCreated(level.getCreated()));
    }
    columns.addAll(addPeriodTypeColumns("ps"));
    String approvalCol = isApprovalEnabled(year) ? "coalesce(des.datasetapprovallevel, aon.approvallevel, da.minlevel, " + APPROVAL_LEVEL_UNAPPROVED + ") as approvallevel " : DataApprovalLevelService.APPROVAL_LEVEL_HIGHEST + " as approvallevel";
    columns.add(new AnalyticsTableColumn(quote("approvallevel"), INTEGER, approvalCol));
    columns.addAll(getFixedColumns());
    return filterDimensionColumns(columns);
}
Also used : Category(org.hisp.dhis.category.Category) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 4 with DataElementGroupSet

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

the class ResourceTableServiceTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    DataElementGroup degA = createDataElementGroup('A');
    DataElementGroup degB = createDataElementGroup('B');
    DataElementGroup degC = createDataElementGroup('C');
    DataElementGroup degD = createDataElementGroup('D');
    degA.addDataElement(deA);
    degB.addDataElement(deB);
    idObjectManager.save(degA);
    idObjectManager.save(degB);
    idObjectManager.save(degC);
    idObjectManager.save(degD);
    DataElementGroupSet degsA = createDataElementGroupSet('A');
    DataElementGroupSet degsB = createDataElementGroupSet('B');
    degsB.setName("Data \"Element\" Group Set \"B\"");
    degsA.addDataElementGroup(degA);
    degsA.addDataElementGroup(degB);
    degsB.addDataElementGroup(degC);
    degsB.addDataElementGroup(degD);
    idObjectManager.save(degsA);
    idObjectManager.save(degsB);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouB.setParent(ouA);
    ouC.setParent(ouA);
    ouA.getChildren().add(ouB);
    ouA.getChildren().add(ouC);
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsA.addOrganisationUnit(ouA);
    dsB.addOrganisationUnit(ouA);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 5 with DataElementGroupSet

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

the class DataElementGroupSetResourceTable method getCreateTempTableStatement.

@Override
public String getCreateTempTableStatement() {
    String statement = "create table " + getTempTableName() + " (" + "dataelementid bigint not null, " + "dataelementname varchar(230), ";
    for (DataElementGroupSet groupSet : objects) {
        statement += quote(groupSet.getShortName()) + " varchar(230), ";
        statement += quote(groupSet.getUid()) + " character(11), ";
    }
    statement += "primary key (dataelementid))";
    return statement;
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet)

Aggregations

DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)14 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)5 ArrayList (java.util.ArrayList)4 Category (org.hisp.dhis.category.Category)3 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 Test (org.junit.jupiter.api.Test)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 TextUtils.getQuotedCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)2 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)2 DataElementGroupSetDimension (org.hisp.dhis.dataelement.DataElementGroupSetDimension)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BiConsumer (java.util.function.BiConsumer)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1