Search in sources :

Example 16 with QueryItem

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

the class TrackedEntityInstanceQueryParams method conform.

/**
     * Performs a set of operations on this params.
     * <p>
     * <ul>
     * <li>
     * If a query item is specified as an attribute item as well as a filter
     * item, the filter item will be removed. In that case, if the attribute
     * item does not have any filters and the filter item has one or more filters,
     * these will be applied to the attribute item.
     * </li>
     * </ul>
     */
public void conform() {
    Iterator<QueryItem> filterIter = filters.iterator();
    while (filterIter.hasNext()) {
        QueryItem filter = filterIter.next();
        // Filter present as attr
        int index = attributes.indexOf(filter);
        if (index >= 0) {
            QueryItem attribute = attributes.get(index);
            if (!attribute.hasFilter() && filter.hasFilter()) {
                attribute.getFilters().addAll(filter.getFilters());
            }
            filterIter.remove();
        }
    }
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem)

Example 17 with QueryItem

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

the class EventQueryParamsTest method testGetDuplicateQueryItems.

@Test
public void testGetDuplicateQueryItems() {
    QueryItem iA = new QueryItem(createDataElement('A', new DataElementCategoryCombo()));
    QueryItem iB = new QueryItem(createDataElement('B', new DataElementCategoryCombo()));
    QueryItem iC = new QueryItem(createDataElement('B', new DataElementCategoryCombo()));
    QueryItem iD = new QueryItem(createDataElement('D', new DataElementCategoryCombo()));
    EventQueryParams params = new EventQueryParams.Builder().addItem(iA).addItem(iB).addItem(iC).addItem(iD).build();
    List<QueryItem> duplicates = params.getDuplicateQueryItems();
    assertEquals(1, duplicates.size());
    assertTrue(duplicates.contains(iC));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 18 with QueryItem

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

the class EventAnalyticsServiceMetadataTest method testGetQueryItemDimensionMetadata.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
@SuppressWarnings("unchecked")
public void testGetQueryItemDimensionMetadata() {
    DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
    DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA));
    QueryItem itemLegendSet = new QueryItem(deA, lsA, deA.getValueType(), deA.getAggregationType(), null);
    QueryItem itemLegendSetFilter = new QueryItem(deB, lsA, deB.getValueType(), deB.getAggregationType(), null);
    itemLegendSetFilter.addFilter(new QueryFilter(QueryOperator.IN, leA.getUid() + OPTION_SEP + leB.getUid() + OPTION_SEP + leC.getUid()));
    QueryItem item = new QueryItem(deC, null, deC.getValueType(), deC.getAggregationType(), null);
    QueryItem itemFilter = new QueryItem(deD, null, deD.getValueType(), deD.getAggregationType(), null);
    itemFilter.addFilter(new QueryFilter(QueryOperator.GT, "10"));
    QueryItem itemOptionSet = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), osA);
    QueryItem itemOptionSetFilter = new QueryItem(deF, null, deE.getValueType(), deE.getAggregationType(), osA);
    itemOptionSetFilter.addFilter(new QueryFilter(QueryOperator.IN, opA.getCode() + OPTION_SEP + opB.getCode()));
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(itemLegendSet).addItem(itemLegendSetFilter).addItem(item).addItem(itemFilter).addItem(itemOptionSet).addItem(itemOptionSetFilter).withSkipData(true).withSkipMeta(false).withDisplayProperty(DisplayProperty.NAME).withApiVersion(DhisApiVersion.V26).build();
    Grid grid = eventAnalyticsService.getAggregatedEventData(params);
    Map<String, Object> metadata = grid.getMetaData();
    assertNotNull(metadata);
    Map<String, Object> dimensionItems = (Map<String, Object>) metadata.get(AnalyticsMetaDataKey.DIMENSIONS.getKey());
    assertNotNull(dimensionItems);
    List<String> itemsLegendSet = (List<String>) dimensionItems.get(itemLegendSet.getItemId());
    List<String> itemsLegendSetFilter = (List<String>) dimensionItems.get(itemLegendSetFilter.getItemId());
    List<String> items = (List<String>) dimensionItems.get(item.getItemId());
    List<String> itemsFilter = (List<String>) dimensionItems.get(itemFilter.getItemId());
    List<String> itemsOptionSet = (List<String>) dimensionItems.get(itemOptionSet.getItemId());
    List<String> itemsOptionSetFilter = (List<String>) dimensionItems.get(itemOptionSetFilter.getItemId());
    assertNotNull(itemsLegendSet);
    assertNotNull(itemsLegendSetFilter);
    assertNotNull(items);
    assertNotNull(itemsFilter);
    assertNotNull(itemsOptionSet);
    assertNotNull(itemsOptionSetFilter);
    assertEquals(4, itemsLegendSet.size());
    assertEquals(itemsLegendSet, Lists.newArrayList(leA.getUid(), leB.getUid(), leC.getUid(), leD.getUid()));
    assertEquals(3, itemsLegendSetFilter.size());
    assertTrue(itemsLegendSetFilter.containsAll(IdentifiableObjectUtils.getUids(Sets.newHashSet(leA, leB, leC))));
    assertTrue(items.isEmpty());
    assertTrue(itemsFilter.isEmpty());
    assertTrue(itemsOptionSet.isEmpty());
    assertEquals(2, itemsOptionSetFilter.size());
    assertTrue(itemsOptionSetFilter.containsAll(IdentifiableObjectUtils.getCodes(Sets.newHashSet(opA, opB))));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) QueryFilter(org.hisp.dhis.common.QueryFilter) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 19 with QueryItem

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

the class EventQueryPlannerTest method validateInvalidQueryItem.

@Test(expected = IllegalQueryException.class)
public void validateInvalidQueryItem() {
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withOrganisationUnits(Lists.newArrayList(ouB)).addItem(new QueryItem(deA, lsA, ValueType.TEXT, AggregationType.NONE, osA)).build();
    queryPlanner.validate(params);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with QueryItem

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

the class AbstractEventService method getQueryItem.

private QueryItem getQueryItem(String item) {
    String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
    if (split == null || split.length % 2 != 1) {
        throw new IllegalQueryException("Query item or filter is invalid: " + item);
    }
    QueryItem queryItem = getItem(split[0]);
    if (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)

Aggregations

QueryItem (org.hisp.dhis.common.QueryItem)28 ArrayList (java.util.ArrayList)9 QueryFilter (org.hisp.dhis.common.QueryFilter)8 Grid (org.hisp.dhis.common.Grid)7 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)4 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3