Files
doczyai-pipelines/archive/scripts/adhoc/tx_ac_no_reimbursement.py
T
Katon Minhas afb6d5185d Merged in feature/lesser-table-caching-refactor-hybrid (pull request #847)
Feature/lesser table caching refactor hybrid

* chore: Remove unused duplicate main.py from shared pipeline

* fix: Correct crosswalk paths in aarete_derived.py

* chore: Remove unused documentation files from fieldExtraction

* docs: Add documentation files to documentation folder

* docs: Update README with uv setup, expanded project structure, and branching conventions

* docs: Add uv installation steps with Ubuntu/WSL emphasis

* Enable prompt caching for all remaining LLM calls

- Add _INSTRUCTION() functions for: EXHIBIT_HEADER, EXHIBIT_LINKAGE,
  EXHIBIT_TITLE_MATCH, DATE_FIX, DERIVED_TERM_DATE, CHECK_PROVIDER_NAME_MATCH,
  SPECIAL_CASE_ASSIGNMENT
- Update all invoke_claude() calls in saas and clover pipelines to use
  cache=True with corresponding _INSTRUCTION() functions
- Add new instructions to get_cacheable_instructions() for cache warming
- Update tests for new instruction functions

Functions now using caching:
- prompt_exhibit_level
- prompt_exhibit_lesser (EXHIBIT_LEVEL_LESSER_OF)
- prompt_fee_schedule_breakout
- prompt_grouper_breakout
- prompt_special_case_assignment
- prompt_exhibit_linkage
- prompt_exhibit_header
- prompt_smart_chunked (ONE_TO_ONE templates)
- prompt_date_fix
- prompt_derived_term_date
- prompt_exhibit_title_match
- provider_name_match_check

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Reorder

* feat: Add bcbs_promise client pipeline with OFFSET_TERM extraction

- Add new bcbs_promise client with HSC-based OFFSET_TERM field extraction
- Extract full paragraph text of offset/recoupment provisions from contracts
- Derive OFFSET_INDICATOR (Y/N) from OFFSET_TERM presence
- Fix reorder_columns to preserve extra columns not in COLUMN_ORDER
- Update QC/QA output path to outputs/qc_qa/

* fix: Update dev deps and test assertions for QC/QA output path

- Add pytest/pytest-mock to dev dependencies for mypy type checking
- Update test assertions to expect outputs/qc_qa instead of qa_qc_output

* style: Apply black formatting to prompt_templates.py

* Merge main, move scripts

* Archive some scripts

* update py version

* remove .py version file

* Remove ASCII characters

* Restore testbed code

* restore tracking

* Update testbed metrics

* Enable prompt caching for CODE_LAST_CHECK, FILL_BILL_TYPE, DUAL_LOB_CHECK, and GROUPER_BREAKOUT

- Add CODE_LAST_CHECK_INSTRUCTION() for service specificity classification
- Add FILL_BILL_TYPE_INSTRUCTION() for bill type code determination
- Add DUAL_LOB_CHECK_INSTRUCTION() for Medicare/Medicaid classification
- Update code_funcs.py to use caching for CODE_LAST_CHECK, FILL_BILL_TYPE, GROUPER_BREAKOUT
- Update postprocessing_funcs.py to use caching for DUAL_LOB_CHECK
- Add new instructions to get_cacheable_instructions() for cache warming
- Add unit tests for new instruction functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix postprocessing_funcs to remove invalid columns

* Merge branch 'main' into feature/lesser-table-caching-refactor-hybrid

* Revert prompt caching changes from aed1b73c

* update formatting

* Update imports


Approved-by: Sha Brown
Approved-by: Praneel Panchigar
2026-01-26 16:52:55 +00:00

101 lines
3.5 KiB
Python

import concurrent.futures
import traceback
import os
import csv
import time
import sys
import random
import pandas as pd
import random
random.seed(42)
import utils
import config
import claude_funcs
import file_processing
import tracking
import consolidate_output
def process_b(item):
filename, contract_text = item
if utils.contains_reimbursement(contract_text, 0):
try:
results = file_processing.run_b_prompts(item)
if results is not None:
tracking.update_results_csv(item, results)
return item, results
except Exception as e:
print(f"Error processing item {filename}: {e}")
traceback.print_exc()
else:
print(f"No reimbursement information found in {filename}. Skipping processing.")
def process_ac(item):
filename, contract_text = item
try:
results = file_processing.run_new_ac_prompts(item)
if results is not None:
tracking.update_results_csv(item, results)
return item, results
except Exception as e:
print(f"Error processing item {filename}: {e}")
traceback.print_exc()
def main():
if config.TEST:
# Note: Claude 2 support has been removed - using Claude 3 Haiku instead
print(claude_funcs.invoke_claude("Write 'test', nothing more.", model_id=config.MODEL_ID_CLAUDE3_HAIKU, filename="test", max_tokens=10))
else:
input_dict = utils.read_input() # keys are contract names, values are full contract text
total_files = len(input_dict)
print(f"Input Files : {len(input_dict)}")
# Filter no reimbursement
input_dict = {k: input_dict[k] for k in list(input_dict)[:100]}
input_dict = {k : v for k, v in input_dict.items() if utils.contains_reimbursement(str(v))} # Filter out non-contracts
print(f"Input Files after reimbursement filter: {len(input_dict)} | {total_files-len(input_dict)} files removed")
# Filter already processed
if config.FILTER_ALREADY_PROCESSED:
input_dict = utils.filter_already_processed(input_dict)
print(f"Input Files left to be processed : {len(input_dict)}")
batch_results = []
processed_count = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=config.MAX_WORKERS) as executor:
if 'b' in config.FIELDS:
futures = [executor.submit(process_b, item) for item in input_dict.items()]
if 'a' in config.FIELDS and 'c' in config.FIELDS:
futures = [executor.submit(process_ac, item) for item in input_dict.items()]
for future in concurrent.futures.as_completed(futures):
try:
result = future.result()
if result:
batch_results.append(result)
processed_count += 1
if processed_count % 5 == 0:
tracking.write_batch_results(batch_results)
batch_results = []
except Exception as e:
print(f"Error in future: {e}")
traceback.print_exc()
if batch_results:
tracking.write_batch_results(batch_results)
tracking.write_stats_to_csv()
print("\nIndividual Processing Complete")
print("Consolidation starting...")
consolidate_output.consolidate_output()
print("Consolidation complete...")
if __name__ == "__main__":
main()