Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 4 additions & 301 deletions packages/flow/openadapt_flow/form_tx/pack_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,307 +142,10 @@ class PackInductionReport(BaseModel):


def build_patient_registration_domain_schema() -> CanonicalDomainSchema:
"""Build generic clinical patient registration domain schema."""
return CanonicalDomainSchema(
schema_id="patient_registration.v1",
fields=(
CanonicalFieldSpec(
dossier_key="first_name",
synonyms=(
"first name",
"given name",
"patient first name",
"legal first name",
"fname",
"first_name",
"given_name",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("patient", "demographics", "personal", "identity"),
required=True,
),
CanonicalFieldSpec(
dossier_key="middle_name",
synonyms=(
"middle name",
"middle initial",
"mname",
"middle_name",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("patient", "demographics", "personal"),
required=False,
),
CanonicalFieldSpec(
dossier_key="last_name",
synonyms=(
"last name",
"surname",
"family name",
"patient last name",
"legal last name",
"lname",
"last_name",
"family_name",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("patient", "demographics", "personal", "identity"),
required=True,
),
CanonicalFieldSpec(
dossier_key="date_of_birth",
synonyms=(
"date of birth",
"birth date",
"birthdate",
"dob",
"patient dob",
"born on",
"date_of_birth",
"birth_date",
),
expected_codec=FieldCodecSpec(
kind=FormCodecKind.ISO_DATE, date_order="MDY"
),
section_hints=("patient", "demographics", "personal"),
required=True,
),
CanonicalFieldSpec(
dossier_key="administrative_sex",
synonyms=(
"administrative sex",
"sex at birth",
"biological sex",
"legal sex",
"sex",
"gender",
"sex_at_birth",
"administrative_sex",
),
expected_codec=FieldCodecSpec(
kind=FormCodecKind.ENUM_MAP,
enum_aliases={
"F": ("female", "f"),
"M": ("male", "m"),
"X": ("non-binary", "other", "unknown", "x", "u"),
},
),
section_hints=("patient", "demographics", "personal"),
required=False,
),
CanonicalFieldSpec(
dossier_key="phone_number",
synonyms=(
"phone number",
"mobile phone",
"primary phone",
"contact phone",
"cell phone",
"telephone",
"phone",
"mobile",
"tel",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.PHONE_DIGITS),
section_hints=("contact", "patient", "demographics"),
required=True,
),
CanonicalFieldSpec(
dossier_key="email_address",
synonyms=(
"email address",
"email",
"patient email",
"electronic mail",
"email_address",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD),
section_hints=("contact", "patient", "demographics"),
required=False,
),
CanonicalFieldSpec(
dossier_key="street_address",
synonyms=(
"street address",
"home address",
"address line 1",
"residential address",
"street",
"address1",
"addr_line1",
"street_address",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("address", "contact", "residence", "demographics"),
required=False,
),
CanonicalFieldSpec(
dossier_key="city",
synonyms=("city", "town", "municipality", "patient_city"),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("address", "contact", "residence"),
required=False,
),
CanonicalFieldSpec(
dossier_key="state_code",
synonyms=("state", "province", "state code", "region", "state_code"),
expected_codec=FieldCodecSpec(kind=FormCodecKind.UPPER),
section_hints=("address", "contact", "residence"),
required=False,
triggers_re_render_hint=True,
),
CanonicalFieldSpec(
dossier_key="postal_code",
synonyms=(
"postal code",
"zip code",
"zip",
"postcode",
"postal_code",
"zip_code",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("address", "contact", "residence"),
required=False,
),
CanonicalFieldSpec(
dossier_key="insurance_plan_name",
synonyms=(
"insurance plan",
"payer name",
"coverage plan",
"health plan",
"insurance carrier",
"payer",
"insurance_plan",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("insurance", "coverage", "billing", "payer"),
required=False,
triggers_re_render_hint=True,
),
CanonicalFieldSpec(
dossier_key="insurance_member_id",
synonyms=(
"member id",
"subscriber id",
"insurance member id",
"policy member number",
"member number",
"member_id",
"subscriber_id",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.UPPER),
section_hints=("insurance", "coverage", "billing", "payer"),
required=False,
),
CanonicalFieldSpec(
dossier_key="emergency_contact_name",
synonyms=(
"emergency contact name",
"emergency contact",
"next of kin name",
"emergency_contact_name",
"emerg_name",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
section_hints=("emergency", "next of kin"),
required=False,
),
CanonicalFieldSpec(
dossier_key="emergency_contact_phone",
synonyms=(
"emergency contact phone",
"emergency phone",
"next of kin phone",
"emergency_contact_phone",
"emerg_phone",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.PHONE_DIGITS),
section_hints=("emergency", "next of kin"),
required=False,
),
CanonicalFieldSpec(
dossier_key="consent_to_treat",
synonyms=(
"consent to treat",
"treatment consent",
"hipaa consent",
"patient consent",
"consent_to_treat",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.BOOLEAN_YES_NO),
section_hints=("consent", "authorization", "agreement"),
required=False,
),
CanonicalFieldSpec(
dossier_key="full_name",
synonyms=(
"patient full name",
"full name",
"legal full name",
"complete name",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.TITLE_CASE),
section_hints=("patient", "demographics", "personal"),
required=False,
),
CanonicalFieldSpec(
dossier_key="visit_type",
synonyms=(
"visit category",
"visit type",
"appointment type",
"visit_type",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD),
section_hints=("queue", "visit", "routing", "appointment"),
required=False,
),
CanonicalFieldSpec(
dossier_key="clinical_department",
synonyms=(
"clinical department",
"department",
"specialty",
"clinic department",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD),
section_hints=("queue", "department", "routing"),
required=False,
triggers_re_render_hint=True,
),
CanonicalFieldSpec(
dossier_key="consulting_provider",
synonyms=(
"consulting doctor",
"attending physician",
"consulting provider",
"attending doctor",
"consulting_doctor",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD),
section_hints=("queue", "department", "routing", "provider"),
required=False,
),
),
expected_outputs=(
CanonicalFieldSpec(
dossier_key="medical_record_number",
synonyms=(
"medical record number",
"mrn",
"patient id",
"chart number",
"registration number",
"record number",
"mrn_output",
),
expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE),
required=True,
),
),
)
"""The patient registration preset (``presets/patient_registration.json``)."""
from openadapt_flow.form_tx.presets import load_domain_schema

return load_domain_schema("patient_registration")


def build_property_quote_domain_schema() -> CanonicalDomainSchema:
Expand Down
51 changes: 51 additions & 0 deletions packages/flow/openadapt_flow/form_tx/presets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Domain presets for ``form_tx`` pack induction, kept as data.

A preset is a canonical domain schema (the fields a kind of form asks for,
with label synonyms) used by ``induce_form_pack`` and the ``--domain`` flag.
It is vocabulary for one kind of form, so it lives here as JSON
(``openadapt.form-domain-preset/v1``), not in the engine's code. The
``build_*_domain_schema`` functions in ``pack_compiler`` load these files and
return the same objects they used to build.
"""

from __future__ import annotations

import json
from functools import lru_cache
from pathlib import Path
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from openadapt_flow.form_tx.pack_compiler import CanonicalDomainSchema

__all__ = ["PRESET_SCHEMA", "load_domain_schema", "preset_names"]

PRESET_SCHEMA = "openadapt.form-domain-preset/v1"
_DIR = Path(__file__).resolve().parent


def preset_names() -> tuple[str, ...]:
"""The names of the presets shipped with this package."""

return tuple(sorted(p.stem for p in _DIR.glob("*.json")))


@lru_cache(maxsize=None)
def _raw(name: str) -> dict[str, Any]:
if name not in preset_names():
raise ValueError(f"unknown form_tx domain preset {name!r}")
data = json.loads((_DIR / f"{name}.json").read_text(encoding="utf-8"))
if not isinstance(data, dict) or data.get("schema") != PRESET_SCHEMA:
raise ValueError(f"preset {name!r} is not {PRESET_SCHEMA}")
preset = data.get("preset")
if not isinstance(preset, dict):
raise ValueError(f"preset {name!r} has no preset object")
return preset


def load_domain_schema(name: str) -> "CanonicalDomainSchema":
"""The canonical domain schema stored as preset ``name``."""

from openadapt_flow.form_tx.pack_compiler import CanonicalDomainSchema

return CanonicalDomainSchema.model_validate(_raw(name))
Loading