Search in sources :

Example 11 with RuleValidationResult

use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.

the class ProgramRuleActionController method getDataExpressionDescription.

@PostMapping(value = "/data/expression/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage getDataExpressionDescription(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDataExpressionDescription(condition, programId);
    if (result.isValid()) {
        return new DescriptiveWebMessage(Status.OK, HttpStatus.OK).setDescription(result.getDescription()).setMessage(i18n.getString(ProgramIndicator.VALID));
    }
    String description = null;
    if (result.getErrorMessage() != null) {
        description = result.getErrorMessage();
    } else if (result.getException() != null) {
        description = result.getException().getMessage();
    }
    return new DescriptiveWebMessage(Status.ERROR, HttpStatus.CONFLICT).setDescription(description).setMessage(i18n.getString(ProgramIndicator.EXPRESSION_NOT_VALID));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with RuleValidationResult

use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.

the class ProgramRuleEngineDescriptionTest method testProgramRuleWithD2HasValueTrackedEntityAttribute2.

@Test
void testProgramRuleWithD2HasValueTrackedEntityAttribute2() {
    programRuleWithD2HasValue.setCondition(conditionWithD2HasValue2);
    RuleValidationResult result = validateRuleCondition(programRuleWithD2HasValue.getCondition(), program);
    assertNotNull(result);
    assertEquals("AttributeA", result.getDescription());
    assertTrue(result.isValid());
}
Also used : RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with RuleValidationResult

use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.

the class ProgramRuleEngineDescriptionTest method testProgramRuleWithNumericDataElement.

@Test
void testProgramRuleWithNumericDataElement() {
    RuleValidationResult result = validateRuleCondition(programRuleNumericDE.getCondition(), program);
    assertNotNull(result);
    assertEquals("DataElementE == 14", result.getDescription());
    assertTrue(result.isValid());
}
Also used : RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with RuleValidationResult

use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.

the class ProgramRuleEngineDescriptionTest method testExtractDataMatrixValue.

@Test
void testExtractDataMatrixValue() {
    RuleValidationResult result = validateRuleCondition(extractDataMatrixValueExpression, program);
    assertNotNull(result);
    assertTrue(result.isValid());
}
Also used : RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with RuleValidationResult

use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.

the class ProgramRuleEngineDescriptionTest method testProgramRuleWithNumericTrackedEntityAttribute.

@Test
void testProgramRuleWithNumericTrackedEntityAttribute() {
    RuleValidationResult result = validateRuleCondition(programRuleNumericAtt.getCondition(), program);
    assertNotNull(result);
    assertEquals("AttributeB == 12 || Current date", result.getDescription());
    assertTrue(result.isValid());
}
Also used : RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

RuleValidationResult (org.hisp.dhis.rules.models.RuleValidationResult)18 Test (org.junit.jupiter.api.Test)16 DhisSpringTest (org.hisp.dhis.DhisSpringTest)15 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)2 I18n (org.hisp.dhis.i18n.I18n)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1