{% extends "base.html" %} {% block title %}{{ dossier.source_file or filepath }}{% endblock %} {% block content %} ← Retour à la liste {# ==================================================================== #} {# 1. BANDEAU PATIENT — Identité + Séjour + Codage DP + GHM + Score #} {# ==================================================================== #} {% set s = dossier.sejour %} {% set dp = dossier.diagnostic_principal %} {% set ghm = dossier.ghm_estimation %} {% set vr = dossier.veto_report %}
{# Titre patient + identifiants #}

{{ current_group | format_dossier_name if current_group else (dossier.source_file or filepath) }}

N° {{ current_group | format_dossier_name if current_group else filepath }} {% if dossier.controles_cpam %} {% for ctrl in dossier.controles_cpam %} OGC {{ ctrl.numero_ogc }} {% endfor %} {% endif %} {% if dossier.document_type %} {{ dossier.document_type }} {% endif %} {% if dossier.source_files %} fusionné {% endif %} {% if dossier.processing_time_s is not none %} {{ dossier.processing_time_s|format_duration }} {% endif %}
{# Colonne gauche — Identité et séjour #}
Patient & Séjour
{% if s.sexe %}
{{ s.sexe }}
{% endif %} {% if s.age is not none %}
{{ s.age }} ans
{% endif %} {% if s.date_entree %}
{{ s.date_entree }}
{% endif %} {% if s.date_sortie %}
{{ s.date_sortie }}
{% endif %} {% if s.duree_sejour is not none %}
{{ s.duree_sejour }} j
{% endif %} {% if s.mode_entree %}
{{ s.mode_entree }}
{% endif %} {% if s.mode_sortie %}
{{ s.mode_sortie }}
{% endif %} {% if s.poids %}
{{ s.poids }} kg
{% endif %} {% if s.taille %}
{{ s.taille }} cm
{% endif %} {% if s.imc %}
{{ s.imc }}
{% endif %}
{# Colonne droite — Codage #}
Codage
{# DP en gros #} {% if dp %}
DIAGNOSTIC PRINCIPAL
{% if dp.cim10_suggestion %} {% if dp.cim10_final and dp.cim10_final != dp.cim10_suggestion %} {{ dp.cim10_suggestion }} {{ dp.cim10_final }} {% else %} {{ dp.cim10_suggestion }} {% endif %} {{ dp.cim10_confidence | confidence_badge }} {% endif %} {% if dp.niveau_cma and dp.niveau_cma > 1 %}{{ dp.niveau_cma | cma_level_badge }}{% endif %} {{ dp.niveau_severite | severity_badge }}
{% if dp.status == 'ruled_out' %}{{ dp.texte }}{% else %}{{ dp.texte }}{% endif %} {% if dp.source_page %}{% endif %}
{% endif %} {# GHM estimé #} {% if ghm %}
GHM ESTIMÉ
{% if ghm.ghm_approx %} {{ ghm.ghm_approx }} {% endif %} {% if ghm.type_ghm == 'C' %} C — Chirurgical {% elif ghm.type_ghm == 'K' %} K — Interventionnel {% elif ghm.type_ghm == 'M' %} M — Médical {% endif %} {% if ghm.severite <= 1 %} Niv. {{ ghm.severite }} {% elif ghm.severite == 2 %} Niv. {{ ghm.severite }} {% elif ghm.severite == 3 %} Niv. {{ ghm.severite }} {% else %} Niv. {{ ghm.severite }} {% endif %} {{ ghm.cma_count }} CMA, {{ ghm.cms_count }} CMS
{% endif %} {# Score de contestabilité #} {% if vr %}
CONTESTABILITÉ
{% if vr.verdict == 'PASS' %}{% set vr_color = '#22c55e' %} {% elif vr.verdict == 'NEED_INFO' %}{% set vr_color = '#f59e0b' %} {% else %}{% set vr_color = '#ef4444' %}{% endif %}
{% if vr.verdict == 'PASS' %} CONFORME {% elif vr.verdict == 'NEED_INFO' %} À COMPLÉTER {% else %} NON CONFORME {% endif %}
{{ vr.score_contestabilite }}/100
{% endif %}
{# Actions (compact, sous le bandeau) #}
{# ==================================================================== #} {# 1b. COMPLÉTUDE DOCUMENTAIRE DIM #} {# ==================================================================== #} {% set compl = dossier.completude %} {% if compl and compl.checks %}

Complétude Documentaire DIM

{% if compl.verdict_global == 'defendable' %} DÉFENDABLE {% set compl_color = '#22c55e' %} {% elif compl.verdict_global == 'fragile' %} FRAGILE {% set compl_color = '#f59e0b' %} {% else %} INDÉFENDABLE {% set compl_color = '#ef4444' %} {% endif %}
{{ compl.score_global }}/100
{% if compl.documents_manquants %}
Documents manquants : {{ compl.documents_manquants | join(', ') }}
{% endif %} {% for check in compl.checks %}
{{ check.code }} {{ check.libelle | truncate(60) }} {{ check.type_diag }} {% if check.verdict == 'defendable' %} ✓ {{ check.resume }} {% elif check.verdict == 'fragile' %} ⚠ {{ check.resume }} {% else %} ✗ {{ check.resume }} {% endif %}
{% for item in check.items %} {% if item.statut == 'present_confirme' %} ✓ {{ item.element }}{% if item.valeur %} ({{ item.valeur | truncate(20) }}){% endif %} {% if item.confirmation_detail %} — confirmé{% endif %} {% elif item.statut == 'present_non_confirme' %} ⚠ {{ item.element }}{% if item.valeur %} ({{ item.valeur | truncate(20) }}){% endif %} {% if item.confirmation_detail %} — seuil non atteint{% endif %} {% elif item.statut == 'present_indirect' %} ~ {{ item.element }}{% if item.valeur %} ({{ item.valeur | truncate(25) }}){% endif %} — preuve clinique {% elif item.statut == 'present' %} ✓ {{ item.element }}{% if item.valeur %} ({{ item.valeur | truncate(20) }}){% endif %} {% elif item.importance == 'obligatoire' %} ✗ {{ item.element }} (obligatoire) {% else %} — {{ item.element }} (recommandé) {% endif %} {% endfor %}
{% endfor %} {% if compl.documents_presents %}
Documents présents : {{ compl.documents_presents | join(', ') }}
{% endif %}
{% endif %} {# ==================================================================== #} {# 2. DAS + ACTES CCAM #} {# ==================================================================== #} {# ---- Diagnostic principal (détail) ---- #} {% set dp_has_detail = dp and (dp.justification or dp.preuves_cliniques or dp.raisonnement or dp.sources_rag or (dp.cim10_decision and dp.cim10_decision.action != 'KEEP') or dp.status == 'ruled_out') %} {% if dp_has_detail %}

Diagnostic principal — Détail

{% if dp.status == 'ruled_out' and dp.ruled_out_reason %}
{{ dp.ruled_out_reason }}
{% endif %} {% if dp.cim10_decision and dp.cim10_decision.action != 'KEEP' %}
{{ dp.cim10_decision | decision_badge }} {% for rule in dp.cim10_decision.applied_rules %} {{ rule }} {% endfor %} {% if dp.cim10_decision.reason %}
{{ dp.cim10_decision.reason }}
{% endif %}
{% endif %} {% if dp.justification %}
{{ dp.justification }}
{% endif %} {% if dp.preuves_cliniques %}
Preuves cliniques ({{ dp.preuves_cliniques|length }})
{% endif %} {% if dp.raisonnement %}
Raisonnement LLM
{{ dp.raisonnement }}
{% endif %} {% if dp.sources_rag %}
Sources RAG ({{ dp.sources_rag|length }}) {% for src in dp.sources_rag %}
{{ src.document }}{% if src.code %} — {{ src.code }}{% endif %}{% if src.page %} [p.{{ src.page }}]{% endif %}
{{ src.extrait or '' }}
{% endfor %}
{% endif %}
{% elif dp and not dp_has_detail and dp.source == 'trackare' %}

Diagnostic principal — Détail

Codage issu de Trackare — pas de détail IA disponible.
{% endif %} {# ---- Diagnostics associés ---- #} {% if dossier.diagnostics_associes %}

Diagnostics associés ({{ dossier.diagnostics_associes|length }})

{% for das in dossier.diagnostics_associes %} {% if das.status == 'ruled_out' and das.ruled_out_reason %} {% endif %} {% if das.cim10_decision and das.cim10_decision.action != 'KEEP' and das.cim10_decision.reason and das.status != 'ruled_out' %} {% endif %} {% if das.raisonnement %} {% endif %} {% if das.sources_rag %} {% endif %} {% endfor %}
Code CIM-10LibelléCMAConfianceSource
{% if das.cim10_suggestion %} {% if das.cim10_final and das.cim10_final != das.cim10_suggestion %} {{ das.cim10_suggestion }} {{ das.cim10_final }} {% elif das.status == 'ruled_out' %} {{ das.cim10_suggestion }} {% else %} {{ das.cim10_suggestion }} {% endif %} {% if das.cim10_decision and das.cim10_decision.action != 'KEEP' %}
{{ das.cim10_decision | decision_badge }} {% for rule in das.cim10_decision.applied_rules %} {{ rule }} {% endfor %}
{% endif %} {% if das.status == 'needs_info' %}
Info requise {% if das.cim10_decision and das.cim10_decision.needs_info %}
détails
    {% for ni in das.cim10_decision.needs_info %}
  • {{ ni }}
  • {% endfor %}
{% endif %}
{% endif %} {% endif %}
{{ das.texte }} {% if das.justification %}
{{ das.justification }}
{% endif %} {% if das.preuves_cliniques %}
preuves ({{ das.preuves_cliniques|length }})
    {% for p in das.preuves_cliniques %}
  • [{{ p.type }}] {{ p.element }} → {{ p.interpretation }}
  • {% endfor %}
{% endif %}
{% if das.niveau_cma and das.niveau_cma > 1 %} {{ das.niveau_cma | cma_level_badge }} {% elif das.est_cma %} CMA {% else %} — {% endif %} {{ das.cim10_confidence | confidence_badge }} {% if das.source %} {{ das.source }} {% endif %} {% if das.source_page %} {% endif %}
{{ das.ruled_out_reason }}
{{ das.cim10_decision.reason }}
Raisonnement LLM
{{ das.raisonnement }}
Sources RAG ({{ das.sources_rag|length }}) {% for src in das.sources_rag %}
{{ src.document }}{% if src.code %} — {{ src.code }}{% endif %}{% if src.page %} [p.{{ src.page }}]{% endif %}
{{ src.extrait or '' }}
{% endfor %}
{% endif %} {# ---- Actes CCAM ---- #} {% if dossier.actes_ccam %}

Actes CCAM ({{ dossier.actes_ccam|length }})

{% for a in dossier.actes_ccam %} {% endfor %}
Code CCAMLibelléRegroupementDateValiditéSource
{% if a.code_ccam_suggestion %}{{ a.code_ccam_suggestion }}{% endif %} {{ a.texte }} {% if a.code_ccam_suggestion and ccam_dict.get(a.code_ccam_suggestion, {}).get('regroupement') %} {{ ccam_dict[a.code_ccam_suggestion]['regroupement'] }} {% else %}—{% endif %} {{ a.date or '' }} {% if a.validite == 'valide' %}Valide {% elif a.validite == 'obsolete' %}Obsolète {% else %}—{% endif %} {% for alerte in a.alertes %}
{{ alerte }}
{% endfor %}
{% if a.source_page %}{% endif %}
{% endif %} {# ==================================================================== #} {# 3. CONTRÔLE QUALITÉ CODAGE (section repliable) #} {# ==================================================================== #}

Contrôle Qualité Codage

{# Anomalies de codage #}

Anomalies de codage

{% if dossier.veto_report and dossier.veto_report.issues %} {% for issue in dossier.veto_report.issues if issue.severity in ['HARD', 'MEDIUM'] %}
[{{ issue.severity|replace('HARD', 'Bloquant')|replace('MEDIUM', 'À vérifier') }}] {{ issue.message }} {% if issue.citation %}
ATIH: {{ issue.citation }}{% endif %}
{% endfor %} {% else %}
Aucune anomalie majeure détectée.
{% endif %}
{# Valorisation CMA #}

Valorisation (CMA)

{% set cma_alerts = [] %} {% for alerte in dossier.alertes_codage if alerte.startswith('CMA') %}{% set _ = cma_alerts.append(alerte) %}{% endfor %} {% if cma_alerts %}
    {% for alerte in cma_alerts %}
  • {{ alerte }}
  • {% endfor %}
{% else %}
Aucune comorbidité (CMA) détectée.
{% endif %}
{# Audit IA (QC) #}

Audit de l'Expert IA

{% set qc_alerts = [] %} {% for alerte in dossier.alertes_codage if alerte.startswith('QC:') %}{% set _ = qc_alerts.append(alerte) %}{% endfor %} {% if qc_alerts %} {% for alerte in qc_alerts | sort_qc_alerts %}
{{ alerte|replace('QC: ', '') }}
{% endfor %} {% else %}
Aucune recommandation particulière.
{% endif %}
{# Détail Contestabilité (VetoReport) #} {% if vr and vr.issues %}
Détail des contrôles qualité ({{ vr.issues|length }}) {% for issue in vr.issues %} {% endfor %}
RègleSévéritéLocalisationMessage d'alerteSource / Référence
{{ issue.veto }} {% if issue.severity == 'HARD' %}Bloquant {% elif issue.severity == 'MEDIUM' %}À vérifier {% else %}Optimisation{% endif %} {{ issue.where|human_where }} {{ issue.message }} {{ issue.citation or '—' }}
{% endif %} {# GHM alertes #} {% if ghm and ghm.alertes %}
{% for alerte in ghm.alertes %}
{{ alerte }}
{% endfor %}
{% endif %}
{# ==================================================================== #} {# 4. CONTRÔLE CPAM (si applicable) #} {# ==================================================================== #} {% if dossier.controles_cpam %}

Contrôle UCR ({{ dossier.controles_cpam|length }})

{% if dossier_strength and dossier_strength.is_weak %}
Dossier à preuves limitées (score {{ dossier_strength.score }}/10) — manque : {{ dossier_strength.missing|join(', ') }}
{% endif %} {% for ctrl in dossier.controles_cpam %}
OGC {{ ctrl.numero_ogc }} — {{ ctrl.titre }} {% if 'retient' in ctrl.decision_ucr|lower %} {{ ctrl.decision_ucr }} {% elif 'confirme' in ctrl.decision_ucr|lower %} {{ ctrl.decision_ucr }} {% else %} {{ ctrl.decision_ucr }} {% endif %} {% if ctrl.quality_tier == 'A' %} Qualité A {% elif ctrl.quality_tier == 'B' %} Qualité B {% elif ctrl.quality_tier == 'C' %} Qualité C {% endif %}
{% if ctrl.arg_ucr %}
Argument UCR
{{ ctrl.arg_ucr }}
{% endif %} {% if ctrl.dp_ucr or ctrl.da_ucr or ctrl.dr_ucr or ctrl.actes_ucr %}
Codes contestés
{% if ctrl.dp_ucr %}DP: {{ ctrl.dp_ucr }}{% endif %} {% if ctrl.da_ucr %}DA: {{ ctrl.da_ucr }}{% endif %} {% if ctrl.dr_ucr %}DR: {{ ctrl.dr_ucr }}{% endif %} {% if ctrl.actes_ucr %}Actes: {{ ctrl.actes_ucr }}{% endif %}
{% endif %} {% if ctrl.requires_review %}
Revue manuelle requise — la contre-argumentation contient des incohérences détectées
{% endif %} {% if ctrl.response_data %}
Contre-argumentation
{% if ctrl.response_data.analyse_contestation %}
Analyse de la contestation
{{ ctrl.response_data.analyse_contestation | format_cpam_text }}
{% endif %} {% if ctrl.response_data.points_accord and ctrl.response_data.points_accord|lower not in ['aucun', 'non applicable', 'n/a', ''] %}
Points d'accord
{{ ctrl.response_data.points_accord | format_cpam_text }}
{% endif %} {% if ctrl.response_data.contre_arguments_medicaux %}
Contre-arguments médicaux
{{ ctrl.response_data.contre_arguments_medicaux | format_cpam_text }}
{% endif %} {% if ctrl.response_data.preuves_dossier %}
Preuves du dossier
    {% for p in ctrl.response_data.preuves_dossier %} {% if p is mapping %}
  • {{ p.element or p.get('type', '') }} {{ p.valeur or '' }} → {{ p.signification or '' }}
  • {% endif %} {% endfor %}
{% endif %} {% if ctrl.response_data.contre_arguments_asymetrie %}
Asymétrie d'information
{{ ctrl.response_data.contre_arguments_asymetrie | format_cpam_text }}
{% endif %} {% if ctrl.response_data.contre_arguments_reglementaires %}
Contre-arguments réglementaires
{{ ctrl.response_data.contre_arguments_reglementaires | format_cpam_text }}
{% endif %} {% if ctrl.response_data.references %}
Références
{% for ref in ctrl.response_data.references %} {% if ref is mapping %}
[{{ ref.document or '' }}{% if ref.page %}, p.{{ ref.page }}{% endif %}] {{ ref.citation or '' }}
{% elif ref is string %}

{{ ref }}

{% endif %} {% endfor %}
{% endif %} {% if ctrl.response_data.conclusion %}
Conclusion
{{ ctrl.response_data.conclusion | format_cpam_text }}
{% endif %}
{% elif ctrl.contre_argumentation %}
Contre-argumentation
{{ ctrl.contre_argumentation }}
{% endif %} {% if ctrl.sources_reponse %}
Sources RAG ({{ ctrl.sources_reponse|length }}) {% for src in ctrl.sources_reponse %}
{{ src.document }}{% if src.code %} — {{ src.code }}{% endif %}{% if src.page %} [p.{{ src.page }}]{% endif %}
{{ src.extrait or '' }}
{% endfor %}
{% endif %} {% if ctrl.quality_warnings %}
Avertissements qualité ({{ ctrl.quality_warnings|length }})
    {% for w in ctrl.quality_warnings %} {% if w.startswith('[CRITIQUE]') %}
  • {{ w }}
  • {% else %}
  • {{ w }}
  • {% endif %} {% endfor %}
{% endif %}
Délai réglementaire
{% if ctrl.date_limite_reponse %}Limite : {{ ctrl.date_limite_reponse }}{% endif %}
Validation DIM
{% if ctrl.validation_dim == 'valide' %} Validé {% elif ctrl.validation_dim == 'rejete' %} Rejeté {% elif ctrl.validation_dim == 'en_revision' %} En révision {% else %} Non validé {% endif %} {% if ctrl.date_validation %} {{ ctrl.date_validation }} {% endif %}
Versions précédentes
Chargement...
{% endfor %}
{% endif %} {# ==================================================================== #} {# Sections complémentaires (repliables) #} {# ==================================================================== #} {# ---- Biologie clé ---- #} {% if dossier.biologie_cle %}

Biologie clé ({{ dossier.biologie_cle|length }})

{% for b in dossier.biologie_cle %} {% endfor %}
TestValeurAnomalieSource
{{ b.test }} {{ b.valeur or '' }} {% if b.quality == 'suspect' %} Suspect {% elif b.anomalie %} Oui {% if b.test in bio_normals and b.valeur_num is not none %} {% set lo, hi = bio_normals[b.test] %} {% if b.valeur_num > hi %} ↑ {{ b.valeur }} > {{ hi }} (N: {{ lo }}–{{ hi }}) {% elif b.valeur_num < lo %} ↓ {{ b.valeur }} < {{ lo }} (N: {{ lo }}–{{ hi }}) {% endif %} {% elif b.test in bio_normals %} {% set lo, hi = bio_normals[b.test] %} (N: {{ lo }}–{{ hi }}) {% endif %} {% else %}—{% endif %} {% if b.source_page %}{% endif %}
{% if dossier.biologie_discarded %}
Valeurs écartées ({{ dossier.biologie_discarded|length }}) {% for b in dossier.biologie_discarded %} {% endfor %}
TestValeurRaison
{{ b.test or '' }}{{ b.valeur or '' }}{{ b.discard_reason or '—' }}
{% endif %}
{% endif %} {# ---- Imagerie ---- #} {% if dossier.imagerie %}

Imagerie ({{ dossier.imagerie|length }})

{% for img in dossier.imagerie %}
{{ img.type }} {% if img.score %} — Score : {{ img.score }}{% endif %} {% if img.source_page %}{% endif %} {% if img.conclusion %}
{{ img.conclusion }}
{% endif %}
{% endfor %}
{% endif %} {# ---- Traitements de sortie ---- #} {% if dossier.traitements_sortie %}

Traitements de sortie ({{ dossier.traitements_sortie|length }})

{% for t in dossier.traitements_sortie %} {% endfor %}
MédicamentPosologieCode ATCSource
{{ t.medicament }} {{ t.posologie or '' }} {% if t.code_atc %}{{ t.code_atc }}{% endif %} {% if t.source_page %}{% endif %}
{% endif %} {# ---- Antécédents ---- #} {% if dossier.antecedents %}

Antécédents ({{ dossier.antecedents|length }})

{% endif %} {# ---- Complications ---- #} {% if dossier.complications %}

Complications ({{ dossier.complications|length }})

{% endif %} {# ==================================================================== #} {# 5. DOCUMENTS SOURCES (nouveau — en bas de page) #} {# ==================================================================== #} {% if siblings and siblings|length > 1 %}

Documents du dossier

{% for sib in siblings %} {% endfor %}
DocumentTypeDASActes
{{ sib.name | format_doc_name }} {% if sib.path_rel == filepath %} actuel {% endif %} {% if 'fusionne' in sib.name %} fusionné {% endif %} {% if sib.dossier.document_type %}{{ sib.dossier.document_type }}{% endif %} {{ sib.dossier.diagnostics_associes|length }} {{ sib.dossier.actes_ccam|length }}
{% endif %} {# ---- Modal source ---- #}
Document source
{% endblock %} {% block scripts %} {% endblock %}