Search in sources :

Example 1 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithRelativePeriod.

@Test
void convertAnalyticsRequestWithRelativePeriod() {
    mockDimensionService();
    when(i18n.getString("LAST_12_MONTHS")).thenReturn("Last 12 months");
    when(i18n.getString("LAST_YEAR")).thenReturn("Last year");
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addPeDimension(PERIOD_DIMENSION);
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject dimension = params.getDimension(PERIOD_DIM_ID);
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("LAST_12_MONTHS"));
    assertEquals("Last 12 months", keywords.getKeyword("LAST_12_MONTHS").getMetadataItem().getName());
    assertNotNull(keywords.getKeyword("LAST_YEAR"));
    assertEquals("Last year", keywords.getKeyword("LAST_YEAR").getMetadataItem().getName());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 2 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method assertOrgUnitGroup.

private void assertOrgUnitGroup(String ouGroupUID, DimensionalObject dimension) {
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword(ouGroupUID));
    assertEquals("Chiefdom", keywords.getKeyword(ouGroupUID).getMetadataItem().getName());
    assertEquals("CODE_001", keywords.getKeyword(ouGroupUID).getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(rootOu.getUid()));
    assertEquals("Sierra Leone", keywords.getKeyword(rootOu.getUid()).getMetadataItem().getName());
    assertEquals(rootOu.getCode(), keywords.getKeyword(rootOu.getUid()).getMetadataItem().getCode());
}
Also used : DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords)

Example 3 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithMultipleOuLevelToDataQueryParam.

@Test
void convertAnalyticsRequestWithMultipleOuLevelToDataQueryParam() {
    mockDimensionService();
    when(organisationUnitService.getOrganisationUnitLevelByLevel(2)).thenReturn(buildOrgUnitLevel(2, "level2UID", "District", null));
    when(organisationUnitService.getOrganisationUnitLevelByLevel(3)).thenReturn(buildOrgUnitLevel(3, "level3UID", "Chiefdom", null));
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("3")).thenReturn(3);
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("2")).thenReturn(2);
    when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())).thenReturn(Lists.newArrayList(new OrganisationUnit(), new OrganisationUnit()));
    rb.addOuFilter("LEVEL-2;LEVEL-3;ImspTQPwCqd");
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addPeDimension(PERIOD_DIMENSION);
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject filter = params.getFilters().get(0);
    DimensionItemKeywords keywords = filter.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("level2UID"));
    assertEquals("District", keywords.getKeyword("level2UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level2UID").getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword("level3UID"));
    assertEquals("Chiefdom", keywords.getKeyword("level3UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level3UID").getMetadataItem().getCode());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 4 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithRelativePeriodAsFilter.

@Test
void convertAnalyticsRequestWithRelativePeriodAsFilter() {
    mockDimensionService();
    when(i18n.getString("LAST_12_MONTHS")).thenReturn("Last 12 months");
    when(i18n.getString("LAST_YEAR")).thenReturn("Last year");
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addPeDimension(PERIOD_DIMENSION);
    rb.addFilter("pe", "QUARTERS_THIS_YEAR");
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject dimension = params.getDimension(PERIOD_DIM_ID);
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("LAST_12_MONTHS"));
    assertEquals("Last 12 months", keywords.getKeyword("LAST_12_MONTHS").getMetadataItem().getName());
    assertNotNull(keywords.getKeyword("LAST_YEAR"));
    assertEquals("Last year", keywords.getKeyword("LAST_YEAR").getMetadataItem().getName());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 5 with DimensionItemKeywords

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

the class AnalyticsServiceMetadataTest method metadataContainsOuLevelData.

@SuppressWarnings("unchecked")
@Test
void metadataContainsOuLevelData() {
    DataQueryParams params = DataQueryParams.newBuilder().withPeriod(new Period(YearlyPeriodType.getPeriodFromIsoString("2017W10"))).withDataElements(newArrayList(createDataElement('A', new CategoryCombo()))).withIgnoreLimit(true).withFilters(Collections.singletonList(new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"), new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2")), new DimensionItemKeywords(Lists.newArrayList(buildOrgUnitLevel(2, "wjP19dkFeIk", "District", null), buildOrgUnitLevel(1, "tTUf91fCytl", "Chiefdom", "OU_12345")))))).build();
    initMock(params);
    Grid grid = target.getAggregatedDataValueGrid(params);
    Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
    assertThat(items.get("wjP19dkFeIk"), allOf(hasProperty("name", is("District")), hasProperty("uid", is("wjP19dkFeIk")), hasProperty("code", is(nullValue()))));
    assertThat(items.get("tTUf91fCytl"), allOf(hasProperty("name", is("Chiefdom")), hasProperty("uid", is("tTUf91fCytl")), hasProperty("code", is("OU_12345"))));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseNameableObject(org.hisp.dhis.common.BaseNameableObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)15 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)13 Test (org.junit.jupiter.api.Test)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 DimensionalObject (org.hisp.dhis.common.DimensionalObject)9 DataQueryRequest (org.hisp.dhis.common.DataQueryRequest)8 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)6 BaseNameableObject (org.hisp.dhis.common.BaseNameableObject)6 Grid (org.hisp.dhis.common.Grid)6 ArrayList (java.util.ArrayList)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)5 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)3 IndicatorGroup (org.hisp.dhis.indicator.IndicatorGroup)3 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)3 Period (org.hisp.dhis.period.Period)3 DateTime (org.joda.time.DateTime)3