Skip to content

refactor(form-tx): move the patient registration preset to JSON - #2503

Merged
abrichr merged 4 commits into
mainfrom
claude/form-preset-patient-schema
Nov 22, 2026
Merged

abrichr merged 4 commits into
mainfrom
claude/form-preset-patient-schema

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

What this does

The generality audit found domain vocabulary in the form_tx engine. This is the first of five small PRs that move it into data. Each PR moves one preset, and each keeps an import shim so callers don't change.

This one moves the patient registration domain schema: 20 field keys with their label synonyms and section hints.

  • The schema now ships as form_tx/presets/patient_registration.json, under the new format openadapt.form-domain-preset/v1.
  • form_tx/presets/__init__.py adds load_domain_schema(name) and preset_names(). An unknown name, or a file in another format, is refused.
  • build_patient_registration_domain_schema() is now a four-line shim that loads the JSON. pack_compiler.py loses 301 lines.
  • Hatchling ships the JSON as package data.

No behaviour change

tests/test_form_tx_presets.py takes pack_compiler.py from the commit before the move (2f506d6c4), rebuilds the old builder from it, and checks that the shim returns an equal object with an equal JSON dump. CI's shallow checkout has no history, so that test skips there. The round-trip and refusal tests still run.

Stack

PR Preset Base
this one patient registration schema main
next property insurance quote schema this branch
then primary entity kinds the insurance branch
then the wizard's next-button words the entity-kinds branch
separate placeholder option texts #2461, because the list there differs from main

Effect-location record: #2500.

Tests

On this branch:

  • tests/test_form_tx_presets.py: 3 passed.
  • ruff check is clean.
  • check_engine_generality.py: OK.
  • On the top of the stack (claude/form-preset-wizard-words), the run of test_form_tx_presets.py, test_form_tx_lease_and_compiler.py and test_form_tx_reconciler_and_receipts.py is posted in a comment.

The patient registration domain schema (field keys and label synonyms) is
vocabulary for one kind of form, not engine code. It now ships as
form_tx/presets/patient_registration.json (openadapt.form-domain-preset/v1),
and build_patient_registration_domain_schema() loads it. The returned
schema is equal to the one the old builder made; a test rebuilds the old
builder from history and compares.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini (gemini-3.1-pro-preview), round 1
Reviewed-Head: 3c2ab790a6

Sent the full diff of this PR's own files, those files in full, and any earlier findings.

This PR cleanly extracts the patient_registration domain schema from the engine code into a JSON preset, advancing the generality rule by treating domain vocabulary as pack data.

The JSON serialization is an exact match for the old Python object (including Pydantic's default fields like date_order and enum_aliases), and CanonicalDomainSchema.model_validate strictly enforces the schema with extra="forbid". There are no fail-open paths or behaviour changes introduced here.

The differential test using git show to rebuild the old function is a clever way to ensure the migration is exact without leaving dead code around. Skipping it in shallow CI checkouts is acceptable because the round-trip test (test_each_moved_preset_ships_as_json) still runs and guarantees the JSON is valid and matches the shim's output.

APPROVE

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 3c2ab79

Author declaration. I wrote this change and checked it at the head above. Everything here is synthetic; no real app was run.

  • tests/test_form_tx_presets.py: 3 passed. The differential test ran here, with history, and did not skip.
  • Gemini round 1 approved with no findings. Codex review is unavailable until Nov 27.
  • On the top of the stack (refactor(form-tx): move the wizard next-button words to a JSON word list #2506, head c6964917c): test_form_tx_presets.py, test_form_tx_lease_and_compiler.py and test_form_tx_reconciler_and_receipts.py gave 51 passed. Those files cover the preset builders and pack induction.

@abrichr
abrichr marked this pull request as ready for review November 22, 2026 03:38
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 3c2ab79

Independent cross-vendor adversarial review of 3c2ab790ad917d1817da66858dd359d66f818c9b (Claude-authored claude/form-preset-patient-schema; I authored none of this PR).

Findings & fail-closed verification

  • Safe preset loader (form_tx/presets/__init__.py): _raw(name) allowlists name against preset_names() (*.json stems in _DIR) before path construction, blocking path traversal (../pack_compiler) and unknown names. It enforces schema == "openadapt.form-domain-preset/v1" and a dict preset payload, and load_domain_schema validates through CanonicalDomainSchema.model_validate(...) on each call.
  • No behavior change: build_patient_registration_domain_schema() in pack_compiler.py is reduced to a 4-line shim loading patient_registration.json (−301 lines of hardcoded vocabulary), backed by round-trip, refusal, and git-history differential tests in test_form_tx_presets.py.

Generality gate

  1. No per-app code in engine: Directly advances this rule by moving 301 lines of patient-registration domain vocabulary out of pack_compiler.py into form_tx/presets/patient_registration.json data.
  2. Fix the class, not the instance: Establishes the openadapt.form-domain-preset/v1 data format and load_domain_schema loader reused across the remaining preset-extraction stack.
  3. Held-out evidence: Honestly scoped as synthetic unit/differential tests only (behavior-preserving refactor; no real app run).

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: e9a4497

Delta versus Gemini APPROVE at 3c2ab790ad917d1817da66858dd359d66f818c9b (request 7082940962). No prior Grok verdict at this head. pack_compiler.py, the preset loader, patient_registration.json, and test_form_tx_presets.py are byte-identical to that head. The only unique-file change at this head is registering openadapt_flow/form_tx/presets/patient_registration.json in packages/flow/public-artifacts.json (plus main's later artifact-list entries that arrived with the origin/main merge). Versus current main, the artifacts file adds only that one preset path. I did not merge, tag, publish, or dispatch.

The loader is still path-safe: preset_names() allowlists *.json stems in the presets directory, _raw refuses any other name (including ../pack_compiler), and the file must be openadapt.form-domain-preset/v1 with a preset object before CanonicalDomainSchema.model_validate. The JSON is field vocabulary and codecs only; it has no instance records. The shim in build_patient_registration_domain_schema loads that data. Tests still cover the unknown-name refusal, the traversal-style name, the schema round-trip, and the differential against the pre-move builder (skipped only when git history is absent).

No package version, lock, or changelog change. This does not auto-publish. I did not merge.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: a2b73a1

Delta-only review vs prior approved head e9a44971 (zero code delta — clean origin/main merge of efdf76c9 picking up #2553's packages/flow/tests/fixtures/cli_surface.json fix). Clear to merge on green CI.

@abrichr
abrichr merged commit 24034b5 into main Nov 22, 2026
55 of 56 checks passed
@abrichr
abrichr deleted the claude/form-preset-patient-schema branch November 22, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant