Search in sources :

Example 71 with CategoryOption

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

the class DefaultAggregateAccessManager method canWrite.

@Override
public List<String> canWrite(User user, DataElementOperand dataElementOperand) {
    List<String> errors = new ArrayList<>();
    if (user == null || user.isSuper()) {
        return errors;
    }
    Set<CategoryOption> options = new HashSet<>();
    CategoryOptionCombo categoryOptionCombo = dataElementOperand.getCategoryOptionCombo();
    if (categoryOptionCombo != null) {
        options.addAll(categoryOptionCombo.getCategoryOptions());
    }
    CategoryOptionCombo attributeOptionCombo = dataElementOperand.getAttributeOptionCombo();
    if (attributeOptionCombo != null) {
        options.addAll(attributeOptionCombo.getCategoryOptions());
    }
    options.forEach(option -> {
        if (!aclService.canDataWrite(user, option)) {
            errors.add("User has no data write access for CategoryOption: " + option.getUid());
        }
    });
    return errors;
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 72 with CategoryOption

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

the class PredictionServiceTest method testPredictMultipleAttributeOptionCombos.

@Test
void testPredictMultipleAttributeOptionCombos() {
    CategoryOption optionJ = new CategoryOption("CategoryOptionJ");
    CategoryOption optionK = new CategoryOption("CategoryOptionK");
    CategoryOption optionL = new CategoryOption("CategoryOptionL");
    categoryService.addCategoryOption(optionJ);
    categoryService.addCategoryOption(optionK);
    categoryService.addCategoryOption(optionL);
    Category categoryJ = createCategory('J', optionJ, optionK);
    Category categoryL = createCategory('L', optionL);
    categoryJ.setDataDimension(true);
    categoryL.setDataDimension(true);
    categoryService.addCategory(categoryJ);
    categoryService.addCategory(categoryL);
    CategoryCombo categoryComboJL = createCategoryCombo('A', categoryJ, categoryL);
    categoryService.addCategoryCombo(categoryComboJL);
    CategoryOptionCombo optionComboJL = createCategoryOptionCombo(categoryComboJL, optionJ, optionK);
    CategoryOptionCombo optionComboKL = createCategoryOptionCombo(categoryComboJL, optionK, optionL);
    categoryService.addCategoryOptionCombo(optionComboJL);
    categoryService.addCategoryOptionCombo(optionComboKL);
    useDataValue(dataElementA, makeMonth(2011, 6), sourceA, optionComboJL, 1);
    useDataValue(dataElementB, makeMonth(2011, 6), sourceA, optionComboJL, 2);
    useDataValue(dataElementA, makeMonth(2011, 6), sourceA, optionComboKL, 3);
    useDataValue(dataElementB, makeMonth(2011, 6), sourceA, optionComboKL, 4);
    dataValueBatchHandler.flush();
    Predictor p = createPredictor(dataElementX, defaultCombo, "A", expressionG, null, periodTypeMonthly, orgUnitLevel1, 1, 0, 0);
    predictionService.predict(p, monthStart(2011, 7), monthStart(2011, 8), summary);
    assertEquals("Pred 1 Ins 2 Upd 0 Del 0 Unch 0", shortSummary(summary));
    assertEquals("3.0", getDataValue(dataElementX, defaultCombo, optionComboJL, sourceA, makeMonth(2011, 7)));
    assertEquals("7.0", getDataValue(dataElementX, defaultCombo, optionComboKL, sourceA, makeMonth(2011, 7)));
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 73 with CategoryOption

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

the class ValidationServiceTest method testValidateWithAttributeOptions.

@Test
void testValidateWithAttributeOptions() {
    CategoryOption optionA = new CategoryOption("CategoryOptionA");
    CategoryOption optionB = new CategoryOption("CategoryOptionB");
    CategoryOption optionC = new CategoryOption("CategoryOptionC");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    categoryService.addCategoryOption(optionC);
    Category categoryA = createCategory('A', optionA, optionB);
    Category categoryB = createCategory('B', optionC);
    categoryA.setDataDimension(true);
    categoryB.setDataDimension(true);
    categoryService.addCategory(categoryA);
    categoryService.addCategory(categoryB);
    CategoryCombo categoryComboAB = createCategoryCombo('A', categoryA, categoryB);
    categoryService.addCategoryCombo(categoryComboAB);
    CategoryOptionCombo optionComboAC = createCategoryOptionCombo(categoryComboAB, optionA, optionC);
    CategoryOptionCombo optionComboBC = createCategoryOptionCombo(categoryComboAB, optionB, optionC);
    categoryService.addCategoryOptionCombo(optionComboAC);
    categoryService.addCategoryOptionCombo(optionComboBC);
    useDataValue(dataElementA, periodA, sourceA, "4", optionCombo, optionComboAC);
    useDataValue(dataElementB, periodA, sourceA, "3", optionCombo, optionComboAC);
    useDataValue(dataElementA, periodA, sourceA, "2", optionCombo, optionComboBC);
    useDataValue(dataElementB, periodA, sourceA, "1", optionCombo, optionComboBC);
    // deA + deB < deB * 2
    validationRuleService.saveValidationRule(ruleD);
    // deA + deB = deB * 2
    validationRuleService.saveValidationRule(ruleX);
    // 
    // optionComboAC
    // 
    Collection<ValidationResult> results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).withAttributeOptionCombo(optionComboAC).build());
    Collection<ValidationResult> reference = new HashSet<>();
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    assertResultsEquals(reference, results);
    // 
    // All optionCombos
    // 
    results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).build());
    reference = new HashSet<>();
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboBC, 3.0, 2.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboBC, 3.0, 2.0, dayInPeriodA));
    assertResultsEquals(reference, results);
    // 
    // Default optionCombo
    // 
    results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).withAttributeOptionCombo(optionCombo).build());
    assertResultsEmpty(results);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 74 with CategoryOption

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

