Search in sources :

Example 26 with DimensionalItemId

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

the class DataDimensionExtractorTest method testGetAtomicIdsForProgramIndicator.

@Test
void testGetAtomicIdsForProgramIndicator() {
    // Given
    final DimensionalItemId programIndicatorItem = new DimensionalItemId(PROGRAM_INDICATOR, "id0");
    final Set<DimensionalItemId> someItemIds = newHashSet(programIndicatorItem);
    // When
    final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
    // Then
    assertThat(result.size(), is(equalTo(1)));
    assertThat(result.get(ProgramIndicator.class), containsInAnyOrder(programIndicatorItem.getId0()));
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 27 with DimensionalItemId

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

the class DataDimensionExtractorTest method testGetAtomicIdsForDataElementOperand.

@Test
void testGetAtomicIdsForDataElementOperand() {
    // Given
    final DimensionalItemId dataElementOperandItem = new DimensionalItemId(DATA_ELEMENT_OPERAND, "id0", "id1", "id2");
    final Set<DimensionalItemId> someItemIds = newHashSet(dataElementOperandItem);
    // When
    final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
    // Then
    assertThat(result.size(), is(equalTo(2)));
    assertThat(result.get(DataElement.class), containsInAnyOrder(dataElementOperandItem.getId0()));
    assertThat(result.get(CategoryOptionCombo.class), containsInAnyOrder(dataElementOperandItem.getId1(), dataElementOperandItem.getId2()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 28 with DimensionalItemId

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

the class ExpressionServiceTest method testIndicatorFunctionParsing.

@Test
void testIndicatorFunctionParsing() {
    DimensionalItemId id;
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", (QueryModifiers) null);
    assertEquals(id, parseItemId("#{dataElemenA}"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().aggregationType(LAST).build());
    assertEquals(id, parseItemId("#{dataElemenA}.aggregationType(LAST)"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().periodOffset(10).build());
    assertEquals(id, parseItemId("#{dataElemenA}.periodOffset(10)"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().periodOffset(-5).build());
    assertEquals(id, parseItemId("#{dataElemenA}.periodOffset(-2).periodOffset(-3)"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().minDate(parseDate("2020-01-01")).build());
    assertEquals(id, parseItemId("#{dataElemenA}.minDate(2020-1-1)"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().maxDate(parseDate("2021-12-31")).build());
    assertEquals(id, parseItemId("#{dataElemenA}.maxDate(2021-12-31)"));
    id = new DimensionalItemId(DATA_ELEMENT, "dataElemenA", QueryModifiers.builder().periodOffset(-3).minDate(parseDate("2021-04-01")).maxDate(parseDate("2021-04-30")).build());
    assertEquals(id, parseItemId("#{dataElemenA}.periodOffset(-3).minDate(2021-04-1).maxDate(2021-4-30)"));
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 29 with DimensionalItemId

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

the class ExpressionServiceTest method testMultipleNestedIndicators.

// -------------------------------------------------------------------------
// Indicator expression tests
// -------------------------------------------------------------------------
@Test
void testMultipleNestedIndicators() {
    Indicator indicatorB = createIndicator('B', indicatorTypeB, "10");
    Indicator indicatorC = createIndicator('C', indicatorTypeB, "20");
    Indicator indicatorD = createIndicator('D', indicatorTypeB, "30");
    Indicator indicatorE = createIndicator('E', indicatorTypeB, "N{mindicatorC}*N{mindicatorB}-N{mindicatorD}");
    DimensionalItemId idB = new DimensionalItemId(DimensionItemType.INDICATOR, indicatorB.getUid());
    DimensionalItemId idC = new DimensionalItemId(DimensionItemType.INDICATOR, indicatorC.getUid());
    DimensionalItemId idD = new DimensionalItemId(DimensionItemType.INDICATOR, indicatorD.getUid());
    List<Indicator> indicators = singletonList(indicatorE);
    Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(idB, indicatorB, idC, indicatorC, idD, indicatorD);
    Map<DimensionalItemId, DimensionalItemObject> itemMap = expressionService.getIndicatorDimensionalItemMap(indicators);
    assertMapEquals(expectedItemMap, itemMap);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 30 with DimensionalItemId

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

the class DimensionServiceTest method setUpTest.

@Override
public void setUpTest() {
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deC.setDomainType(DataElementDomain.TRACKER);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    cocA = categoryService.getDefaultCategoryOptionCombo();
    dsA = createDataSet('A');
    dataSetService.addDataSet(dsA);
    prA = createProgram('A');
    idObjectManager.save(prA);
    psA = createProgramStage('A', 1);
    idObjectManager.save(psA);
    atA = createTrackedEntityAttribute('A');
    idObjectManager.save(atA);
    piA = createProgramIndicator('A', prA, null, null);
    idObjectManager.save(piA);
    peA = createPeriod("201201");
    peB = createPeriod("201202");
    peLast12Months = new BaseDimensionalItemObject(LAST_12_MONTHS.toString());
    peA.setUid("201201");
    peB.setUid("201202");
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    ouD = createOrganisationUnit('D');
    ouE = createOrganisationUnit('E');
    ouB.updateParent(ouA);
    ouC.updateParent(ouA);
    ouD.updateParent(ouB);
    ouE.updateParent(ouB);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    String level2 = KEY_LEVEL + 2;
    ouUser = new BaseDimensionalItemObject(KEY_USER_ORGUNIT);
    ouLevel2 = new BaseDimensionalItemObject(level2);
    deGroupSetA = createDataElementGroupSet('A');
    dataElementService.addDataElementGroupSet(deGroupSetA);
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupC = createDataElementGroup('C');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupC.getGroupSets().add(deGroupSetA);
    dataElementService.addDataElementGroup(deGroupA);
    dataElementService.addDataElementGroup(deGroupB);
    dataElementService.addDataElementGroup(deGroupC);
    deGroupSetA.getMembers().add(deGroupA);
    deGroupSetA.getMembers().add(deGroupB);
    deGroupSetA.getMembers().add(deGroupC);
    dataElementService.updateDataElementGroupSet(deGroupSetA);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupService.addOrganisationUnitGroupSet(ouGroupSetA);
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupC = createOrganisationUnitGroup('C');
    ouGroupA.getGroupSets().add(ouGroupSetA);
    ouGroupB.getGroupSets().add(ouGroupSetA);
    ouGroupC.getGroupSets().add(ouGroupSetA);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupC);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupA);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupB);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupC);
    organisationUnitGroupService.updateOrganisationUnitGroupSet(ouGroupSetA);
    queryModsA = QueryModifiers.builder().periodOffset(10).build();
    queryModsB = QueryModifiers.builder().minDate(new Date()).build();
    queryModsC = QueryModifiers.builder().maxDate(new Date()).build();
    itemObjectA = deA;
    itemObjectB = new DataElementOperand(deA, cocA);
    itemObjectC = new DataElementOperand(deA, null, cocA);
    itemObjectD = new DataElementOperand(deA, cocA, cocA);
    itemObjectE = new ReportingRate(dsA);
    itemObjectF = new ProgramDataElementDimensionItem(prA, deA);
    itemObjectG = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
    itemObjectH = piA;
    itemIdA = new DimensionalItemId(DATA_ELEMENT, deA.getUid());
    itemIdB = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), cocA.getUid());
    itemIdC = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), null, cocA.getUid());
    itemIdD = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), cocA.getUid(), cocA.getUid());
    itemIdE = new DimensionalItemId(REPORTING_RATE, dsA.getUid(), ReportingRateMetric.REPORTING_RATE.name());
    itemIdF = new DimensionalItemId(PROGRAM_DATA_ELEMENT, prA.getUid(), deA.getUid());
    itemIdG = new DimensionalItemId(PROGRAM_ATTRIBUTE, prA.getUid(), atA.getUid());
    itemIdH = new DimensionalItemId(PROGRAM_INDICATOR, piA.getUid());
    itemIds = new HashSet<>();
    itemIds.add(itemIdA);
    itemIds.add(itemIdB);
    itemIds.add(itemIdC);
    itemIds.add(itemIdD);
    itemIds.add(itemIdE);
    itemIds.add(itemIdF);
    itemIds.add(itemIdG);
    itemIds.add(itemIdH);
    itemMap = ImmutableMap.<DimensionalItemId, DimensionalItemObject>builder().put(itemIdA, itemObjectA).put(itemIdB, itemObjectB).put(itemIdC, itemObjectC).put(itemIdD, itemObjectD).put(itemIdE, itemObjectE).put(itemIdF, itemObjectF).put(itemIdG, itemObjectG).put(itemIdH, itemObjectH).build();
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Date(java.util.Date) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Aggregations

DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)46 Test (org.junit.jupiter.api.Test)32 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)21 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Indicator (org.hisp.dhis.indicator.Indicator)12 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 HashMap (java.util.HashMap)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)9 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)9 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)6 DataElement (org.hisp.dhis.dataelement.DataElement)5 List (java.util.List)4 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)4 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AllArgsConstructor (lombok.AllArgsConstructor)3