1837 Commits

Author SHA1 Message Date
Katon Minhas 9b89b0a10a Merged main into bugfix/UT-reimbursement-dates 2025-12-15 21:00:27 +00:00
Katon Minhas 33241d5808 Pipeline 2025-12-15 12:52:53 -05:00
Mayank db92b42679 reimb terms based on dates 2025-12-15 15:11:35 +00:00
Praneel Panchigar 87a2b8b4ce Merged in issuefix/hmk-1-to-n (pull request #806)
Issuefix/hmk 1 to n

* Merge branch 'main' into feature/1toN-Optimization

* Merge branch 'main' into feature/1toN-Optimization

* Update preprocessing to make the exhibit_chunk_mapping start at first page

* Merge row_funcs.py changes from feature/cross-exhibit-dynamic

* Merged in bugfix/UT-grouper-issues (pull request #796)

Bugfix/UT grouper issues

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* prompt update

* prompt update

* Merged feature/1toN-Optimization into bugfix/nv_issue_fixes

* add service term in mb prompts

* Merged feature/1toN-Optimization into bugfix/UT-methodology-breakout

* print statement removed

* Merge branch 'bugfix/UT-methodology-breakout' of https://bitbucket.org/aarete/doczy.ai into bugfix/UT-methodology-breakout

* primary prompt update

* prompt update

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into bugfix/UT-grouper-issues

* removed temp changes

* removed temp changes

* Update reimb primary


Approved-by: Katon Minhas

* Merged in bugfix/validation_fixes (pull request #795)

bugfix/validation_fixes to feature/1toN-Optimization

* updated validation of clean claims reimbursement

* Merged feature/1toN-Optimization into bugfix/validation_fixes


Approved-by: Katon Minhas

* Re-add dynamic codes and reimb-info

* Re-structure empty reimbursement prompt

* Fix lesser of check overfiltering

* Merged in bugfix/generic-methodology-breakout (pull request #797)

Bugfix/generic methodology breakout

* fee schedule fix

* carveout+special case prompt changed

* fee schedule changes

* prompt changes and column order


Approved-by: Katon Minhas

* pytest fix

* remove prints

* Update valid_carveouts.json to include level designations in PAYMENT_CARVEOUT definition and add adultBasic mapping for Highmark

* Fix REIMB_DATES extraction to capture only relevant date range per term

- Updated REIMB_DATES prompt to extract only the date range that applies to the specific reimbursement term
- Added proximity-based extraction: looks for dates in same section/table as the term
- Prevents cross-contamination from other contract sections
- Handles 'Same as Effective Date of Agreement' case
- Returns single date range instead of multiple comma-separated ranges

* Update prompt templates

* Update tracked files and add untracked_tests to gitignore

* Merge branch 'main' into issuefix/hmk-1-to-n

* complete merge

* complete merge

* Merge branch 'main' into issuefix/hmk-1-to-n

* Remove prints

* Update gitignore

* Revert BASE_COVERED_SERVICES and REIMB_DATES prompts to original definitions

- Revert BASE_COVERED_SERVICES definition to original concise version
- Revert REIMB_DATES prompt to original general description (specific assignment logic handled by dedicated template)
- Add DEBUG comment blocks around print statements in dynamic_funcs.py and file_processing.py for easy identification and toggling

* remove prints

* Merge branch 'main' into issuefix/hmk-1-to-n


Approved-by: Katon Minhas
2025-12-12 18:36:57 +00:00
Mayank Aamseek 042a429ffb Merged in bugfix/UT-special-cases (pull request #807)
Bugfix/UT special cases

* stoploss fix

* Merged main into bugfix/UT-special-cases

* added IPPS

* added Federal PPS

* added IRF PPS

* Merged main into bugfix/UT-special-cases


Approved-by: Katon Minhas
2025-12-12 16:56:36 +00:00
Mayank 06a889781f added IRF PPS 2025-12-12 15:21:35 +00:00
Mayank 5032968f9a added Federal PPS 2025-12-12 15:07:04 +00:00
Mayank 89165c36f7 added IPPS 2025-12-12 15:00:42 +00:00
Katon Minhas 57a2907bbd Update for confusing language 2025-12-11 17:18:37 -06:00
Katon Minhas a00ffd4b98 Update mappings 2025-12-11 17:15:23 -06:00
Katon Minhas 9e7f8840af Merged main into bugfix/UT-special-cases 2025-12-11 20:55:07 +00:00
VenkataKrishna Reddy Avula c91435d2f1 Merged in bugfix/reimb_method_grouper (pull request #805)
bugfix/reimb_method_grouper to main

* modified grouper reimb_method

* Merged main into bugfix/reimb_method_grouper


Approved-by: Katon Minhas
2025-12-11 20:54:47 +00:00
Sha Brown 3bf8860ca6 Merged in bugfix/prov_info (pull request #803)
Bugfix/prov info

* Added logic to extract provider name from first page

* Added prompt to extract provider name from first page

* Added prompts and provider name extraction using Hybrid Smart Chunking

* Cleaned up code

* Added additional logic to check if the provider name on tin/npi page matches provider name extracted from page 1.

* Added fix for IS_GROUP issue in provider info json

* Remove commented out code

* unit test fix

* uni test fix

* Merge branch 'main' into bugfix/prov_info

* Change to string_utils.is_empty

* Minor refactor


Approved-by: Katon Minhas
2025-12-11 20:53:21 +00:00
Mayank 93d3fa93e2 stoploss fix 2025-12-11 15:00:28 +00:00
Karan Desai 290a1e7315 Merged in issuefix/hmk-1-to-1 (pull request #804)
Issuefix/hmk 1 to 1

* prompt fix for auto renew ind

* filename tin regex update

* amendment  number prompt fix

* effective date prompt tunning

* Merge remote-tracking branch 'origin/main' into issuefix/hmk-1-to-1


Approved-by: Katon Minhas
2025-12-10 23:26:24 +00:00
Mayank Aamseek 1de74c9322 Merged in Optimization/reimb-primary (pull request #800)
Optimization/reimb primary

* Merged in bugfix/UT-methodology-breakout (pull request #794)

Bugfix/UT methodology breakout

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* prompt update

* prompt update

* Merged feature/1toN-Optimization into bugfix/nv_issue_fixes

* add service term in mb prompts

* Merged feature/1toN-Optimization into bugfix/UT-methodology-breakout

* print statement removed

* Merge branch 'bugfix/UT-methodology-breakout' of https://bitbucket.org/aarete/doczy.ai into bugfix/UT-methodology-breakout

* primary prompt update

* remove duplicate prompt


Approved-by: Katon Minhas

* Merge branch 'main' into feature/1toN-Optimization

* Merge branch 'main' into feature/1toN-Optimization

* Update preprocessing to make the exhibit_chunk_mapping start at first page

* Merge row_funcs.py changes from feature/cross-exhibit-dynamic

* Merged in bugfix/UT-grouper-issues (pull request #796)

Bugfix/UT grouper issues

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* prompt update

* prompt update

* Merged feature/1toN-Optimization into bugfix/nv_issue_fixes

* add service term in mb prompts

* Merged feature/1toN-Optimization into bugfix/UT-methodology-breakout

* print statement removed

* Merge branch 'bugfix/UT-methodology-breakout' of https://bitbucket.org/aarete/doczy.ai into bugfix/UT-methodology-breakout

* primary prompt update

* prompt update

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into bugfix/UT-grouper-issues

* removed temp changes

* removed temp changes

* Update reimb primary


Approved-by: Katon Minhas

* Merged in bugfix/validation_fixes (pull request #795)

bugfix/validation_fixes to feature/1toN-Optimization

* updated validation of clean claims reimbursement

* Merged feature/1toN-Optimization into bugfix/validation_fixes


Approved-by: Katon Minhas

* Re-add dynamic codes and reimb-info

* Re-structure empty reimbursement prompt

* Fix lesser of check overfiltering

* Merged in bugfix/generic-methodology-breakout (pull request #797)

Bugfix/generic methodology breakout

* fee schedule fix

* carveout+special case prompt changed

* fee schedule changes

* prompt changes and column order


Approved-by: Katon Minhas

* fix not_to_exceed distribution

* pytest fix

* remove prints

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into Optimization/reimb-primary

* prompt update for reimb primary

* Update mapping

* Update tests

* Update test

* row order fixed

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into Optimization/reimb-primary

* chargemaster fix

* Merge branch 'main' into Optimization/reimb-primary

* Complete merge

* Final updates


Approved-by: Katon Minhas
2025-12-10 22:24:44 +00:00
Katon Minhas 0e2622f156 Merged in feature/1toN-Optimization (pull request #799)
Feature/1toN Optimization

* Update config - remove Haiku 3

* Merged in optimization/trigger-cap (pull request #792)

Optimization/trigger cap

* trigger cap breakout added

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into optimization/trigger-cap

* carveout breakout added


Approved-by: Katon Minhas

* Merged in bugfix/utah_issue_fixes (pull request #791)

Bugfix/utah issue fixes to feature/1toN-Optimization

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* removed reciprocatory agreements section reimbs

* Merged feature/1toN-Optimization into bugfix/utah_issue_fixes

* update reimb primary


Approved-by: Katon Minhas

* Update unit tests

* Update llm_utils

* Merge branch 'feature/deprecate-haiku-3' into feature/1toN-Optimization

* fix over-filtering of lesser of

* Merged in bugfix/UT-methodology-breakout (pull request #794)

Bugfix/UT methodology breakout

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* prompt update

* prompt update

* Merged feature/1toN-Optimization into bugfix/nv_issue_fixes

* add service term in mb prompts

* Merged feature/1toN-Optimization into bugfix/UT-methodology-breakout

* print statement removed

* Merge branch 'bugfix/UT-methodology-breakout' of https://bitbucket.org/aarete/doczy.ai into bugfix/UT-methodology-breakout

* primary prompt update

* remove duplicate prompt


Approved-by: Katon Minhas

* Merge branch 'main' into feature/1toN-Optimization

* Merge branch 'main' into feature/1toN-Optimization

* Update preprocessing to make the exhibit_chunk_mapping start at first page

* Merge row_funcs.py changes from feature/cross-exhibit-dynamic

* Merged in bugfix/UT-grouper-issues (pull request #796)

Bugfix/UT grouper issues

* updated valid values for AARETE_DERIVED_REIMB_METHOD

* removed example reimbursements

* prompt update

* prompt update

* Merged feature/1toN-Optimization into bugfix/nv_issue_fixes

* add service term in mb prompts

* Merged feature/1toN-Optimization into bugfix/UT-methodology-breakout

* print statement removed

* Merge branch 'bugfix/UT-methodology-breakout' of https://bitbucket.org/aarete/doczy.ai into bugfix/UT-methodology-breakout

* primary prompt update

* prompt update

* Merge remote-tracking branch 'origin/feature/1toN-Optimization' into bugfix/UT-grouper-issues

* removed temp changes

* removed temp changes

* Update reimb primary


Approved-by: Katon Minhas

* Merged in bugfix/validation_fixes (pull request #795)

bugfix/validation_fixes to feature/1toN-Optimization

* updated validation of clean claims reimbursement

* Merged feature/1toN-Optimization into bugfix/validation_fixes


Approved-by: Katon Minhas

* Re-add dynamic codes and reimb-info

* Re-structure empty reimbursement prompt

* Fix lesser of check overfiltering

* Merged in bugfix/generic-methodology-breakout (pull request #797)

Bugfix/generic methodology breakout

* fee schedule fix

* carveout+special case prompt changed

* fee schedule changes

* prompt changes and column order


Approved-by: Katon Minhas

* pytest fix

* remove prints

* Update mapping

* Update tests

* Update test

* Address PR review comments: add logging, fix return types, fix variable propagation, and add tests

- Add warning log in code_funcs.py try/except block for grouper code parsing failures
- Add warning log in hybrid_smart_chunking_funcs.py except block for JSON parsing failures
- Add return type annotation to lesser_of_distribution function
- Fix first_reimbursement_page variable propagation issue by returning updated value
- Add comprehensive tests for simplify_exhibit, chunk_by_exhibit, and lesser_of_distribution functions

* Merged in bugfix/prov_info_json (pull request #802)

Bugfix/prov info json to feature/1toN-Optimization

* prov_info_json added

* remove print statements


Approved-by: Katon Minhas


Approved-by: Siddhant Medar
2025-12-10 20:01:52 +00:00
Katon Minhas 83fcb104a2 Merged in feature/deprecate-haiku-3 (pull request #793)
Feature/deprecate haiku 3

* Update config - remove Haiku 3

* Update llm_utils

* Merged main into feature/deprecate-haiku-3


Approved-by: Siddhant Medar
2025-12-02 17:34:15 +00:00
Karan Desai 407b4bd55e optimized sig field query 2025-12-01 16:21:10 -06:00
VenkataKrishna Reddy Avula 2482adb465 Merged in optimization/tin_npi (pull request #790)
Optimization/tin npi

* updated signature page and added for tin  npi

* updated signature page

* removed print statements

* removed print statement

* updated test for extract signature page

* updated data type


Approved-by: Katon Minhas
2025-11-26 17:21:44 +00:00
Karan Desai 4334800fa3 Merged in feature/pc_code_optimization (pull request #788)
added stopwords json

* added stopwords json


Approved-by: Katon Minhas
2025-11-25 23:03:05 +00:00
Karan Desai e0e0ceee8b Merged in feature/available_signature_lines (pull request #786)
Available Signature Lines

* pp funcs for sig fields


Approved-by: Katon Minhas
2025-11-24 17:01:29 +00:00
Katon Minhas 89c4447c75 Merged in hotfix/clover-errors (pull request #785)
Hotfix/clover errors

* Update function name

* Update logging

* remove excess info

* remove breakout print

* Typehints

* Don't add lists

* remove prints


Approved-by: Siddhant Medar
Approved-by: Karan Desai
2025-11-21 22:38:49 +00:00
Katon Minhas 5e9de5021d Merged in hotfix/nltk-bug (pull request #784)
backup - tempfix

* backup - tempfix


Approved-by: Karan Desai
2025-11-21 19:21:56 +00:00
Mayank Aamseek 8ea69063b1 Merged in bugfix/code-list-format (pull request #781)
Bugfix/code list format

* replace | with comma in lists

* partial revert

* remove test changes

* Merged main into bugfix/code-list-format

* fix list format

* pipeline error fixed

* pipeline error fixed

* pipeline error fixed


Approved-by: Katon Minhas
2025-11-21 14:59:54 +00:00
VenkataKrishna Reddy Avula 18d893c40a Merged in bugfix/payer_name_provider_state (pull request #780)
Bugfix/payer name provider state to main

* updated provider state

* updated prompt

* Merged main into bugfix/payer_name_provider_state

* updated smart chunked field types

* added post processing for provider state

* field check added

* filter by field_type instead of retrieval question

* Merged main into bugfix/payer_name_provider_state


Approved-by: Katon Minhas
2025-11-19 19:02:45 +00:00
Karan Desai f8ceb39111 Merged in feature/signatures_present (pull request #779)
Feature/signatures present

* initial commit

* shifted from pp to one_to_one

* moved func in one_to_one_funcs

* Merged main into feature/signatures_present


Approved-by: Katon Minhas
2025-11-19 18:42:04 +00:00
Siddhant Medar 36a5ff938e Merged in feature/automated-qc-qa (pull request #778)
Feature/automated qc qa

* Moved automation_saas.py from alien_strings to qc_qa module

* Moved from alien_string

* Moved from alien_string

* clean up

* WIP: prepare saas automation script for integration

* format code and fix mypy issue

* minor fixes during e2e testing

* add tests

* format and fix mypy issues

* Merge remote-tracking branch 'origin/main' into feature/automated-qc-qa

* Remove print - replace with logging


Approved-by: Katon Minhas
2025-11-19 18:40:11 +00:00
Karan Desai 5887cf651e Merged in feature/pc (pull request #773)
Feature/pc

* file read update

* removed unused code

* replace pring with logging.info

* input args for docczy output

* input args for docczy output

* added json for loading mappings

* exception for bool keys

* exception for bool keys

* added init.py

* write to s3/local functionality

* write to s3/local functionality

* logging errors and main functionality fix

* pc functionality from main

* pc functionality from main

* function signature fix

* fixed path returns

* Updated names for varaibles; Modified termination date cleaning function

* Removed commented out function

* Renamed client column names to SAAS column names

* Merge remote-tracking branch 'origin/main' into feature/pc

* removed pc utils

* black formatting

* rename function

* rename func

* additional file removed


Approved-by: Katon Minhas
2025-11-17 14:16:39 +00:00
Praneel Panchigar ff400f4b1c Merged in feature/llm-utils-refactor (pull request #776)
Feature/llm utils refactor

* - Removed some temporary logging code
- Removed unused imports (uuid, datetime) from llm_utils.py
- Added cache token columns (cache_creation_tokens, cache_read_tokens) to CSV exports
- Added tracking for cache warming
- Updated usage_tracking.py to track cache tokens separately in data structure

All token tracking functionality remains intact.

* Split input tokens into fresh and cache in summary section

- Add total_fresh_input_tokens and total_cache_tokens to GLOBAL_USAGE
- Update summary CSV to include split token columns for better tractability
- Add averages for fresh_input_tokens and cache_tokens
- Maintain total_input_tokens = fresh_input_tokens + cache_tokens relationship
- All calculations verified and match per-file totals correctly

* upload files functionality

* Add comprehensive unit tests for usage_tracking module

- Implement Phase 1-4 tests covering all 10 functions in usage_tracking.py
- Add 98 test cases with parametrized tests for comprehensive coverage
- Fix extract_usage_from_response to handle None input gracefully
- Add python-dotenv dependency to pyproject.toml
- Tests cover: core functions, data access, export functions, and utilities
- All tests passing (98/98)

* Add S3 upload tests for main.py and fix f-string syntax error

- Add tests/test_investment_main_s3.py with 3 test cases:
  * test_main_writes_final_and_error_to_s3: validates both final and error DataFrames uploaded when processing has errors
  * test_main_writes_only_final_when_no_errors: validates only final DataFrame uploaded when all files succeed
  * test_main_writes_usage_when_present: validates usage tracking files uploaded when usage data exists
- Tests use monkeypatching and module stubs to isolate S3 write logic without external dependencies
- Fix syntax error in src/codes/code_funcs.py: nested f-string quotes (level_dict['level_suffix'])
- All tests passing

* Add comprehensive test for usage_tracking.get_usage_dataframes S3 uploads

- Add test_usage_dataframes_written_to_s3 to validate per_file_usage_df and batch_summary_df
- Test verifies both dataframes from usage_tracking.get_usage_dataframes() are written to S3
- Validates 'usage' suffix writes per_file_usage_df with correct schema (file_name, tokens, cost)
- Validates 'usage_summary' suffix writes batch_summary_df with correct schema (totals, averages, region_mode)
- Uses pd.testing.assert_frame_equal to ensure exact dataframes are uploaded
- Fix module caching issue between tests by clearing sys.modules cache
- All 4 tests passing

* Add cleanup fixture to prevent test pollution

- Add autouse pytest fixture to clean up stubbed modules after each test
- Remove manual cache clearing from individual tests (now handled by fixture)
- Prevents our module stubs from affecting other test files in CI/CD pipeline
- Fixes Bitbucket pipeline failures where other tests couldn't find llm_utils attributes

* Refactor tests: add comprehensive io_utils coverage; disable usage_tracking suite

- Added 22 focused tests for write_local and write_s3 plus existing IO behaviors
- Introduced FakeS3Client to avoid boto3 network/credential dependency
- Added preserve_config fixture (no monkeypatch) to isolate config side effects
- Marked test_usage_tracking.py skipped per new consolidation approach
- Verified 26 tests (io_utils + investment_main) all pass locally without AWS exceptions

* Fix S3_CLIENT mocking: use mocker.patch instead of direct assignment

- Changed preserve_config fixture to NOT save/restore S3_CLIENT
- Updated all 5 write_s3 tests to use mocker.patch('src.config.S3_CLIENT', fake)
- This prevents pollution of config.S3_CLIENT across test modules
- Fixes NoCredentialsError in other tests that were importing config after our tests set FakeS3Client
- All 22 io_utils tests pass + 4 investment_main_s3 tests pass
- test_llm_utils::test_invoke_claude_local_mode now passes

* Add tests for write_s3 function

* Resolve merge conflict: keep mocker-based write_s3 tests

* Remove rogue skip mark from test_usage_tracking.py

The skip mark was incorrectly added by remote branch claiming tests were
migrated to io_utils. However, test_io_utils.py only tests io_utils functions
(read/write operations), not usage_tracking functions.

Restore the comprehensive usage_tracking tests from commit 26a556f0 which
includes 98 test cases covering all 10 functions in usage_tracking.py.

* Fix test pollution: add config cleanup fixture and restore RUN_MODE

- Add autouse fixture in test_io_utils.py to restore config values after each test
- Fix test_llm_utils.py to restore RUN_MODE after test_invoke_claude_local_mode
- Prevents config patches from leaking into subsequent tests causing NoCredentialsError

* Remove redundant test_investment_main_s3.py

- File was testing same write_s3 functionality already covered in test_io_utils.py
- Was causing module pollution by stubbing src.utils.llm_utils
- Caused test failures in other test files due to module cache issues
- Integration testing was minimal and mocked write_s3 anyway

* Phase 1: Remove unused code and align cost constants

- Remove count_tokens() function (unused, replaced by exact API counts)
- Remove unused cost constants from invoke_claude() and invoke_claude_with_image_array()
- Remove unused math import
- Update usage_tracking.py to match correct cost constants from llm_utils.py:
  - Corrected Haiku cache_read: 0.000025 -> 0.00003
  - Implemented correct cache creation cost calculation:
    * Sonnet models: 25% higher than input (0.00375 vs 0.003)
    * Haiku: 20% higher than input (0.0003 vs 0.00025)
- Remove test_count_tokens() test
- Update test_track_usage_single_call() to account for corrected cache creation costs

All 437 tests passing. Token counts verified against previous runs.

* Phase 2: Remove redundant update_stats() tracking

- Remove all update_stats() calls from EC2 mode (3 locations)
- Remove update_stats() function definition
- Remove estimated token counting (tokens_sent, tokens_received)
- Remove elapsed_time calculations
- Remove unused start_time assignments
- Remove test_update_stats() test case
- Clean up setUp() method in test_llm_utils.py
- Update docstrings to reflect usage_tracking.py as source of truth

All token tracking now uses exact API counts via usage_tracking.track_usage().
All 436 tests passing.

* Merge main into feature/llm-utils-refactor

Resolved merge conflicts:
- llm_utils.py: Kept refactored code (removed legacy update_stats, math import)
- usage_tracking.py: Kept corrected cost constants and cache creation pricing logic
- io_utils.py: Merged main's new 'dtc' and 'dtc_summary' output types
- test_usage_tracking.py: Kept corrected test values for cache_read and cache_creation costs

All conflicts resolved while preserving Phase 1 & 2 refactoring work.

* Fix merge conflict artifact in test_usage_tracking.py

Removed leftover merge conflict marker (<<<<<<< HEAD) that was missed
during merge resolution. The test now correctly calculates cache creation
costs for Sonnet (25% higher) and Haiku (20% higher) models.

* Phase 3: Add thread safety and enhance cache key generation

Step 3.1: Add thread safety to cache operations
- Added _cache_lock = threading.Lock() at module level
- Wrapped all cache operations (get, set, move_to_end, popitem) with lock
- All 4 cache operation locations now thread-safe:
  * Cache check/retrieval in invoke_claude()
  * Cache storage in invoke_claude()
  * Cache check/retrieval in invoke_claude_with_image_array()
  * Cache storage in invoke_claude_with_image_array()

Step 3.2: Enhance cache key generation
- Updated get_cache_key() to include instruction, max_tokens, and cache flag
- Updated get_cache_key_with_image_array() with same enhancements
- Cache keys now differentiate based on all relevant parameters
- Backward compatible (all new parameters are optional)

Step 3.3: Update call sites
- Updated invoke_claude() to pass instruction, max_tokens, cache to get_cache_key()
- Updated invoke_claude_with_image_array() to pass max_tokens

All 412 tests passing. Cache operations are now thread-saf…
* Phase 4: Add comprehensive tests for cache operations and token tracking

Step 4.1: Remove legacy test cases
- Already completed in Phase 2 (test_update_stats, test_count_tokens removed)
- setUp() cleaned up (no MODEL_STATS/GLOBAL_STATS setup needed)

Step 4.2: Add tests for thread-safe cache operations
- test_cache_thread_safety_concurrent_reads: 10 concurrent cache reads
- test_cache_thread_safety_concurrent_writes: 10 concurrent cache writes
- test_cache_thread_safety_mixed_operations: mixed read/write operations

Step 4.3: Add tests for enhanced cache key generation
- test_get_cache_key_basic: backward compatibility test
- test_get_cache_key_with_instruction: instruction parameter
- test_get_cache_key_with_max_tokens: max_tokens parameter
- test_get_cache_key_with_cache_flag: cache flag
- test_get_cache_key_all_parameters: all parameters together
- test_get_cache_key_with_image_array: image array variant
- test_invoke_claude_uses_enhanced_cache_key: integration test

Step 4.4: Verify token tracking uses e…
* Phase 5: Replace legacy CSV export with usage_tracking.py

Step 5.1: Replace write_stats_to_csv() implementation
- Updated write_stats_to_csv() to use usage_tracking.get_usage_dataframes() instead of config.MODEL_STATS/GLOBAL_STATS
- Added import for usage_tracking module
- Function now reads from usage_tracking.py as the single source of truth

Step 5.2: Add optional run_id and timestamp parameters
- Added optional run_id parameter (defaults to config.BATCH_ID)
- Added optional timestamp parameter (defaults to current timestamp)
- Updated upload_tracking_logs() to pass batch_id and run_timestamp

Step 5.3: Transform usage_tracking format to legacy CSV format
- Aggregates per-file, per-model data to per-file data
- Maps model names to Claude 2/3/3.5 request counts
- Calculates tokens_sent (fresh input tokens) and tokens_received (output tokens)
- Maintains backward compatibility with legacy CSV structure
- Handles empty data gracefully (writes headers-only CSV)

Step 5.4: Verify call sites work with updated f…
* refactor(llm_utils): extract helper functions and reduce code duplication

- Add private helper functions: _track_usage_from_response(), _build_claude_3_request_body(), _store_in_cache()
- Simplify routing logic using model sets (_CLAUDE_2_MODELS, _CLAUDE_3_AND_UP_MODELS)
- Replace 8 instances of usage tracking pattern with single function call
- Replace 3 instances of request body building with helper function
- Replace 2 instances of cache storage with helper function
- Add Claude 4.5 Sonnet to cache support list
- Reduce file size from 1,004 to 860 lines (14.3% reduction, 144 lines removed)
- All tests passing (422 tests)
- Maintains backward compatibility and functionality

* Re-support Claude 3 Haiku and add comprehensive tests for new helper functions

- Re-added Claude 3 Haiku to supported models (removed from deprecated patterns)
- Updated model validation to include Haiku in supported models list
- Added comprehensive test coverage for new helper functions:
  - _validate_model_support() - 5 tests covering deprecation, support, and context
  - _supports_prompt_cache() - 2 tests for cache support detection
  - _build_claude_3_request_body() - 4 tests for request body building with/without cache
- Updated error messages to reflect Claude 3+ models (Haiku, Sonnet 3.5/3.7/4/4.5)
- All 23 tests passing

* Merged main into feature/llm-utils-refactor

* Merged main into feature/llm-utils-refactor


Approved-by: Siddhant Medar
Approved-by: Katon Minhas
2025-11-17 14:15:46 +00:00
VenkataKrishna Reddy Avula 2ac6d58f08 Merged in bugfix/effective_dt (pull request #777)
Bugfix/effective dt to main

* removed secondary instruction

* paased right field to full context

* added secondary rule

* remove print statements


Approved-by: Katon Minhas
2025-11-14 16:00:34 +00:00
VenkataKrishna Reddy Avula ca5a0619ba Merged in bugfix/tin_exception (pull request #775)
bugfix/tin_exception to main

* added additional TIN instruction


Approved-by: Katon Minhas
2025-11-12 15:12:30 +00:00
Mayank Aamseek 7e863f5fc8 Merged in bugfix/Molina-UT-conversion-factor (pull request #772)
Bugfix/Molina UT conversion factor

* handle multiple default_terms in one reimb_term

* remove incorrect trigger cap cases

* carveout_cd fixes

* Merge branch 'main' into bugfix/Molina-UT-carveout-cd

* fix variable naming

* methodology prompt updated

* Merge branch 'main' into bugfix/Molina-UT-carveout-cd

* revert test changes

* revert test changes

* fixed incorrect conversion factor

* Merge branch 'main' into bugfix/Molina-UT-conversion-factor

* test to fix service term

* Merge branch 'main' into bugfix/Molina-UT-conversion-factor

* revert test changes

* Merged main into bugfix/Molina-UT-conversion-factor


Approved-by: Katon Minhas
2025-11-12 15:11:58 +00:00
VenkataKrishna Reddy Avula 1045dccbbe Merged in bugfix/outlier_terms (pull request #771)
Bugfix/outlier terms to main

* added split sepcial term

* additional instrcution added

* Merged main into bugfix/outlier_terms

* modified special case primary

* removed split special case primary

* remove additional instruction

* remove print statements

* removed print statements

* updated special case primary prompt

* Merged main into bugfix/outlier_terms


Approved-by: Katon Minhas
2025-11-12 15:11:16 +00:00
Katon Minhas 4142992c5e Merged in feature/missingness-analysis (pull request #770)
Add missingness_analysis script

* Add missingness_analysis script


Approved-by: Siddhant Medar
2025-11-11 22:52:29 +00:00
Siddhant Medar f7a9d80162 Merged in feature/dtc-clean (pull request #767)
Feature/dtc clean

* dtc v1 initial commit

* second layer of prompt

* Added MAX_PAGES_TO_CHECK and page looping to get answer from llm

* Edited contract_type prompt to get cleaner output with no additional text

* Updated document_type_classification prompt

* Added non-contract type classifcation

* Added dtc_v1_test.py for testing only

* Updated prompt

* Updated prompt

* at scale changes

* add save feature for individual file output

* update dockerfile

* clean dtc to prepare for merge

* clean up dtc script

* Merge remote-tracking branch 'origin/main' into feature/dtc-clean

* reafactor code

* Merge remote-tracking branch 'origin/main' into feature/dtc-clean


Approved-by: Katon Minhas
2025-11-10 20:18:33 +00:00
Praneel Panchigar 7056c1c687 Merged in feature/automated-cost-logging-csv (pull request #768)
Feature/automated cost logging csv

* feat: Add usage and cost tracking with CSV export

- Add usage_tracking.py module for thread-safe token and cost tracking
- Extract actual tokens from Bedrock API responses (replaces word count estimation)
- Integrate usage tracking into llm_utils.py for all LLM invocations
- Add CSV export functionality (per-file/per-model and batch summary)
- Integrate CSV export into main.py for local runs
- Update .gitignore to exclude PRD

Phase 1: Data collection and local CSV export implemented
- Tracks all LLM calls including utility functions (date_fix, derive_term_date)
- Calculates costs per model using centralized cost constants
- Generates two CSV files: USAGE.csv and USAGE-SUMMARY.csv
- Exports to same directory as final results when write_to_s3=False

* - Removed some temporary logging code
- Removed unused imports (uuid, datetime) from llm_utils.py
- Added cache token columns (cache_creation_tokens, cache_read_tokens) to CSV exports
- Added tracking for cache warming
- Updated usage_tracking.py to track cache tokens separately in data structure

All token tracking functionality remains intact.

* Split input tokens into fresh and cache in summary section

- Add total_fresh_input_tokens and total_cache_tokens to GLOBAL_USAGE
- Update summary CSV to include split token columns for better tractability
- Add averages for fresh_input_tokens and cache_tokens
- Maintain total_input_tokens = fresh_input_tokens + cache_tokens relationship
- All calculations verified and match per-file totals correctly

* upload files functionality

* Add comprehensive unit tests for usage_tracking module

- Implement Phase 1-4 tests covering all 10 functions in usage_tracking.py
- Add 98 test cases with parametrized tests for comprehensive coverage
- Fix extract_usage_from_response to handle None input gracefully
- Add python-dotenv dependency to pyproject.toml
- Tests cover: core functions, data access, export functions, and utilities
- All tests passing (98/98)

* Add S3 upload tests for main.py and fix f-string syntax error

- Add tests/test_investment_main_s3.py with 3 test cases:
  * test_main_writes_final_and_error_to_s3: validates both final and error DataFrames uploaded when processing has errors
  * test_main_writes_only_final_when_no_errors: validates only final DataFrame uploaded when all files succeed
  * test_main_writes_usage_when_present: validates usage tracking files uploaded when usage data exists
- Tests use monkeypatching and module stubs to isolate S3 write logic without external dependencies
- Fix syntax error in src/codes/code_funcs.py: nested f-string quotes (level_dict['level_suffix'])
- All tests passing

* Add comprehensive test for usage_tracking.get_usage_dataframes S3 uploads

- Add test_usage_dataframes_written_to_s3 to validate per_file_usage_df and batch_summary_df
- Test verifies both dataframes from usage_tracking.get_usage_dataframes() are written to S3
- Validates 'usage' suffix writes per_file_usage_df with correct schema (file_name, tokens, cost)
- Validates 'usage_summary' suffix writes batch_summary_df with correct schema (totals, averages, region_mode)
- Uses pd.testing.assert_frame_equal to ensure exact dataframes are uploaded
- Fix module caching issue between tests by clearing sys.modules cache
- All 4 tests passing

* Add cleanup fixture to prevent test pollution

- Add autouse pytest fixture to clean up stubbed modules after each test
- Remove manual cache clearing from individual tests (now handled by fixture)
- Prevents our module stubs from affecting other test files in CI/CD pipeline
- Fixes Bitbucket pipeline failures where other tests couldn't find llm_utils attributes

* Refactor tests: add comprehensive io_utils coverage; disable usage_tracking suite

- Added 22 focused tests for write_local and write_s3 plus existing IO behaviors
- Introduced FakeS3Client to avoid boto3 network/credential dependency
- Added preserve_config fixture (no monkeypatch) to isolate config side effects
- Marked test_usage_tracking.py skipped per new consolidation approach
- Verified 26 tests (io_utils + investment_main) all pass locally without AWS exceptions

* Fix S3_CLIENT mocking: use mocker.patch instead of direct assignment

- Changed preserve_config fixture to NOT save/restore S3_CLIENT
- Updated all 5 write_s3 tests to use mocker.patch('src.config.S3_CLIENT', fake)
- This prevents pollution of config.S3_CLIENT across test modules
- Fixes NoCredentialsError in other tests that were importing config after our tests set FakeS3Client
- All 22 io_utils tests pass + 4 investment_main_s3 tests pass
- test_llm_utils::test_invoke_claude_local_mode now passes

* Add tests for write_s3 function

* Resolve merge conflict: keep mocker-based write_s3 tests

* Remove rogue skip mark from test_usage_tracking.py

The skip mark was incorrectly added by remote branch claiming tests were
migrated to io_utils. However, test_io_utils.py only tests io_utils functions
(read/write operations), not usage_tracking functions.

Restore the comprehensive usage_tracking tests from commit 26a556f0 which
includes 98 test cases covering all 10 functions in usage_tracking.py.

* Fix test pollution: add config cleanup fixture and restore RUN_MODE

- Add autouse fixture in test_io_utils.py to restore config values after each test
- Fix test_llm_utils.py to restore RUN_MODE after test_invoke_claude_local_mode
- Prevents config patches from leaking into subsequent tests causing NoCredentialsError

* Remove redundant test_investment_main_s3.py

- File was testing same write_s3 functionality already covered in test_io_utils.py
- Was causing module pollution by stubbing src.utils.llm_utils
- Caused test failures in other test files due to module cache issues
- Integration testing was minimal and mocked write_s3 anyway

* Merged main into feature/automated-cost-logging-csv


Approved-by: Karan Desai
Approved-by: Katon Minhas
2025-11-10 19:29:45 +00:00
VenkataKrishna Reddy Avula 69d72e6c99 Merged in bugfix/table_reimb_term (pull request #765)
bugfix/table_reimb_term to main

* table instruction added

* Merged main into bugfix/table_reimb_term

* Merged main into bugfix/table_reimb_term

* Merged main into bugfix/table_reimb_term


Approved-by: Katon Minhas
2025-11-07 21:02:54 +00:00
Mayank Aamseek 67e93b7de6 Merged in bugfix/Molina-UT-carveout-cd (pull request #762)
Bugfix/Molina UT carveout cd

* handle multiple default_terms in one reimb_term

* remove incorrect trigger cap cases

* carveout_cd fixes

* Merge branch 'main' into bugfix/Molina-UT-carveout-cd

* fix variable naming

* methodology prompt updated

* Merge branch 'main' into bugfix/Molina-UT-carveout-cd

* revert test changes

* revert test changes

* Merged main into bugfix/Molina-UT-carveout-cd


Approved-by: Katon Minhas
2025-11-07 21:02:17 +00:00
Katon Minhas 212f93257a Merged in feature/docker-constants (pull request #766)
Modify Docker

* Modify Docker
2025-11-07 17:43:34 +00:00
Katon Minhas 6e65b36b4a Merged in feature/change-docker-file (pull request #764)
Change Docker file

Approved-by: Sha Brown
2025-11-06 21:12:40 +00:00
Katon Minhas 70ca9c7236 Merged in Katon-Minhas/dockerfile-edited-online-with-bitbucket-1762462810542 (pull request #763)
Dockerfile edited online with Bitbucket

Approved-by: Sha Brown
2025-11-06 21:01:50 +00:00
Siddhant Medar 55643b5a04 Merged in feature/saas-hybrid-smart-chunking (pull request #760)
Feature/saas hybrid smart chunking

* WIP: Initial work on SaaS HSC integration

* clean up hsc funcs script

* fix merging dict issue

* Merge remote-tracking branch 'origin/main' into feature/saas-hybrid-smart-chunking

* added changes as per feedback comments

* add tests and remove old smart chunking funcs

* add more tests


Approved-by: Katon Minhas
2025-11-05 15:20:33 +00:00
VenkataKrishna Reddy Avula 992e891388 Merged in bugfix/prov_group_full_name (pull request #759)
bugfix/prov_group_full_name to main

* modified string utils is empty


Approved-by: Katon Minhas
2025-11-04 18:17:24 +00:00
Katon Minhas 3eed26b558 Merged in bugfix/ut-errors (pull request #756)
Bugfix/ut errors

* Update universal_json_load and unit tests

* Update tests

* Fix unit tests

* remove test

* remove imports

* Update function

* update pd Series is_empty

* Update reimbursement check

* added some test cases

* Merged main into bugfix/ut-errors

* Merged main into bugfix/ut-errors

* remove import

* Merged main into bugfix/ut-errors


Approved-by: Karan Desai
2025-11-03 20:45:58 +00:00
VenkataKrishna Reddy Avula 6d4ebd3dac Merged in bugfix/split_reimb (pull request #757)
bugfix/split_reimb to main

* updated compound indicators

* comppund reimb

* Merged main into bugfix/split_reimb


Approved-by: Katon Minhas
2025-11-03 16:12:33 +00:00
Mayank Aamseek ee8314f574 Merged in bugfix/Moline-NV-carveout-cd (pull request #758)
handle multiple default_terms in one reimb_term

* handle multiple default_terms in one reimb_term


Approved-by: Katon Minhas
2025-11-03 16:11:44 +00:00
Katon Minhas 07dc47e9d1 Merged in feature/update-testbed-metrics (pull request #750)
Feature/update testbed metrics

* Clean up filename filter function

* Strip out unused tests

* Strip out page-level comparison

* Add 1:1 fields back to analysis:

* Run through

* Merged main into feature/update-testbed-metrics

* Merged main into feature/update-testbed-metrics

* Merged main into feature/update-testbed-metrics

* Merged main into feature/update-testbed-metrics

* Merged main into feature/update-testbed-metrics


Approved-by: Faizan Mohiuddin
2025-10-31 19:08:10 +00:00
VenkataKrishna Reddy Avula 3361c689fb Merged in bugfix/reimb_excess_language_issues (pull request #755)
Bugfix/reimb excess language issues to main

* updated trigger cap def

* updated trigger cap carveout def

* Merged main into bugfix/reimb_excess_language_issues

* updated split reimb prompt

* remove print statements

* Merged main into bugfix/reimb_excess_language_issues

* updated split reimb prompt with complex example


Approved-by: Katon Minhas
2025-10-31 14:03:09 +00:00
Katon Minhas 2b9bf50c2e Merged in feature/effective-dt (pull request #752)
Feature/effective dt

* move prompt_smart_chunked to prompt_calls.py

* refactor pass_smart_chunked_to_full_context

* Mypy fix

* Update field to EFFECTIVE_DT

* move to prompt_calls

* Update vision funcs

* Restructure prompt-based date derivation

* E2E passed

* Remove test

* Merge branch 'main' into feature/effective-dt

* remove deprecated postprocessing_func

* Docstrings

* refactor - send global lesser of to prompt_calls.py

* remove deprecated function

* more docstrings

* Merged main into feature/effective-dt

* Merged main into feature/effective-dt

* added base field for aarete derived effective date


Approved-by: VenkataKrishna Reddy Avula
2025-10-30 15:28:39 +00:00