Search in sources :

Example 1 with OrganisationUnitLevel

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

the class AbstractWebApiTest method createTestObject.

@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
    if (DataElementGroup.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroup(uniqueName);
    } else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
        return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
    } else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOption(uniqueName);
    } else if (DataElement.class.isAssignableFrom(clazz)) {
        return (T) createDataElement(uniqueName);
    } else if (DataElementCategory.class.isAssignableFrom(clazz)) {
        return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
    } else if (Program.class.isAssignableFrom(clazz)) {
        OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
        manager.save(organisationUnitA);
        return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
    } else if (DataElementOperand.class.isAssignableFrom(clazz)) {
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
        manager.save(coc);
        return (T) new DataElementOperand(deA, coc);
    } else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroupSet(uniqueName);
    } else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        return (T) createCategoryOptionCombo(cc, co);
    } else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(co);
        return (T) createCategoryOptionGroup(uniqueName, co);
    } else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOptionGroupSet(uniqueName);
    } else if (EventChart.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventChart ecA = new EventChart("evc" + uniqueName);
        ecA.setProgram(prA);
        ecA.setType(ChartType.COLUMN);
        return (T) ecA;
    } else if (EventReport.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventReport erA = new EventReport("er" + uniqueName);
        erA.setProgram(prA);
        return (T) erA;
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        return (T) new ProgramDataElementDimensionItem(prA, deA);
    } else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
        Program program = (Program) createTestObject(Program.class, uniqueName);
        manager.save(program);
        Constant constantA = createConstant(uniqueName, 7.0);
        manager.save(constantA);
        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
        return (T) createProgramIndicator(uniqueName, program, expressionA, null);
    } else if (Indicator.class.isAssignableFrom(clazz)) {
        IndicatorType indicatorType = createIndicatorType(uniqueName);
        manager.save(indicatorType);
        return (T) createIndicator(uniqueName, indicatorType);
    } else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroup(uniqueName);
    } else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroupSet(uniqueName);
    } else if (IndicatorType.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorType(uniqueName);
    } else if (Legend.class.isAssignableFrom(clazz)) {
        return (T) createLegend(uniqueName, 0d, 10d);
    } else if (LegendSet.class.isAssignableFrom(clazz)) {
        return (T) createLegendSet(uniqueName);
    } else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnit(uniqueName);
    } else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroup(uniqueName);
    } else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroupSet(uniqueName);
    } else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
        return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
    } else if (Color.class.isAssignableFrom(clazz)) {
        Color color = new Color("#ff3200");
        color.setName("Color" + uniqueName);
        return (T) color;
    } else if (ColorSet.class.isAssignableFrom(clazz)) {
        ColorSet colorSet = new ColorSet();
        colorSet.setName("ColorSet" + uniqueName);
        return (T) colorSet;
    } else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
        org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
        map.setName("Map" + uniqueName);
        map.setDisplayName("DisplayName" + uniqueName);
        map.setLatitude(952175.62553525);
        map.setLongitude(-1378543.6774686);
        return (T) map;
    } else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
        ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
        externalMapLayer.setMapService(MapService.WMS);
        externalMapLayer.setUrl("testUrl");
        externalMapLayer.setImageFormat(ImageFormat.JPG);
        externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
        return (T) externalMapLayer;
    } else if (OptionGroup.class.isAssignableFrom(clazz)) {
        OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
        optionGroup.setShortName("Group" + uniqueName);
        return (T) optionGroup;
    } else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
    } else if (Option.class.isAssignableFrom(clazz)) {
        return (T) new Option("Option" + uniqueName, "code" + uniqueName);
    } else if (OptionSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
    } else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
        ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
        ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
        group.addAttribute(attr);
        return (T) group;
    } else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
        return (T) createProgramTrackedEntityAttribute(uniqueName);
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        return (T) createProgramDataElement(uniqueName);
    }
    return null;
}
Also used : ColorSet(org.hisp.dhis.color.ColorSet) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ExternalMapLayer(org.hisp.dhis.mapping.ExternalMapLayer) Legend(org.hisp.dhis.legend.Legend) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Constant(org.hisp.dhis.constant.Constant) EventReport(org.hisp.dhis.eventreport.EventReport) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) IndicatorType(org.hisp.dhis.indicator.IndicatorType) OptionGroup(org.hisp.dhis.option.OptionGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) Color(org.hisp.dhis.color.Color) EventChart(org.hisp.dhis.eventchart.EventChart) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.option.Option) ProgramTrackedEntityAttributeGroup(org.hisp.dhis.program.ProgramTrackedEntityAttributeGroup) OptionSet(org.hisp.dhis.option.OptionSet) Map(java.util.Map) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 2 with OrganisationUnitLevel

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

the class JdbcEventAnalyticsTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    final String dbl = statementBuilder.getDoubleColumnType();
    final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
    final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
    //TODO dateClause regular expression
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    if (table.getProgram().hasCategoryCombo()) {
        List<DataElementCategory> categories = table.getProgram().getCategoryCombo().getCategories();
        for (DataElementCategory category : categories) {
            if (category.isDataDimension()) {
                columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
            }
        }
    }
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + 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 (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
    }
    for (DataElement dataElement : table.getProgram().getDataElements()) {
        ValueType valueType = dataElement.getValueType();
        String dataType = getColumnType(valueType);
        String dataClause = dataElement.isNumericType() ? numericClause : dataElement.getValueType().isDate() ? dateClause : "";
        String select = getSelectClause(valueType);
        boolean skipIndex = NO_INDEX_VAL_TYPES.contains(dataElement.getValueType()) && !dataElement.hasOptionSet();
        String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + "and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote(dataElement.getUid());
        columns.add(new AnalyticsTableColumn(quote(dataElement.getUid()), dataType, sql, skipIndex));
    }
    for (DataElement dataElement : table.getProgram().getDataElementsWithLegendSet()) {
        for (LegendSet legendSet : dataElement.getLegendSets()) {
            String column = quote(dataElement.getUid() + PartitionUtils.SEP + legendSet.getUid());
            String select = getSelectClause(dataElement.getValueType());
            String sql = "(select l.uid from maplegend l " + "inner join trackedentitydatavalue dv on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and dv.programstageinstanceid=psi.programstageinstanceid " + "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
            columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
        }
    }
    for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributes()) {
        String dataType = getColumnType(attribute.getValueType());
        String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
        String select = getSelectClause(attribute.getValueType());
        boolean skipIndex = NO_INDEX_VAL_TYPES.contains(attribute.getValueType()) && !attribute.hasOptionSet();
        String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote(attribute.getUid());
        columns.add(new AnalyticsTableColumn(quote(attribute.getUid()), dataType, sql, skipIndex));
    }
    for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributesWithLegendSet()) {
        for (LegendSet legendSet : attribute.getLegendSets()) {
            String column = quote(attribute.getUid() + PartitionUtils.SEP + legendSet.getUid());
            String select = getSelectClause(attribute.getValueType());
            String sql = "(select l.uid from maplegend l " + "inner join trackedentityattributevalue av on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and av.trackedentityinstanceid=pi.trackedentityinstanceid " + "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
            columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
        }
    }
    AnalyticsTableColumn psi = new AnalyticsTableColumn(quote("psi"), "character(11) not null", "psi.uid");
    AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
    AnalyticsTableColumn ps = new AnalyticsTableColumn(quote("ps"), "character(11) not null", "ps.uid");
    AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
    AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
    AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
    AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", "psi.executiondate");
    AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", "psi.duedate");
    AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "psi.completeddate");
    AnalyticsTableColumn pes = new AnalyticsTableColumn(quote("pistatus"), "character(25)", "pi.status");
    AnalyticsTableColumn es = new AnalyticsTableColumn(quote("psistatus"), "character(25)", "psi.status");
    AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "psi.longitude");
    AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "psi.latitude");
    AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
    AnalyticsTableColumn oun = new AnalyticsTableColumn(quote("ouname"), "character varying(230) not null", "ou.name");
    AnalyticsTableColumn ouc = new AnalyticsTableColumn(quote("oucode"), "character varying(50)", "ou.code");
    columns.addAll(Lists.newArrayList(psi, pi, ps, ao, erd, id, ed, dd, cd, pes, es, longitude, latitude, ou, oun, ouc));
    if (databaseInfo.isSpatialSupport()) {
        String alias = "(select ST_SetSRID(ST_MakePoint(psi.longitude, psi.latitude), 4326)) as geom";
        columns.add(new AnalyticsTableColumn(quote("geom"), "geometry(Point, 4326)", alias, false, "gist"));
    }
    if (table.hasProgram() && table.getProgram().isRegistration()) {
        columns.add(new AnalyticsTableColumn(quote("tei"), "character(11)", "tei.uid"));
    }
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ValueType(org.hisp.dhis.common.ValueType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) LegendSet(org.hisp.dhis.legend.LegendSet) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 3 with OrganisationUnitLevel

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

the class JdbcOrgUnitTargetTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    AnalyticsTableColumn ds = new AnalyticsTableColumn(quote("oug"), "character(11) not null", "oug.uid");
    columns.add(ds);
    return filterDimensionColumns(columns);
}
Also used : OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn)

Example 4 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.
     */
private String getApprovalJoinClause(AnalyticsTable table) {
    if (isApprovalEnabled(table)) {
        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)

Example 5 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel 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)

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