Skip to content

Enhancement : Expression Engine : Set Value Effect Redesign #95

Description

@lattln

Context

This ticket tracks the follow-up work needed for the setValue effect on the
feature/add-fhir-requirements branch.

Problem Statement

The current setValue implementation mixes two separate concerns:

  1. When the rule should fire.
  2. What value should be assigned when it does fire.

That design works for simple expression-based cases, but it breaks down for:

  • Conditional set-value rules where a non-expression condition gates the rule.
  • Selection fields where the target value should be an optionId, not a free-form expression.
  • FHIR import mapping, where initialExpression / related inputs should round-trip into a more explicit setValue payload.

Proposed Solution

Add a dedicated setValue payload to each rule instead of encoding the value source inside the condition list.

Suggested shape:

type SetValuePayload =
  | { type: 'expression'; expression: string }
  | { type: 'option'; optionId: string };

interface Rule {
  effect: EffectType;
  conditions: Condition[];
  setValue?: SetValuePayload;
}

Implementation Checklist

  • Update packages/core/src/lib/types.ts to add SetValuePayload and setValue? on Rule
  • Update packages/core/src/lib/logic/resolve.ts so resolveSetValue() reads rule.setValue first
  • Keep backward compatibility for existing expression-only rules during migration
  • Update selection field handling so computed option values map to the correct selected state
  • Update packages/builder/src/lib/components/edit-panel/LogicEditor.tsx to expose the right authoring UI per field type
  • Update packages/adapters/src/fhir/fhir-adapter.ts so imported FHIR expressions map into the new setValue shape
  • Add or update unit tests around resolveSetValue() and rule hydration

Success Criteria

  • A field can use a field-based condition gate and still resolve a separate computed value
  • Selection fields can be driven by an optionId payload instead of a free-form expression
  • Existing expression-based setValue rules continue to work
  • FHIR import/export behavior preserves the intent of initialExpression style rules

Related Files

  • packages/core/src/lib/types.ts
  • packages/core/src/lib/logic/resolve.ts
  • packages/core/src/lib/field-component-props.ts
  • packages/builder/src/lib/components/edit-panel/LogicEditor.tsx
  • packages/adapters/src/fhir/fhir-adapter.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions