Search in sources :

Example 21 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventQueryParamsTest method testIsOrgUnitFieldValidWithOneProgramIndicator.

@Test
void testIsOrgUnitFieldValidWithOneProgramIndicator() {
    QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
    ProgramIndicator programIndicatorA = createProgramIndicator('A', prA, "", "");
    EventQueryParams params = new EventQueryParams.Builder().withProgram(null).withOrgUnitField(deD.getUid()).addItem(iA).addItemProgramIndicator(programIndicatorA).build();
    assertTrue(params.orgUnitFieldIsValid());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 22 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventQueryParamsTest method testIsTimeFieldValid.

@Test
void testIsTimeFieldValid() {
    QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withTimeField(deC.getUid()).addItem(iA).build();
    assertTrue(params.timeFieldIsValid());
    params = new EventQueryParams.Builder().withProgram(prA).withTimeField(TimeField.SCHEDULED_DATE.name()).addItem(iA).build();
    assertTrue(params.timeFieldIsValid());
    params = new EventQueryParams.Builder().withProgram(prA).withTimeField("someInvalidTimeField").addItem(iA).build();
    assertFalse(params.timeFieldIsValid());
}
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 23 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType.

@Test
void verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType() {
    // DataQueryParams with **two** DataElement as filter
    // One Data Element has Type Numeric
    // 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.TEXT, 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 24 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType.

@Test
void verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType() {
    // DataQueryParams with **two** DataElement as filter
    // Both have DataType NUMERIC and AggregationType SUM
    DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo()))));
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    assertTrue(dataQueryParam.getAggregationType().isAggregationType(AggregationType.SUM));
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(DataType.NUMERIC));
    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 25 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType.

@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType() {
    // DataQueryParams with **two** DataElement as filter
    // Both have DataType NUMERIC but different AggregationType
    DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.INTEGER, AggregationType.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)

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