open-formulieren / open-forms

Smart and dynamic forms
https://open-forms.readthedocs.io
Other
36 stars 26 forks source link

Integrate DMN evaluation into form logic #3730

Closed sergei-maertens closed 9 months ago

sergei-maertens commented 10 months ago

Decision Model and Notation (DMN) is a worldwide-standard for modelling decisions. DMN can be executed by DMN engines, such as Camunda.

Massively simplified, it allows you to define rules in an almost-Excel-like interface, that given a particular set of inputs produces a set of outputs. You could compare it with a pure function def decision(input1, input2, ...): ... that operates as a black box.

We want to enable form builders to call decision models as part of our logic evaluation process.

Functional UX

The functional user experience, as a person who creates and maintains forms.

As an example case, consider "applying for a some sort of financial benefits". The conditions for such a hypothetical application are not straightforward, and those are (can be) modeled in a DMN table with name "application conditions":

  • if you are younger than 20 and are employed, you may not apply
  • if you are younger than 25 and have a yearly income of 40K+, you may not apply
  • if you are 25 or older and live by yourself with an income of 45K or less, you may apply
  • if you are 65+ with an income of 35K or less, you may apply

It has the following input parameter names: age, income, hasAJob, numHouseholdMembers and ouput parameter names: conditionsFulfilled, reason

  1. Set up a form with the fields:
    • employment status (yes/no)
    • age (number)
    • household size (number of people, integer, >= 1)
    • yearly income (currency)
    • content ("You are not allowed to apply because you don't meet the criteria", initially hidden)
  2. Define user defined variable isAllowedToApply, default value true
  3. Navigate to logic tab
  4. Add complex logic rule
    • trigger: true (always evaluate, optionally optimize to only evaluate once employment status, age and household size are all non-empty)
    • action: "call decision model"
    • click button "configure" (similar to service fetch)
  5. Modal opens to configure the DMN call action
    • From a dropdown, select the applicable decision model ("application conditions")
    • (optionally) select the version of the decision model
    • map the input parameters:
      • age: age
      • income: yearly income
      • hasAJob: employment status
      • numHouseholdMembers: household size
    • map the output parameters:
      • conditionsFulfilled -> isAllowedToApply
    • Click the "save" button
  6. Add a second logic rule
    • trigger: {"!=": "isAllowedToApply"}
    • action 1: prevent form submissions
    • action 2: change content from hidden to visible

Technical tasks

Must have

Should have

Nice to haves (moved to #3855)

Resources

sergei-maertens commented 9 months ago

still WIP

SilviaAmAm commented 9 months ago

Discuss the PRIO of the other checkboxes