From 5bb7b2ab5b1f66076c71151aafc44274f62775cf Mon Sep 17 00:00:00 2001 From: Mark Waddle Date: Wed, 11 Dec 2024 12:27:34 -0800 Subject: [PATCH] Add text_list and currency form field types (#283) To better handle lists of information, like a list of addresses, or medications, for example And for values that are expected to be currency --- .../assistant/form_fill_extension/state.py | 2 ++ .../steps/fill_form_step.py | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/assistants/prospector-assistant/assistant/form_fill_extension/state.py b/assistants/prospector-assistant/assistant/form_fill_extension/state.py index 52ed879d..71daf418 100644 --- a/assistants/prospector-assistant/assistant/form_fill_extension/state.py +++ b/assistants/prospector-assistant/assistant/form_fill_extension/state.py @@ -13,6 +13,8 @@ class FieldType(StrEnum): text = "text" + text_list = "text_list" + currency = "currency" date = "date" signature = "signature" multiple_choice = "multiple_choice" diff --git a/assistants/prospector-assistant/assistant/form_fill_extension/steps/fill_form_step.py b/assistants/prospector-assistant/assistant/form_fill_extension/steps/fill_form_step.py index b47f4404..69d4c350 100644 --- a/assistants/prospector-assistant/assistant/form_fill_extension/steps/fill_form_step.py +++ b/assistants/prospector-assistant/assistant/form_fill_extension/steps/fill_form_step.py @@ -249,6 +249,12 @@ def _form_fields_to_artifact_basemodel(form_fields: list[state.FormField]): case state.FieldType.text | state.FieldType.signature | state.FieldType.date: field_type = str + case state.FieldType.text_list: + field_type = list[str] + + case state.FieldType.currency: + field_type = float + case state.FieldType.multiple_choice: match field.option_selections_allowed: case state.AllowedOptionSelections.one: @@ -330,12 +336,14 @@ def _generate_populated_form( form: state.Form, populated_fields: dict, ) -> str: - def field_value(field_id: str) -> str: + def field_value(field_id: str) -> str | list[str]: value = populated_fields.get(field_id) or "" if value == "Unanswered": return "" if value == "null": return "" + if isinstance(value, list): + return value return value def field_values(fields: list[state.FormField]) -> str: @@ -349,8 +357,23 @@ def field_values(fields: list[state.FormField]) -> str: markdown_fields.append(f'ℹ️ {field.description}\n') match field.type: - case state.FieldType.text | state.FieldType.signature | state.FieldType.date: - markdown_fields.append(f"{value}") + case ( + state.FieldType.text + | state.FieldType.signature + | state.FieldType.date + | state.FieldType.text_list + | state.FieldType.currency + ): + match value: + case str(): + markdown_fields.append(value) + + case int() | float(): + markdown_fields.append(str(value)) + + case list(): + for item in value: + markdown_fields.append(f"- {item}") case state.FieldType.multiple_choice: for option in field.options: