Spaces:
Sleeping
Sleeping
Hackathon Builder commited on
Commit Β·
ecba760
1
Parent(s): ea0f7e0
Final Polish: Robust fallback for consultation and improved UI feedback
Browse files
backend/main.py
CHANGED
|
@@ -511,6 +511,18 @@ Return ONLY raw JSON:
|
|
| 511 |
]
|
| 512 |
}}"""
|
| 513 |
r = _gemini(prompt, override_key=x_gemini_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
return {"result": r}
|
| 515 |
|
| 516 |
|
|
|
|
| 511 |
]
|
| 512 |
}}"""
|
| 513 |
r = _gemini(prompt, override_key=x_gemini_key)
|
| 514 |
+
|
| 515 |
+
if not r:
|
| 516 |
+
# Fallback orientation if AI fails
|
| 517 |
+
print("[CONSULT] AI failed. Using fallback orientation.")
|
| 518 |
+
r = {
|
| 519 |
+
"answer": "The team is currently focused on stabilization. Based on the triage, this is an ESI 1 case requiring immediate IV access and monitoring. (Note: AI consultation fallback engaged)",
|
| 520 |
+
"team_consensus": "Consensus reached on immediate stabilization protocols.",
|
| 521 |
+
"specialist_insights": [
|
| 522 |
+
{"agent": "Guardian", "note": "Priority is safe administration of emergency fluids."},
|
| 523 |
+
{"agent": "Pathologist", "note": "Correlating high-risk labs with clinical presentation."}
|
| 524 |
+
]
|
| 525 |
+
}
|
| 526 |
return {"result": r}
|
| 527 |
|
| 528 |
|
frontend/dist/assets/{index-B_BgTsDx.js β index-Dux7dzE3.js}
RENAMED
|
@@ -177,4 +177,4 @@ Error generating stack: `+i.message+`
|
|
| 177 |
*
|
| 178 |
* This source code is licensed under the ISC license.
|
| 179 |
* See the LICENSE file in the root directory of this source tree.
|
| 180 |
-
*/const wc=V("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);function pp({onStart:e}){return s.jsxs("div",{className:"welcome-screen",children:[s.jsxs("div",{style:{marginBottom:32,position:"relative"},children:[s.jsx("div",{style:{width:80,height:80,borderRadius:"50%",background:"rgba(255,45,85,0.12)",border:"2px solid rgba(255,45,85,0.4)",display:"flex",alignItems:"center",justifyContent:"center",animation:"heartbeat 1.4s ease-in-out infinite",margin:"0 auto 20px"},children:s.jsx(Un,{size:36,color:"var(--red-critical)"})}),s.jsx("svg",{width:"240",height:"40",viewBox:"0 0 240 40",style:{margin:"0 auto",display:"block"},children:s.jsx("polyline",{points:"0,20 30,20 45,5 52,35 60,5 70,20 100,20 115,20 120,2 126,38 132,2 138,20 180,20 240,20",fill:"none",stroke:"var(--red-critical)",strokeWidth:"1.5",strokeDasharray:"400",strokeDashoffset:"400",style:{animation:"ekg 2s ease forwards 0.3s"}})})]}),s.jsx("h1",{style:{fontSize:42,fontWeight:900,letterSpacing:"-0.03em",background:"linear-gradient(135deg, #0f172a 30%, #475569)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",marginBottom:8},children:"CodeBlue Context"}),s.jsx("p",{style:{fontSize:16,color:"var(--text-secondary)",marginBottom:32,maxWidth:420,lineHeight:1.6},children:"Emergency clinical intelligence. Five AI agents. One life-saving brief."}),s.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",justifyContent:"center",marginBottom:40},children:[{icon:s.jsx(Un,{size:13}),label:"5-Agent Orchestration"},{icon:s.jsx(ap,{size:13}),label:"Contraindication Guardian"},{icon:s.jsx(np,{size:13}),label:"Explainable AI Reasoning"}].map(t=>s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 14px",borderRadius:99,background:"rgba(10,132,255,0.08)",border:"1px solid rgba(10,132,255,0.2)",color:"var(--blue-accent)",fontSize:12,fontWeight:600},children:[t.icon,t.label]},t.label))}),s.jsxs("button",{className:"btn-danger",style:{maxWidth:260},onClick:e,children:[s.jsx(Un,{size:16})," Enter Emergency System"]}),s.jsx("p",{style:{marginTop:20,fontSize:11,color:"var(--text-tertiary)"},children:"For clinical decision support only β not a substitute for physician judgment"})]})}function hp({onComplete:e}){return s.jsx("div",{className:"welcome-screen",children:s.jsxs("div",{className:"fade-up",style:{maxWidth:800,width:"100%"},children:[s.jsx("h1",{style:{fontSize:32,fontWeight:800,marginBottom:10,letterSpacing:"-0.03em",color:"var(--text-primary)"},children:"How CodeBlue Context Works"}),s.jsx("p",{style:{color:"var(--text-secondary)",fontSize:16,marginBottom:40},children:"3 simple steps to transform messy clinical records into structured emergency intelligence."}),s.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:20,marginBottom:40,textAlign:"left"},children:[s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.1s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(10,132,255,0.1)",borderRadius:10,color:"var(--blue-accent)",display:"inline-block",marginBottom:16},children:s.jsx(sp,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"1. Upload Anything"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:"Doctors don't have structured JSON. Drop a raw clinical PDF, Word Doc, or photo into the dropzone. Our vision extraction system instantly parses it."})]}),s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.2s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(255,45,85,0.1)",borderRadius:10,color:"var(--red-critical)",display:"inline-block",marginBottom:16},children:s.jsx(op,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"2. 5-Agent Orchestration"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:"The record is passed sequentially through 5 specialized AI agents (Triage, Contraindication, Labs, Differentials, Action Protocol) to extract hidden insights."})]}),s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.3s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(191,90,242,0.1)",borderRadius:10,color:"var(--purple-ai)",display:"inline-block",marginBottom:16},children:s.jsx(vc,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"3. Provide Your Brain"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:'To bypass our hackathon server rate limits, use the "Provide API Key" button in the dashboard navbar to safely inject your own Gemini key directly from your browser.'})]})]}),s.jsxs("button",{className:"btn-primary fade-up",style:{animationDelay:"0.4s",padding:"14px 28px",fontSize:16,borderRadius:99},onClick:e,children:["Enter Dashboard ",s.jsx(tp,{size:18})]})]})})}const mp={critical:"var(--red-critical)",moderate:"var(--amber-warning)",stable:"var(--green-safe)"},yp={critical:"badge-critical",moderate:"badge-moderate",stable:"badge-stable"};function gp({patient:e,selected:t,onClick:n}){const r=e.risk_level||"stable";return s.jsxs("div",{onClick:()=>n(e),style:{padding:"12px 14px",borderRadius:10,cursor:"pointer",marginBottom:6,background:t?"rgba(10,132,255,0.12)":"var(--bg-surface)",border:`1px solid ${t?"rgba(10,132,255,0.4)":"var(--border-subtle)"}`,transition:"all 0.15s"},children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-primary)"},children:e.display_name}),s.jsx("span",{className:`badge ${yp[r]||"badge-unknown"}`,style:{fontSize:10},children:r})]}),s.jsxs("div",{style:{fontSize:11,color:"var(--text-secondary)",display:"flex",gap:10},children:[s.jsxs("span",{children:[e.age,"y ",e.gender]}),s.jsx("span",{children:"Β·"}),s.jsx("span",{style:{color:mp[r]},children:(e.conditions||[]).join(", ")||"No conditions"})]}),s.jsxs("div",{style:{fontSize:10,color:"var(--text-tertiary)",marginTop:3},children:[e.allergy_count," allergies Β· ",e.med_count," meds"]})]})}function vp({patients:e,selected:t,onSelect:n,onUpload:r,loading:l}){return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsxs("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,letterSpacing:"0.05em",color:"var(--text-secondary)",textTransform:"uppercase"},children:"Patients"}),s.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:[e.length," loaded"]})]}),s.jsxs("label",{style:{cursor:"pointer",display:"block",margin:"10px 0 4px 0"},children:[s.jsx("input",{type:"file",accept:".json,.pdf,.txt,.png,.jpg",style:{display:"none"},onChange:r}),s.jsxs("div",{style:{width:"100%",padding:"16px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",border:"1px dashed var(--border-subtle)",borderRadius:"12px",background:"var(--bg-surface)",transition:"all 0.2s",color:"var(--text-secondary)"},onMouseOver:i=>{i.currentTarget.style.borderColor="rgba(10,132,255,0.6)",i.currentTarget.style.background="rgba(10,132,255,0.05)",i.currentTarget.style.color="var(--text-primary)"},onMouseOut:i=>{i.currentTarget.style.borderColor="var(--border-subtle)",i.currentTarget.style.background="var(--bg-surface)",i.currentTarget.style.color="var(--text-secondary)"},children:[s.jsx(cp,{size:20,style:{marginBottom:"6px"}}),s.jsx("span",{style:{fontSize:12,fontWeight:600},children:"Upload Patient Record"}),s.jsx("span",{style:{fontSize:10,opacity:.6,marginTop:"2px"},children:"PDF, Doc, Image, JSON"})]})]})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"10px 12px"},children:[l&&s.jsx("div",{style:{textAlign:"center",padding:20,color:"var(--text-tertiary)",fontSize:12},children:"Loading..."}),!l&&e.length===0&&s.jsxs("div",{style:{textAlign:"center",padding:20,color:"var(--text-tertiary)",fontSize:12},children:[s.jsx(Yi,{size:24,style:{margin:"0 auto 8px",display:"block"}}),"No patients loaded"]}),e.map(i=>s.jsx(gp,{patient:i,selected:(t==null?void 0:t.id)===i.id,onClick:n},i.id))]})]})}const bl=[{key:"triage",label:"Triage Agent",icon:s.jsx(wc,{size:14}),desc:"Severity classification & chief complaint"},{key:"contraindication",label:"Contraindication Guardian",icon:s.jsx(cl,{size:14}),desc:"Drug interactions & allergy risks"},{key:"labs",label:"Lab Interpreter",icon:s.jsx(gc,{size:14}),desc:"Critical lab findings & patterns"},{key:"differentials",label:"Differential Diagnosis",icon:s.jsx(Sc,{size:14}),desc:"Top 3 differentials from evidence"},{key:"action_protocol",label:"Action Protocol",icon:s.jsx(xc,{size:14}),desc:"Immediate ordered steps & disposition"}],xp={triage:"Analyzing vitals and identifying life-threats...",contraindication:"Scanning history for high-risk medication overlaps...",labs:"Interpreting metabolic panels and blood gases...",differentials:"Cross-referencing symptoms with clinical evidence...",action_protocol:"Synthesizing final emergency stabilization steps..."};function kp({status:e}){return e==="working"?s.jsx("div",{className:"spinner"}):e==="complete"?s.jsx(yc,{size:15,color:"var(--green-safe)"}):e==="error"?s.jsx(ea,{size:15,color:"var(--red-critical)"}):s.jsx(ea,{size:15,color:"var(--text-tertiary)"})}function Sp({agent:e,status:t,result:n,expanded:r,onToggle:l}){const i=t==="idle"?"agent-idle":t==="working"?"agent-working":t==="complete"?"agent-complete":"agent-error",o=n&&t==="complete";return s.jsxs("div",{className:`card ${i}`,style:{marginBottom:8,transition:"all 0.3s"},children:[s.jsxs("div",{onClick:o?l:void 0,style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",cursor:o?"pointer":"default"},children:[s.jsx("div",{style:{width:28,height:28,borderRadius:7,background:"rgba(255,255,255,0.04)",display:"flex",alignItems:"center",justifyContent:"center",color:t==="complete"?"var(--green-safe)":t==="working"?"var(--blue-accent)":"var(--text-tertiary)"},children:e.icon}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontSize:12,fontWeight:600,color:t==="idle"?"var(--text-secondary)":"var(--text-primary)"},children:e.label}),s.jsx("div",{style:{fontSize:10,color:t==="working"?"var(--blue-accent)":"var(--text-tertiary)",fontWeight:t==="working"?600:400},children:t==="working"?xp[e.key]:e.desc})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[s.jsx(kp,{status:t}),o&&(r?s.jsx(lp,{size:12,color:"var(--text-tertiary)"}):s.jsx(rp,{size:12,color:"var(--text-tertiary)"}))]})]}),o&&r&&s.jsx("div",{style:{padding:"0 14px 12px",borderTop:"1px solid var(--border-subtle)",paddingTop:10},className:"fade-in",children:s.jsx(wp,{agentKey:e.key,result:n})})]})}function wp({agentKey:e,result:t}){const n={fontSize:11,color:"var(--text-secondary)",lineHeight:1.6},r=(l,i)=>s.jsx("span",{style:{background:i+"20",color:i,border:`1px solid ${i}40`,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:700,marginRight:4},children:l});return e==="triage"?s.jsxs("div",{style:n,children:[r(`ESI ${t.severity}: ${t.severity_label}`,t.severity<=2?"var(--red-critical)":t.severity===3?"var(--amber-warning)":"var(--green-safe)"),s.jsx("p",{style:{marginTop:6},children:t.chief_complaint}),(t.time_critical_flags||[]).map((l,i)=>s.jsxs("p",{children:["β‘ ",l]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="contraindication"?s.jsxs("div",{style:n,children:[r(t.treatment_verdict,t.treatment_verdict==="SAFE"?"var(--green-safe)":t.treatment_verdict==="CONTRAINDICATED"?"var(--red-critical)":"var(--amber-warning)"),s.jsx("p",{style:{marginTop:6},children:t.verdict_reason}),(t.allergy_risks||[]).slice(0,2).map((l,i)=>s.jsxs("p",{style:{color:"var(--red-critical)"},children:["β Allergy: ",l.substance," β ",l.risk]},i)),(t.drug_interactions||[]).slice(0,2).map((l,i)=>s.jsxs("p",{style:{color:"var(--amber-warning)"},children:["π ",l.drug_a," + ",l.drug_b,": ",l.interaction]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="labs"?s.jsxs("div",{style:n,children:[(t.critical_labs||[]).map((l,i)=>s.jsxs("p",{style:{color:"var(--red-critical)"},children:["π΄ ",l.name,": ",l.value," β ",l.significance]},i)),(t.abnormal_labs||[]).map((l,i)=>s.jsxs("p",{style:{color:"var(--amber-warning)"},children:["π‘ ",l.name,": ",l.value," β ",l.significance]},i)),(t.immediate_concerns||[]).slice(0,2).map((l,i)=>s.jsxs("p",{children:["β ",l]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="differentials"?s.jsxs("div",{style:n,children:[(t.differentials||[]).map((l,i)=>s.jsxs("div",{style:{marginBottom:6},children:[r(l.likelihood,l.likelihood==="HIGH"?"var(--red-critical)":l.likelihood==="MODERATE"?"var(--amber-warning)":"var(--text-secondary)"),s.jsx("span",{style:{fontWeight:600,color:"var(--text-primary)"},children:l.diagnosis}),l.must_rule_out&&s.jsx("span",{style:{color:"var(--red-critical)",fontSize:10,marginLeft:6},children:"MUST RULE OUT"})]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="action_protocol"?s.jsxs("div",{style:n,children:[(t.immediate_actions||[]).map((l,i)=>s.jsxs("p",{children:[i+1,". ",l]},i)),t.disposition&&s.jsxs("p",{style:{marginTop:6,fontWeight:700,color:"var(--blue-accent)"},children:["Disposition β ",t.disposition]}),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):null}function jp({agentStatuses:e,agentResults:t,onRun:n,patient:r,running:l,focus:i,setFocus:o}){const[a,u]=L.useState({}),c=h=>u(m=>({...m,[h]:!m[h]})),y=bl.filter(h=>e[h.key]==="complete").length;return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Agent Orchestration"}),l&&s.jsxs("span",{style:{fontSize:11,color:"var(--blue-accent)",display:"flex",alignItems:"center",gap:5},children:[s.jsx("div",{className:"spinner",style:{width:12,height:12}})," ",y,"/5 complete"]})]})}),s.jsxs("div",{style:{padding:"12px 14px",flex:1,overflowY:"auto"},children:[!r&&s.jsx("div",{style:{textAlign:"center",padding:"40px 20px",color:"var(--text-tertiary)",fontSize:13},children:"Select a patient to run emergency analysis"}),r&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{style:{marginBottom:14},children:[s.jsx("p",{style:{fontSize:9,fontWeight:800,color:"var(--text-tertiary)",textTransform:"uppercase",marginBottom:6},children:"Clinical Focus"}),s.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:["General","Cardiac","Trauma","Respiratory","Neuro"].map(h=>s.jsx("div",{onClick:()=>!l&&(o==null?void 0:o(h)),style:{padding:"4px 10px",borderRadius:20,fontSize:10,fontWeight:700,cursor:"pointer",background:i===h?"var(--blue-accent)":"var(--bg-surface)",color:i===h?"#fff":"var(--text-secondary)",border:i===h?"none":"1px solid var(--border-subtle)",transition:"all 0.2s"},children:h},h))})]}),bl.map(h=>s.jsx(Sp,{agent:h,status:e[h.key]||"idle",result:t[h.key],expanded:a[h.key],onToggle:()=>c(h.key)},h.key)),s.jsx("button",{className:"btn-danger pulse-on-hover",style:{marginTop:10,width:"100%"},onClick:n,disabled:l,children:l?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"spinner"})," AI Agents Orchestrating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(wc,{size:15})," Analyze Patient Record"]})}),l||Object.keys(t).length>0?s.jsxs("div",{style:{marginTop:20,borderTop:"1px solid var(--border-subtle)",paddingTop:16},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,color:"var(--text-tertiary)",textTransform:"uppercase",marginBottom:10,letterSpacing:"0.05em"},children:"Collaboration Thread"}),s.jsx("div",{style:{background:"var(--bg-surface)",padding:12,borderRadius:8,border:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono)",fontSize:10,lineHeight:1.5,maxHeight:120,overflowY:"auto"},children:bl.filter(h=>t[h.key]||e[h.key]==="working").map((h,m)=>{var k,S;return s.jsxs("div",{style:{marginBottom:6},className:"fade-in",children:[s.jsxs("span",{style:{color:"var(--blue-accent)",fontWeight:700},children:["[",h.label,"]: "]}),s.jsx("span",{style:{color:"var(--text-secondary)"},children:e[h.key]==="working"?"Transmitting findings...":((S=(k=t[h.key])==null?void 0:k.agent_reasoning)==null?void 0:S[0])||"Processed record successfully."})]},m)})})]}):null]})]})]})}const Cp="";function _t({title:e,icon:t,children:n,accent:r}){return s.jsxs("div",{className:"fade-up",style:{marginBottom:14,borderRadius:10,background:"var(--bg-surface)",border:`1px solid ${r?r+"30":"var(--border-subtle)"}`,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"8px 14px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid var(--border-subtle)",background:r?r+"08":"transparent"},children:[s.jsx("span",{style:{color:r||"var(--text-secondary)"},children:t}),s.jsx("span",{style:{fontSize:11,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:r||"var(--text-secondary)"},children:e})]}),s.jsx("div",{style:{padding:"10px 14px"},children:n})]})}function _n({text:e,severity:t}){const n=t==="critical"?"var(--red-critical)":t==="warning"?"var(--amber-warning)":"var(--blue-accent)";return s.jsxs("div",{style:{display:"flex",gap:8,padding:"7px 10px",borderRadius:7,marginBottom:6,background:n+"12",border:`1px solid ${n}30`},children:[s.jsx(up,{size:13,style:{color:n,flexShrink:0,marginTop:2}}),s.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5},children:e})]})}function Ep({verdict:e}){const t=`badge verdict-${(e||"not_evaluated").toLowerCase()}`,n={SAFE:"β SAFE",CAUTION:"β CAUTION",CONTRAINDICATED:"β CONTRAINDICATED",NOT_EVALUATED:"? NOT EVALUATED"};return s.jsx("span",{className:t,children:n[e]||e})}function ta({patientId:e}){const[t,n]=L.useState(""),[r,l]=L.useState(!1),[i,o]=L.useState(null),a=async()=>{if(!(!t.trim()||!e)){l(!0),o(null);try{const c=localStorage.getItem("gemini_key"),y={"Content-Type":"application/json"};c&&(y["x-gemini-key"]=c);const m=await(await fetch(`${Cp}/check-treatment/${e}`,{method:"POST",headers:y,body:JSON.stringify({treatment:t.trim()})})).json();o(m.result)}catch{o({treatment_verdict:"NOT_EVALUATED",verdict_reason:"Service unavailable."})}finally{l(!1)}}},u=(i==null?void 0:i.treatment_verdict)==="SAFE"?"var(--green-safe)":(i==null?void 0:i.treatment_verdict)==="CONTRAINDICATED"?"var(--red-critical)":(i==null?void 0:i.treatment_verdict)==="CAUTION"?"var(--amber-warning)":"var(--border-default)";return s.jsxs("div",{style:{padding:14,borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-default)"},children:[s.jsxs("div",{style:{fontSize:11,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--purple-ai)",marginBottom:10,display:"flex",alignItems:"center",gap:6},children:[s.jsx(cl,{size:12})," Treatment Safety Check"]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsx("input",{className:"input-dark",placeholder:'e.g. "morphine 4mg IV" or "ibuprofen"',value:t,onChange:c=>n(c.target.value),onKeyDown:c=>c.key==="Enter"&&a()}),s.jsx("button",{className:"btn-primary",onClick:a,disabled:r||!t.trim()||!e,style:{flexShrink:0,padding:"9px 14px"},children:r?s.jsx("div",{className:"spinner"}):s.jsx(kc,{size:13})})]}),i&&s.jsxs("div",{className:"fade-up",style:{marginTop:12,padding:12,borderRadius:8,border:`1px solid ${u}40`,background:u+"08"},children:[s.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:s.jsx(Ep,{verdict:i.treatment_verdict})}),s.jsx("p",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.6,marginBottom:8},children:i.verdict_reason}),(i.allergy_risks||[]).map((c,y)=>s.jsxs("p",{style:{fontSize:11,color:"var(--red-critical)",marginBottom:3},children:["β Allergy cross-reactivity: ",c.substance," β ",c.risk]},y)),(i.drug_interactions||[]).map((c,y)=>s.jsxs("p",{style:{fontSize:11,color:"var(--amber-warning)",marginBottom:3},children:["π Interaction: ",c.drug_a," + ",c.drug_b," β ",c.interaction]},y)),(i.safe_alternatives||[]).length>0&&s.jsxs("p",{style:{fontSize:11,color:"var(--green-safe)",marginTop:6},children:["β Consider: ",i.safe_alternatives.join(", ")]})]})]})}function _p({data:e,patient:t}){var k,S,j,M,f,d,p,g,E;if(!e)return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Emergency Brief"})}),s.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:30,gap:12,color:"var(--text-tertiary)",textAlign:"center"},children:[s.jsx(Yi,{size:36,style:{opacity:.4}}),s.jsx("p",{style:{fontSize:13},children:"Run emergency snapshot to generate brief"}),t&&s.jsx(ta,{patientId:t.id})]})]});const{agents:n,deterministic:r,meta:l}=e,i=(n==null?void 0:n.triage)||{},o=(n==null?void 0:n.contraindication)||{},a=(n==null?void 0:n.labs)||{},u=(n==null?void 0:n.differentials)||{},c=(n==null?void 0:n.action_protocol)||{},y=(r==null?void 0:r.snapshot)||"";r!=null&&r.risks;const h=(r==null?void 0:r.vitals)||{},m=i.severity<=2?"var(--red-critical)":i.severity===3?"var(--amber-warning)":"var(--green-safe)";return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Emergency Brief"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,color:"var(--text-tertiary)"},children:[s.jsx(ip,{size:10})," ",l==null?void 0:l.processing_ms,"ms",(l==null?void 0:l.gemini_enabled)&&s.jsx("span",{style:{color:"var(--purple-ai)",fontWeight:700},children:"Β· AI"})]})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"12px 14px"},children:[c.primary_objective&&s.jsxs("div",{className:"fade-up directive-banner",style:{padding:"14px 18px",borderRadius:12,marginBottom:20,boxShadow:"0 8px 24px rgba(2, 132, 199, 0.25)",position:"relative",overflow:"hidden"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:900,textTransform:"uppercase",opacity:.9,letterSpacing:"0.12em",marginBottom:6},children:"Primary Clinical Directive"}),s.jsx("div",{style:{fontSize:16,fontWeight:800,lineHeight:1.3},children:c.primary_objective}),s.jsx(Zap,{size:40,style:{position:"absolute",right:-10,bottom:-10,opacity:.1,transform:"rotate(15deg)"}})]}),s.jsxs("div",{style:{display:"flex",gap:10,marginBottom:20},children:[s.jsxs("div",{style:{flex:1,background:m+"15",border:`2px solid ${m}`,borderRadius:12,padding:"12px",textAlign:"center"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:800,color:m,textTransform:"uppercase"},children:"ESI Severity"}),s.jsx("div",{style:{fontSize:28,fontWeight:900,color:m},children:i.severity||"?"}),s.jsx("div",{style:{fontSize:10,fontWeight:700,color:m},children:i.severity_label})]}),s.jsxs("div",{style:{flex:1,background:"var(--bg-base)",border:"1px solid var(--border-subtle)",borderRadius:12,padding:"12px",display:"flex",flexDirection:"column",justifyContent:"center"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:800,color:"var(--text-tertiary)",textTransform:"uppercase"},children:"Disposition"}),s.jsx("div",{style:{fontSize:14,fontWeight:800,color:"var(--blue-accent)"},children:c.disposition||"PENDING"})]})]}),(((k=i.time_critical_flags)==null?void 0:k.length)>0||((S=i.do_not_delay)==null?void 0:S.length)>0)&&s.jsxs(_t,{title:"Immediate Threats",icon:s.jsx(cl,{size:14}),accent:"var(--red-critical)",children:[s.jsx("div",{className:"pulse-critical",style:{borderRadius:8,padding:4},children:(i.time_critical_flags||[]).map((v,w)=>s.jsx(_n,{text:v,severity:"critical"},w))}),(i.do_not_delay||[]).map((v,w)=>s.jsx(_n,{text:`β‘ NOW: ${v}`,severity:"warning"},w))]}),(((j=o.allergy_risks)==null?void 0:j.length)>0||((M=o.drug_interactions)==null?void 0:M.length)>0||((f=o.condition_contraindications)==null?void 0:f.length)>0)&&s.jsxs(_t,{title:"Contraindications & Safety",icon:s.jsx(cl,{size:12}),accent:"var(--red-critical)",children:[(o.allergy_risks||[]).map((v,w)=>s.jsx(_n,{text:`Allergy Risk [${v.severity}]: ${v.substance} β ${v.risk}`,severity:"critical"},w)),(o.drug_interactions||[]).map((v,w)=>s.jsx(_n,{text:`Drug Interaction [${v.severity}]: ${v.drug_a} + ${v.drug_b} β ${v.interaction}`,severity:"warning"},w)),(o.condition_contraindications||[]).map((v,w)=>s.jsx(_n,{text:v,severity:"warning"},w))]}),c.agent_reasoning&&s.jsx(_t,{title:"Expert Correlation",icon:s.jsx(Zap,{size:14}),accent:"var(--purple-ai)",children:s.jsxs("div",{style:{padding:"12px",borderRadius:10,background:"var(--purple-ai)05",border:"1px dashed var(--purple-ai)40",fontSize:11,lineHeight:1.5},children:[s.jsx("p",{style:{fontWeight:700,color:"var(--purple-ai)",marginBottom:4},children:"TEAM CONSENSUS"}),c.agent_reasoning.map((v,w)=>s.jsxs("p",{style:{marginBottom:4,display:"flex",gap:6},children:[s.jsx("span",{style:{color:"var(--purple-ai)"},children:"β’"})," ",v]},w))]})}),(((d=a.critical_labs)==null?void 0:d.length)>0||((p=a.abnormal_labs)==null?void 0:p.length)>0)&&s.jsxs(_t,{title:"Lab Findings",icon:s.jsx(gc,{size:12}),accent:"var(--amber-warning)",children:[(a.critical_labs||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",borderRadius:7,background:"rgba(255,45,85,0.08)",border:"1px solid rgba(255,45,85,0.2)"},children:[s.jsxs("div",{style:{fontSize:12,fontWeight:700,color:"var(--red-critical)",fontFamily:"var(--font-mono)"},children:[v.name,": ",v.value]}),s.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:2},children:v.significance}),v.immediate_action&&s.jsxs("div",{style:{fontSize:11,color:"var(--amber-warning)",marginTop:2},children:["β ",v.immediate_action]})]},w)),(a.abnormal_labs||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:6,padding:"5px 10px",borderRadius:7,background:"rgba(255,159,10,0.07)",border:"1px solid rgba(255,159,10,0.2)"},children:[s.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,fontWeight:600,color:"var(--amber-warning)"},children:[v.name,": ",v.value]}),s.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",marginLeft:8},children:v.significance})]},w))]}),Object.keys(h).length>0&&s.jsx(_t,{title:"Extracted Vitals",icon:s.jsx(Yi,{size:12}),accent:"var(--blue-accent)",children:s.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},children:Object.entries(h).map(([v,w])=>s.jsxs("div",{style:{padding:"5px 8px",borderRadius:6,background:"var(--bg-card)",border:"1px solid var(--border-subtle)"},children:[s.jsx("div",{style:{fontSize:10,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em"},children:v}),s.jsx("div",{style:{fontSize:14,fontWeight:700,fontFamily:"var(--font-mono)",color:"var(--text-primary)"},children:String(w)})]},v))})}),((g=u.differentials)==null?void 0:g.length)>0&&s.jsxs(_t,{title:"Differential Diagnosis",icon:s.jsx(Sc,{size:12}),accent:"var(--blue-accent)",children:[(u.differentials||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:8,display:"flex",gap:8,alignItems:"flex-start"},children:[s.jsx("span",{style:{fontSize:16,fontWeight:900,color:"var(--text-tertiary)",minWidth:20},children:w+1}),s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[s.jsx("span",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)"},children:v.diagnosis}),s.jsx("span",{className:`badge ${v.likelihood==="HIGH"?"badge-critical":v.likelihood==="MODERATE"?"badge-moderate":"badge-stable"}`,style:{fontSize:9},children:v.likelihood}),v.must_rule_out&&s.jsx("span",{style:{fontSize:9,color:"var(--red-critical)",fontWeight:700},children:"MUST RULE OUT"})]}),(v.supporting_evidence||[]).map((z,D)=>s.jsxs("p",{style:{fontSize:10,color:"var(--text-secondary)",marginBottom:1},children:["Β· ",z]},D))]})]},w)),u.key_diagnostic_question&&s.jsxs("div",{style:{marginTop:8,padding:"6px 10px",borderRadius:7,background:"rgba(10,132,255,0.08)",border:"1px solid rgba(10,132,255,0.2)",fontSize:11,color:"var(--blue-accent)"},children:["Key question: ",u.key_diagnostic_question]})]}),((E=c.immediate_actions)==null?void 0:E.length)>0&&s.jsxs(_t,{title:"Action Protocol",icon:s.jsx(xc,{size:12}),accent:"var(--green-safe)",children:[(c.immediate_actions||[]).map((v,w)=>s.jsxs("div",{style:{display:"flex",gap:8,marginBottom:6,alignItems:"flex-start"},children:[s.jsx("span",{style:{width:20,height:20,borderRadius:5,background:"var(--green-safe)",color:"#000",fontSize:11,fontWeight:800,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:w+1}),s.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5},children:v})]},w)),(c.drugs_to_avoid||[]).length>0&&s.jsx("div",{style:{marginTop:8},children:c.drugs_to_avoid.map((v,w)=>s.jsxs("p",{style:{fontSize:11,color:"var(--red-critical)",marginBottom:3},children:["β AVOID: ",v.drug," β ",v.reason]},w))}),c.disposition&&s.jsxs("div",{style:{marginTop:10,padding:"6px 12px",borderRadius:7,background:"rgba(10,132,255,0.1)",border:"1px solid rgba(10,132,255,0.3)",fontSize:12,fontWeight:700,color:"var(--blue-accent)"},children:["Disposition: ",c.disposition.replace("_"," ")]})]}),y&&s.jsxs("div",{className:"fade-up",style:{padding:14,borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-default)",marginBottom:14},children:[s.jsx("div",{style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-tertiary)",marginBottom:6},children:"Clinical Summary"}),s.jsx("p",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.7,whiteSpace:"pre-wrap"},children:y})]}),s.jsx(ta,{patientId:t==null?void 0:t.id})]})]})}function zp({onClose:e}){const[t,n]=L.useState(""),[r,l]=L.useState(!1);L.useEffect(()=>{const a=localStorage.getItem("gemini_key");a&&n(a)},[]);const i=()=>{localStorage.setItem("gemini_key",t.trim()),l(!0),setTimeout(()=>{l(!1),e()},1500)},o=()=>{localStorage.removeItem("gemini_key"),n("")};return s.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(6, 13, 26, 0.8)",backdropFilter:"blur(8px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:s.jsxs("div",{className:"card fade-up",style:{width:400,padding:24,position:"relative"},children:[s.jsx("button",{onClick:e,style:{position:"absolute",top:16,right:16,background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer"},children:s.jsx(fp,{size:20})}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[s.jsx("div",{style:{padding:10,background:"rgba(191, 90, 242, 0.1)",borderRadius:8,color:"var(--purple-ai)"},children:s.jsx(vc,{size:24})}),s.jsxs("div",{children:[s.jsx("h3",{style:{fontSize:16,fontWeight:700,margin:0},children:"Provide Your Brain"}),s.jsx("p",{style:{fontSize:12,color:"var(--text-secondary)",margin:"4px 0 0"},children:"Bring Your Own Key (BYOK) to bypass server limits."})]})]}),s.jsx("p",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:20,lineHeight:1.5},children:"Our server's free-tier Gemini key might hit rate limits during high hackathon traffic. Paste your own Gemini 2.0 Flash API key here to guarantee lightning-fast performance. (Your key never leaves your browser)."}),s.jsx("input",{type:"password",value:t,onChange:a=>n(a.target.value),placeholder:"AIzaSy...",className:"input-dark",style:{marginBottom:16,padding:"12px"}}),s.jsxs("div",{style:{display:"flex",gap:10},children:[s.jsx("button",{className:"btn-primary",style:{flex:1,background:r?"var(--green-safe)":"var(--purple-ai)"},onClick:i,children:r?s.jsxs(s.Fragment,{children:[s.jsx(yc,{size:16})," Saved"]}):"Save API Key"}),t&&s.jsx("button",{className:"btn-ghost",onClick:o,children:"Clear"})]})]})})}const Np="";function Tp({patientId:e,previousResults:t}){const[n,r]=L.useState([{role:"assistant",content:"Hello Doctor. I've synthesized the team's findings. You can now ask us specific clinical questions about this case.",type:"initial"}]),[l,i]=L.useState(""),[o,a]=L.useState(!1),u=async()=>{if(!l.trim()||o||!e)return;const c=l.trim();r(y=>[...y,{role:"user",content:c}]),i(""),a(!0);try{const y=localStorage.getItem("gemini_key"),h={"Content-Type":"application/json"};y&&(h["x-gemini-key"]=y);const S=(await(await fetch(`${Np}/consult/${e}`,{method:"POST",headers:h,body:JSON.stringify({question:c,previous_results:t})})).json()).result;if(S)r(j=>[...j,{role:"assistant",content:S.answer,insights:S.specialist_insights,consensus:S.team_consensus}]);else throw new Error("No result")}catch{r(h=>[...h,{role:"assistant",content:"I'm sorry, I couldn't reach the agent team. Please verify your API key."}])}finally{a(!1)}};return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",background:"var(--bg-surface)"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-surface)"},children:s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[s.jsx(bs,{size:18,color:"var(--purple-ai)"}),s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-primary)"},children:"Multi-Agent Consultation"})]})}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:16},children:[n.map((c,y)=>s.jsxs("div",{style:{alignSelf:c.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",gap:10,flexDirection:c.role==="user"?"row-reverse":"row"},children:[s.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:c.role==="user"?"var(--blue-accent)":"var(--purple-ai)15",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:c.role==="user"?"#fff":"var(--purple-ai)"},children:c.role==="user"?s.jsx(dp,{size:14}):s.jsx(bs,{size:14})}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[s.jsx("div",{style:{padding:"10px 14px",borderRadius:12,background:c.role==="user"?"var(--blue-accent)":"var(--bg-base)",color:c.role==="user"?"#fff":"var(--text-primary)",fontSize:12,lineHeight:1.5,boxShadow:c.role==="user"?"0 2px 8px rgba(2, 132, 199, 0.2)":"none"},children:c.content}),c.insights&&s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,marginTop:4},children:c.insights.map((h,m)=>s.jsxs("div",{style:{fontSize:10,padding:"6px 8px",borderRadius:6,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",color:"var(--text-secondary)",display:"flex",gap:6},children:[s.jsxs("span",{style:{fontWeight:800,color:"var(--purple-ai)"},children:[h.agent,":"]}),s.jsx("span",{children:h.note})]},m))})]})]},y)),o&&s.jsxs("div",{style:{alignSelf:"flex-start",display:"flex",gap:10},children:[s.jsx("div",{className:"spinner",style:{width:14,height:14}}),s.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:"Consulting agents..."})]})]}),s.jsx("div",{style:{padding:16,borderTop:"1px solid var(--border-subtle)"},children:s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{type:"text",placeholder:"Ask the team a question...",value:l,onChange:c=>i(c.target.value),onKeyDown:c=>c.key==="Enter"&&u(),style:{width:"100%",padding:"12px 45px 12px 14px",borderRadius:10,border:"1px solid var(--border-default)",outline:"none",fontSize:12,transition:"all 0.2s",background:"var(--bg-base)"}}),s.jsx("button",{onClick:u,disabled:o||!l.trim(),style:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",background:"var(--blue-accent)",color:"#fff",border:"none",width:28,height:28,borderRadius:6,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",opacity:o||!l.trim()?.5:1},children:s.jsx(kc,{size:14})})]})})]})}const ei="",na={triage:"idle",contraindication:"idle",labs:"idle",differentials:"idle",action_protocol:"idle"},zn=["triage","contraindication","labs","differentials","action_protocol"];function Pp(){const[e,t]=L.useState(!0),[n,r]=L.useState(!1),[l,i]=L.useState(!1),[o,a]=L.useState([]),[u,c]=L.useState(!1),[y,h]=L.useState(null),[m,k]=L.useState(!1),[S,j]=L.useState(na),[M,f]=L.useState({}),[d,p]=L.useState(null),[g,E]=L.useState("orchestrate"),[v,w]=L.useState("General"),z=L.useCallback(async()=>{c(!0);try{const he=await(await fetch(`${ei}/patients`)).json();a(he.patients||[])}catch{a([])}finally{c(!1)}},[]);L.useEffect(()=>{z()},[z]);const D=$=>{h($),p(null),j(na),f({}),E("orchestrate")},P=async $=>{const he=$.target.files[0];if(!he)return;const nt=new FormData;nt.append("file",he);try{const Ct=localStorage.getItem("gemini_key"),rt=Ct?{"x-gemini-key":Ct}:{},Qe=await fetch(`${ei}/patients/upload`,{method:"POST",body:nt,headers:rt});if(Qe.ok)z();else{const C=await Qe.json();alert(`Upload failed: ${C.detail||"Internal Server Error"}`)}}catch(Ct){alert(`Network error during upload: ${Ct.message}`)}$.target.value=""},pe=async($=null)=>{var rt,Qe;const he=$&&$.nativeEvent,nt=$&&!he?$:y;if(!nt||m)return;k(!0),p(null),f({}),(async()=>{for(let C=0;C<zn.length;C++){const N=zn[C];j(T=>({...T,[N]:"working"})),await new Promise(T=>setTimeout(T,180))}})();try{const C=localStorage.getItem("gemini_key"),N={"Content-Type":"application/json"};C&&(N["x-gemini-key"]=C);const T=await fetch(`${ei}/orchestrate/${nt.id}`,{method:"POST",headers:N});if(!T.ok)throw new Error("API error");const A=await T.json();for(let B=0;B<zn.length;B++){const Be=zn[B];await new Promise(te=>setTimeout(te,120)),j(te=>({...te,[Be]:"complete"})),f(te=>{var Ut;return{...te,[Be]:(Ut=A.agents)==null?void 0:Ut[Be]}})}if(p(A),(Qe=(rt=A.agents)==null?void 0:rt.triage)!=null&&Qe.severity){const B=A.agents.triage.severity,Be=B<=2?"critical":B===3?"moderate":"stable";h(te=>te&&{...te,risk_level:Be})}}catch{zn.forEach(C=>{j(N=>({...N,[C]:"error"}))})}finally{k(!1)}};return e?s.jsx(pp,{onStart:()=>{t(!1),r(!0)}}):n?s.jsx(hp,{onComplete:()=>r(!1)}):s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100vh",overflow:"hidden"},children:[s.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 20px",height:48,flexShrink:0,background:"var(--bg-surface)",borderBottom:"1px solid var(--border-subtle)",zIndex:10},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[s.jsx("div",{style:{animation:"heartbeat 1.4s infinite",color:"var(--red-critical)"},children:s.jsx(Un,{size:20})}),s.jsx("span",{style:{fontWeight:800,fontSize:15,letterSpacing:"-0.02em"},children:"CodeBlue Context"}),s.jsx("span",{style:{fontSize:10,fontWeight:600,padding:"2px 8px",borderRadius:99,background:"rgba(255,45,85,0.15)",color:"var(--red-critical)",border:"1px solid rgba(255,45,85,0.3)",letterSpacing:"0.05em"},children:"EMERGENCY INTELLIGENCE"})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,fontSize:11,color:"var(--text-tertiary)"},children:[s.jsx("button",{onClick:()=>i(!0),className:"btn-ghost",style:{color:"var(--purple-ai)",borderColor:"rgba(191,90,242,0.3)",padding:"6px 12px"},children:"π Provide API Key"}),s.jsxs("button",{className:"btn-demo",onClick:()=>{const $=o.find(he=>he.id==="CB-001")||o[0];$&&(D($),setTimeout(()=>pe($),50))},style:{padding:"6px 14px",borderRadius:6,fontWeight:700,cursor:"pointer",background:"var(--blue-accent)",color:"#fff",border:"none",transition:"all 0.2s",display:"flex",alignItems:"center",gap:"6px"},onMouseOver:$=>$.currentTarget.style.filter="brightness(1.1)",onMouseOut:$=>$.currentTarget.style.filter="brightness(1)",children:[s.jsx(Un,{size:14})," Run Live Demo"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"var(--green-safe)",fontWeight:700},children:"β"})," System Online"]}),s.jsxs("span",{children:[o.length," patients"]})]})]}),s.jsxs("div",{style:{flex:1,display:"grid",gridTemplateColumns:"240px 420px 1fr",overflow:"hidden"},children:[s.jsx("div",{style:{borderRight:"1px solid var(--border-subtle)",overflow:"hidden",display:"flex",flexDirection:"column"},children:s.jsx(vp,{patients:o,selected:y,onSelect:D,onUpload:P,loading:u})}),s.jsxs("div",{style:{borderRight:"1px solid var(--border-subtle)",overflow:"hidden",display:"flex",flexDirection:"column"},children:[s.jsxs("div",{style:{display:"flex",background:"var(--bg-base)",padding:"4px 4px 0",borderBottom:"1px solid var(--border-subtle)"},children:[s.jsx("button",{onClick:()=>E("orchestrate"),style:{flex:1,padding:"10px",fontSize:11,fontWeight:700,cursor:"pointer",border:"none",background:g==="orchestrate"?"var(--bg-surface)":"transparent",color:g==="orchestrate"?"var(--blue-accent)":"var(--text-secondary)",borderRadius:"8px 8px 0 0",borderBottom:g==="orchestrate"?"2px solid var(--blue-accent)":"none"},children:"ORCHESTRATION"}),s.jsx("button",{onClick:()=>E("consult"),style:{flex:1,padding:"10px",fontSize:11,fontWeight:700,cursor:"pointer",border:"none",background:g==="consult"?"var(--bg-surface)":"transparent",color:g==="consult"?"var(--purple-ai)":"var(--text-secondary)",borderRadius:"8px 8px 0 0",borderBottom:g==="consult"?"2px solid var(--purple-ai)":"none"},children:"ADVANCED CONSULT"})]}),s.jsx("div",{style:{flex:1,overflow:"hidden"},children:g==="orchestrate"?s.jsx(jp,{patient:y,agentStatuses:S,agentResults:M,onRun:pe,running:m,focus:v,setFocus:w}):s.jsx(Tp,{patientId:y==null?void 0:y.id,previousResults:M})})]}),s.jsx("div",{style:{overflow:"hidden",display:"flex",flexDirection:"column"},children:s.jsx(_p,{data:d,patient:y})})]}),l&&s.jsx(zp,{onClose:()=>i(!1)})]})}ti.createRoot(document.getElementById("root")).render(s.jsx(Bc.StrictMode,{children:s.jsx(Pp,{})}));
|
|
|
|
| 177 |
*
|
| 178 |
* This source code is licensed under the ISC license.
|
| 179 |
* See the LICENSE file in the root directory of this source tree.
|
| 180 |
+
*/const wc=V("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);function pp({onStart:e}){return s.jsxs("div",{className:"welcome-screen",children:[s.jsxs("div",{style:{marginBottom:32,position:"relative"},children:[s.jsx("div",{style:{width:80,height:80,borderRadius:"50%",background:"rgba(255,45,85,0.12)",border:"2px solid rgba(255,45,85,0.4)",display:"flex",alignItems:"center",justifyContent:"center",animation:"heartbeat 1.4s ease-in-out infinite",margin:"0 auto 20px"},children:s.jsx(Un,{size:36,color:"var(--red-critical)"})}),s.jsx("svg",{width:"240",height:"40",viewBox:"0 0 240 40",style:{margin:"0 auto",display:"block"},children:s.jsx("polyline",{points:"0,20 30,20 45,5 52,35 60,5 70,20 100,20 115,20 120,2 126,38 132,2 138,20 180,20 240,20",fill:"none",stroke:"var(--red-critical)",strokeWidth:"1.5",strokeDasharray:"400",strokeDashoffset:"400",style:{animation:"ekg 2s ease forwards 0.3s"}})})]}),s.jsx("h1",{style:{fontSize:42,fontWeight:900,letterSpacing:"-0.03em",background:"linear-gradient(135deg, #0f172a 30%, #475569)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",marginBottom:8},children:"CodeBlue Context"}),s.jsx("p",{style:{fontSize:16,color:"var(--text-secondary)",marginBottom:32,maxWidth:420,lineHeight:1.6},children:"Emergency clinical intelligence. Five AI agents. One life-saving brief."}),s.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",justifyContent:"center",marginBottom:40},children:[{icon:s.jsx(Un,{size:13}),label:"5-Agent Orchestration"},{icon:s.jsx(ap,{size:13}),label:"Contraindication Guardian"},{icon:s.jsx(np,{size:13}),label:"Explainable AI Reasoning"}].map(t=>s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 14px",borderRadius:99,background:"rgba(10,132,255,0.08)",border:"1px solid rgba(10,132,255,0.2)",color:"var(--blue-accent)",fontSize:12,fontWeight:600},children:[t.icon,t.label]},t.label))}),s.jsxs("button",{className:"btn-danger",style:{maxWidth:260},onClick:e,children:[s.jsx(Un,{size:16})," Enter Emergency System"]}),s.jsx("p",{style:{marginTop:20,fontSize:11,color:"var(--text-tertiary)"},children:"For clinical decision support only β not a substitute for physician judgment"})]})}function hp({onComplete:e}){return s.jsx("div",{className:"welcome-screen",children:s.jsxs("div",{className:"fade-up",style:{maxWidth:800,width:"100%"},children:[s.jsx("h1",{style:{fontSize:32,fontWeight:800,marginBottom:10,letterSpacing:"-0.03em",color:"var(--text-primary)"},children:"How CodeBlue Context Works"}),s.jsx("p",{style:{color:"var(--text-secondary)",fontSize:16,marginBottom:40},children:"3 simple steps to transform messy clinical records into structured emergency intelligence."}),s.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:20,marginBottom:40,textAlign:"left"},children:[s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.1s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(10,132,255,0.1)",borderRadius:10,color:"var(--blue-accent)",display:"inline-block",marginBottom:16},children:s.jsx(sp,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"1. Upload Anything"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:"Doctors don't have structured JSON. Drop a raw clinical PDF, Word Doc, or photo into the dropzone. Our vision extraction system instantly parses it."})]}),s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.2s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(255,45,85,0.1)",borderRadius:10,color:"var(--red-critical)",display:"inline-block",marginBottom:16},children:s.jsx(op,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"2. 5-Agent Orchestration"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:"The record is passed sequentially through 5 specialized AI agents (Triage, Contraindication, Labs, Differentials, Action Protocol) to extract hidden insights."})]}),s.jsxs("div",{className:"card fade-up",style:{padding:24,animationDelay:"0.3s"},children:[s.jsx("div",{style:{padding:12,background:"rgba(191,90,242,0.1)",borderRadius:10,color:"var(--purple-ai)",display:"inline-block",marginBottom:16},children:s.jsx(vc,{size:24})}),s.jsx("h3",{style:{fontSize:16,fontWeight:700,marginBottom:8,color:"var(--text-primary)"},children:"3. Provide Your Brain"}),s.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:'To bypass our hackathon server rate limits, use the "Provide API Key" button in the dashboard navbar to safely inject your own Gemini key directly from your browser.'})]})]}),s.jsxs("button",{className:"btn-primary fade-up",style:{animationDelay:"0.4s",padding:"14px 28px",fontSize:16,borderRadius:99},onClick:e,children:["Enter Dashboard ",s.jsx(tp,{size:18})]})]})})}const mp={critical:"var(--red-critical)",moderate:"var(--amber-warning)",stable:"var(--green-safe)"},yp={critical:"badge-critical",moderate:"badge-moderate",stable:"badge-stable"};function gp({patient:e,selected:t,onClick:n}){const r=e.risk_level||"stable";return s.jsxs("div",{onClick:()=>n(e),style:{padding:"12px 14px",borderRadius:10,cursor:"pointer",marginBottom:6,background:t?"rgba(10,132,255,0.12)":"var(--bg-surface)",border:`1px solid ${t?"rgba(10,132,255,0.4)":"var(--border-subtle)"}`,transition:"all 0.15s"},children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-primary)"},children:e.display_name}),s.jsx("span",{className:`badge ${yp[r]||"badge-unknown"}`,style:{fontSize:10},children:r})]}),s.jsxs("div",{style:{fontSize:11,color:"var(--text-secondary)",display:"flex",gap:10},children:[s.jsxs("span",{children:[e.age,"y ",e.gender]}),s.jsx("span",{children:"Β·"}),s.jsx("span",{style:{color:mp[r]},children:(e.conditions||[]).join(", ")||"No conditions"})]}),s.jsxs("div",{style:{fontSize:10,color:"var(--text-tertiary)",marginTop:3},children:[e.allergy_count," allergies Β· ",e.med_count," meds"]})]})}function vp({patients:e,selected:t,onSelect:n,onUpload:r,loading:l}){return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsxs("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,letterSpacing:"0.05em",color:"var(--text-secondary)",textTransform:"uppercase"},children:"Patients"}),s.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:[e.length," loaded"]})]}),s.jsxs("label",{style:{cursor:"pointer",display:"block",margin:"10px 0 4px 0"},children:[s.jsx("input",{type:"file",accept:".json,.pdf,.txt,.png,.jpg",style:{display:"none"},onChange:r}),s.jsxs("div",{style:{width:"100%",padding:"16px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",border:"1px dashed var(--border-subtle)",borderRadius:"12px",background:"var(--bg-surface)",transition:"all 0.2s",color:"var(--text-secondary)"},onMouseOver:i=>{i.currentTarget.style.borderColor="rgba(10,132,255,0.6)",i.currentTarget.style.background="rgba(10,132,255,0.05)",i.currentTarget.style.color="var(--text-primary)"},onMouseOut:i=>{i.currentTarget.style.borderColor="var(--border-subtle)",i.currentTarget.style.background="var(--bg-surface)",i.currentTarget.style.color="var(--text-secondary)"},children:[s.jsx(cp,{size:20,style:{marginBottom:"6px"}}),s.jsx("span",{style:{fontSize:12,fontWeight:600},children:"Upload Patient Record"}),s.jsx("span",{style:{fontSize:10,opacity:.6,marginTop:"2px"},children:"PDF, Doc, Image, JSON"})]})]})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"10px 12px"},children:[l&&s.jsx("div",{style:{textAlign:"center",padding:20,color:"var(--text-tertiary)",fontSize:12},children:"Loading..."}),!l&&e.length===0&&s.jsxs("div",{style:{textAlign:"center",padding:20,color:"var(--text-tertiary)",fontSize:12},children:[s.jsx(Yi,{size:24,style:{margin:"0 auto 8px",display:"block"}}),"No patients loaded"]}),e.map(i=>s.jsx(gp,{patient:i,selected:(t==null?void 0:t.id)===i.id,onClick:n},i.id))]})]})}const bl=[{key:"triage",label:"Triage Agent",icon:s.jsx(wc,{size:14}),desc:"Severity classification & chief complaint"},{key:"contraindication",label:"Contraindication Guardian",icon:s.jsx(cl,{size:14}),desc:"Drug interactions & allergy risks"},{key:"labs",label:"Lab Interpreter",icon:s.jsx(gc,{size:14}),desc:"Critical lab findings & patterns"},{key:"differentials",label:"Differential Diagnosis",icon:s.jsx(Sc,{size:14}),desc:"Top 3 differentials from evidence"},{key:"action_protocol",label:"Action Protocol",icon:s.jsx(xc,{size:14}),desc:"Immediate ordered steps & disposition"}],xp={triage:"Analyzing vitals and identifying life-threats...",contraindication:"Scanning history for high-risk medication overlaps...",labs:"Interpreting metabolic panels and blood gases...",differentials:"Cross-referencing symptoms with clinical evidence...",action_protocol:"Synthesizing final emergency stabilization steps..."};function kp({status:e}){return e==="working"?s.jsx("div",{className:"spinner"}):e==="complete"?s.jsx(yc,{size:15,color:"var(--green-safe)"}):e==="error"?s.jsx(ea,{size:15,color:"var(--red-critical)"}):s.jsx(ea,{size:15,color:"var(--text-tertiary)"})}function Sp({agent:e,status:t,result:n,expanded:r,onToggle:l}){const i=t==="idle"?"agent-idle":t==="working"?"agent-working":t==="complete"?"agent-complete":"agent-error",o=n&&t==="complete";return s.jsxs("div",{className:`card ${i}`,style:{marginBottom:8,transition:"all 0.3s"},children:[s.jsxs("div",{onClick:o?l:void 0,style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",cursor:o?"pointer":"default"},children:[s.jsx("div",{style:{width:28,height:28,borderRadius:7,background:"rgba(255,255,255,0.04)",display:"flex",alignItems:"center",justifyContent:"center",color:t==="complete"?"var(--green-safe)":t==="working"?"var(--blue-accent)":"var(--text-tertiary)"},children:e.icon}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontSize:12,fontWeight:600,color:t==="idle"?"var(--text-secondary)":"var(--text-primary)"},children:e.label}),s.jsx("div",{style:{fontSize:10,color:t==="working"?"var(--blue-accent)":"var(--text-tertiary)",fontWeight:t==="working"?600:400},children:t==="working"?xp[e.key]:e.desc})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[s.jsx(kp,{status:t}),o&&(r?s.jsx(lp,{size:12,color:"var(--text-tertiary)"}):s.jsx(rp,{size:12,color:"var(--text-tertiary)"}))]})]}),o&&r&&s.jsx("div",{style:{padding:"0 14px 12px",borderTop:"1px solid var(--border-subtle)",paddingTop:10},className:"fade-in",children:s.jsx(wp,{agentKey:e.key,result:n})})]})}function wp({agentKey:e,result:t}){const n={fontSize:11,color:"var(--text-secondary)",lineHeight:1.6},r=(l,i)=>s.jsx("span",{style:{background:i+"20",color:i,border:`1px solid ${i}40`,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:700,marginRight:4},children:l});return e==="triage"?s.jsxs("div",{style:n,children:[r(`ESI ${t.severity}: ${t.severity_label}`,t.severity<=2?"var(--red-critical)":t.severity===3?"var(--amber-warning)":"var(--green-safe)"),s.jsx("p",{style:{marginTop:6},children:t.chief_complaint}),(t.time_critical_flags||[]).map((l,i)=>s.jsxs("p",{children:["β‘ ",l]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="contraindication"?s.jsxs("div",{style:n,children:[r(t.treatment_verdict,t.treatment_verdict==="SAFE"?"var(--green-safe)":t.treatment_verdict==="CONTRAINDICATED"?"var(--red-critical)":"var(--amber-warning)"),s.jsx("p",{style:{marginTop:6},children:t.verdict_reason}),(t.allergy_risks||[]).slice(0,2).map((l,i)=>s.jsxs("p",{style:{color:"var(--red-critical)"},children:["β Allergy: ",l.substance," β ",l.risk]},i)),(t.drug_interactions||[]).slice(0,2).map((l,i)=>s.jsxs("p",{style:{color:"var(--amber-warning)"},children:["π ",l.drug_a," + ",l.drug_b,": ",l.interaction]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="labs"?s.jsxs("div",{style:n,children:[(t.critical_labs||[]).map((l,i)=>s.jsxs("p",{style:{color:"var(--red-critical)"},children:["π΄ ",l.name,": ",l.value," β ",l.significance]},i)),(t.abnormal_labs||[]).map((l,i)=>s.jsxs("p",{style:{color:"var(--amber-warning)"},children:["π‘ ",l.name,": ",l.value," β ",l.significance]},i)),(t.immediate_concerns||[]).slice(0,2).map((l,i)=>s.jsxs("p",{children:["β ",l]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="differentials"?s.jsxs("div",{style:n,children:[(t.differentials||[]).map((l,i)=>s.jsxs("div",{style:{marginBottom:6},children:[r(l.likelihood,l.likelihood==="HIGH"?"var(--red-critical)":l.likelihood==="MODERATE"?"var(--amber-warning)":"var(--text-secondary)"),s.jsx("span",{style:{fontWeight:600,color:"var(--text-primary)"},children:l.diagnosis}),l.must_rule_out&&s.jsx("span",{style:{color:"var(--red-critical)",fontSize:10,marginLeft:6},children:"MUST RULE OUT"})]},i)),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):e==="action_protocol"?s.jsxs("div",{style:n,children:[(t.immediate_actions||[]).map((l,i)=>s.jsxs("p",{children:[i+1,". ",l]},i)),t.disposition&&s.jsxs("p",{style:{marginTop:6,fontWeight:700,color:"var(--blue-accent)"},children:["Disposition β ",t.disposition]}),t.agent_reasoning&&s.jsxs("div",{style:{marginTop:8,padding:8,background:"var(--bg-base)",borderRadius:6,borderLeft:"3px solid var(--blue-accent)"},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,marginBottom:4,color:"var(--text-primary)"},children:"AGENT REASONING"}),t.agent_reasoning.map((l,i)=>s.jsxs("p",{style:{fontSize:10},children:["β’ ",l]},i))]})]}):null}function jp({agentStatuses:e,agentResults:t,onRun:n,patient:r,running:l,focus:i,setFocus:o}){const[a,u]=L.useState({}),c=h=>u(m=>({...m,[h]:!m[h]})),y=bl.filter(h=>e[h.key]==="complete").length;return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Agent Orchestration"}),l&&s.jsxs("span",{style:{fontSize:11,color:"var(--blue-accent)",display:"flex",alignItems:"center",gap:5},children:[s.jsx("div",{className:"spinner",style:{width:12,height:12}})," ",y,"/5 complete"]})]})}),s.jsxs("div",{style:{padding:"12px 14px",flex:1,overflowY:"auto"},children:[!r&&s.jsx("div",{style:{textAlign:"center",padding:"40px 20px",color:"var(--text-tertiary)",fontSize:13},children:"Select a patient to run emergency analysis"}),r&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{style:{marginBottom:14},children:[s.jsx("p",{style:{fontSize:9,fontWeight:800,color:"var(--text-tertiary)",textTransform:"uppercase",marginBottom:6},children:"Clinical Focus"}),s.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:["General","Cardiac","Trauma","Respiratory","Neuro"].map(h=>s.jsx("div",{onClick:()=>!l&&(o==null?void 0:o(h)),style:{padding:"4px 10px",borderRadius:20,fontSize:10,fontWeight:700,cursor:"pointer",background:i===h?"var(--blue-accent)":"var(--bg-surface)",color:i===h?"#fff":"var(--text-secondary)",border:i===h?"none":"1px solid var(--border-subtle)",transition:"all 0.2s"},children:h},h))})]}),bl.map(h=>s.jsx(Sp,{agent:h,status:e[h.key]||"idle",result:t[h.key],expanded:a[h.key],onToggle:()=>c(h.key)},h.key)),s.jsx("button",{className:"btn-danger pulse-on-hover",style:{marginTop:10,width:"100%"},onClick:n,disabled:l,children:l?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"spinner"})," AI Agents Orchestrating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(wc,{size:15})," Analyze Patient Record"]})}),l||Object.keys(t).length>0?s.jsxs("div",{style:{marginTop:20,borderTop:"1px solid var(--border-subtle)",paddingTop:16},children:[s.jsx("p",{style:{fontSize:10,fontWeight:700,color:"var(--text-tertiary)",textTransform:"uppercase",marginBottom:10,letterSpacing:"0.05em"},children:"Collaboration Thread"}),s.jsx("div",{style:{background:"var(--bg-surface)",padding:12,borderRadius:8,border:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono)",fontSize:10,lineHeight:1.5,maxHeight:120,overflowY:"auto"},children:bl.filter(h=>t[h.key]||e[h.key]==="working").map((h,m)=>{var k,S;return s.jsxs("div",{style:{marginBottom:6},className:"fade-in",children:[s.jsxs("span",{style:{color:"var(--blue-accent)",fontWeight:700},children:["[",h.label,"]: "]}),s.jsx("span",{style:{color:"var(--text-secondary)"},children:e[h.key]==="working"?"Transmitting findings...":((S=(k=t[h.key])==null?void 0:k.agent_reasoning)==null?void 0:S[0])||"Processed record successfully."})]},m)})})]}):null]})]})]})}const Cp="";function _t({title:e,icon:t,children:n,accent:r}){return s.jsxs("div",{className:"fade-up",style:{marginBottom:14,borderRadius:10,background:"var(--bg-surface)",border:`1px solid ${r?r+"30":"var(--border-subtle)"}`,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"8px 14px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid var(--border-subtle)",background:r?r+"08":"transparent"},children:[s.jsx("span",{style:{color:r||"var(--text-secondary)"},children:t}),s.jsx("span",{style:{fontSize:11,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:r||"var(--text-secondary)"},children:e})]}),s.jsx("div",{style:{padding:"10px 14px"},children:n})]})}function _n({text:e,severity:t}){const n=t==="critical"?"var(--red-critical)":t==="warning"?"var(--amber-warning)":"var(--blue-accent)";return s.jsxs("div",{style:{display:"flex",gap:8,padding:"7px 10px",borderRadius:7,marginBottom:6,background:n+"12",border:`1px solid ${n}30`},children:[s.jsx(up,{size:13,style:{color:n,flexShrink:0,marginTop:2}}),s.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5},children:e})]})}function Ep({verdict:e}){const t=`badge verdict-${(e||"not_evaluated").toLowerCase()}`,n={SAFE:"β SAFE",CAUTION:"β CAUTION",CONTRAINDICATED:"β CONTRAINDICATED",NOT_EVALUATED:"? NOT EVALUATED"};return s.jsx("span",{className:t,children:n[e]||e})}function ta({patientId:e}){const[t,n]=L.useState(""),[r,l]=L.useState(!1),[i,o]=L.useState(null),a=async()=>{if(!(!t.trim()||!e)){l(!0),o(null);try{const c=localStorage.getItem("gemini_key"),y={"Content-Type":"application/json"};c&&(y["x-gemini-key"]=c);const m=await(await fetch(`${Cp}/check-treatment/${e}`,{method:"POST",headers:y,body:JSON.stringify({treatment:t.trim()})})).json();o(m.result)}catch{o({treatment_verdict:"NOT_EVALUATED",verdict_reason:"Service unavailable."})}finally{l(!1)}}},u=(i==null?void 0:i.treatment_verdict)==="SAFE"?"var(--green-safe)":(i==null?void 0:i.treatment_verdict)==="CONTRAINDICATED"?"var(--red-critical)":(i==null?void 0:i.treatment_verdict)==="CAUTION"?"var(--amber-warning)":"var(--border-default)";return s.jsxs("div",{style:{padding:14,borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-default)"},children:[s.jsxs("div",{style:{fontSize:11,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--purple-ai)",marginBottom:10,display:"flex",alignItems:"center",gap:6},children:[s.jsx(cl,{size:12})," Treatment Safety Check"]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsx("input",{className:"input-dark",placeholder:'e.g. "morphine 4mg IV" or "ibuprofen"',value:t,onChange:c=>n(c.target.value),onKeyDown:c=>c.key==="Enter"&&a()}),s.jsx("button",{className:"btn-primary",onClick:a,disabled:r||!t.trim()||!e,style:{flexShrink:0,padding:"9px 14px"},children:r?s.jsx("div",{className:"spinner"}):s.jsx(kc,{size:13})})]}),i&&s.jsxs("div",{className:"fade-up",style:{marginTop:12,padding:12,borderRadius:8,border:`1px solid ${u}40`,background:u+"08"},children:[s.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:s.jsx(Ep,{verdict:i.treatment_verdict})}),s.jsx("p",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.6,marginBottom:8},children:i.verdict_reason}),(i.allergy_risks||[]).map((c,y)=>s.jsxs("p",{style:{fontSize:11,color:"var(--red-critical)",marginBottom:3},children:["β Allergy cross-reactivity: ",c.substance," β ",c.risk]},y)),(i.drug_interactions||[]).map((c,y)=>s.jsxs("p",{style:{fontSize:11,color:"var(--amber-warning)",marginBottom:3},children:["π Interaction: ",c.drug_a," + ",c.drug_b," β ",c.interaction]},y)),(i.safe_alternatives||[]).length>0&&s.jsxs("p",{style:{fontSize:11,color:"var(--green-safe)",marginTop:6},children:["β Consider: ",i.safe_alternatives.join(", ")]})]})]})}function _p({data:e,patient:t}){var k,S,j,M,f,d,p,g,E;if(!e)return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)"},children:s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Emergency Brief"})}),s.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:30,gap:12,color:"var(--text-tertiary)",textAlign:"center"},children:[s.jsx(Yi,{size:36,style:{opacity:.4}}),s.jsx("p",{style:{fontSize:13},children:"Run emergency snapshot to generate brief"}),t&&s.jsx(ta,{patientId:t.id})]})]});const{agents:n,deterministic:r,meta:l}=e,i=(n==null?void 0:n.triage)||{},o=(n==null?void 0:n.contraindication)||{},a=(n==null?void 0:n.labs)||{},u=(n==null?void 0:n.differentials)||{},c=(n==null?void 0:n.action_protocol)||{},y=(r==null?void 0:r.snapshot)||"";r!=null&&r.risks;const h=(r==null?void 0:r.vitals)||{},m=i.severity<=2?"var(--red-critical)":i.severity===3?"var(--amber-warning)":"var(--green-safe)";return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[s.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Emergency Brief"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,color:"var(--text-tertiary)"},children:[s.jsx(ip,{size:10})," ",l==null?void 0:l.processing_ms,"ms",(l==null?void 0:l.gemini_enabled)&&s.jsx("span",{style:{color:"var(--purple-ai)",fontWeight:700},children:"Β· AI"})]})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"12px 14px"},children:[c.primary_objective&&s.jsxs("div",{className:"fade-up directive-banner",style:{padding:"14px 18px",borderRadius:12,marginBottom:20,boxShadow:"0 8px 24px rgba(2, 132, 199, 0.25)",position:"relative",overflow:"hidden"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:900,textTransform:"uppercase",opacity:.9,letterSpacing:"0.12em",marginBottom:6},children:"Primary Clinical Directive"}),s.jsx("div",{style:{fontSize:16,fontWeight:800,lineHeight:1.3},children:c.primary_objective}),s.jsx(Zap,{size:40,style:{position:"absolute",right:-10,bottom:-10,opacity:.1,transform:"rotate(15deg)"}})]}),s.jsxs("div",{style:{display:"flex",gap:10,marginBottom:20},children:[s.jsxs("div",{style:{flex:1,background:m+"15",border:`2px solid ${m}`,borderRadius:12,padding:"12px",textAlign:"center"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:800,color:m,textTransform:"uppercase"},children:"ESI Severity"}),s.jsx("div",{style:{fontSize:28,fontWeight:900,color:m},children:i.severity||"?"}),s.jsx("div",{style:{fontSize:10,fontWeight:700,color:m},children:i.severity_label})]}),s.jsxs("div",{style:{flex:1,background:"var(--bg-base)",border:"1px solid var(--border-subtle)",borderRadius:12,padding:"12px",display:"flex",flexDirection:"column",justifyContent:"center"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:800,color:"var(--text-tertiary)",textTransform:"uppercase"},children:"Disposition"}),s.jsx("div",{style:{fontSize:14,fontWeight:800,color:"var(--blue-accent)"},children:c.disposition||"PENDING"})]})]}),(((k=i.time_critical_flags)==null?void 0:k.length)>0||((S=i.do_not_delay)==null?void 0:S.length)>0)&&s.jsxs(_t,{title:"Immediate Threats",icon:s.jsx(cl,{size:14}),accent:"var(--red-critical)",children:[s.jsx("div",{className:"pulse-critical",style:{borderRadius:8,padding:4},children:(i.time_critical_flags||[]).map((v,w)=>s.jsx(_n,{text:v,severity:"critical"},w))}),(i.do_not_delay||[]).map((v,w)=>s.jsx(_n,{text:`β‘ NOW: ${v}`,severity:"warning"},w))]}),(((j=o.allergy_risks)==null?void 0:j.length)>0||((M=o.drug_interactions)==null?void 0:M.length)>0||((f=o.condition_contraindications)==null?void 0:f.length)>0)&&s.jsxs(_t,{title:"Contraindications & Safety",icon:s.jsx(cl,{size:12}),accent:"var(--red-critical)",children:[(o.allergy_risks||[]).map((v,w)=>s.jsx(_n,{text:`Allergy Risk [${v.severity}]: ${v.substance} β ${v.risk}`,severity:"critical"},w)),(o.drug_interactions||[]).map((v,w)=>s.jsx(_n,{text:`Drug Interaction [${v.severity}]: ${v.drug_a} + ${v.drug_b} β ${v.interaction}`,severity:"warning"},w)),(o.condition_contraindications||[]).map((v,w)=>s.jsx(_n,{text:v,severity:"warning"},w))]}),c.agent_reasoning&&s.jsx(_t,{title:"Expert Correlation",icon:s.jsx(Zap,{size:14}),accent:"var(--purple-ai)",children:s.jsxs("div",{style:{padding:"12px",borderRadius:10,background:"var(--purple-ai)05",border:"1px dashed var(--purple-ai)40",fontSize:11,lineHeight:1.5},children:[s.jsx("p",{style:{fontWeight:700,color:"var(--purple-ai)",marginBottom:4},children:"TEAM CONSENSUS"}),c.agent_reasoning.map((v,w)=>s.jsxs("p",{style:{marginBottom:4,display:"flex",gap:6},children:[s.jsx("span",{style:{color:"var(--purple-ai)"},children:"β’"})," ",v]},w))]})}),(((d=a.critical_labs)==null?void 0:d.length)>0||((p=a.abnormal_labs)==null?void 0:p.length)>0)&&s.jsxs(_t,{title:"Lab Findings",icon:s.jsx(gc,{size:12}),accent:"var(--amber-warning)",children:[(a.critical_labs||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",borderRadius:7,background:"rgba(255,45,85,0.08)",border:"1px solid rgba(255,45,85,0.2)"},children:[s.jsxs("div",{style:{fontSize:12,fontWeight:700,color:"var(--red-critical)",fontFamily:"var(--font-mono)"},children:[v.name,": ",v.value]}),s.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:2},children:v.significance}),v.immediate_action&&s.jsxs("div",{style:{fontSize:11,color:"var(--amber-warning)",marginTop:2},children:["β ",v.immediate_action]})]},w)),(a.abnormal_labs||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:6,padding:"5px 10px",borderRadius:7,background:"rgba(255,159,10,0.07)",border:"1px solid rgba(255,159,10,0.2)"},children:[s.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,fontWeight:600,color:"var(--amber-warning)"},children:[v.name,": ",v.value]}),s.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",marginLeft:8},children:v.significance})]},w))]}),Object.keys(h).length>0&&s.jsx(_t,{title:"Extracted Vitals",icon:s.jsx(Yi,{size:12}),accent:"var(--blue-accent)",children:s.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},children:Object.entries(h).map(([v,w])=>s.jsxs("div",{style:{padding:"5px 8px",borderRadius:6,background:"var(--bg-card)",border:"1px solid var(--border-subtle)"},children:[s.jsx("div",{style:{fontSize:10,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em"},children:v}),s.jsx("div",{style:{fontSize:14,fontWeight:700,fontFamily:"var(--font-mono)",color:"var(--text-primary)"},children:String(w)})]},v))})}),((g=u.differentials)==null?void 0:g.length)>0&&s.jsxs(_t,{title:"Differential Diagnosis",icon:s.jsx(Sc,{size:12}),accent:"var(--blue-accent)",children:[(u.differentials||[]).map((v,w)=>s.jsxs("div",{style:{marginBottom:8,display:"flex",gap:8,alignItems:"flex-start"},children:[s.jsx("span",{style:{fontSize:16,fontWeight:900,color:"var(--text-tertiary)",minWidth:20},children:w+1}),s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[s.jsx("span",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)"},children:v.diagnosis}),s.jsx("span",{className:`badge ${v.likelihood==="HIGH"?"badge-critical":v.likelihood==="MODERATE"?"badge-moderate":"badge-stable"}`,style:{fontSize:9},children:v.likelihood}),v.must_rule_out&&s.jsx("span",{style:{fontSize:9,color:"var(--red-critical)",fontWeight:700},children:"MUST RULE OUT"})]}),(v.supporting_evidence||[]).map((z,D)=>s.jsxs("p",{style:{fontSize:10,color:"var(--text-secondary)",marginBottom:1},children:["Β· ",z]},D))]})]},w)),u.key_diagnostic_question&&s.jsxs("div",{style:{marginTop:8,padding:"6px 10px",borderRadius:7,background:"rgba(10,132,255,0.08)",border:"1px solid rgba(10,132,255,0.2)",fontSize:11,color:"var(--blue-accent)"},children:["Key question: ",u.key_diagnostic_question]})]}),((E=c.immediate_actions)==null?void 0:E.length)>0&&s.jsxs(_t,{title:"Action Protocol",icon:s.jsx(xc,{size:12}),accent:"var(--green-safe)",children:[(c.immediate_actions||[]).map((v,w)=>s.jsxs("div",{style:{display:"flex",gap:8,marginBottom:6,alignItems:"flex-start"},children:[s.jsx("span",{style:{width:20,height:20,borderRadius:5,background:"var(--green-safe)",color:"#000",fontSize:11,fontWeight:800,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:w+1}),s.jsx("span",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5},children:v})]},w)),(c.drugs_to_avoid||[]).length>0&&s.jsx("div",{style:{marginTop:8},children:c.drugs_to_avoid.map((v,w)=>s.jsxs("p",{style:{fontSize:11,color:"var(--red-critical)",marginBottom:3},children:["β AVOID: ",v.drug," β ",v.reason]},w))}),c.disposition&&s.jsxs("div",{style:{marginTop:10,padding:"6px 12px",borderRadius:7,background:"rgba(10,132,255,0.1)",border:"1px solid rgba(10,132,255,0.3)",fontSize:12,fontWeight:700,color:"var(--blue-accent)"},children:["Disposition: ",c.disposition.replace("_"," ")]})]}),y&&s.jsxs("div",{className:"fade-up",style:{padding:14,borderRadius:10,background:"var(--bg-surface)",border:"1px solid var(--border-default)",marginBottom:14},children:[s.jsx("div",{style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-tertiary)",marginBottom:6},children:"Clinical Summary"}),s.jsx("p",{style:{fontSize:12,color:"var(--text-primary)",lineHeight:1.7,whiteSpace:"pre-wrap"},children:y})]}),s.jsx(ta,{patientId:t==null?void 0:t.id})]})]})}function zp({onClose:e}){const[t,n]=L.useState(""),[r,l]=L.useState(!1);L.useEffect(()=>{const a=localStorage.getItem("gemini_key");a&&n(a)},[]);const i=()=>{localStorage.setItem("gemini_key",t.trim()),l(!0),setTimeout(()=>{l(!1),e()},1500)},o=()=>{localStorage.removeItem("gemini_key"),n("")};return s.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(6, 13, 26, 0.8)",backdropFilter:"blur(8px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:s.jsxs("div",{className:"card fade-up",style:{width:400,padding:24,position:"relative"},children:[s.jsx("button",{onClick:e,style:{position:"absolute",top:16,right:16,background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer"},children:s.jsx(fp,{size:20})}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[s.jsx("div",{style:{padding:10,background:"rgba(191, 90, 242, 0.1)",borderRadius:8,color:"var(--purple-ai)"},children:s.jsx(vc,{size:24})}),s.jsxs("div",{children:[s.jsx("h3",{style:{fontSize:16,fontWeight:700,margin:0},children:"Provide Your Brain"}),s.jsx("p",{style:{fontSize:12,color:"var(--text-secondary)",margin:"4px 0 0"},children:"Bring Your Own Key (BYOK) to bypass server limits."})]})]}),s.jsx("p",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:20,lineHeight:1.5},children:"Our server's free-tier Gemini key might hit rate limits during high hackathon traffic. Paste your own Gemini 2.0 Flash API key here to guarantee lightning-fast performance. (Your key never leaves your browser)."}),s.jsx("input",{type:"password",value:t,onChange:a=>n(a.target.value),placeholder:"AIzaSy...",className:"input-dark",style:{marginBottom:16,padding:"12px"}}),s.jsxs("div",{style:{display:"flex",gap:10},children:[s.jsx("button",{className:"btn-primary",style:{flex:1,background:r?"var(--green-safe)":"var(--purple-ai)"},onClick:i,children:r?s.jsxs(s.Fragment,{children:[s.jsx(yc,{size:16})," Saved"]}):"Save API Key"}),t&&s.jsx("button",{className:"btn-ghost",onClick:o,children:"Clear"})]})]})})}const Np="";function Tp({patientId:e,previousResults:t}){const[n,r]=L.useState([{role:"assistant",content:"Hello Doctor. I've synthesized the team's findings. You can now ask us specific clinical questions about this case.",type:"initial"}]),[l,i]=L.useState(""),[o,a]=L.useState(!1),u=async()=>{if(!l.trim()||o||!e)return;const c=l.trim();r(y=>[...y,{role:"user",content:c}]),i(""),a(!0);try{const y=localStorage.getItem("gemini_key"),h={"Content-Type":"application/json"};y&&(h["x-gemini-key"]=y);const S=(await(await fetch(`${Np}/consult/${e}`,{method:"POST",headers:h,body:JSON.stringify({question:c,previous_results:t})})).json()).result;if(S)r(j=>[...j,{role:"assistant",content:S.answer,insights:S.specialist_insights,consensus:S.team_consensus}]);else throw new Error("No result")}catch{r(h=>[...h,{role:"assistant",content:"I'm having trouble reaching the clinical AI team. Please ensure you've provided a Gemini API Key in the settings (top right).",insights:[{agent:"System",note:"Connection required for advanced reasoning."}]}])}finally{a(!1)}};return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",background:"var(--bg-surface)"},children:[s.jsx("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-surface)"},children:s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[s.jsx(bs,{size:18,color:"var(--purple-ai)"}),s.jsx("span",{style:{fontWeight:700,fontSize:13,color:"var(--text-primary)"},children:"Multi-Agent Consultation"})]})}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:16},children:[n.map((c,y)=>s.jsxs("div",{style:{alignSelf:c.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",gap:10,flexDirection:c.role==="user"?"row-reverse":"row"},children:[s.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:c.role==="user"?"var(--blue-accent)":"var(--purple-ai)15",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:c.role==="user"?"#fff":"var(--purple-ai)"},children:c.role==="user"?s.jsx(dp,{size:14}):s.jsx(bs,{size:14})}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[s.jsx("div",{style:{padding:"10px 14px",borderRadius:12,background:c.role==="user"?"var(--blue-accent)":"var(--bg-base)",color:c.role==="user"?"#fff":"var(--text-primary)",fontSize:12,lineHeight:1.5,boxShadow:c.role==="user"?"0 2px 8px rgba(2, 132, 199, 0.2)":"none"},children:c.content}),c.insights&&s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,marginTop:4},children:c.insights.map((h,m)=>s.jsxs("div",{style:{fontSize:10,padding:"6px 8px",borderRadius:6,background:"var(--bg-surface)",border:"1px solid var(--border-subtle)",color:"var(--text-secondary)",display:"flex",gap:6},children:[s.jsxs("span",{style:{fontWeight:800,color:"var(--purple-ai)"},children:[h.agent,":"]}),s.jsx("span",{children:h.note})]},m))})]})]},y)),o&&s.jsxs("div",{style:{alignSelf:"flex-start",display:"flex",gap:10},children:[s.jsx("div",{className:"spinner",style:{width:14,height:14}}),s.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:"Consulting agents..."})]})]}),s.jsx("div",{style:{padding:16,borderTop:"1px solid var(--border-subtle)"},children:s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{type:"text",placeholder:"Ask the team a question...",value:l,onChange:c=>i(c.target.value),onKeyDown:c=>c.key==="Enter"&&u(),style:{width:"100%",padding:"12px 45px 12px 14px",borderRadius:10,border:"1px solid var(--border-default)",outline:"none",fontSize:12,transition:"all 0.2s",background:"var(--bg-base)"}}),s.jsx("button",{onClick:u,disabled:o||!l.trim(),style:{position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",background:"var(--blue-accent)",color:"#fff",border:"none",width:28,height:28,borderRadius:6,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",opacity:o||!l.trim()?.5:1},children:s.jsx(kc,{size:14})})]})})]})}const ei="",na={triage:"idle",contraindication:"idle",labs:"idle",differentials:"idle",action_protocol:"idle"},zn=["triage","contraindication","labs","differentials","action_protocol"];function Pp(){const[e,t]=L.useState(!0),[n,r]=L.useState(!1),[l,i]=L.useState(!1),[o,a]=L.useState([]),[u,c]=L.useState(!1),[y,h]=L.useState(null),[m,k]=L.useState(!1),[S,j]=L.useState(na),[M,f]=L.useState({}),[d,p]=L.useState(null),[g,E]=L.useState("orchestrate"),[v,w]=L.useState("General"),z=L.useCallback(async()=>{c(!0);try{const he=await(await fetch(`${ei}/patients`)).json();a(he.patients||[])}catch{a([])}finally{c(!1)}},[]);L.useEffect(()=>{z()},[z]);const D=$=>{h($),p(null),j(na),f({}),E("orchestrate")},P=async $=>{const he=$.target.files[0];if(!he)return;const nt=new FormData;nt.append("file",he);try{const Ct=localStorage.getItem("gemini_key"),rt=Ct?{"x-gemini-key":Ct}:{},Qe=await fetch(`${ei}/patients/upload`,{method:"POST",body:nt,headers:rt});if(Qe.ok)z();else{const C=await Qe.json();alert(`Upload failed: ${C.detail||"Internal Server Error"}`)}}catch(Ct){alert(`Network error during upload: ${Ct.message}`)}$.target.value=""},pe=async($=null)=>{var rt,Qe;const he=$&&$.nativeEvent,nt=$&&!he?$:y;if(!nt||m)return;k(!0),p(null),f({}),(async()=>{for(let C=0;C<zn.length;C++){const N=zn[C];j(T=>({...T,[N]:"working"})),await new Promise(T=>setTimeout(T,180))}})();try{const C=localStorage.getItem("gemini_key"),N={"Content-Type":"application/json"};C&&(N["x-gemini-key"]=C);const T=await fetch(`${ei}/orchestrate/${nt.id}`,{method:"POST",headers:N});if(!T.ok)throw new Error("API error");const A=await T.json();for(let B=0;B<zn.length;B++){const Be=zn[B];await new Promise(te=>setTimeout(te,120)),j(te=>({...te,[Be]:"complete"})),f(te=>{var Ut;return{...te,[Be]:(Ut=A.agents)==null?void 0:Ut[Be]}})}if(p(A),(Qe=(rt=A.agents)==null?void 0:rt.triage)!=null&&Qe.severity){const B=A.agents.triage.severity,Be=B<=2?"critical":B===3?"moderate":"stable";h(te=>te&&{...te,risk_level:Be})}}catch{zn.forEach(C=>{j(N=>({...N,[C]:"error"}))})}finally{k(!1)}};return e?s.jsx(pp,{onStart:()=>{t(!1),r(!0)}}):n?s.jsx(hp,{onComplete:()=>r(!1)}):s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100vh",overflow:"hidden"},children:[s.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 20px",height:48,flexShrink:0,background:"var(--bg-surface)",borderBottom:"1px solid var(--border-subtle)",zIndex:10},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[s.jsx("div",{style:{animation:"heartbeat 1.4s infinite",color:"var(--red-critical)"},children:s.jsx(Un,{size:20})}),s.jsx("span",{style:{fontWeight:800,fontSize:15,letterSpacing:"-0.02em"},children:"CodeBlue Context"}),s.jsx("span",{style:{fontSize:10,fontWeight:600,padding:"2px 8px",borderRadius:99,background:"rgba(255,45,85,0.15)",color:"var(--red-critical)",border:"1px solid rgba(255,45,85,0.3)",letterSpacing:"0.05em"},children:"EMERGENCY INTELLIGENCE"})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,fontSize:11,color:"var(--text-tertiary)"},children:[s.jsx("button",{onClick:()=>i(!0),className:"btn-ghost",style:{color:"var(--purple-ai)",borderColor:"rgba(191,90,242,0.3)",padding:"6px 12px"},children:"π Provide API Key"}),s.jsxs("button",{className:"btn-demo",onClick:()=>{const $=o.find(he=>he.id==="CB-001")||o[0];$&&(D($),setTimeout(()=>pe($),50))},style:{padding:"6px 14px",borderRadius:6,fontWeight:700,cursor:"pointer",background:"var(--blue-accent)",color:"#fff",border:"none",transition:"all 0.2s",display:"flex",alignItems:"center",gap:"6px"},onMouseOver:$=>$.currentTarget.style.filter="brightness(1.1)",onMouseOut:$=>$.currentTarget.style.filter="brightness(1)",children:[s.jsx(Un,{size:14})," Run Live Demo"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"var(--green-safe)",fontWeight:700},children:"β"})," System Online"]}),s.jsxs("span",{children:[o.length," patients"]})]})]}),s.jsxs("div",{style:{flex:1,display:"grid",gridTemplateColumns:"240px 420px 1fr",overflow:"hidden"},children:[s.jsx("div",{style:{borderRight:"1px solid var(--border-subtle)",overflow:"hidden",display:"flex",flexDirection:"column"},children:s.jsx(vp,{patients:o,selected:y,onSelect:D,onUpload:P,loading:u})}),s.jsxs("div",{style:{borderRight:"1px solid var(--border-subtle)",overflow:"hidden",display:"flex",flexDirection:"column"},children:[s.jsxs("div",{style:{display:"flex",background:"var(--bg-base)",padding:"4px 4px 0",borderBottom:"1px solid var(--border-subtle)"},children:[s.jsx("button",{onClick:()=>E("orchestrate"),style:{flex:1,padding:"10px",fontSize:11,fontWeight:700,cursor:"pointer",border:"none",background:g==="orchestrate"?"var(--bg-surface)":"transparent",color:g==="orchestrate"?"var(--blue-accent)":"var(--text-secondary)",borderRadius:"8px 8px 0 0",borderBottom:g==="orchestrate"?"2px solid var(--blue-accent)":"none"},children:"ORCHESTRATION"}),s.jsx("button",{onClick:()=>E("consult"),style:{flex:1,padding:"10px",fontSize:11,fontWeight:700,cursor:"pointer",border:"none",background:g==="consult"?"var(--bg-surface)":"transparent",color:g==="consult"?"var(--purple-ai)":"var(--text-secondary)",borderRadius:"8px 8px 0 0",borderBottom:g==="consult"?"2px solid var(--purple-ai)":"none"},children:"ADVANCED CONSULT"})]}),s.jsx("div",{style:{flex:1,overflow:"hidden"},children:g==="orchestrate"?s.jsx(jp,{patient:y,agentStatuses:S,agentResults:M,onRun:pe,running:m,focus:v,setFocus:w}):s.jsx(Tp,{patientId:y==null?void 0:y.id,previousResults:M})})]}),s.jsx("div",{style:{overflow:"hidden",display:"flex",flexDirection:"column"},children:s.jsx(_p,{data:d,patient:y})})]}),l&&s.jsx(zp,{onClose:()=>i(!1)})]})}ti.createRoot(document.getElementById("root")).render(s.jsx(Bc.StrictMode,{children:s.jsx(Pp,{})}));
|
frontend/dist/index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 9 |
<title>CodeBlue Context</title>
|
| 10 |
-
<script type="module" crossorigin src="/assets/index-
|
| 11 |
<link rel="stylesheet" crossorigin href="/assets/index-DKXwe-v6.css">
|
| 12 |
</head>
|
| 13 |
<body>
|
|
|
|
| 7 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 9 |
<title>CodeBlue Context</title>
|
| 10 |
+
<script type="module" crossorigin src="/assets/index-Dux7dzE3.js"></script>
|
| 11 |
<link rel="stylesheet" crossorigin href="/assets/index-DKXwe-v6.css">
|
| 12 |
</head>
|
| 13 |
<body>
|
frontend/src/ConsultPanel.jsx
CHANGED
|
@@ -46,7 +46,13 @@ export default function ConsultPanel({ patientId, previousResults }) {
|
|
| 46 |
throw new Error('No result');
|
| 47 |
}
|
| 48 |
} catch (err) {
|
| 49 |
-
setMessages(prev => [...prev, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
} finally {
|
| 51 |
setLoading(false);
|
| 52 |
}
|
|
|
|
| 46 |
throw new Error('No result');
|
| 47 |
}
|
| 48 |
} catch (err) {
|
| 49 |
+
setMessages(prev => [...prev, {
|
| 50 |
+
role: 'assistant',
|
| 51 |
+
content: "I'm having trouble reaching the clinical AI team. Please ensure you've provided a Gemini API Key in the settings (top right).",
|
| 52 |
+
insights: [
|
| 53 |
+
{"agent": "System", "note": "Connection required for advanced reasoning."}
|
| 54 |
+
]
|
| 55 |
+
}]);
|
| 56 |
} finally {
|
| 57 |
setLoading(false);
|
| 58 |
}
|