Search in sources :

Example 6 with DimensionItemKeywords

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

the class AnalyticsServiceMetadataTest method metadataContainsOuGroupData.

@SuppressWarnings("unchecked")
@Test
void metadataContainsOuGroupData() {
    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(new BaseNameableObject("tTUf91fCytl", "OU_12345", "Chiefdom")))))).build();
    initMock(params);
    Grid grid = target.getAggregatedDataValueGrid(params);
    Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
    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) BaseNameableObject(org.hisp.dhis.common.BaseNameableObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 7 with DimensionItemKeywords

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

the class AnalyticsServiceMetadataTest method metadataContainsDataElementGroupMetadata.

@SuppressWarnings("unchecked")
@Test
void metadataContainsDataElementGroupMetadata() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    DataElementGroup dataElementGroup = new DataElementGroup("ANC");
    dataElementGroup.setCode("COD_1000");
    dataElementGroup.setUid("wjP19dkFeIk");
    DataQueryParams params = DataQueryParams.newBuilder().withDimensions(Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", ImmutableList.of(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo())), new DimensionItemKeywords(Collections.singletonList(dataElementGroup))))).withFilters(Collections.singletonList(new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"))))).withIgnoreLimit(true).withSkipData(true).build();
    initMock(params);
    Grid grid = target.getAggregatedDataValueGrid(params);
    Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
    assertThat(items.get(dataElementGroup.getUid()), allOf(hasProperty("name", is(dataElementGroup.getName())), hasProperty("uid", is(dataElementGroup.getUid())), hasProperty("code", is(dataElementGroup.getCode()))));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) 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)

Example 8 with DimensionItemKeywords

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

the class AnalyticsServiceMetadataTest method metadataContainsIndicatorGroupMetadata.

@SuppressWarnings("unchecked")
@Test
void metadataContainsIndicatorGroupMetadata() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    IndicatorGroup indicatorGroup = new IndicatorGroup("ANC");
    indicatorGroup.setCode("COD_1000");
    indicatorGroup.setUid("wjP19dkFeIk");
    DataQueryParams params = DataQueryParams.newBuilder().withDimensions(Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(new Indicator(), new Indicator(), createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo())), new DimensionItemKeywords(Collections.singletonList(indicatorGroup))))).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"))))).withIgnoreLimit(true).withSkipData(true).build();
    initMock(params);
    Grid grid = target.getAggregatedDataValueGrid(params);
    Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
    assertThat(items.get(indicatorGroup.getUid()), allOf(hasProperty("name", is(indicatorGroup.getName())), hasProperty("uid", is(indicatorGroup.getUid())), hasProperty("code", is(indicatorGroup.getCode()))));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IndicatorGroup(org.hisp.dhis.indicator.IndicatorGroup) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) Indicator(org.hisp.dhis.indicator.Indicator) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) 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)

Example 9 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithOrgUnitLevelAndOrgUnitGroupAsFilter.

@Test
void convertAnalyticsRequestWithOrgUnitLevelAndOrgUnitGroupAsFilter() {
    OrganisationUnit level2OuA = new OrganisationUnit("Bo");
    OrganisationUnit level2OuB = new OrganisationUnit("Bombali");
    OrganisationUnit ou1Group = new OrganisationUnit("ou1-group");
    OrganisationUnit ou2Group = new OrganisationUnit("ou2-group");
    OrganisationUnitGroup groupOu = rnd.nextObject(OrganisationUnitGroup.class);
    mockDimensionService();
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("wjP19dkFeIk")).thenReturn(2);
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "ImspTQPwCqd")).thenReturn(rootOu);
    when(idObjectManager.getObject(OrganisationUnitGroup.class, UID, "tDZVQ1WtwpA")).thenReturn(groupOu);
    when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())).thenReturn(Lists.newArrayList(level2OuA, level2OuB));
    when(organisationUnitService.getOrganisationUnitLevelByLevel(2)).thenReturn(buildOrgUnitLevel(2, "level2UID", "District", null));
    when(organisationUnitService.getOrganisationUnits(Lists.newArrayList(groupOu), Lists.newArrayList(rootOu))).thenReturn(Lists.newArrayList(ou1Group, ou2Group));
    rb.addOuFilter("LEVEL-wjP19dkFeIk;OU_GROUP-tDZVQ1WtwpA;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(3, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("level2UID"));
    assertEquals("District", keywords.getKeyword("level2UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level2UID").getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(groupOu.getUid()));
    assertEquals(groupOu.getName(), keywords.getKeyword(groupOu.getUid()).getMetadataItem().getName());
    assertEquals(groupOu.getCode(), keywords.getKeyword(groupOu.getUid()).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 : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) 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 10 with DimensionItemKeywords

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithDataElementGroupAndIndicatorGroup.

@Test
void convertAnalyticsRequestWithDataElementGroupAndIndicatorGroup() {
    final String DATA_ELEMENT_GROUP_UID = "oehv9EO3vP7";
    final String INDICATOR_GROUP_UID = "iezv4GO4vD9";
    when(dimensionService.getDataDimensionalItemObject(UID, "cYeuwXTCPkU")).thenReturn(new DataElement());
    DataElementGroup dataElementGroup = new DataElementGroup("dummyDG");
    dataElementGroup.setUid(DATA_ELEMENT_GROUP_UID);
    dataElementGroup.setCode("CODE_10");
    dataElementGroup.setMembers(Sets.newHashSet(new DataElement(), new DataElement()));
    IndicatorGroup indicatorGroup = new IndicatorGroup("dummyIG");
    indicatorGroup.setUid(INDICATOR_GROUP_UID);
    indicatorGroup.setCode("CODE_10");
    indicatorGroup.setMembers(Sets.newHashSet(new Indicator(), new Indicator()));
    when(idObjectManager.getObject(DataElementGroup.class, UID, DATA_ELEMENT_GROUP_UID)).thenReturn(dataElementGroup);
    when(idObjectManager.getObject(IndicatorGroup.class, UID, INDICATOR_GROUP_UID)).thenReturn(indicatorGroup);
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "goRUwCHPg1M")).thenReturn(new OrganisationUnit("aaa"));
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "fdc6uOvgoji")).thenReturn(new OrganisationUnit("bbb"));
    rb.addOuFilter("goRUwCHPg1M;fdc6uOvgoji");
    rb.addDimension("DE_GROUP-" + DATA_ELEMENT_GROUP_UID + ";cYeuwXTCPkU;Jtf34kNZhz;IN_GROUP-" + INDICATOR_GROUP_UID);
    rb.addPeDimension(PERIOD_DIMENSION);
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject dimension = params.getDimension("dx");
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword(dataElementGroup.getUid()));
    assertEquals("dummyDG", keywords.getKeyword(dataElementGroup.getUid()).getMetadataItem().getName());
    assertEquals("CODE_10", keywords.getKeyword(dataElementGroup.getUid()).getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(indicatorGroup.getUid()));
    assertEquals("dummyIG", keywords.getKeyword(indicatorGroup.getUid()).getMetadataItem().getName());
    assertEquals("CODE_10", keywords.getKeyword(indicatorGroup.getUid()).getMetadataItem().getCode());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IndicatorGroup(org.hisp.dhis.indicator.IndicatorGroup) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) Indicator(org.hisp.dhis.indicator.Indicator) DimensionalObject(org.hisp.dhis.common.DimensionalObject) 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