Search in sources :

Example 6 with IndicatorType

use of org.hisp.dhis.indicator.IndicatorType in project dhis2-core by dhis2.

the class ExpressionServiceTest method testGetIndicatorValue.

@Test
public void testGetIndicatorValue() {
    IndicatorType indicatorType = new IndicatorType("A", 100, false);
    Indicator indicatorA = createIndicator('A', indicatorType);
    indicatorA.setNumerator(expressionE);
    indicatorA.setDenominator(expressionF);
    Indicator indicatorB = createIndicator('B', indicatorType);
    indicatorB.setNumerator(expressionN);
    indicatorB.setDenominator(expressionF);
    Map<DataElementOperand, Double> valueMap = new HashMap<>();
    valueMap.put(new DataElementOperand(deA, coc), 12d);
    valueMap.put(new DataElementOperand(deB, coc), 34d);
    valueMap.put(new DataElementOperand(deA, cocA, cocB), 46d);
    valueMap.put(new DataElementOperand(deB, cocA), 10d);
    Map<String, Double> constantMap = new HashMap<>();
    constantMap.put(constantA.getUid(), 2.0);
    assertEquals(200d, expressionService.getIndicatorValue(indicatorA, period, valueMap, constantMap, null), DELTA);
    assertEquals(300d, expressionService.getIndicatorValue(indicatorB, period, valueMap, constantMap, null), DELTA);
}
Also used : IndicatorType(org.hisp.dhis.indicator.IndicatorType) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with IndicatorType

use of org.hisp.dhis.indicator.IndicatorType in project dhis2-core by dhis2.

the class ExpressionServiceTest method testGetIndicatorValueObject.

@Test
public void testGetIndicatorValueObject() {
    IndicatorType indicatorType = new IndicatorType("A", 100, false);
    Indicator indicatorA = createIndicator('A', indicatorType);
    indicatorA.setNumerator(expressionE);
    indicatorA.setDenominator(expressionF);
    Indicator indicatorB = createIndicator('B', indicatorType);
    indicatorB.setNumerator(expressionN);
    indicatorB.setDenominator(expressionF);
    Map<DataElementOperand, Double> valueMap = new HashMap<>();
    valueMap.put(new DataElementOperand(deA, coc), 12d);
    valueMap.put(new DataElementOperand(deB, coc), 34d);
    valueMap.put(new DataElementOperand(deA, cocA, cocB), 46d);
    valueMap.put(new DataElementOperand(deB, cocA), 10d);
    Map<String, Double> constantMap = new HashMap<>();
    constantMap.put(constantA.getUid(), 2.0);
    IndicatorValue value = expressionService.getIndicatorValueObject(indicatorA, period, valueMap, constantMap, null);
    assertEquals(24d, value.getNumeratorValue(), DELTA);
    assertEquals(12d, value.getDenominatorValue(), DELTA);
    assertEquals(100, value.getFactor());
    assertEquals(200d, value.getValue(), DELTA);
    value = expressionService.getIndicatorValueObject(indicatorB, period, valueMap, constantMap, null);
    assertEquals(36d, value.getNumeratorValue(), DELTA);
    assertEquals(12d, value.getDenominatorValue(), DELTA);
    assertEquals(100, value.getFactor());
    assertEquals(300d, value.getValue(), DELTA);
}
Also used : IndicatorType(org.hisp.dhis.indicator.IndicatorType) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with IndicatorType

use of org.hisp.dhis.indicator.IndicatorType in project dhis2-core by dhis2.

