medicafe 0.250812.5__tar.gz → 0.250812.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot.bat +9 -10
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Crosswalk_Library.py +2 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Crosswalk_Utils.py +6 -4
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Preprocessor_lib.py +5 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/update_medicafe.py +36 -13
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_837p_cob_library.py +8 -1
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_837p_encoder.py +6 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_837p_encoder_library.py +38 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_UI.py +2 -0
- {medicafe-0.250812.5/medicafe.egg-info → medicafe-0.250812.6}/PKG-INFO +1 -1
- {medicafe-0.250812.5 → medicafe-0.250812.6/medicafe.egg-info}/PKG-INFO +1 -1
- {medicafe-0.250812.5 → medicafe-0.250812.6}/setup.py +1 -1
- {medicafe-0.250812.5 → medicafe-0.250812.6}/LICENSE +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MANIFEST.in +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Charges.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Post.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_Preprocessor.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_UI.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_dataformat_library.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_docx_decoder.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/MediBot_smart_import.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/__init__.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/get_medicafe_version.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediBot/update_json.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/MediLink_ConfigLoader.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/__init__.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/__main__.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/api_core.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/api_core_backup.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/api_factory.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/api_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/core_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/graphql_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/logging_config.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/logging_demo.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/migration_helpers.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/smart_import.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediCafe/submission_index.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/InsuranceTypeService.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_837p_utilities.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_API_Generator.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Azure.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_ClaimStatus.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_DataMgmt.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Decoder.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Deductible.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Deductible_Validator.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Display_Utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Down.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Gmail.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Mailer.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Parser.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_PatientProcessor.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Scan.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Scheduler.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_Up.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_insurance_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_main.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/MediLink_smart_import.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/Soumit_api.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/__init__.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/gmail_http_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/gmail_oauth_utils.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/insurance_type_integration_test.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/openssl.cnf +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/test.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/test_cob_library.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/test_timing.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/test_validation.py +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/MediLink/webapp.html +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/README.md +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/SOURCES.txt +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/dependency_links.txt +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/entry_points.txt +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/not-zip-safe +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/requires.txt +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/medicafe.egg-info/top_level.txt +0 -0
- {medicafe-0.250812.5 → medicafe-0.250812.6}/setup.cfg +0 -0
@@ -405,8 +405,6 @@ echo 6. Run MediBot
|
|
405
405
|
echo.
|
406
406
|
echo 7. Troubleshooting
|
407
407
|
echo.
|
408
|
-
echo 9. Toggle Performance Logging (session)
|
409
|
-
echo.
|
410
408
|
echo 8. Exit
|
411
409
|
echo.
|
412
410
|
set /p choice=Enter your choice:
|
@@ -420,7 +418,6 @@ if "!choice!"=="4" goto united_claims_status
|
|
420
418
|
if "!choice!"=="3" goto medilink_flow
|
421
419
|
if "!choice!"=="2" goto download_emails
|
422
420
|
if "!choice!"=="1" goto check_updates
|
423
|
-
if "!choice!"=="9" goto toggle_perf_logging
|
424
421
|
if "!choice!"=="0" goto end_script
|
425
422
|
|
426
423
|
echo Invalid choice. Please try again.
|
@@ -572,7 +569,7 @@ if not exist "%_UPD_RUNNER%" (
|
|
572
569
|
echo.
|
573
570
|
echo Launching updater and closing this window...
|
574
571
|
start "MediCafe Update" "%_UPD_RUNNER%"
|
575
|
-
exit
|
572
|
+
exit 0
|
576
573
|
|
577
574
|
:: Download Carol's Emails
|
578
575
|
:download_emails
|
@@ -636,7 +633,7 @@ if /I "%MEDICAFE_PERFORMANCE_LOGGING%"=="1" (
|
|
636
633
|
echo.
|
637
634
|
echo Note: This affects current session only. To persist, set in config.json.
|
638
635
|
pause
|
639
|
-
goto
|
636
|
+
goto troubleshooting_menu
|
640
637
|
|
641
638
|
:: United Claims Status
|
642
639
|
:united_claims_status
|
@@ -715,14 +712,16 @@ echo Troubleshooting Options:
|
|
715
712
|
echo.
|
716
713
|
echo 1. Open Latest Log File
|
717
714
|
echo 2. Clear Python Cache
|
718
|
-
echo 3.
|
719
|
-
echo 4.
|
715
|
+
echo 3. Toggle Performance Logging ^(session^)
|
716
|
+
echo 4. Forced MediCafe version rollback
|
717
|
+
echo 5. Back to Main Menu
|
720
718
|
echo.
|
721
719
|
set /p tchoice=Enter your choice:
|
722
720
|
if "%tchoice%"=="1" goto open_latest_log
|
723
721
|
if "%tchoice%"=="2" goto clear_cache_menu
|
724
|
-
if "%tchoice%"=="3" goto
|
725
|
-
if "%tchoice%"=="4" goto
|
722
|
+
if "%tchoice%"=="3" goto toggle_perf_logging
|
723
|
+
if "%tchoice%"=="4" goto forced_version_rollback
|
724
|
+
if "%tchoice%"=="5" goto main_menu
|
726
725
|
echo Invalid choice. Please try again.
|
727
726
|
pause
|
728
727
|
goto troubleshooting_menu
|
@@ -743,7 +742,7 @@ goto troubleshooting_menu
|
|
743
742
|
:: End Script
|
744
743
|
:end_script
|
745
744
|
echo Exiting MediBot
|
746
|
-
exit
|
745
|
+
exit 0
|
747
746
|
|
748
747
|
:: Full Debug Mode moved to external script full_debug_suite.bat
|
749
748
|
|
@@ -376,6 +376,8 @@ def crosswalk_update(client, config, crosswalk): # Upstream of this is only Medi
|
|
376
376
|
'medisoft_medicare_id': [] # PERFORMANCE FIX: Use list instead of set to avoid conversions
|
377
377
|
}
|
378
378
|
MediLink_ConfigLoader.log("Initialized payer ID {} in crosswalk with endpoint '{}'.".format(payer_id, selected_endpoint), config, level="DEBUG")
|
379
|
+
# TODO (MEDICARE ENDPOINTS): If payer_id is Medicare (e.g., in config['MediLink_Config']['cob_settings']['medicare_payer_ids']),
|
380
|
+
# set endpoint to 'MEDICARE_PRIMARY' and optionally store 'crossover_endpoint' for later automation.
|
379
381
|
|
380
382
|
# Add the insurance ID to the payer ID entry (PERFORMANCE FIX: Use list operations)
|
381
383
|
insurance_id_str = str(insurance_id) # Ensure ID is string
|
@@ -370,10 +370,12 @@ def save_crosswalk(client, config, crosswalk, skip_api_operations=False, api_cac
|
|
370
370
|
crosswalk['payer_id'][payer_id]['endpoint'] = select_endpoint(config) # Use the helper function to set the endpoint
|
371
371
|
MediLink_ConfigLoader.log("Initialized 'endpoint' for payer ID {}.".format(payer_id), config, level="DEBUG")
|
372
372
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
373
|
+
# Initialize medisoft_id and medisoft_medicare_id as empty lists if they do not exist
|
374
|
+
crosswalk['payer_id'][payer_id].setdefault('medisoft_id', [])
|
375
|
+
crosswalk['payer_id'][payer_id].setdefault('medisoft_medicare_id', []) # does this work in 3.4.4?
|
376
|
+
MediLink_ConfigLoader.log("Ensured 'medisoft_id' and 'medisoft_medicare_id' for payer ID {} are initialized.".format(payer_id), config, level="DEBUG")
|
377
|
+
# TODO (CROSSWALK VALIDATION): Enforce distinctness between 'medisoft_id' and 'medisoft_medicare_id' and support optional
|
378
|
+
# 'crossover_endpoint' per payer. Use config['MediLink_Config']['cob_settings']['medicare_payer_ids'] to detect Medicare payers.
|
377
379
|
|
378
380
|
# Convert sets to sorted lists for JSON serialization
|
379
381
|
for payer_id, details in crosswalk.get('payer_id', {}).items():
|
@@ -816,6 +816,11 @@ def update_insurance_ids(csv_data, config, crosswalk):
|
|
816
816
|
|
817
817
|
# Assign the resolved insurance ID to the row
|
818
818
|
row['Ins1 Insurance ID'] = insurance_id
|
819
|
+
# TODO (SECONDARY QUEUE): When building a secondary-claims queue after Medicare crossover,
|
820
|
+
# set claim_type='secondary' and attach prior payer fields here from the Medicare primary outcome:
|
821
|
+
# - row['prior_payer_name'] = 'MEDICARE'
|
822
|
+
# - row['prior_payer_id'] = best Medicare ID from config/crosswalk
|
823
|
+
# - optionally row['primary_paid_amount'], row['cas_adjustments'] extracted from 835
|
819
824
|
processed_count += 1
|
820
825
|
# LOGGING STRATEGY: Remove success logging - DEBUG is typically silent anyway
|
821
826
|
# if processed_count <= 10 or processed_count % 100 == 0: # Log first 10 and every 100th
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#update_medicafe.py
|
2
|
-
import subprocess, sys, time, platform, os, shutil
|
2
|
+
import subprocess, sys, time, platform, os, shutil, random
|
3
3
|
|
4
4
|
# Safe import for pkg_resources with fallback
|
5
5
|
try:
|
@@ -162,6 +162,8 @@ def get_latest_version(package, retries=3, delay=1):
|
|
162
162
|
time.sleep(delay)
|
163
163
|
return None
|
164
164
|
|
165
|
+
|
166
|
+
|
165
167
|
def check_internet_connection():
|
166
168
|
try:
|
167
169
|
requests.get("http://www.google.com", timeout=5)
|
@@ -288,7 +290,7 @@ def compare_versions(version1, version2):
|
|
288
290
|
v2_parts = list(map(int, version2.split(".")))
|
289
291
|
return (v1_parts > v2_parts) - (v1_parts < v2_parts)
|
290
292
|
|
291
|
-
def upgrade_package(package, retries=
|
293
|
+
def upgrade_package(package, retries=4, delay=2, target_version=None): # Updated retries to 4
|
292
294
|
"""
|
293
295
|
Attempts to upgrade the package multiple times with delays in between.
|
294
296
|
"""
|
@@ -296,23 +298,33 @@ def upgrade_package(package, retries=3, delay=2): # Updated retries to 3
|
|
296
298
|
print_status("No internet connection detected. Please check your internet connection and try again.", "ERROR")
|
297
299
|
print_final_result(False, "No internet connection available")
|
298
300
|
|
301
|
+
# Light verbosity: show pinned target once
|
302
|
+
if target_version:
|
303
|
+
print("Pinned target version: {}".format(target_version))
|
304
|
+
|
299
305
|
for attempt in range(1, retries + 1):
|
300
|
-
print("Attempt {} to upgrade {}...".format(attempt, package))
|
306
|
+
print("Attempt {}/{} to upgrade {}...".format(attempt, retries, package))
|
301
307
|
|
302
308
|
# Use a more compatible approach for Python 3.4
|
303
309
|
# Try with --no-deps first to avoid dependency resolution issues
|
310
|
+
pkg_spec = package
|
311
|
+
if target_version:
|
312
|
+
pkg_spec = "{}=={}".format(package, target_version)
|
313
|
+
|
304
314
|
cmd = [
|
305
315
|
sys.executable, '-m', 'pip', 'install', '--upgrade',
|
306
|
-
'--no-deps', '--no-cache-dir', '--disable-pip-version-check', '-q',
|
316
|
+
'--no-deps', '--no-cache-dir', '--disable-pip-version-check', '-q', pkg_spec
|
307
317
|
]
|
308
318
|
|
319
|
+
print("Using pip upgrade with --no-deps and --no-cache-dir")
|
309
320
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
310
321
|
stdout, stderr = process.communicate()
|
311
322
|
|
312
323
|
if process.returncode == 0:
|
313
324
|
print(stdout.decode().strip())
|
314
325
|
new_version = get_installed_version(package) # Get new version after upgrade
|
315
|
-
|
326
|
+
expected_version = target_version or get_latest_version(package)
|
327
|
+
if expected_version and compare_versions(new_version, expected_version) >= 0: # Compare versions
|
316
328
|
if attempt == 1:
|
317
329
|
print_status("Upgrade succeeded!", "SUCCESS")
|
318
330
|
else:
|
@@ -320,20 +332,27 @@ def upgrade_package(package, retries=3, delay=2): # Updated retries to 3
|
|
320
332
|
time.sleep(delay)
|
321
333
|
return True
|
322
334
|
else:
|
323
|
-
print_status("Upgrade
|
335
|
+
print_status("Upgrade incomplete. Current version: {} Expected at least: {}".format(new_version, expected_version), "WARNING")
|
324
336
|
if attempt < retries:
|
325
337
|
print("Retrying in {} seconds...".format(delay))
|
326
|
-
|
338
|
+
try:
|
339
|
+
time.sleep(delay + (random.random() * 0.5))
|
340
|
+
except Exception:
|
341
|
+
time.sleep(delay)
|
327
342
|
else:
|
328
343
|
print(stderr.decode().strip())
|
329
344
|
print_status("Attempt {}: Upgrade failed with --no-deps.".format(attempt), "WARNING")
|
330
345
|
|
331
346
|
# If --no-deps failed, try with --force-reinstall to bypass dependency issues
|
332
347
|
if attempt < retries:
|
333
|
-
print("
|
348
|
+
print("Fallback this attempt: retrying with --force-reinstall...")
|
349
|
+
pkg_spec = package
|
350
|
+
if target_version:
|
351
|
+
pkg_spec = "{}=={}".format(package, target_version)
|
352
|
+
|
334
353
|
cmd = [
|
335
354
|
sys.executable, '-m', 'pip', 'install', '--upgrade',
|
336
|
-
'--force-reinstall', '--no-cache-dir', '--disable-pip-version-check', '-q',
|
355
|
+
'--force-reinstall', '--no-cache-dir', '--disable-pip-version-check', '-q', pkg_spec
|
337
356
|
]
|
338
357
|
|
339
358
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
@@ -342,19 +361,23 @@ def upgrade_package(package, retries=3, delay=2): # Updated retries to 3
|
|
342
361
|
if process.returncode == 0:
|
343
362
|
print(stdout.decode().strip())
|
344
363
|
new_version = get_installed_version(package)
|
345
|
-
|
364
|
+
expected_version = target_version or get_latest_version(package)
|
365
|
+
if expected_version and compare_versions(new_version, expected_version) >= 0:
|
346
366
|
print_status("Attempt {}: Upgrade succeeded with --force-reinstall!".format(attempt), "SUCCESS")
|
347
367
|
time.sleep(delay)
|
348
368
|
return True
|
349
369
|
else:
|
350
|
-
print_status("Upgrade
|
370
|
+
print_status("Upgrade incomplete. Current version: {} Expected at least: {}".format(new_version, expected_version), "WARNING")
|
351
371
|
else:
|
352
372
|
print(stderr.decode().strip())
|
353
373
|
print_status("Attempt {}: Upgrade failed with --force-reinstall.".format(attempt), "WARNING")
|
354
374
|
|
355
375
|
if attempt < retries:
|
356
376
|
print("Retrying in {} seconds...".format(delay))
|
357
|
-
|
377
|
+
try:
|
378
|
+
time.sleep(delay + (random.random() * 0.5))
|
379
|
+
except Exception:
|
380
|
+
time.sleep(delay)
|
358
381
|
|
359
382
|
print_status("All upgrade attempts failed.", "ERROR")
|
360
383
|
return False
|
@@ -566,7 +589,7 @@ def main():
|
|
566
589
|
print("Current version: {}".format(current_version))
|
567
590
|
print("Target version: {}".format(latest_version))
|
568
591
|
|
569
|
-
if upgrade_package(package):
|
592
|
+
if upgrade_package(package, target_version=latest_version):
|
570
593
|
# STEP 8: Verify upgrade
|
571
594
|
debug_step(8, "Upgrade Verification")
|
572
595
|
new_version = get_installed_version(package)
|
@@ -101,6 +101,10 @@ def create_2320_other_subscriber_segments(patient_data, config, crosswalk):
|
|
101
101
|
is_secondary = patient_data.get('claim_type', 'primary') == 'secondary'
|
102
102
|
|
103
103
|
if is_secondary:
|
104
|
+
# TODO (DATA CONTRACT): If 835-derived fields are present on patient_data, prefer them:
|
105
|
+
# - total_paid -> AMT*D
|
106
|
+
# - cas_adjustments -> CAS
|
107
|
+
# Otherwise accept 'primary_paid_amount' and 'cas_adjustments' provided by upstream workflow.
|
104
108
|
# SBR segment for secondary payer
|
105
109
|
responsibility_code = "S" # Secondary
|
106
110
|
insurance_type = determine_medicare_payer_type(patient_data, config)
|
@@ -111,7 +115,9 @@ def create_2320_other_subscriber_segments(patient_data, config, crosswalk):
|
|
111
115
|
segments.append(sbr_segment)
|
112
116
|
|
113
117
|
# AMT*D segment for total amount paid by primary
|
114
|
-
|
118
|
+
# TODO (STRICT MODE): When config['MediLink_Config']['cob_settings']['validation_level'] >= 2,
|
119
|
+
# require presence of a numeric total (from 'total_paid' or 'primary_paid_amount').
|
120
|
+
total_paid = patient_data.get('total_paid', patient_data.get('primary_paid_amount', '0.00'))
|
115
121
|
amt_segment = "AMT*D*{}~".format(total_paid)
|
116
122
|
segments.append(amt_segment)
|
117
123
|
|
@@ -152,6 +158,7 @@ def create_2330B_prior_payer_segments(patient_data, config, crosswalk):
|
|
152
158
|
segments = []
|
153
159
|
|
154
160
|
# Get prior payer information
|
161
|
+
# TODO (CONFIG): Resolve Medicare payer ID from config['MediLink_Config']['cob_settings']['medicare_payer_ids'] if prior_payer_id not provided.
|
155
162
|
prior_payer_name = patient_data.get('prior_payer_name', 'MEDICARE')
|
156
163
|
prior_payer_id = patient_data.get('prior_payer_id', '00850')
|
157
164
|
|
@@ -613,6 +613,12 @@ def process_claim(config, endpoint, patient_data_list, crosswalk, client, suffix
|
|
613
613
|
document_segments = []
|
614
614
|
|
615
615
|
for patient_data in patient_data_list:
|
616
|
+
# TODO (SECONDARY PREP): Upstream should mark secondary claims and provide Medicare prior payer info when applicable.
|
617
|
+
# Expected minimal keys for Medicare-secondary:
|
618
|
+
# - claim_type='secondary'
|
619
|
+
# - prior_payer_name='MEDICARE'
|
620
|
+
# - prior_payer_id from config cob_settings.medicare_payer_ids (default '00850')
|
621
|
+
# - optional: primary_paid_amount, cas_adjustments
|
616
622
|
# Validate each patient's data before processing
|
617
623
|
is_valid, validation_errors = validate_claim_data(patient_data, medi)
|
618
624
|
if is_valid:
|
@@ -980,6 +980,43 @@ def create_clm_and_related_segments(parsed_data, config, crosswalk):
|
|
980
980
|
# - create_2330B_prior_payer_segments() for Medicare prior payer
|
981
981
|
# - create_2430_service_line_cob_segments() for service-level adjudication
|
982
982
|
# - create_2330C_other_subscriber_name_segments() when patient != subscriber
|
983
|
+
#
|
984
|
+
# Minimal, safe integration (guarded by feature flag):
|
985
|
+
if COB is not None:
|
986
|
+
cob_enabled = False
|
987
|
+
try:
|
988
|
+
# Read feature flag from configuration (expects medi['cob_settings']['enabled'])
|
989
|
+
from MediCafe.core_utils import extract_medilink_config
|
990
|
+
medi_cfg = extract_medilink_config(config)
|
991
|
+
cob_enabled = bool(medi_cfg.get('cob_settings', {}).get('enabled', False))
|
992
|
+
except Exception:
|
993
|
+
cob_enabled = False
|
994
|
+
|
995
|
+
# Only add COB loops when explicitly enabled and claim is secondary
|
996
|
+
# TODO (COB VALIDATION): When COB is enabled and claim is secondary, validate required fields:
|
997
|
+
# - prior_payer_id/prior_payer_name present
|
998
|
+
# - primary_paid_amount present when sending AMT*D (or skip AMT if not available)
|
999
|
+
# - cas_adjustments schema if provided (list of {group, reason, amount})
|
1000
|
+
# If critical fields are missing, log and proceed with best-effort unless config enforces strict mode.
|
1001
|
+
if cob_enabled and validated_data.get('claim_type') == 'secondary':
|
1002
|
+
try:
|
1003
|
+
# 2320 - Other Subscriber Information (OI, AMT, CAS, etc.)
|
1004
|
+
segments.extend(COB.create_2320_other_subscriber_segments(validated_data, config, crosswalk))
|
1005
|
+
except Exception as _e1:
|
1006
|
+
try:
|
1007
|
+
MediLink_ConfigLoader.log("COB 2320 insertion failed: {}".format(str(_e1)), config, level="WARNING")
|
1008
|
+
except Exception:
|
1009
|
+
pass
|
1010
|
+
|
1011
|
+
try:
|
1012
|
+
# 2330B - Prior Payer (Medicare prior payer info, e.g., 00850)
|
1013
|
+
segments.extend(COB.create_2330B_prior_payer_segments(validated_data, config, crosswalk))
|
1014
|
+
except Exception as _e2:
|
1015
|
+
try:
|
1016
|
+
MediLink_ConfigLoader.log("COB 2330B insertion failed: {}".format(str(_e2)), config, level="WARNING")
|
1017
|
+
except Exception:
|
1018
|
+
pass
|
1019
|
+
|
983
1020
|
# TODO (COB ENHANCEMENT): Optional attachment references (PWK) for non-electronic EOB handling
|
984
1021
|
# See MediLink_837p_cob_library.create_pwk_attachment_segment() for implementation
|
985
1022
|
# Example: PWK*EB*FX*123456~ for attachment control number
|
@@ -1002,6 +1039,7 @@ def create_clm_and_related_segments(parsed_data, config, crosswalk):
|
|
1002
1039
|
segments.append("DTP*472*D8*{}~".format(convert_date_format(validated_data['DATE'])))
|
1003
1040
|
|
1004
1041
|
# Is there REF - Line Item Control Number missing here? Private insurance doesn't need it, but Medicare does?
|
1042
|
+
# TODO (MEDICARE REF): Add conditional REF*6R (line item control number) when payer is Medicare or when crosswalk/config requires it.
|
1005
1043
|
# segments.append("REF*6R*1~") # REF01, Reference Identification Qualifier; REF02, Line Item Control Number.
|
1006
1044
|
# 6R - Provider Control Number (Number assigned by information provider company for tracking and billing purposes)
|
1007
1045
|
# 1 - Reference information as defined for a particular Transaction Set or as specified by the Reference Identification Qualifier
|
@@ -201,6 +201,8 @@ def select_and_adjust_files(detailed_patient_data, config, crosswalk):
|
|
201
201
|
)
|
202
202
|
if updated_crosswalk:
|
203
203
|
crosswalk = updated_crosswalk
|
204
|
+
# TODO (MEDICARE ROUTING): If original primary was Medicare and crossover failed, prompt to create secondary claim
|
205
|
+
# and set claim_type='secondary' with prior_payer fields for the selected patient.
|
204
206
|
else:
|
205
207
|
print("Invalid selection. Keeping the current endpoint.")
|
206
208
|
data['confirmed_endpoint'] = current_effective_endpoint
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|