""" PMJAY package configuration — loaded from packages.json. packages.json is the single source of truth: each package carries the mandatory document checklist for both stages (pre-auth / claim) plus the "TMS rule" content checks the STG asks processing doctors to verify. Edit the JSON to add packages, documents, or rules — no code change required. The verdict engine treats `documents` as a deterministic presence checklist, and `rules` as content checks the LLM evaluates against OCR'd text. Source PDFs: stg_guidelines/STGs_ps1/ """ import json import os _DATA_PATH = os.path.join(os.path.dirname(__file__), "packages.json") # Stage identifiers used across the app. STAGE_PREAUTH = "preauth" STAGE_CLAIM = "claim" def _load(): with open(_DATA_PATH, encoding="utf-8") as fh: raw = json.load(fh) stage_labels = raw.get("stages", {}) packages = {} for pkg in raw.get("packages", []): code = pkg["code"] documents = {} for stage, items in pkg.get("documents", {}).items(): documents[stage] = [ { "id": d["id"], "label": d["label"], "verify": d["verify"], "note": d.get("note", ""), } for d in items ] rules = [ { "id": r["id"], "check": r["check"], "expected": r.get("expected", "Yes"), } for r in pkg.get("rules", []) ] packages[code] = { "code": code, "name": pkg["name"], "procedure": pkg.get("procedure", ""), "specialty": pkg.get("specialty", ""), "price": pkg.get("price", ""), "documents": documents, "rules": rules, } return stage_labels, packages STAGE_LABELS, PACKAGES = _load() def dropdown_choices(): """Return [(label, code), ...] for the Gradio dropdown, grouped sensibly.""" # Count how many codes share each display name; only disambiguate with the # procedure when a name is used by more than one package (e.g. the 4 # cholecystectomy variants). name_counts = {} for pkg in PACKAGES.values(): name_counts[pkg["name"]] = name_counts.get(pkg["name"], 0) + 1 choices = [] for code, pkg in PACKAGES.items(): label = f"{code} — {pkg['name']}" if name_counts[pkg["name"]] > 1 and pkg.get("procedure"): label += f" — {pkg['procedure']}" choices.append((label, code)) return choices def get_package(code): return PACKAGES.get(code) def required_documents(code, stage): pkg = PACKAGES.get(code) if not pkg: return [] return pkg["documents"].get(stage, [])