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