Search in sources :

Example 1 with QuestionnaireItemOperator

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemOperator in project org.hl7.fhir.core by hapifhir.

the class EnableWhenEvaluator method evaluateCondition.

protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) {
    List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition);
    QuestionnaireItemOperator operator = enableCondition.getOperator();
    if (operator == QuestionnaireItemOperator.EXISTS) {
        DataType answer = enableCondition.getAnswer();
        if (!(answer instanceof BooleanType)) {
            throw new UnprocessableEntityException("Exists-operator requires answerBoolean");
        }
        return new EnableWhenResult(((BooleanType) answer).booleanValue() != answerItems.isEmpty(), enableCondition);
    }
    boolean result = false;
    for (Element answer : answerItems) {
        result = result || evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator());
    }
    return new EnableWhenResult(result, enableCondition);
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) Element(org.hl7.fhir.r5.elementmodel.Element) BooleanType(org.hl7.fhir.r5.model.BooleanType) QuestionnaireItemOperator(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemOperator) DataType(org.hl7.fhir.r5.model.DataType)

Aggregations

UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 Element (org.hl7.fhir.r5.elementmodel.Element)1 BooleanType (org.hl7.fhir.r5.model.BooleanType)1 DataType (org.hl7.fhir.r5.model.DataType)1 QuestionnaireItemOperator (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemOperator)1