From c838d75174614fe8e7b94d477493c58c5d847929 Mon Sep 17 00:00:00 2001
From: dom
Date: Fri, 13 Feb 2026 19:00:44 +0100
Subject: [PATCH] =?UTF-8?q?feat:=20affichage=20des=20r=C3=A9f=C3=A9rentiel?=
=?UTF-8?q?s=20int=C3=A9gr=C3=A9s=20dans=20la=20page=20admin=20RAG?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Ajout d'une section listant les 6 sources built-in (CIM-10, CCAM, Guide Métho,
dictionnaires) avec compteurs de chunks et statut. Séparation claire entre
référentiels intégrés et référentiels utilisateur uploadés.
Co-Authored-By: Claude Opus 4.6
---
src/viewer/app.py | 46 +++++++++++++++++-
src/viewer/templates/admin_referentiels.html | 50 +++++++++++++++++++-
2 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/src/viewer/app.py b/src/viewer/app.py
index 4d91c2d..cfa39a4 100644
--- a/src/viewer/app.py
+++ b/src/viewer/app.py
@@ -15,7 +15,11 @@ from werkzeug.utils import secure_filename
from collections import Counter
-from ..config import STRUCTURED_DIR, OLLAMA_URL, CCAM_DICT_PATH, DossierMedical, ALLOWED_EXTENSIONS, UPLOAD_MAX_SIZE_MB
+from ..config import (
+ 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,
+)
from .. import config as cfg
from .referentiels import ReferentielManager
@@ -154,6 +158,43 @@ def collect_cpam_controls(groups: dict[str, list[dict]]) -> list[dict]:
return controls
+def get_builtin_referentiels() -> list[dict]:
+ """Retourne les infos sur les référentiels intégrés (PDFs + dicts)."""
+ rag_index_meta = Path(STRUCTURED_DIR).parent / "data" / "rag_index" / "metadata.json"
+ chunks_by_doc: dict[str, int] = {}
+ if rag_index_meta.exists():
+ try:
+ import json as _json
+ meta = _json.loads(rag_index_meta.read_text(encoding="utf-8"))
+ for m in meta:
+ doc = m.get("document", "")
+ chunks_by_doc[doc] = chunks_by_doc.get(doc, 0) + 1
+ except Exception:
+ pass
+
+ refs = []
+ builtin_sources = [
+ ("CIM-10 FR 2026", CIM10_PDF, ".pdf", ["cim10", "cim10_alpha"]),
+ ("Guide Méthodologique MCO 2026", GUIDE_METHODO_PDF, ".pdf", ["guide_methodo"]),
+ ("CCAM 2025", CCAM_PDF, ".pdf", ["ccam"]),
+ ("Dictionnaire CIM-10", CIM10_DICT_PATH, ".json", []),
+ ("Suppléments CIM-10", CIM10_SUPPLEMENTS_PATH, ".json", []),
+ ("Dictionnaire CCAM", CCAM_DICT_PATH, ".json", []),
+ ]
+ for name, path, ext, doc_keys in builtin_sources:
+ size_mb = path.stat().st_size / (1024 * 1024) if path.exists() else 0
+ chunks = sum(chunks_by_doc.get(k, 0) for k in doc_keys)
+ refs.append({
+ "name": name,
+ "filename": path.name,
+ "extension": ext,
+ "size_mb": size_mb,
+ "chunks": chunks,
+ "exists": path.exists(),
+ })
+ return refs
+
+
def load_ccam_dict() -> dict[str, dict]:
"""Charge le dictionnaire CCAM pour les regroupements."""
if CCAM_DICT_PATH.exists():
@@ -424,7 +465,8 @@ def create_app() -> Flask:
@app.route("/admin/referentiels")
def admin_referentiels():
refs = ref_manager.list_all()
- return render_template("admin_referentiels.html", referentiels=refs, max_size=UPLOAD_MAX_SIZE_MB)
+ builtin = get_builtin_referentiels()
+ return render_template("admin_referentiels.html", referentiels=refs, builtin_refs=builtin, max_size=UPLOAD_MAX_SIZE_MB)
@app.route("/admin/referentiels/upload", methods=["POST"])
def upload_referentiel():
diff --git a/src/viewer/templates/admin_referentiels.html b/src/viewer/templates/admin_referentiels.html
index c84b5e2..bdbce7c 100644
--- a/src/viewer/templates/admin_referentiels.html
+++ b/src/viewer/templates/admin_referentiels.html
@@ -34,10 +34,56 @@
-
+
+
+
Référentiels intégrés
+
+ Sources intégrées automatiquement dans l'index FAISS au build.
+
+
+
+
+ | Nom |
+ Fichier |
+ Type |
+ Taille |
+ Chunks |
+ Statut |
+
+
+
+ {% for ref in builtin_refs %}
+
+ | {{ ref.name }} |
+ {{ ref.filename }} |
+ {{ ref.extension }} |
+ {{ "%.1f"|format(ref.size_mb) }} Mo |
+
+ {% if ref.chunks %}
+ {{ ref.chunks }}
+ {% else %}
+ —
+ {% endif %}
+ |
+
+ {% if not ref.exists %}
+ Fichier absent
+ {% elif ref.chunks %}
+ Indexé
+ {% else %}
+ Dictionnaire
+ {% endif %}
+ |
+
+ {% endfor %}
+
+
+
+
+
-
Référentiels indexés
+ Référentiels utilisateur