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"))));
}
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()))));
}
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()))));
}
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());
}
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());
}
Aggregations