Qustionnaires Unliked Patient filter

This commit is contained in:
2026-05-06 01:58:01 +01:00
parent 51864267d7
commit e3a1ef78cf
12 changed files with 17 additions and 10042 deletions

View File

@@ -767,7 +767,7 @@ def _execute_custom_function(function_name, args, output_inclusion):
# Unified conditional function
# Syntax: ["operator", arg1, arg2_optional, result_if_true, result_if_false]
# Operators: "is_true", "is_false", "all_true", "any_true", "is_defined", "is_undefined", "all_defined", "==", "!=", ">", ">=", "<", "<="
# Sentinel propagation: "undefined" (inconnu) > "N/A" (non applicable) > vraie valeur.
# Sentinel propagation: "undefined" (unknown) > "N/A" (not applicable) > real value.
if not args or len(args) < 4:
return "$$$$ Argument Error: if_then_else requires at least 4 arguments"
@@ -1217,6 +1217,17 @@ def get_all_questionnaires_by_patient(patient_id, record_data):
q_name = get_nested_value(item, path=["questionnaire", "name"])
q_category = get_nested_value(item, path=["questionnaire", "category"])
answers = get_nested_value(item, path=["answers"], default={})
# ── UNLINKED PATIENT FILTER ─────────────────────────────────────────────
# If answers.patient is missing, null, or does not match the requested
# patient_id, the questionnaire is considered unlinked → clear answers
# to prevent use of orphaned data.
# (disable: comment out the block below)
answers_patient = answers.get("subject") if isinstance(answers, dict) else None
if not answers_patient or answers_patient != patient_id:
answers = {}
# ────────────────────────────────────────────────────────────────────────
if q_id:
results[q_id] = {
"questionnaire": {
@@ -1556,9 +1567,9 @@ def main():
organizations_list.sort(key=lambda org: (-org.get('patients_count', 0), org.get('name', '')))
# ╔══════════════════════════════════════════════════════════════════╗
# ║ TEST INSTRUMENTATION — À SUPPRIMER AVANT MISE EN PRODUCTION
# ║ Limite le tableau aux organisations aux rangs 33 et 34 ║
# ║ (indices 32 et 33, après tri décroissant par patients_count)
# ║ TEST INSTRUMENTATION — REMOVE BEFORE PRODUCTION
# ║ Limits the table to organizations at ranks 33 and 34
# ║ (indices 32 and 33, after descending sort by patients_count) ║
# ╚══════════════════════════════════════════════════════════════════╝
# organizations_list = [org for i, org in enumerate(organizations_list) if i in (32, 33)]
# ══════════════════════════════════════════════════════════════════