Search in sources :

Example 81 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DataValueDimensionTest method testGetDimensions.

@Test
public void testGetDimensions() {
    List<DataElementCategoryOption> categoryOptions = new ArrayList<>();
    categoryOptions.add(male);
    categoryOptions.add(under15);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
    DataValue dataValue = dataValueService.getDataValue(dataElementA, periodA, sourceA, categoryOptionCombo);
    assertNotNull(dataValue);
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 82 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DataValueDimensionTest method testGetByCategoryOptionCombos.

@Test
public void testGetByCategoryOptionCombos() {
    List<DataElementCategoryOption> categoryOptions = new ArrayList<>();
    categoryOptions.add(male);
    categoryOptions.add(under15);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
    assertNotNull(categoryOptionCombo);
    assertEquals(genderAndAgeGroup, categoryOptionCombo.getCategoryCombo());
    assertTrue(CollectionUtils.isEqualCollection(categoryOptions, categoryOptionCombo.getCategoryOptions()));
    categoryOptions.clear();
    categoryOptions.add(female);
    categoryOptions.add(over15);
    categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
    assertNotNull(categoryOptionCombo);
    assertEquals(genderAndAgeGroup, categoryOptionCombo.getCategoryCombo());
    assertTrue(CollectionUtils.isEqualCollection(categoryOptions, categoryOptionCombo.getCategoryOptions()));
    categoryOptions.clear();
    categoryOptions.add(male);
    categoryOptions.add(female);
    categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
    assertNull(categoryOptionCombo);
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 83 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class PredictorServiceTest 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', ValueType.NUMBER, AggregationType.NONE);
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementX);
    dataElements = new HashSet<>();
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B');
    sourceC = createOrganisationUnit('C', sourceB);
    sourceD = createOrganisationUnit('D', sourceB);
    sourceE = createOrganisationUnit('E', sourceD);
    sourceF = createOrganisationUnit('F', sourceD);
    sourceG = createOrganisationUnit('G');
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    organisationUnitService.addOrganisationUnit(sourceE);
    organisationUnitService.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceG);
    periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
    dataSetMonthly = createDataSet('M', periodTypeMonthly);
    dataSetMonthly.addDataSetElement(dataElementA);
    dataSetMonthly.addDataSetElement(dataElementB);
    dataSetMonthly.addDataSetElement(dataElementC);
    dataSetMonthly.addDataSetElement(dataElementD);
    dataSetMonthly.addDataSetElement(dataElementX);
    dataSetMonthly.addOrganisationUnit(sourceA);
    dataSetMonthly.addOrganisationUnit(sourceB);
    dataSetMonthly.addOrganisationUnit(sourceC);
    dataSetMonthly.addOrganisationUnit(sourceD);
    dataSetMonthly.addOrganisationUnit(sourceE);
    dataSetMonthly.addOrganisationUnit(sourceG);
    dataSetService.addDataSet(dataSetMonthly);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    altCategoryOption = new DataElementCategoryOption("AltCategoryOption");
    categoryService.addDataElementCategoryOption(altCategoryOption);
    altDataElementCategory = createDataElementCategory('A', altCategoryOption);
    categoryService.addDataElementCategory(altDataElementCategory);
    altDataElementCategoryCombo = createCategoryCombo('Y', altDataElementCategory);
    categoryService.addDataElementCategoryCombo(altDataElementCategoryCombo);
    altCombo = createCategoryOptionCombo('Z', altDataElementCategoryCombo, altCategoryOption);
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    optionCombos.add(altCombo);
    categoryService.addDataElementCategoryOptionCombo(altCombo);
    expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
    expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
    expressionC = new Expression("1234", "descriptionC");
    expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
    expressionService.addExpression(expressionA);
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionC);
    expressionService.addExpression(expressionD);
    Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
    CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
    setDependency(predictorService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 84 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class ExpressionStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    DataElement dataElementD = createDataElement('D');
    dataElementIdA = dataElementService.addDataElement(dataElementA);
    dataElementIdB = dataElementService.addDataElement(dataElementB);
    dataElementIdC = dataElementService.addDataElement(dataElementC);
    dataElementIdD = dataElementService.addDataElement(dataElementD);
    DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryComboByName(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = "[" + dataElementIdA + "] + [" + dataElementIdB + "]";
    expressionB = "[" + dataElementIdC + "] - [" + dataElementIdD + "]";
    descriptionA = "Expression A";
    descriptionB = "Expression B";
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 85 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class InputUtils method getAttributeOptionCombo.

/**
     * Validates and retrieves the attribute option combo. 409 conflict as
     * status code along with a textual message will be set on the response in
     * case of invalid input.
     *
     * @param categoryCombo the category combo.
     * @param opts list of category option uid.
     * @param attributeOptionCombo the explicit attribute option combo
     *        identifier.
     * @return the attribute option combo identified from the given input, or
     *         null if the input was invalid.
     */
public DataElementCategoryOptionCombo getAttributeOptionCombo(DataElementCategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
    if (categoryCombo == null) {
        throw new IllegalQueryException("Illegal category combo");
    }
    // ---------------------------------------------------------------------
    // Attribute category options validation
    // ---------------------------------------------------------------------
    DataElementCategoryOptionCombo attrOptCombo = null;
    if (opts != null) {
        Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
        for (String uid : opts) {
            DataElementCategoryOption categoryOption = idObjectManager.getObject(DataElementCategoryOption.class, idScheme, uid);
            if (categoryOption == null) {
                throw new IllegalQueryException("Illegal category option identifier: " + uid);
            }
            categoryOptions.add(categoryOption);
        }
        attrOptCombo = categoryService.getDataElementCategoryOptionCombo(categoryCombo, categoryOptions);
        if (attrOptCombo == null) {
            throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
        }
    } else if (attributeOptionCombo != null) {
        attrOptCombo = categoryService.getDataElementCategoryOptionCombo(attributeOptionCombo);
    }
    if (attrOptCombo == null) {
        attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    }
    if (attrOptCombo == null) {
        throw new IllegalQueryException("Default attribute option combo does not exist");
    }
    return attrOptCombo;
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4