Patient context
This commit is contained in:
@@ -86,7 +86,8 @@ from eb_dashboard_utils import (
|
||||
clear_httpx_client,
|
||||
get_thread_position,
|
||||
get_config_path,
|
||||
thread_local_storage
|
||||
thread_local_storage,
|
||||
run_with_context
|
||||
)
|
||||
from eb_dashboard_quality_checks import (
|
||||
backup_output_files,
|
||||
@@ -1127,14 +1128,16 @@ def _process_inclusion_data(inclusion, organization):
|
||||
pseudo = get_nested_value(inclusion, path=["pseudo"], default="Unknown")
|
||||
|
||||
# Set thread-local context for detailed error logging in decorators
|
||||
thread_local_storage.current_patient_context = {"id": patient_id, "pseudo": pseudo}
|
||||
ctx = {"id": patient_id, "pseudo": pseudo}
|
||||
thread_local_storage.current_patient_context = ctx
|
||||
|
||||
# Initialize empty output structure
|
||||
output_inclusion = {}
|
||||
|
||||
# --- Prepare all data sources ---
|
||||
# 1. Launch Visit Search asynchronously (it's slow, ~5s)
|
||||
visit_future = subtasks_thread_pool.submit(search_visit_by_pseudo_and_order, pseudo, 2)
|
||||
# We use run_with_context to pass the patient identity to the new thread
|
||||
visit_future = subtasks_thread_pool.submit(run_with_context, search_visit_by_pseudo_and_order, ctx, pseudo, 2)
|
||||
|
||||
# 2. Prepare inclusion_data: enrich inclusion with organization info
|
||||
inclusion_data = dict(inclusion)
|
||||
@@ -1148,7 +1151,7 @@ def _process_inclusion_data(inclusion, organization):
|
||||
|
||||
# 4. Get tube_id for request and launch in parallel with questionnaires
|
||||
tube_id = get_nested_value(record_data, path=["record", "clinicResearchData", 0, "requestMetaData", "tubeId"], default="undefined")
|
||||
request_future = subtasks_thread_pool.submit(get_request_by_tube_id, tube_id)
|
||||
request_future = subtasks_thread_pool.submit(run_with_context, get_request_by_tube_id, ctx, tube_id)
|
||||
all_questionnaires = get_all_questionnaires_by_patient(patient_id, record_data)
|
||||
|
||||
# --- Synchronize all asynchronous tasks ---
|
||||
|
||||
Reference in New Issue
Block a user