Search in sources :

Example 81 with CategoryCombo

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));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 82 with CategoryCombo

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))))));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 83 with CategoryCombo

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));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) CategoryOption(org.hisp.dhis.category.CategoryOption) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 84 with CategoryCombo

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));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 85 with CategoryCombo

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());
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19