feat: affichage des référentiels intégrés dans la page admin RAG
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user