Search in sources :

Example 1 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramIndicator.

public static ProgramIndicator createProgramIndicator(char uniqueCharacter, Program program, String expression, String filter) {
    ProgramIndicator indicator = new ProgramIndicator();
    indicator.setAutoFields();
    indicator.setName("Indicator" + uniqueCharacter);
    indicator.setShortName("IndicatorShort" + uniqueCharacter);
    indicator.setCode("IndicatorCode" + uniqueCharacter);
    indicator.setDescription("IndicatorDescription" + uniqueCharacter);
    indicator.setProgram(program);
    indicator.setExpression(expression);
    indicator.setFilter(filter);
    return indicator;
}
Also used : ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 2 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetByDataDimensionType.

@Test
public void testGetByDataDimensionType() {
    Program prA = createProgram('A');
    DataElement deA = createDataElement('A', new DataElementCategoryCombo());
    DataElement deB = createDataElement('B', new DataElementCategoryCombo());
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
    List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
    assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
    assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 3 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class DefaultEventQueryPlanner method groupByQueryItems.

/**
     * Group by items if query items are to be collapsed in order to aggregate
     * each item individually.
     * 
     * @param params the event query parameters.
     * @return a list of {@link EventQueryParams}.
     */
private List<EventQueryParams> groupByQueryItems(EventQueryParams params) {
    List<EventQueryParams> queries = new ArrayList<>();
    if (params.isAggregateData()) {
        for (QueryItem item : params.getItemsAndItemFilters()) {
            EventQueryParams.Builder query = new EventQueryParams.Builder(params).removeItems().removeItemProgramIndicators().withValue(item.getItem());
            if (item.hasProgram()) {
                query.withProgram(item.getProgram());
            }
            queries.add(query.build());
        }
        for (ProgramIndicator programIndicator : params.getItemProgramIndicators()) {
            EventQueryParams query = new EventQueryParams.Builder(params).removeItems().removeItemProgramIndicators().withProgramIndicator(programIndicator).withProgram(programIndicator.getProgram()).build();
            queries.add(query);
        }
    } else if (params.isCollapseDataDimensions() && !params.getItems().isEmpty()) {
        for (QueryItem item : params.getItems()) {
            EventQueryParams.Builder query = new EventQueryParams.Builder(params).removeItems().addItem(item);
            if (item.hasProgram()) {
                query.withProgram(item.getProgram());
            }
            queries.add(query.build());
        }
    } else {
        queries.add(new EventQueryParams.Builder(params).build());
    }
    return queries;
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 4 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class EventQueryParams method fromDataQueryParams.

public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
    EventQueryParams params = new EventQueryParams();
    dataQueryParams.copyTo(params);
    EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
    for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
        ProgramIndicator programIndicator = (ProgramIndicator) object;
        builder.addItemProgramIndicator(programIndicator);
    }
    return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 5 with ProgramIndicator

use of org.hisp.dhis.program.ProgramIndicator in project dhis2-core by dhis2.

the class JdbcEnrollmentAnalyticsManager method getSelectColumns.

/**
     * Returns the dynamic select columns. Dimensions come first and query items
     * second. Program indicator expressions are converted to SQL expressions.
     */
private List<String> getSelectColumns(EventQueryParams params) {
    List<String> columns = Lists.newArrayList();
    for (DimensionalObject dimension : params.getDimensions()) {
        columns.add(statementBuilder.columnQuote(dimension.getDimensionName()));
    }
    for (QueryItem queryItem : params.getItems()) {
        if (queryItem.isProgramIndicator()) {
            ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
            String asClause = " as " + statementBuilder.columnQuote(in.getUid());
            columns.add("(" + programIndicatorService.getAnalyticsSQl(in.getExpression(), in.getAnalyticsType(), params.getEarliestStartDate(), params.getLatestEndDate()) + ")" + asClause);
        } else if (ValueType.COORDINATE == queryItem.getValueType()) {
            String colName = statementBuilder.columnQuote(queryItem.getItemName());
            String coordSql = "'[' || round(ST_X(" + colName + ")::numeric, 6) || ',' || round(ST_Y(" + colName + ")::numeric, 6) || ']' as " + colName;
            columns.add(coordSql);
        } else {
            columns.add(statementBuilder.columnQuote(queryItem.getItemName()));
        }
    }
    return columns;
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Aggregations

ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 DataElement (org.hisp.dhis.dataelement.DataElement)6 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 ArrayList (java.util.ArrayList)3 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 QueryItem (org.hisp.dhis.common.QueryItem)2 Program (org.hisp.dhis.program.Program)2 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 DimensionType (org.hisp.dhis.common.DimensionType)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 MapMap (org.hisp.dhis.common.MapMap)1 SetMap (org.hisp.dhis.common.SetMap)1