diff --git a/packages/flow/openadapt_flow/form_tx/pack_compiler.py b/packages/flow/openadapt_flow/form_tx/pack_compiler.py index acde36f3ed..9799163833 100644 --- a/packages/flow/openadapt_flow/form_tx/pack_compiler.py +++ b/packages/flow/openadapt_flow/form_tx/pack_compiler.py @@ -24,7 +24,6 @@ FieldAnchorSpec, FieldBindingSpec, FieldCodecSpec, - FormCodecKind, FormPack, FormSnapshot, ObservedControl, @@ -149,258 +148,10 @@ def build_patient_registration_domain_schema() -> CanonicalDomainSchema: def build_property_quote_domain_schema() -> CanonicalDomainSchema: - """Build generic residential/commercial property quote domain schema.""" - return CanonicalDomainSchema( - schema_id="property_quote.v1", - fields=( - CanonicalFieldSpec( - dossier_key="applicant_first_name", - synonyms=( - "applicant first name", - "insured first name", - "primary insured first name", - "first name", - "given name", - "applicant_first_name", - "insured_fname", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - section_hints=("applicant", "insured", "policyholder", "client"), - required=True, - ), - CanonicalFieldSpec( - dossier_key="applicant_last_name", - synonyms=( - "applicant last name", - "insured last name", - "primary insured last name", - "last name", - "surname", - "applicant_last_name", - "insured_lname", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - section_hints=("applicant", "insured", "policyholder", "client"), - required=True, - ), - CanonicalFieldSpec( - dossier_key="effective_date", - synonyms=( - "effective date", - "policy effective date", - "coverage start date", - "inception date", - "effective_date", - ), - expected_codec=FieldCodecSpec( - kind=FormCodecKind.ISO_DATE, date_order="MDY" - ), - section_hints=("policy", "term", "coverage", "quote"), - required=False, - ), - CanonicalFieldSpec( - dossier_key="property_street_address", - synonyms=( - "property street address", - "property address", - "risk address", - "location address", - "dwelling address", - "street address", - "premises address", - "property_address", - "risk_street", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - section_hints=("property", "location", "risk", "dwelling", "premises"), - required=True, - triggers_re_render_hint=True, - ), - CanonicalFieldSpec( - dossier_key="property_city", - synonyms=( - "property city", - "risk city", - "location city", - "city", - "property_city", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - section_hints=("property", "location", "risk", "dwelling"), - required=False, - ), - CanonicalFieldSpec( - dossier_key="property_state", - synonyms=( - "property state", - "risk state", - "location state", - "state", - "province", - "property_state", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.UPPER), - section_hints=("property", "location", "risk", "dwelling"), - required=False, - triggers_re_render_hint=True, - ), - CanonicalFieldSpec( - dossier_key="property_postal_code", - synonyms=( - "property postal code", - "property zip", - "risk zip", - "location zip", - "postal code", - "zip code", - "zip", - "property_postal_code", - "risk_zip", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - section_hints=("property", "location", "risk", "dwelling"), - required=True, - triggers_re_render_hint=True, - ), - CanonicalFieldSpec( - dossier_key="year_built", - synonyms=( - "year built", - "construction year", - "yr built", - "year of construction", - "year_built", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.INTEGER), - section_hints=( - "construction", - "building", - "dwelling", - "property", - "risk", - ), - required=True, - ), - CanonicalFieldSpec( - dossier_key="square_footage", - synonyms=( - "square footage", - "total square feet", - "living area", - "heated sq ft", - "sq ft", - "sqft", - "square_footage", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.INTEGER), - section_hints=("construction", "building", "dwelling", "property"), - required=False, - ), - CanonicalFieldSpec( - dossier_key="construction_type", - synonyms=( - "construction type", - "frame type", - "building construction", - "structure type", - "exterior construction", - "construction_type", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD), - section_hints=("construction", "building", "dwelling"), - required=False, - triggers_re_render_hint=True, - ), - CanonicalFieldSpec( - dossier_key="roof_material", - synonyms=( - "roof material", - "roof type", - "roof covering", - "roofing", - "roof_material", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.CASEFOLD), - section_hints=("construction", "roof", "building", "dwelling"), - required=False, - ), - CanonicalFieldSpec( - dossier_key="dwelling_coverage_amount", - synonyms=( - "dwelling coverage amount", - "dwelling coverage", - "coverage a limit", - "coverage a", - "replacement cost", - "building limit", - "insured value", - "dwelling limit", - "dwelling_coverage", - "coverage_amount", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.CURRENCY_CENTS), - section_hints=("coverage", "limits", "rating", "valuation"), - required=True, - triggers_re_render_hint=True, - ), - CanonicalFieldSpec( - dossier_key="deductible_amount", - synonyms=( - "deductible amount", - "all peril deductible", - "policy deductible", - "deductible", - "deductible_amount", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.CURRENCY_CENTS), - section_hints=("coverage", "limits", "deductible", "rating"), - required=False, - ), - CanonicalFieldSpec( - dossier_key="monitored_alarm", - synonyms=( - "monitored alarm", - "central station alarm", - "protective alarm", - "security alarm", - "burglar alarm", - "monitored_alarm", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.BOOLEAN_YES_NO), - section_hints=("discounts", "protection", "safety", "property"), - required=False, - ), - ), - expected_outputs=( - CanonicalFieldSpec( - dossier_key="quote_number", - synonyms=( - "quote number", - "quote id", - "proposal number", - "quote reference", - "quote_number", - "quote_id", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.WHITESPACE_COLLAPSE), - required=True, - ), - CanonicalFieldSpec( - dossier_key="annual_premium", - synonyms=( - "annual premium", - "total premium", - "quoted premium", - "estimated annual premium", - "premium", - "annual_premium", - "quoted_premium", - ), - expected_codec=FieldCodecSpec(kind=FormCodecKind.CURRENCY_CENTS), - required=True, - ), - ), - ) + """The property insurance quote preset (``presets/property_quote.json``).""" + from openadapt_flow.form_tx.presets import load_domain_schema + + return load_domain_schema("property_quote") def _scrub_snapshot_values(snapshot: FormSnapshot) -> FormSnapshot: diff --git a/packages/flow/openadapt_flow/form_tx/presets/property_quote.json b/packages/flow/openadapt_flow/form_tx/presets/property_quote.json new file mode 100644 index 0000000000..a4aedef7ba --- /dev/null +++ b/packages/flow/openadapt_flow/form_tx/presets/property_quote.json @@ -0,0 +1,410 @@ +{ + "schema": "openadapt.form-domain-preset/v1", + "preset": { + "schema_id": "property_quote.v1", + "fields": [ + { + "dossier_key": "applicant_first_name", + "synonyms": [ + "applicant first name", + "insured first name", + "primary insured first name", + "first name", + "given name", + "applicant_first_name", + "insured_fname" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "applicant", + "insured", + "policyholder", + "client" + ], + "required": true, + "triggers_re_render_hint": false + }, + { + "dossier_key": "applicant_last_name", + "synonyms": [ + "applicant last name", + "insured last name", + "primary insured last name", + "last name", + "surname", + "applicant_last_name", + "insured_lname" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "applicant", + "insured", + "policyholder", + "client" + ], + "required": true, + "triggers_re_render_hint": false + }, + { + "dossier_key": "effective_date", + "synonyms": [ + "effective date", + "policy effective date", + "coverage start date", + "inception date", + "effective_date" + ], + "expected_codec": { + "kind": "iso_date", + "date_order": "MDY", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "policy", + "term", + "coverage", + "quote" + ], + "required": false, + "triggers_re_render_hint": false + }, + { + "dossier_key": "property_street_address", + "synonyms": [ + "property street address", + "property address", + "risk address", + "location address", + "dwelling address", + "street address", + "premises address", + "property_address", + "risk_street" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "property", + "location", + "risk", + "dwelling", + "premises" + ], + "required": true, + "triggers_re_render_hint": true + }, + { + "dossier_key": "property_city", + "synonyms": [ + "property city", + "risk city", + "location city", + "city", + "property_city" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "property", + "location", + "risk", + "dwelling" + ], + "required": false, + "triggers_re_render_hint": false + }, + { + "dossier_key": "property_state", + "synonyms": [ + "property state", + "risk state", + "location state", + "state", + "province", + "property_state" + ], + "expected_codec": { + "kind": "upper", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "property", + "location", + "risk", + "dwelling" + ], + "required": false, + "triggers_re_render_hint": true + }, + { + "dossier_key": "property_postal_code", + "synonyms": [ + "property postal code", + "property zip", + "risk zip", + "location zip", + "postal code", + "zip code", + "zip", + "property_postal_code", + "risk_zip" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "property", + "location", + "risk", + "dwelling" + ], + "required": true, + "triggers_re_render_hint": true + }, + { + "dossier_key": "year_built", + "synonyms": [ + "year built", + "construction year", + "yr built", + "year of construction", + "year_built" + ], + "expected_codec": { + "kind": "integer", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "construction", + "building", + "dwelling", + "property", + "risk" + ], + "required": true, + "triggers_re_render_hint": false + }, + { + "dossier_key": "square_footage", + "synonyms": [ + "square footage", + "total square feet", + "living area", + "heated sq ft", + "sq ft", + "sqft", + "square_footage" + ], + "expected_codec": { + "kind": "integer", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "construction", + "building", + "dwelling", + "property" + ], + "required": false, + "triggers_re_render_hint": false + }, + { + "dossier_key": "construction_type", + "synonyms": [ + "construction type", + "frame type", + "building construction", + "structure type", + "exterior construction", + "construction_type" + ], + "expected_codec": { + "kind": "casefold", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "construction", + "building", + "dwelling" + ], + "required": false, + "triggers_re_render_hint": true + }, + { + "dossier_key": "roof_material", + "synonyms": [ + "roof material", + "roof type", + "roof covering", + "roofing", + "roof_material" + ], + "expected_codec": { + "kind": "casefold", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "construction", + "roof", + "building", + "dwelling" + ], + "required": false, + "triggers_re_render_hint": false + }, + { + "dossier_key": "dwelling_coverage_amount", + "synonyms": [ + "dwelling coverage amount", + "dwelling coverage", + "coverage a limit", + "coverage a", + "replacement cost", + "building limit", + "insured value", + "dwelling limit", + "dwelling_coverage", + "coverage_amount" + ], + "expected_codec": { + "kind": "currency_cents", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "coverage", + "limits", + "rating", + "valuation" + ], + "required": true, + "triggers_re_render_hint": true + }, + { + "dossier_key": "deductible_amount", + "synonyms": [ + "deductible amount", + "all peril deductible", + "policy deductible", + "deductible", + "deductible_amount" + ], + "expected_codec": { + "kind": "currency_cents", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "coverage", + "limits", + "deductible", + "rating" + ], + "required": false, + "triggers_re_render_hint": false + }, + { + "dossier_key": "monitored_alarm", + "synonyms": [ + "monitored alarm", + "central station alarm", + "protective alarm", + "security alarm", + "burglar alarm", + "monitored_alarm" + ], + "expected_codec": { + "kind": "boolean_yes_no", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [ + "discounts", + "protection", + "safety", + "property" + ], + "required": false, + "triggers_re_render_hint": false + } + ], + "expected_outputs": [ + { + "dossier_key": "quote_number", + "synonyms": [ + "quote number", + "quote id", + "proposal number", + "quote reference", + "quote_number", + "quote_id" + ], + "expected_codec": { + "kind": "whitespace_collapse", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [], + "required": true, + "triggers_re_render_hint": false + }, + { + "dossier_key": "annual_premium", + "synonyms": [ + "annual premium", + "total premium", + "quoted premium", + "estimated annual premium", + "premium", + "annual_premium", + "quoted_premium" + ], + "expected_codec": { + "kind": "currency_cents", + "date_order": "YMD", + "currency_symbol": null, + "enum_aliases": {} + }, + "section_hints": [], + "required": true, + "triggers_re_render_hint": false + } + ] + } +} diff --git a/packages/flow/tests/test_form_tx_presets.py b/packages/flow/tests/test_form_tx_presets.py index 741a413493..78217b9775 100644 --- a/packages/flow/tests/test_form_tx_presets.py +++ b/packages/flow/tests/test_form_tx_presets.py @@ -15,6 +15,7 @@ import pytest from openadapt_flow.form_tx import pack_compiler +from openadapt_flow.form_tx import types as form_types from openadapt_flow.form_tx.presets import ( PRESET_SCHEMA, load_domain_schema, @@ -31,6 +32,11 @@ "2f506d6c463aef8098fc8fcc2fd5bc46e55c1829", "build_patient_registration_domain_schema", ), + "property_quote": ( + pack_compiler.build_property_quote_domain_schema, + "2f506d6c463aef8098fc8fcc2fd5bc46e55c1829", + "build_property_quote_domain_schema", + ), } @@ -45,7 +51,8 @@ def _old_builder(sha: str, name: str): # type: ignore[no-untyped-def] text = got.stdout start = text.index(f"def {name}(") end = text.index("\ndef ", start + 1) - namespace = dict(vars(pack_compiler)) + # The old builder named form_tx types that pack_compiler may no longer import. + namespace = {**vars(form_types), **vars(pack_compiler)} exec(compile(text[start:end], f"{sha}:{SOURCE}", "exec"), namespace) # noqa: S102 return namespace[name]