Interactive Data Collection

Most rule engines require every input up front. DTRules can instead run a rule set as an interview: it executes the decision tables and, whenever it reaches a field that has not been supplied, it stops and asks for it — on the command line or in a web form. Once the answer comes back, execution resumes. Batch execution is unchanged and pays no overhead.

For an illustrated overview of the feature, see the Interview page. This guide is the hands-on version: how to mark fields, run an interview, and embed it. The SinusitisTherapy live demo is a complete working example — a clinical advisor that interviews you one question at a time and recommends a treatment.

How It Works

  1. You mark input fields in the EDD as collect="true" and attach a question.
  2. You run the rule set in interactive mode (--interactive or --web).
  3. The engine evaluates the tables. The first time it reads a collect field that has no value, it asks the question and waits for the answer.
  4. It only ever asks for fields a decision actually reaches — branches that are never taken never prompt for their inputs.

Marking a Field for Collection

In the Entity Data Dictionary, a collectable field carries question metadata. The question type determines how it is presented:

Question type Presented as
multiple_choice A list of options to pick from
ascii Free-text input
number A numeric input, optionally with a reference range
date A date input

Number questions can carry a lab-style reference range (ref_low, ref_high, units). The range is shown as guidance and answers outside it are flagged High or Low — they are never rejected. All of this metadata round-trips through Excel, XML, and the JSON authoring API, so Excel remains the system of record.

Running an Interview

The dtrules run command drives the interview. It takes the project path and the entry decision table to run:

# Prompt for each reached field on the command line
dtrules run ./sampleprojects/SinusitisTherapy --entry Determine_Therapy --interactive

# Run the same interview as a web form in the browser
dtrules run ./sampleprojects/SinusitisTherapy --entry Determine_Therapy --web

Save, Replay, and Review

Collected answers can be saved to a mapping-free, EDD-shaped data file and reused. This supports a collect → save → replay loop without re-entering data:

# Collect answers and save them
dtrules run . --entry Determine_Therapy --interactive --save case.xml

# Replay saved answers as authoritative batch input (no questions)
dtrules run . --entry Determine_Therapy --data case.xml

# Re-interview with previous answers pre-filled, so you can revise
dtrules run . --entry Determine_Therapy --review case.xml --interactive

Embedding It

The interview loop is exposed as a small set of Go packages so you can host it in your own application:

  • pkg/dtrules/collect — per-instance tracking of which fields were collected or defaulted, plus the read-point resolver that triggers a question.
  • pkg/dtrules/interview — a UI⇄engine Runner interface; bring your own front end.
  • pkg/dtrules/web — the default browser UI (per-session, stacked transcript, with download/upload and review).
  • pkg/dtrules/datafile — canonical save/replay of collected data.

cmd/sinusitis-web is a self-contained, //go:embed example that wires these together into a single binary — the same one that powers the live demo.

Next Steps