use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType.
@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType() {
// DataQueryParams with **two** DataElement as filter
// Both have DataType NUMERIC but different AggregationType
// Aggregation type is overridden (COUNT)
DataQueryParams queryParams = createDataQueryParamsWithAggregationType(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.INTEGER, AggregationType.COUNT))), AnalyticsAggregationType.COUNT);
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
// Aggregation type defaults to SUM
assertDefaultAggregationType(dataQueryParam);
assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
assertThat(dataQueryParam.getPeriods(), hasSize(1));
assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent.
@Test
void verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent() {
List<DimensionalItemObject> periods = new ArrayList<>();
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
// DataQueryParams with **two** DataElement with different data type as
// dimension
DataQueryParams queryParams = DataQueryParams.newBuilder().withDimensions(// PERIOD DIMENSION
Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.TEXT, AggregationType.COUNT, DataElementDomain.AGGREGATE))))).withFilters(Lists.newArrayList(// OU FILTER
new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))).withAggregationType(AnalyticsAggregationType.AVERAGE).build();
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(2));
assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.NUMERIC))))));
assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.TEXT))))));
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class AnalyticsDimensionServiceTest method testGetRecommendedDimensions.
@Test
void testGetRecommendedDimensions() {
CategoryOption coA = createCategoryOption('A');
CategoryOption coB = createCategoryOption('B');
CategoryOption coC = createCategoryOption('C');
CategoryOption coD = createCategoryOption('D');
Category caA = createCategory('A', coA);
Category caB = createCategory('B', coB);
Category caC = createCategory('C', coC);
Category caD = createCategory('D', coD);
caD.setDataDimension(false);
CategoryCombo ccA = createCategoryCombo('A', caA, caB);
CategoryCombo ccB = createCategoryCombo('A', caC, caD);
DataSet dsA = createDataSet('A');
dsA.setCategoryCombo(ccB);
DataElement deA = createDataElement('A', ccA);
DataElement deB = createDataElement('B', ccA);
dsA.addDataSetElement(deB);
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA, deB)).build();
List<DimensionalObject> dimensons = dimensionService.getRecommendedDimensions(params);
assertEquals(3, dimensons.size());
assertTrue(dimensons.contains(caA));
assertTrue(dimensons.contains(caB));
assertTrue(dimensons.contains(caC));
params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA)).build();
dimensons = dimensionService.getRecommendedDimensions(params);
assertEquals(2, dimensons.size());
assertTrue(dimensons.contains(caA));
assertTrue(dimensons.contains(caB));
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class EventQueryParamsTest method testGetDuplicateQueryItems.
@Test
void testGetDuplicateQueryItems() {
QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
QueryItem iB = new QueryItem(createDataElement('B', new CategoryCombo()));
QueryItem iC = new QueryItem(createDataElement('B', new CategoryCombo()));
QueryItem iD = new QueryItem(createDataElement('D', new CategoryCombo()));
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));
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class DataElementTest method testGetCategoryCombos.
@Test
void testGetCategoryCombos() {
CategoryCombo ccA = new CategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION);
CategoryCombo ccB = new CategoryCombo("CategoryComboB", DataDimensionType.DISAGGREGATION);
DataSet dsA = new DataSet("DataSetA");
DataSet dsB = new DataSet("DataSetB");
DataElement deA = new DataElement("DataElementA");
DataElement deB = new DataElement("DataElementB");
deA.setCategoryCombo(ccA);
dsA.addDataSetElement(deA);
dsB.addDataSetElement(deA, ccB);
assertEquals(2, deA.getCategoryCombos().size());
assertEquals(Sets.newHashSet(ccA, ccB), deA.getCategoryCombos());
deB.setCategoryCombo(ccA);
dsB.addDataSetElement(deB);
assertEquals(1, deB.getCategoryCombos().size());
assertEquals(Sets.newHashSet(ccA), deB.getCategoryCombos());
}
Aggregations