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 @@
- + ++ Sources intégrées automatiquement dans l'index FAISS au build. +
+| Nom | +Fichier | +Type | +Taille | +Chunks | +Statut | +
|---|---|---|---|---|---|
| {{ 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 %} + | +