feat: traçabilité source systématique + viewer interactif

Ajoute source_page/source_excerpt à tous les types (biologie, imagerie,
traitements, actes CCAM, antécédents, complications). Convertit antecedents
et complications en types structurés (Antecedent/Complication) avec
validators backward-compat pour les vieux JSON. Étend _apply_source_tracking
à tous les éléments du dossier. Ajoute un endpoint /api/source-text/ et un
modal interactif dans le viewer avec surlignage du texte source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dom
2026-02-18 20:59:50 +01:00
parent fe22c0f0f5
commit 40934fdc39
10 changed files with 500 additions and 47 deletions

View File

@@ -16,7 +16,7 @@ from werkzeug.utils import secure_filename
from collections import Counter
from ..config import (
STRUCTURED_DIR, OLLAMA_URL, CCAM_DICT_PATH, DossierMedical,
ANONYMIZED_DIR, STRUCTURED_DIR, OLLAMA_URL, CCAM_DICT_PATH, DossierMedical,
ALLOWED_EXTENSIONS, UPLOAD_MAX_SIZE_MB,
CIM10_PDF, GUIDE_METHODO_PDF, CCAM_PDF, CIM10_DICT_PATH, CIM10_SUPPLEMENTS_PATH,
)
@@ -594,6 +594,27 @@ def create_app() -> Flask:
logger.exception("Erreur lors du retraitement")
return jsonify({"error": str(e)}), 500
# ------------------------------------------------------------------
# API texte source anonymisé
# ------------------------------------------------------------------
@app.route("/api/source-text/<path:dossier_id>")
def source_text(dossier_id: str):
"""Retourne le contenu texte anonymisé de tous les fichiers d'un dossier."""
safe_dir = (ANONYMIZED_DIR / dossier_id).resolve()
if not safe_dir.is_relative_to(ANONYMIZED_DIR.resolve()):
abort(403)
if not safe_dir.is_dir():
abort(404)
result = {}
for txt_path in sorted(safe_dir.glob("*_anonymized.txt")):
try:
result[txt_path.name] = txt_path.read_text(encoding="utf-8")
except Exception:
logger.warning("Impossible de lire %s", txt_path)
return jsonify(result)
# ------------------------------------------------------------------
# Routes admin référentiels
# ------------------------------------------------------------------