the class ValidationServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    this.userService = injectUserService;
    CurrentUserService currentUserService = new MockCurrentUserService(allSources, null);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, validationService);
    ptWeekly = new WeeklyPeriodType();
    ptMonthly = new MonthlyPeriodType();
    ptYearly = new YearlyPeriodType();
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementE = createDataElement('E');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementE);
    CategoryOption optionX = createCategoryOption('X');
    Category categoryX = createCategory('X', optionX);
    categoryComboX = createCategoryCombo('X', categoryX);
    optionComboX = createCategoryOptionCombo(categoryComboX, optionX);
    categoryComboX.getOptionCombos().add(optionComboX);
    categoryService.addCategoryOption(optionX);
    categoryService.addCategory(categoryX);
    categoryService.addCategoryCombo(categoryComboX);
    categoryService.addCategoryOptionCombo(optionComboX);
    optionCombo = categoryService.getDefaultCategoryOptionCombo();
    String suffixX = SEPARATOR + optionComboX.getUid();
    String suffix = SEPARATOR + optionCombo.getUid();
    optionCombos = new HashSet<>();
    optionCombos.add(optionCombo);
    Expression expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
    Expression expressionA2 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA2");
    Expression expressionA3 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA3");
    Expression expressionA4 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA4");
    Expression expressionA5 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA5");
    Expression expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
    Expression expressionB2 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB2");
    Expression expressionB3 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB3");
    Expression expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
    Expression expressionC2 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC2");
    Expression expressionC3 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC3");
    Expression expressionI = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI");
    Expression expressionI2 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI2");
    Expression expressionI3 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI3");
    Expression expressionJ = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ");
    Expression expressionJ2 = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ2");
    Expression expressionK = new Expression("#{" + dataElementC.getUid() + "}", "expressionK", NEVER_SKIP);
    Expression expressionL = new Expression("#{" + dataElementD.getUid() + "}", "expressionL", NEVER_SKIP);
    Expression expressionP = new Expression(SYMBOL_DAYS, "expressionP", NEVER_SKIP);
    Expression expressionP2 = new Expression(SYMBOL_DAYS, "expressionP2", NEVER_SKIP);
    Expression expressionQ = new Expression("#{" + dataElementE.getUid() + "}", "expressionQ", NEVER_SKIP);
    Expression expressionR = new Expression("#{" + dataElementA.getUid() + "} + #{" + dataElementB.getUid() + "}", "expressionR");
    Expression expressionS = new Expression("#{" + dataElementA.getUid() + suffixX + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionS");
    Expression expressionT = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionT");
    Expression expressionU = new Expression("1000", "expressionU");
    Expression expressionU2 = new Expression("1000", "expressionU2");
    Expression expressionU3 = new Expression("1000", "expressionU3");
    Expression expressionU4 = new Expression("1000", "expressionU4");
    periodA = createPeriod(ptMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
    periodB = createPeriod(ptMonthly, getDate(2000, 4, 1), getDate(2000, 4, 30));
    periodC = createPeriod(ptMonthly, getDate(2000, 5, 1), getDate(2000, 5, 31));
    periodY = createPeriod(ptYearly, getDate(2000, 1, 1), getDate(2000, 12, 31));
    dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
    dayInPeriodB = periodService.getDayInPeriod(periodB, new Date());
    dayInPeriodC = periodService.getDayInPeriod(periodC, new Date());
    dayInPeriodY = periodService.getDayInPeriod(periodY, new Date());
    dataSetWeekly = createDataSet('W', ptWeekly);
    dataSetMonthly = createDataSet('M', ptMonthly);
    dataSetYearly = createDataSet('Y', ptYearly);
    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');
    allSources.add(sourceA);
    allSources.add(sourceB);
    allSources.add(sourceC);
    allSources.add(sourceD);
    allSources.add(sourceE);
    allSources.add(sourceF);
    allSources.add(sourceG);
    dataSetMonthly.addOrganisationUnit(sourceA);
    dataSetMonthly.addOrganisationUnit(sourceB);
    dataSetMonthly.addOrganisationUnit(sourceC);
    dataSetMonthly.addOrganisationUnit(sourceD);
    dataSetMonthly.addOrganisationUnit(sourceE);
    dataSetMonthly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceB);
    dataSetWeekly.addOrganisationUnit(sourceC);
    dataSetWeekly.addOrganisationUnit(sourceD);
    dataSetWeekly.addOrganisationUnit(sourceE);
    dataSetWeekly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceG);
    dataSetYearly.addOrganisationUnit(sourceB);
    dataSetYearly.addOrganisationUnit(sourceC);
    dataSetYearly.addOrganisationUnit(sourceD);
    dataSetYearly.addOrganisationUnit(sourceE);
    dataSetYearly.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    organisationUnitService.addOrganisationUnit(sourceE);
    organisationUnitService.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceG);
    orgUnitGroupA = createOrganisationUnitGroup('A');
    orgUnitGroupB = createOrganisationUnitGroup('B');
    orgUnitGroupC = createOrganisationUnitGroup('C');
    orgUnitGroupA.addOrganisationUnit(sourceB);
    orgUnitGroupA.addOrganisationUnit(sourceC);
    orgUnitGroupB.addOrganisationUnit(sourceD);
    orgUnitGroupB.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceF);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupC);
    dataSetMonthly.addDataSetElement(dataElementA);
    dataSetMonthly.addDataSetElement(dataElementB);
    dataSetMonthly.addDataSetElement(dataElementC);
    dataSetMonthly.addDataSetElement(dataElementD);
    dataSetWeekly.addDataSetElement(dataElementE);
    dataSetYearly.addDataSetElement(dataElementE);
    dataSetService.addDataSet(dataSetWeekly);
    dataSetService.addDataSet(dataSetMonthly);
    dataSetService.addDataSet(dataSetYearly);
    dataElementService.updateDataElement(dataElementA);
    dataElementService.updateDataElement(dataElementB);
    dataElementService.updateDataElement(dataElementC);
    dataElementService.updateDataElement(dataElementD);
    dataElementService.updateDataElement(dataElementE);
    // deA + deB = deC - deD
    ruleA = createValidationRule("A", equal_to, expressionA, expressionB, ptMonthly);
    // deC - deD > deB * 2
    ruleB = createValidationRule("B", greater_than, expressionB2, expressionC, ptMonthly);
    // deC - deD <= deA + deB
    ruleC = createValidationRule("C", less_than_or_equal_to, expressionB3, expressionA2, ptMonthly);
    // deA + deB < deB * 2
    ruleD = createValidationRule("D", less_than, expressionA3, expressionC2, ptMonthly);
    // deA [Compulsory pair] deB
    ruleE = createValidationRule("E", compulsory_pair, expressionI, expressionJ, ptMonthly);
    // deA [Exclusive pair] deB
    ruleF = createValidationRule("F", exclusive_pair, expressionI2, expressionJ2, ptMonthly);
    // deC = DeD
    ruleG = createValidationRule("G", equal_to, expressionK, expressionL, ptMonthly);
    // deA = [days]
    ruleP = createValidationRule("P", equal_to, expressionI3, expressionP, ptMonthly);
    // deE = [days]
    ruleQ = createValidationRule("Q", equal_to, expressionQ, expressionP2, ptYearly);
    // deA(sum) + deB(sum) = 1000
    ruleR = createValidationRule("R", equal_to, expressionR, expressionU, ptMonthly);
    // deA.optionComboX + deB.optionComboX = 1000
    ruleS = createValidationRule("S", equal_to, expressionS, expressionU2, ptMonthly);
    // deA.default + deB.optionComboX = 1000
    ruleT = createValidationRule("T", equal_to, expressionT, expressionU3, ptMonthly);
    // deA.default + deB.default = 1000
    ruleU = createValidationRule("U", equal_to, expressionA4, expressionU4, ptMonthly);
    // deA + deB = deB * 2
    ruleX = createValidationRule("X", equal_to, expressionA5, expressionC3, ptMonthly);
    group = createValidationRuleGroup('A');
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) Category(org.hisp.dhis.category.Category) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) CategoryOption(org.hisp.dhis.category.CategoryOption) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Date(java.util.Date)

