Search in sources :

Example 6 with QueryOperator

use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getQueryItem.

private QueryItem getQueryItem(String dimensionString, Program program, EventOutputType type) {
    String[] split = dimensionString.split(DIMENSION_NAME_SEP);
    if (split.length % 2 != 1) {
        throwIllegalQueryEx(ErrorCode.E7222, dimensionString);
    }
    QueryItem queryItem = queryItemLocator.getQueryItemFromDimension(split[0], program, type);
    if (// Filters specified
    split.length > 1) {
        for (int i = 1; i < split.length; i += 2) {
            QueryOperator operator = QueryOperator.fromString(split[i]);
            QueryFilter filter = new QueryFilter(operator, split[i + 1]);
            queryItem.addFilter(filter);
        }
    }
    return queryItem;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) QueryOperator(org.hisp.dhis.common.QueryOperator)

Example 7 with QueryOperator

use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapper method getQueryItem.

/**
 * Creates a QueryItem from the given item string. Item is on format
 * {attribute-id}:{operator}:{filter-value}[:{operator}:{filter-value}].
 * Only the attribute-id is mandatory.
 */
private QueryItem getQueryItem(String item, Map<String, TrackedEntityAttribute> attributes) {
    String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
    if (split.length % 2 != 1) {
        throw new IllegalQueryException("Query item or filter is invalid: " + item);
    }
    QueryItem queryItem = getItem(split[0], attributes);
    if (// Filters specified
    split.length > 1) {
        for (int i = 1; i < split.length; i += 2) {
            QueryOperator operator = QueryOperator.fromString(split[i]);
            queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
        }
    }
    return queryItem;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) QueryOperator(org.hisp.dhis.common.QueryOperator)

Example 8 with QueryOperator

use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapper method getQueryFilter.

/**
 * Creates a QueryFilter from the given query string. Query is on format
 * {operator}:{filter-value}. Only the filter-value is mandatory. The EQ
 * QueryOperator is used as operator if not specified.
 */
private QueryFilter getQueryFilter(String query) {
    if (query == null || query.isEmpty()) {
        return null;
    }
    if (!query.contains(DimensionalObject.DIMENSION_NAME_SEP)) {
        return new QueryFilter(QueryOperator.EQ, query);
    } else {
        String[] split = query.split(DimensionalObject.DIMENSION_NAME_SEP);
        if (split.length != 2) {
            throw new IllegalQueryException("Query has invalid format: " + query);
        }
        QueryOperator op = QueryOperator.fromString(split[0]);
        return new QueryFilter(op, split[1]);
    }
}
Also used : QueryFilter(org.hisp.dhis.common.QueryFilter) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) QueryOperator(org.hisp.dhis.common.QueryOperator)

Aggregations

QueryFilter (org.hisp.dhis.common.QueryFilter)8 QueryOperator (org.hisp.dhis.common.QueryOperator)8 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)6 QueryItem (org.hisp.dhis.common.QueryItem)6 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)1 Grid (org.hisp.dhis.common.Grid)1 GridHeader (org.hisp.dhis.common.GridHeader)1 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)1 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)1