{% extends "base.html" %} {% block title %}{{ dossier.source_file or filepath }}{% endblock %} {% block sidebar %}
Navigation
Retour à la liste {% if siblings %}
{{ current_group }}
{% for sib in siblings %} {{ sib.name }} {% endfor %} {% endif %}
Actions
{% endblock %} {% block content %} ← Retour à la liste {# ---- En-tête ---- #}

{{ dossier.source_file or filepath }}

{% if dossier.document_type %}
{{ dossier.document_type }}
{% endif %} {% if dossier.processing_time_s is not none %}
{{ dossier.processing_time_s|format_duration }}
{% endif %}
{% if dossier.source_files %}
{% for sf in dossier.source_files %} {{ sf }}{% if not loop.last %}, {% endif %} {% endfor %}
{% endif %}
{# ---- Synthèse Expert (Refonte) ---- #}
{# 1. Sécurité & Conformité (Vetos) #}

🛡️ Sécurité & Conformité

{% 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 %}
{# 2. Optimisation de la Recette (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 %}
{# 3. Audit & Analyse 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 %}
{{ alerte|replace('QC: ', '') }}
{% endfor %} {% else %}
Aucune recommandation particulière.
{% endif %}
{# ---- Séjour ---- #} {% set s = dossier.sejour %} {% if s.sexe or s.age or s.date_entree or s.date_sortie or s.duree_sejour is not none or s.imc or s.poids or s.taille %}

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 }} jour(s)
{% 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 %}
{% endif %} {# ---- Estimation GHM ---- #} {% if dossier.ghm_estimation %} {% set ghm = dossier.ghm_estimation %}

Estimation GHM

{% if ghm.cmd %}
{{ ghm.cmd }}{% if ghm.cmd_libelle %} — {{ ghm.cmd_libelle }}{% endif %}
{% 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 %} Niveau {{ ghm.severite }} {% elif ghm.severite == 2 %} Niveau {{ ghm.severite }} {% elif ghm.severite == 3 %} Niveau {{ ghm.severite }} {% else %} Niveau {{ ghm.severite }} {% endif %}
{% if ghm.ghm_approx %}
{{ ghm.ghm_approx }}
{% endif %}
{{ ghm.cma_count }} CMA, {{ ghm.cms_count }} CMS
{% if ghm.alertes %}
{% for alerte in ghm.alertes %}
{{ alerte }}
{% endfor %}
{% endif %}
Estimation heuristique — le GHM définitif nécessite le groupeur officiel ATIH
{% endif %} {# ---- Contrôle CPAM ---- #} {% if dossier.controles_cpam %}

Contrôle CPAM ({{ 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 %}
{# Argument CPAM #} {% if ctrl.arg_ucr %}
Argument CPAM
{{ ctrl.arg_ucr }}
{% endif %} {# Codes contestés #} {% 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 %} {# Bandeau revue manuelle si Tier C #} {% if ctrl.requires_review %}
⚠ Revue manuelle requise — la contre-argumentation contient des incohérences détectées
{% endif %} {# Contre-argumentation structurée ou fallback texte brut #} {% 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 %} {# Sources RAG #} {% 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 %} {# Avertissements qualité #} {% 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 %}
{% endfor %}
{% endif %} {# ---- Contestabilité (VetoReport) ---- #} {% if dossier.veto_report %} {% set vr = dossier.veto_report %} {% if vr.verdict == 'PASS' %} {% set vr_color = '#22c55e' %} {% elif vr.verdict == 'NEED_INFO' %} {% set vr_color = '#f59e0b' %} {% else %} {% set vr_color = '#ef4444' %} {% endif %}

Contestabilité du dossier (Qualité PMSI)

{% if vr.verdict == 'PASS' %} CONFORME {% elif vr.verdict == 'NEED_INFO' %} À COMPLÉTER {% else %} NON CONFORME {% endif %}
Score : {{ vr.score_contestabilite }}/100
{% if vr.issues %}
Détail des anomalies détectées ({{ vr.issues|length }}) {% for issue in vr.issues %} {% endfor %}
Code RègleSévéritéLocalisationMessage d'alerteRéférence ATIH
{{ 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 %}
{% endif %} {# ---- Diagnostic principal ---- #} {% if dossier.diagnostic_principal %} {% set dp = dossier.diagnostic_principal %}

Diagnostic principal

{% if dp.status == 'ruled_out' %}{{ dp.texte }}{% else %}{{ dp.texte }}{% endif %} {% if dp.source_page %}{% endif %}
{% if dp.cim10_suggestion %} {% if dp.cim10_final and dp.cim10_final != dp.cim10_suggestion %} {{ dp.cim10_suggestion }} {{ dp.cim10_final }} {% elif dp.status == 'ruled_out' %} {{ dp.cim10_suggestion }} {% else %} {{ dp.cim10_suggestion }} {% endif %} {{ dp.cim10_confidence | confidence_badge }} {% if dp.niveau_cma and dp.niveau_cma > 1 %} {{ dp.niveau_cma | cma_level_badge }} {% elif dp.est_cma %} CMA {% endif %} {{ dp.niveau_severite | severity_badge }} {% 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 %} {% endif %} {% endif %} {% 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' and dp.cim10_decision.reason %}
{{ dp.cim10_decision.reason }}
{% 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 %}
{% 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 %}
TexteCIM-10ConfianceCMASourceJustification
{{ das.texte }} {% 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.cim10_confidence | confidence_badge }} {% if das.niveau_cma and das.niveau_cma > 1 %} {{ das.niveau_cma | cma_level_badge }} {% elif das.est_cma %} CMA {% else %} — {% endif %} {% if das.source %} {{ das.source }} {% endif %} {% if das.source_page %} {% endif %} {{ das.justification or '' }} {% if das.preuves_cliniques %}
preuves ({{ das.preuves_cliniques|length }})
    {% for p in das.preuves_cliniques %}
  • [{{ p.type }}] {{ p.element }} → {{ p.interpretation }}
  • {% endfor %}
{% 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 %}
TexteCode CCAMRegroupementDateValiditéSource
{{ a.texte }} {% if a.code_ccam_suggestion %}{{ a.code_ccam_suggestion }}{% endif %} {% 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 %} {# ---- 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 {% 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 %} {# ---- Modal source ---- #}
Document source
{% endblock %} {% block scripts %} {% endblock %}