the class ChartStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
    // ---------------------------------------------------------------------
    // Indicator
    // ---------------------------------------------------------------------
    IndicatorType indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorC = createIndicator('C', indicatorType);
    indicatorService.addIndicatorType(indicatorType);
    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);
    List<Indicator> indicators = new ArrayList<>();
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    indicators.add(indicatorC);
    // ---------------------------------------------------------------------
    // Period
    // ---------------------------------------------------------------------
    PeriodType periodType = new MonthlyPeriodType();
    periodA = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 1, 2));
    periodB = createPeriod(periodType, getDate(2000, 1, 3), getDate(2000, 1, 4));
    periodC = createPeriod(periodType, getDate(2000, 1, 5), getDate(2000, 1, 6));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    periodService.addPeriod(periodC);
    List<Period> periods = new ArrayList<>();
    periods.add(periodA);
    periods.add(periodB);
    periods.add(periodC);
    // ---------------------------------------------------------------------
    // OrganisationUnit
    // ---------------------------------------------------------------------
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    List<OrganisationUnit> units = new ArrayList<>();
    units.add(unitA);
    units.add(unitB);
    // units.add( unitC );
    chartA = createChart('A', indicators, periods, units);
    chartB = createChart('B', indicators, periods, units);
    chartC = createChart('C', indicators, periods, units);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IndicatorType(org.hisp.dhis.indicator.IndicatorType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Indicator(org.hisp.dhis.indicator.Indicator)

Example 9 with IndicatorType

use of org.hisp.dhis.indicator.IndicatorType in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testHandleGridForDataValueSet.

@Test
public void testHandleGridForDataValueSet() {
    IndicatorType itA = new IndicatorType();
    DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
    ocA.setUid("ceabcdefghA");
    DataElement dxA = createDataElement('A');
    dxA.setUid("deabcdefghA");
    dxA.setValueType(ValueType.INTEGER);
    DataElement dxB = createDataElement('B');
    dxB.setUid("deabcdefghB");
    dxB.setValueType(ValueType.NUMBER);
    Indicator dxC = createIndicator('C', itA);
    dxC.setUid("deabcdefghC");
    dxC.setDecimals(0);
    dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
    Indicator dxD = createIndicator('D', itA);
    dxD.setUid("deabcdefghD");
    dxD.setDecimals(2);
    dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
    DataElementOperand dxE = new DataElementOperand(dxA, ocA);
    DataElementOperand dxF = new DataElementOperand(dxB, ocA);
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
    assertEquals(4, grid.getWidth());
    assertEquals(6, grid.getHeight());
    AnalyticsUtils.handleGridForDataValueSet(params, grid);
    assertEquals(6, grid.getWidth());
    assertEquals(6, grid.getHeight());
    assertEquals("deabcdefghA", grid.getRow(0).get(0));
    assertNull(grid.getRow(0).get(3));
    assertNull(grid.getRow(0).get(4));
    assertEquals(1, grid.getRow(0).get(5));
    assertEquals("deabcdefghB", grid.getRow(1).get(0));
    assertNull(grid.getRow(1).get(3));
    assertNull(grid.getRow(1).get(4));
    assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
    assertEquals("deabcdefghC", grid.getRow(2).get(0));
    assertNull(grid.getRow(2).get(3));
    assertEquals("ceabcdefghA", grid.getRow(2).get(4));
    assertEquals(3, grid.getRow(2).get(5));
    assertEquals("deabcdefghD", grid.getRow(3).get(0));
    assertEquals("ceabcdefghB", grid.getRow(3).get(3));
    assertNull(grid.getRow(3).get(4));
    assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
    assertEquals("deabcdefghA", grid.getRow(4).get(0));
    assertEquals("ceabcdefghA", grid.getRow(4).get(3));
    assertNull(grid.getRow(4).get(4));
    assertEquals(5, grid.getRow(4).get(5));
    assertEquals("deabcdefghB", grid.getRow(5).get(0));
    assertEquals("ceabcdefghA", grid.getRow(5).get(3));
    assertNull(grid.getRow(5).get(4));
    assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

IndicatorType (org.hisp.dhis.indicator.IndicatorType)9 Indicator (org.hisp.dhis.indicator.Indicator)8 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)4 Test (org.junit.Test)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Period (org.hisp.dhis.period.Period)3 ArrayList (java.util.ArrayList)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Map (java.util.Map)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 Color (org.hisp.dhis.color.Color)1 ColorSet (org.hisp.dhis.color.ColorSet)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 ReportingRate (org.hisp.dhis.common.ReportingRate)1 Constant (org.hisp.dhis.constant.Constant)1