Example 75 with CategoryOption

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

the class ValidationServiceTest method testValidateWithCategoryOptions.

@Test
void testValidateWithCategoryOptions() {
    CategoryOption optionA = new CategoryOption("CategoryOptionA");
    CategoryOption optionB = new CategoryOption("CategoryOptionB");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    Category categoryA = createCategory('A', optionA, optionB);
    categoryService.addCategory(categoryA);
    CategoryCombo categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addCategoryCombo(categoryComboA);
    CategoryOptionCombo optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
    CategoryOptionCombo optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
    categoryService.addCategoryOptionCombo(optionComboA);
    categoryService.addCategoryOptionCombo(optionComboB);
    useDataValue(dataElementD, periodA, sourceA, "3", optionComboA, optionCombo);
    useDataValue(dataElementD, periodA, sourceA, "4", optionComboB, optionCombo);
    Expression expressionZ = new Expression("#{" + dataElementD.getUid() + "." + optionComboA.getUid() + "} * 2" + " + #{" + dataElementD.getUid() + "." + optionComboB.getUid() + "}", "expressionZ", NEVER_SKIP);
    Expression expressionV = new Expression("#{" + dataElementD.getUid() + "}", "expressionV", NEVER_SKIP);
    ValidationRule validationRuleZ = createValidationRule("Z", equal_to, expressionV, expressionZ, ptMonthly);
    // deD[all] = deD.optionComboA * 2 + deD.optionComboB
    validationRuleService.saveValidationRule(validationRuleZ);
    Collection<ValidationResult> results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).build());
    Collection<ValidationResult> reference = new HashSet<>();
    reference.add(new ValidationResult(validationRuleZ, periodA, sourceA, defaultCombo, 7.0, 10.0, dayInPeriodA));
    assertResultsEquals(reference, results);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Expression(org.hisp.dhis.expression.Expression) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10