From 2c98b5ebdb1507bcd93059e7d1498150b5fcc64f Mon Sep 17 00:00:00 2001 From: Alex Galarce Date: Wed, 3 Sep 2025 14:04:18 +0000 Subject: [PATCH] Merged in feature/payer-state (pull request #690) Feature/payer state * fix indentation for PROVIDER_STATE prompt * Add PAYER_STATE prompt and normalize state abbreviation in run_full_context_fields * Add PAYER_STATE to COLUMN_ORDER in investment_columns.py * Merged main into feature/payer-state * Only run PAYER_STATE prompt when more than one state in the batch --- fieldExtraction/constants/investment_columns.py | 3 ++- fieldExtraction/src/investment/one_to_one_funcs.py | 14 ++++++++++++++ .../src/prompts/investment_prompts.json | 14 ++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/fieldExtraction/constants/investment_columns.py b/fieldExtraction/constants/investment_columns.py index c0e2b78..3489480 100644 --- a/fieldExtraction/constants/investment_columns.py +++ b/fieldExtraction/constants/investment_columns.py @@ -9,6 +9,7 @@ COLUMN_ORDER = [ "AARETE_DERIVED_AMENDMENT_NUM", "CLIENT_NAME", "PAYER_NAME", + "PAYER_STATE", "PROVIDER_STATE", "PROV_GROUP_TIN", "PROV_GROUP_NPI", @@ -106,7 +107,7 @@ COLUMN_ORDER = [ "GROUPER_CD", "GROUPER_CD_DESC", "GROUPER_PCT_RATE", - "GROUPER_BASE_RATE", + "GROUPER_BASE_RATE", "GROUPER_VERSION", "AARETE_DERIVED_GROUPER_VERSION", "GROUPER_ALTERNATIVE_LEVEL_OF_CARE", diff --git a/fieldExtraction/src/investment/one_to_one_funcs.py b/fieldExtraction/src/investment/one_to_one_funcs.py index 6d79f38..2bfa12d 100644 --- a/fieldExtraction/src/investment/one_to_one_funcs.py +++ b/fieldExtraction/src/investment/one_to_one_funcs.py @@ -290,6 +290,10 @@ def run_full_context_fields( ) -> dict[str, str]: full_context_fields = one_to_one_fields.filter(field_type="full_context") + # If there is only one state in the batch, don't run this, populate with the single state + if len(config.STATE) == 1: + full_context_fields.remove_field(field_name="PAYER_STATE") + full_context_prompt = prompts.ONE_TO_ONE_MULTI_FIELD_TEMPLATE( context=contract_text[0 : min(MAX_CONTEXT_LENGTH, len(contract_text) - 1)], questions=full_context_fields.print_prompt_dict(constants), @@ -305,6 +309,9 @@ def run_full_context_fields( for field in full_context_fields.list_fields(): full_context_answers_dict[field] = f"Error: {str(e)}" + if len(config.STATE) == 1: + full_context_answers_dict["PAYER_STATE"] = config.STATE[0] + # Normalize PROVIDER_STATE to standardized two-letter abbreviation if "PROVIDER_STATE" in full_context_answers_dict: full_context_answers_dict["PROVIDER_STATE"] = ( @@ -312,6 +319,13 @@ def run_full_context_fields( full_context_answers_dict["PROVIDER_STATE"] ) ) + # Normalize PAYER_STATE to standardized two-letter abbreviation + if "PAYER_STATE" in full_context_answers_dict: + full_context_answers_dict["PAYER_STATE"] = ( + string_utils.normalize_state_to_abbreviation( + full_context_answers_dict["PAYER_STATE"] + ) + ) # Handle separate one-to-one fields that require individual processing separate_fields = one_to_one_fields.filter(field_type="full_context_separate") diff --git a/fieldExtraction/src/prompts/investment_prompts.json b/fieldExtraction/src/prompts/investment_prompts.json index 7e8c001..4d7fad3 100644 --- a/fieldExtraction/src/prompts/investment_prompts.json +++ b/fieldExtraction/src/prompts/investment_prompts.json @@ -225,10 +225,16 @@ "prompt": "Extract the amendment number if this document is an amendment to a contract. Follow these guidelines:\n1. Look for phrases like 'Amendment No. X', 'X Amendment', 'Amendment X to the Agreement', 'Xth Amendment' in the document title, preamble, or header sections.\n2. Return only the numeric value (e.g., for 'Amendment No. 3' return '3').\n3. If the amendment number is written as a word (e.g., 'First Amendment'), convert it to a number (e.g., '1').\n4. If the amendment number is an alphanumeric value, return the whole value (e.g., for '2A' return '2A').\n5. If the amendment number uses Roman numerals (e.g., 'Amendment IV'), convert it to a number (e.g., '4').\n6. If the amendment number includes decimal points (e.g., 'Amendment 2.1'), return the full numeric value (e.g., '2.1').\n7. If multiple amendment numbers appear, return the one most clearly associated with the current document.\n8. If the document is an amendment but the number cannot be determined, return 'UNKNOWN'.\n9. If the document is not an amendment, return 'N/A'.\n10. If the Amendment number contains any leading zeroes(e.g. '001'), Drop all leading zeros (e.g. '1').\n11. If the document is an amendment but the number cannot be determined, return '1'." }, { - "field_name": "PROVIDER_STATE", - "relationship": "one_to_one", - "field_type": "full_context", - "prompt": "What US state is the provider based in or where does this contract apply? Look for:\n\n1. Provider address information in the contract header, preamble, or signature sections\n2. State names or abbreviations in provider contact information\n3. Language indicating the governing state or jurisdiction (e.g., 'governed by the laws of [State]')\n4. Service area or coverage area specifications\n5. Provider licensing information that mentions a specific state\n\nReturn the full state name (e.g., 'California', 'Texas', 'New York') or the standard 2-letter abbreviation (e.g., 'CA', 'TX', 'NY') as it appears in the document.\n\nIf multiple states are mentioned, prioritize:\n1. The state in the provider's primary address\n2. The state mentioned in governing law clauses\n3. The state most frequently referenced in the contract\n\nIf no state can be determined, return 'N/A'." + "field_name": "PROVIDER_STATE", + "relationship": "one_to_one", + "field_type": "full_context", + "prompt": "What US state is the provider based in or where does this contract apply? Look for:\n\n1. Provider address information in the contract header, preamble, or signature sections\n2. State names or abbreviations in provider contact information\n3. Language indicating the governing state or jurisdiction (e.g., 'governed by the laws of [State]')\n4. Service area or coverage area specifications\n5. Provider licensing information that mentions a specific state\n\nReturn the full state name (e.g., 'California', 'Texas', 'New York') or standard 2-letter abbreviation (e.g., 'CA', 'TX', 'NY') as it appears in the document.\n\nIf multiple states are mentioned, prioritize:\n1. The state in the provider's primary address\n2. The state mentioned in governing law clauses\n3. The state most frequently referenced in the contract\n\nIf no state can be determined, return 'N/A'." + }, + { + "field_name": "PAYER_STATE", + "relationship": "one_to_one", + "field_type": "full_context", + "prompt": "What US state is the payer based in or incorporated in? Look for:\n\n1. Payer address information in the contract header, preamble, or signature sections\n2. State names or abbreviations in payer contact information\n3. State of incorporation or principal place of business\n4. Payer headquarters location\n5. Payer licensing information that mentions a specific state\n\nReturn the full state name (e.g., 'California', 'Texas', 'New York') or standard 2-letter abbreviation (e.g., 'CA', 'TX', 'NY') as it appears in the document.\n\nIf multiple states are mentioned, prioritize:\n1. The state in the payer's primary/headquarters address\n2. The state of incorporation\n3. The state most frequently referenced for the payer organization\n\nIf no state can be determined, return 'N/A'." }, { "field_name": "CLIENT_NAME",