Search in sources :

Example 71 with DimensionalItemObject

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

the class AnalyticsUtilsTest method testGetByDataDimensionType.

@Test
void testGetByDataDimensionType() {
    Program prA = createProgram('A');
    DataElement deA = createDataElement('A', new CategoryCombo());
    DataElement deB = createDataElement('B', new CategoryCombo());
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
    List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
    assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
    assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 72 with DimensionalItemObject

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

the class AnalyticsUtilsTest method testGetDimensionalItemObjectMap.

@Test
void testGetDimensionalItemObjectMap() {
    DataElement deA = createDataElement('A');
    Indicator inA = createIndicator('A', null);
    DataSet dsA = createDataSet('A');
    DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, DimensionalObjectUtils.getList(deA, inA, dsA));
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, DimensionalItemObject> map = AnalyticsUtils.getDimensionalItemObjectMap(params);
    assertEquals(map.get(deA.getDimensionItem()), deA);
    assertEquals(map.get(inA.getDimensionItem()), inA);
    assertEquals(map.get(dsA.getDimensionItem()), dsA);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataSet(org.hisp.dhis.dataset.DataSet) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 73 with DimensionalItemObject

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

the class ReportRatesHelperTest method testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInFilter.

@Test
void testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInFilter() {
    // Given
    final Double theTarget = 10d;
    final List<DimensionalItemObject> theFilterPeriods = asList(stubPeriod());
    final PeriodType theDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    final int anyNegativePeriodInDimensionIndex = -1;
    final int anyTimeUnits = 1;
    final List<String> anyDataRow = asList("TuL8IOPzpHh");
    final PeriodType aDataSetDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    // When
    final Double actualResult = getCalculatedTarget(anyNegativePeriodInDimensionIndex, anyTimeUnits, anyDataRow, theTarget, theDailyPeriodType, aDataSetDailyPeriodType, theFilterPeriods);
    // Then
    assertThat(actualResult, is(10.0d));
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 74 with DimensionalItemObject

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

the class ReportRatesHelperTest method testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInFilterAndMultiplePeriods.

@Test
void testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInFilterAndMultiplePeriods() {
    // Given
    final Double theTarget = 10d;
    final List<DimensionalItemObject> multipleFilterPeriods = asList(stubPeriod(), stubPeriod(), stubPeriod());
    final PeriodType theDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    final int anyNegativePeriodInDimensionIndex = -1;
    final int anyTimeUnits = 2;
    final List<String> anyDataRow = asList("TuL8IOPzpHh");
    final PeriodType aDataSetDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    // When
    final Double actualResult = getCalculatedTarget(anyNegativePeriodInDimensionIndex, anyTimeUnits, anyDataRow, theTarget, theDailyPeriodType, aDataSetDailyPeriodType, multipleFilterPeriods);
    // Then
    assertThat(actualResult, is(60.0d));
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 75 with DimensionalItemObject

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

the class ReportRatesHelperTest method testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInDimension.

@Test
void testGetCalculatedTargetWhenDataSetIsDailyAndHasPeriodInDimension() {
    // Given
    final Double theTarget = 10d;
    final List<DimensionalItemObject> theFilterPeriods = asList(stubPeriod());
    final PeriodType theDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    // Relates to "aDailyDataPeriodRow" objects
    final int anyPositivePeriodInDimensionIndex = 1;
    final List<String> aDailyDataPeriodRow = asList("TuL8IOPzpHh", "20210415");
    final int anyTimeUnits = 2;
    final PeriodType aDataSetDailyPeriodType = DailyPeriodType.getByNameIgnoreCase("Daily");
    // When
    final Double actualResult = getCalculatedTarget(anyPositivePeriodInDimensionIndex, anyTimeUnits, aDailyDataPeriodRow, theTarget, theDailyPeriodType, aDataSetDailyPeriodType, theFilterPeriods);
    // Then
    assertThat(actualResult, is(20.0d));
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.jupiter.api.Test)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)178 Test (org.junit.jupiter.api.Test)63 ArrayList (java.util.ArrayList)51 DimensionalObject (org.hisp.dhis.common.DimensionalObject)48 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)42 Period (org.hisp.dhis.period.Period)41 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)40 HashMap (java.util.HashMap)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)22 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)20 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)20 DataElement (org.hisp.dhis.dataelement.DataElement)20 List (java.util.List)17 Indicator (org.hisp.dhis.indicator.Indicator)17 Grid (org.hisp.dhis.common.Grid)16 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)16 ListMap (org.hisp.dhis.common.ListMap)15 QueryItem (org.hisp.dhis.common.QueryItem)15