import { useState, KeyboardEvent } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Stethoscope, ChevronDown, Heart, FlaskConical, ClipboardList, Settings, User, X, Loader2, FileText, Pencil, Upload } from "lucide-react"; import { runDiagnosis, checkBackendHealth, PatientForm, DiagnosisResult } from "@/lib/diagnosisEngine"; import { ResultsPanel } from "./ResultsPanel"; import { PatientUpload } from "./PatientUpload"; const initialForm: PatientForm = { patientId: "", age: 58, gender: "Male", chiefComplaint: "Crushing chest pain for 45 minutes with diaphoresis, radiating to left arm.", vitals: { bp_systolic: 154, bp_diastolic: 90, heart_rate: 108, temperature: 37.1, spo2: 95, respiratory_rate: 22 }, labs: { troponin_i: 2.8, bnp: 180, creatinine: 1.0, glucose: 132, wbc: 9.2, hemoglobin: 14.0 }, allergies: ["aspirin"], medications: ["lisinopril"], driftEnabled: true, driftProbability: 75, seed: 123, }; const VITAL_RANGES = { bp_systolic: [90, 140], bp_diastolic: [60, 90], heart_rate: [60, 100], temperature: [36.1, 37.5], spo2: [94, 100], respiratory_rate: [12, 20], }; export const InteractiveDemo = () => { const [form, setForm] = useState(initialForm); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const [backendOnline, setBackendOnline] = useState(null); // Check backend health on mount useState(() => { checkBackendHealth().then(setBackendOnline); }); const [open, setOpen] = useState({ A: true, B: true, C: true, D: true, E: true }); const [mode, setMode] = useState<"manual" | "upload">("manual"); const [loadedMeta, setLoadedMeta] = useState<{ filename: string; patientId: string } | null>(null); const update = (k: K, v: PatientForm[K]) => setForm({ ...form, [k]: v }); const updateNested = (group: "vitals" | "labs", key: string, val: number) => setForm({ ...form, [group]: { ...form[group], [key]: val } }); const handleLoaded = (partial: Partial, meta: { filename: string; patientId: string }) => { setForm((prev) => ({ ...prev, ...partial, vitals: { ...prev.vitals, ...(partial.vitals || {}) }, labs: { ...prev.labs, ...(partial.labs || {}) }, })); setLoadedMeta(meta); setMode("manual"); }; const submit = async () => { setLoading(true); setResult(null); const r = await runDiagnosis({ ...form, patientId: form.patientId || "P-001" }); setResult(r); setLoading(false); }; return (

Run a Live Diagnosis

Fill in a patient record — our AI doctor will diagnose, prescribe, and audit in real time

{/* FORM */}
{/* Mode switcher */}
{([ { id: "manual", label: "Manual Entry", icon: Pencil }, { id: "upload", label: "Upload Patient File", icon: Upload }, ] as const).map((t) => { const Icon = t.icon; const active = mode === t.id; return ( ); })}
{/* Backend status indicator */} {backendOnline !== null && (
{backendOnline ? "🟢 Python backend connected — running real agents" : "🟡 Backend offline — using mock simulation"}
)} {mode === "upload" ? ( ) : ( <> {loadedMeta && (
📂 Loaded from file: {loadedMeta.filename} ·{" "} {loadedMeta.patientId} · Click any field to edit
)}
setOpen({ ...open, A: !open.A })}>
update("patientId", e.target.value)} /> update("age", +e.target.value)} />
{(["Male","Female","Other"] as const).map(g => ( ))}