Search in sources :

Example 31 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class JdbcValidationResultTableManager method getDimensionColumns.

private List<AnalyticsTableColumn> getDimensionColumns() {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<Category> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "ougs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, CHARACTER_11, "ous." + column).withCreated(level.getCreated()));
    }
    for (Category category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, TEXT, "ps." + column));
    }
    columns.addAll(getFixedColumns());
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Category(org.hisp.dhis.category.Category) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 32 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class JdbcAnalyticsTableManager method getApprovalJoinClause.

/**
 * Returns sub-query for approval level. First looks for approval level in
 * data element resource table which will indicate level 0 (highest) if
 * approval is not required. Then looks for highest level in dataapproval
 * table.
 *
 * @param year the data year.
 */
private String getApprovalJoinClause(Integer year) {
    if (isApprovalEnabled(year)) {
        String sql = "left join _dataapprovalminlevel da " + "on des.workflowid=da.workflowid and da.periodid=dv.periodid " + "and da.attributeoptioncomboid=dv.attributeoptioncomboid " + "and (";
        Set<OrganisationUnitLevel> levels = dataApprovalLevelService.getOrganisationUnitApprovalLevels();
        for (OrganisationUnitLevel level : levels) {
            sql += "ous.idlevel" + level.getLevel() + " = da.organisationunitid or ";
        }
        return TextUtils.removeLastOr(sql) + ") ";
    }
    return StringUtils.EMPTY;
}
Also used : OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString)

Example 33 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class JdbcCompletenessTargetTableManager method getDimensionColumns.

private List<AnalyticsTableColumn> getDimensionColumns() {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<Category> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "ougs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, CHARACTER_11, "ous." + column).withCreated(level.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "acs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (Category category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    columns.addAll(getFixedColumns());
    return filterDimensionColumns(columns);
}
Also used : Category(org.hisp.dhis.category.Category) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 34 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class DefaultDataApprovalLevelService method getAllDataApprovalLevels.

@Override
@Transactional(readOnly = true)
public List<DataApprovalLevel> getAllDataApprovalLevels() {
    List<DataApprovalLevel> dataApprovalLevels = dataApprovalLevelStore.getAllDataApprovalLevels();
    for (DataApprovalLevel dataApprovalLevel : dataApprovalLevels) {
        int ouLevelNumber = dataApprovalLevel.getOrgUnitLevel();
        OrganisationUnitLevel ouLevel = organisationUnitService.getOrganisationUnitLevelByLevel(ouLevelNumber);
        String ouLevelName = ouLevel != null ? ouLevel.getName() : "Organisation unit level " + ouLevelNumber;
        dataApprovalLevel.setOrgUnitLevelName(ouLevelName);
    }
    return dataApprovalLevels;
}
Also used : OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class PredictionServiceTest method testPredictOrgUnitGroup.

@Test
void testPredictOrgUnitGroup() {
    useDataValue(dataElementA, makeMonth(2021, 8), sourceA, 1);
    useDataValue(dataElementA, makeMonth(2021, 8), sourceB, 2);
    useDataValue(dataElementA, makeMonth(2021, 8), sourceC, 4);
    useDataValue(dataElementA, makeMonth(2021, 8), sourceD, 8);
    useDataValue(dataElementA, makeMonth(2021, 8), sourceE, 16);
    useDataValue(dataElementA, makeMonth(2021, 8), sourceF, 32);
    dataValueBatchHandler.flush();
    Expression expression = new Expression("if(orgUnit.group( " + ouGroupA.getUid() + " , " + ouGroupB.getUid() + " ), #{" + dataElementA.getUid() + "}, 64)", "description", MissingValueStrategy.SKIP_IF_ALL_VALUES_MISSING);
    Set<OrganisationUnitLevel> allLevels = Sets.newHashSet(orgUnitLevel1, orgUnitLevel2, orgUnitLevel3);
    Predictor predictor = createPredictor(dataElementX, defaultCombo, "A", expression, null, periodTypeMonthly, allLevels, 1, 0, 0);
    predictionService.predict(predictor, monthStart(2021, 8), monthStart(2021, 9), summary);
    assertEquals("Pred 1 Ins 6 Upd 0 Del 0 Unch 0", shortSummary(summary));
    assertEquals("1.0", getDataValue(dataElementX, defaultCombo, sourceA, makeMonth(2021, 8)));
    assertEquals("64.0", getDataValue(dataElementX, defaultCombo, sourceB, makeMonth(2021, 8)));
    assertEquals("4.0", getDataValue(dataElementX, defaultCombo, sourceC, makeMonth(2021, 8)));
    assertEquals("56.0", getDataValue(dataElementX, defaultCombo, sourceD, makeMonth(2021, 8)));
    assertEquals("64.0", getDataValue(dataElementX, defaultCombo, sourceE, makeMonth(2021, 8)));
    assertEquals("32.0", getDataValue(dataElementX, defaultCombo, sourceF, makeMonth(2021, 8)));
}
Also used : Expression(org.hisp.dhis.expression.Expression) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) Test(org.junit.jupiter.api.Test)

Aggregations

OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)38 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)11 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)11 DataElement (org.hisp.dhis.dataelement.DataElement)9 Expression (org.hisp.dhis.expression.Expression)9 PeriodType (org.hisp.dhis.period.PeriodType)9 ArrayList (java.util.ArrayList)8 Category (org.hisp.dhis.category.Category)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 Test (org.junit.jupiter.api.Test)6 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 DateUtils.getLongDateString (org.hisp.dhis.util.DateUtils.getLongDateString)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)3