Search in sources :

Example 21 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testHandleGridForDataValueSet.

@Test
void testHandleGridForDataValueSet() {
    IndicatorType itA = new IndicatorType();
    CategoryOptionCombo 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, 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((Double) grid.getRow(1).get(5), 0.01, 2d);
    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((Double) grid.getRow(3).get(5), 0.01, 4d);
    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((Double) grid.getRow(5).get(5), 0.01, 6d);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IndicatorType(org.hisp.dhis.indicator.IndicatorType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 22 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetCocNameMap.

@Test
void testGetCocNameMap() {
    CategoryCombo ccA = createCategoryCombo('A', new Category[0]);
    CategoryCombo ccB = createCategoryCombo('B', new Category[0]);
    CategoryOptionCombo cocA = createCategoryOptionCombo('A');
    CategoryOptionCombo cocB = createCategoryOptionCombo('B');
    ccA.getOptionCombos().add(cocA);
    ccB.getOptionCombos().add(cocB);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.setCategoryCombo(ccA);
    deB.setCategoryCombo(ccB);
    DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB));
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, String> map = AnalyticsUtils.getCocNameMap(params);
    assertEquals(map.get(cocA.getUid()), cocA.getName());
    assertEquals(map.get(cocB.getUid()), cocB.getName());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 23 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryOptionGroupResolverTest method setUp.

@BeforeEach
public void setUp() {
    uid1 = CodeGenerator.generateUid();
    uid2 = CodeGenerator.generateUid();
    uid3 = CodeGenerator.generateUid();
    CategoryOptionGroup categoryOptionGroup = createCategoryOptionGroup('A');
    coc1 = createCategoryOptionCombo('X');
    coc2 = createCategoryOptionCombo('Y');
    coc3 = createCategoryOptionCombo('Z');
    resolver = new CategoryOptionGroupResolver(expressionService, categoryOptionGroupStore, categoryOptionComboStore);
    when(categoryOptionGroupStore.getByUid(anyString())).thenReturn(categoryOptionGroup);
    List<CategoryOptionCombo> cocList = new ArrayList<>();
    cocList.add(coc1);
    cocList.add(coc2);
    cocList.add(coc3);
    when(categoryOptionComboStore.getCategoryOptionCombosByGroupUid(anyString(), anyString())).thenReturn(cocList);
}
Also used : DhisConvenienceTest.createCategoryOptionGroup(org.hisp.dhis.DhisConvenienceTest.createCategoryOptionGroup) CategoryOptionGroup(org.hisp.dhis.category.CategoryOptionGroup) ArrayList(java.util.ArrayList) DhisConvenienceTest.createCategoryOptionCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryOptionCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class PredictorStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementX = createDataElement('X');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementX);
    CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    defaultCombo = categoryOptionCombo;
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    expressionC = new Expression("expressionC", "descriptionC");
    expressionD = new Expression("expressionD", "descriptionD");
    periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Also used : Expression(org.hisp.dhis.expression.Expression) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 25 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AttributeOptionComboDateCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
    Date executionDate = null;
    if (event.getEventDate() != null) {
        executionDate = DateUtils.parseDate(event.getEventDate());
    }
    Date dueDate = new Date();
    if (event.getDueDate() != null) {
        dueDate = DateUtils.parseDate(event.getDueDate());
    }
    Date eventDate = executionDate != null ? executionDate : dueDate;
    if (eventDate == null) {
        return error("Event date can not be empty", event.getEvent());
    }
    Program program = ctx.getProgramsMap().get(event.getProgram());
    for (CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions()) {
        if (categoryOption.getStartDate() != null && eventDate.compareTo(categoryOption.getStartDate()) < 0) {
            return error("Event date " + getMediumDateString(eventDate) + " is before start date " + getMediumDateString(categoryOption.getStartDate()) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent());
        }
        if (categoryOption.getEndDate() != null && eventDate.compareTo(categoryOption.getAdjustedEndDate(program)) > 0) {
            return error("Event date " + getMediumDateString(eventDate) + " is after end date " + getMediumDateString(categoryOption.getAdjustedEndDate(program)) + " for attributeOption '" + categoryOption.getName() + "' in program '" + program.getName() + "'", event.getEvent());
        }
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16