import json from typing import Dict from safety import POLICY_NOTICE DECISION_FRAME = """FRAME: - SAFETY/RISK: crowding proxy; p95 boarding time; # critical waits; isolation/telemetry constraints. - CAPACITY: staffed beds now; free beds; unit occupancy & imbalance; EVS/transport turnaround. - DISCHARGES: # ready now; # by noon; barriers (AH, placement, Rx, paperwork). - ADMISSIONS: ED admits waiting (by service/needs); forecast next 6–24h; elective admits deferrable. - STAFFING: RN/RT/Allied gaps; redeploy/OT/agency options. - MATH: beds needed now to clear ED; additional buffer for next 12h; target occupancy. - DECISION: ranked actions with owner, ETA, expected beds, and risks. """ EXEC_FRAME = """EXECUTIVE FRAME: - OBJECTIVE: clarify success criteria, time horizon, and constraints. - CONTEXT: scenario details, population, geography, cultural considerations. - DATA INPUTS: population/community, health indicators, cost/ops, longitudinal outcomes. - ANALYTICS: prioritization method, capacity simulation, cost model, outcome deltas. - OUTPUTS: tables + bullets + assumptions + short narrative justifications. """ def build_system_preamble(snapshot: Dict, policy_context: str, computed_numbers: Dict, scenario_text: str = "", session_snips: str = "") -> str: return f""" {POLICY_NOTICE} Use (a) the snapshot JSON, (b) policy excerpts, (c) computed numbers, and (d) uploaded/scenario evidence to recommend next actions and provide structured estimates with tables, bullets, and assumptions. Cite specific policies where applicable. Policies & SOP Excerpts: {policy_context} Snapshot (JSON): {json.dumps(snapshot, indent=2)} Computed Numbers: {json.dumps(computed_numbers, indent=2)} Scenario (if provided): {scenario_text if scenario_text else "(none)"} Uploaded Evidence (session): {session_snips if session_snips else "(none)"} {DECISION_FRAME} {EXEC_FRAME} """.strip()