"""Readable, self-contained HTML screening report with provenance."""
from __future__ import annotations
import hashlib, html, json, datetime
from . import __version__
DISCLAIMER = ("Educational screening prototype for a university assignment. It is NOT a clinical "
"enrollment decision tool and must not be used to include or exclude real patients.")
_COL = {"included": "#1b7350", "not excluded": "#1b7350", "not included": "#b42318", "excluded": "#b42318",
"not enough information": "#8a5a00", "not applicable": "#555", "invalid output": "#b42318"}
def provenance(note, criteria, settings):
blob = json.dumps({"note": note, "criteria": criteria}, sort_keys=True).encode()
return {"generated_utc": datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"),
"app_version": __version__, "input_sha256": hashlib.sha256(blob).hexdigest(), **settings}
def html_report(trial_name, sentences, results, verdict, prov):
e = html.escape
rows = []
for i, r in enumerate(results, 1):
ev = "
".join(f"[{sid}] {e(t)}" for sid, t in zip(r["evidence"], r["evidence_text"])) or "none cited"
rows.append(f"
Notice: {e(DISCLAIMER)}
{e(trial_name or 'Unnamed trial')}
{e(verdict['verdict'])} — {verdict['n_criteria']} criteria,
{verdict['n_blocking']} blocking, {verdict['n_unknown']} undetermined.
Rule: {e(verdict['rule'])} This aggregation is not a
ground-truth label; the dataset only labels individual criteria.
| # | Type | Criterion | Prediction | Evidence (sentence ID) | Explanation |
|---|
{e(json.dumps(prov, indent=1))}"""