Search in sources :

Example 6 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class PredictorDeletionHandler method deleteExpression.

@Override
public void deleteExpression(Expression expression) {
    Iterator<Predictor> iterator = predictorService.getAllPredictors().iterator();
    while (iterator.hasNext()) {
        Predictor predictor = iterator.next();
        Expression generator = predictor.getGenerator();
        Expression skipTest = predictor.getSampleSkipTest();
        if (generator != null && generator.equals(expression) || skipTest != null && skipTest.equals(expression)) {
            iterator.remove();
            predictorService.deletePredictor(predictor);
        }
    }
}
Also used : Expression(org.hisp.dhis.expression.Expression)

Example 7 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class ValidationRuleServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    periodTypeWeekly = new WeeklyPeriodType();
    periodTypeMonthly = new MonthlyPeriodType();
    periodTypeYearly = 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);
    optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    String suffix = SEPARATOR + optionCombo.getUid();
    optionCombos = new HashSet<>();
    optionCombos.add(optionCombo);
    expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
    expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
    expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
    expressionService.addExpression(expressionA);
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionC);
    dataSetWeekly = createDataSet('W', periodTypeWeekly);
    dataSetMonthly = createDataSet('M', periodTypeMonthly);
    dataSetYearly = createDataSet('Y', periodTypeYearly);
    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');
    sourcesA.add(sourceA);
    sourcesA.add(sourceB);
    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);
    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
    validationRuleA = createValidationRule("A", equal_to, expressionA, expressionB, periodTypeMonthly);
    // deC - deD > deB * 2
    validationRuleB = createValidationRule("B", greater_than, expressionB, expressionC, periodTypeMonthly);
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType)

Example 8 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class ValidationRuleStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElements = new HashSet<>();
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionA);
    periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Also used : Expression(org.hisp.dhis.expression.Expression) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 9 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class DefaultCsvImportService method validationRulesFromCsv.

private List<ValidationRule> validationRulesFromCsv(CsvReader reader) throws IOException {
    List<ValidationRule> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            Expression leftSide = new Expression();
            Expression rightSide = new Expression();
            ValidationRule object = new ValidationRule();
            setIdentifiableObject(object, values);
            object.setDescription(getSafe(values, 3, null, 255));
            object.setInstruction(getSafe(values, 4, null, 255));
            object.setImportance(Importance.valueOf(getSafe(values, 5, Importance.MEDIUM.toString(), 255)));
            // Left here so nobody wonders what field 6 is for
            // object.setRuleType( RuleType.valueOf( getSafe( values, 6, RuleType.VALIDATION.toString(), 255 ) ) );
            object.setOperator(Operator.safeValueOf(getSafe(values, 7, Operator.equal_to.toString(), 255)));
            object.setPeriodType(PeriodType.getByNameIgnoreCase(getSafe(values, 8, MonthlyPeriodType.NAME, 255)));
            leftSide.setExpression(getSafe(values, 9, null, 255));
            leftSide.setDescription(getSafe(values, 10, null, 255));
            leftSide.setMissingValueStrategy(MissingValueStrategy.safeValueOf(getSafe(values, 11, MissingValueStrategy.NEVER_SKIP.toString(), 50)));
            rightSide.setExpression(getSafe(values, 12, null, 255));
            rightSide.setDescription(getSafe(values, 13, null, 255));
            rightSide.setMissingValueStrategy(MissingValueStrategy.safeValueOf(getSafe(values, 14, MissingValueStrategy.NEVER_SKIP.toString(), 50)));
            object.setLeftSide(leftSide);
            object.setRightSide(rightSide);
            object.setAutoFields();
            list.add(object);
        }
    }
    return list;
}
Also used : Expression(org.hisp.dhis.expression.Expression) ArrayList(java.util.ArrayList) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Example 10 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class ValidationRuleGroupStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionA);
    periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Also used : Expression(org.hisp.dhis.expression.Expression) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

Expression (org.hisp.dhis.expression.Expression)18 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 DataElement (org.hisp.dhis.dataelement.DataElement)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 DhisTest (org.hisp.dhis.DhisTest)2 IntegrationTest (org.hisp.dhis.IntegrationTest)2 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Predictor (org.hisp.dhis.predictor.Predictor)2 CurrentUserService (org.hisp.dhis.user.CurrentUserService)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ArrayList (java.util.ArrayList)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1