Skip to main content

Overview

The /api/emergency endpoint provides rapid triage for emergency scenarios:
  • Bypasses multi-agent debate for speed
  • Single-agent analysis focused on red flags and urgency
  • Target latency: <5 seconds
  • Returns ESI score (Emergency Severity Index 1-5)
Emergency mode sacrifices depth for speed. Use the full analyze endpoint for non-urgent cases requiring comprehensive analysis.

Endpoint

POST http://localhost:8000/api/emergency

Request Body

text
string
required
Free-text clinical input describing the emergency presentation
The emergency endpoint only accepts text input (not fhir_bundle or patient_context)

Response

emergency
EmergencyOutput
Fast-path emergency analysis results

EmergencyOutput Schema

top_differentials
array
Top 3-5 differential diagnoses ranked by urgency
red_flags
array
Critical warning signs requiring immediate intervention
call_to_action
string
Immediate recommended action (e.g., “Activate STEMI protocol”, “Urgent CT head”)
esi_score
integer
Emergency Severity Index score (1-5, where 1 = most urgent)
safety_flags
array
Critical safety warnings
latency_ms
integer
Processing time in milliseconds

Differential Schema (within EmergencyOutput)

ESI Score Interpretation

ESI ScoreUrgencyDescription
1ImmediateLife-threatening, requires immediate intervention (e.g., cardiac arrest, severe trauma)
2EmergentHigh risk, should be seen within 10 minutes (e.g., chest pain, stroke symptoms)
3UrgentStable but requires multiple resources (e.g., abdominal pain requiring labs + imaging)
4Less urgentStable, requires 1 resource (e.g., simple laceration)
5Non-urgentStable, no resources needed (e.g., prescription refill)

Example Request

curl -X POST http://localhost:8000/api/emergency \
  -H "Content-Type: application/json" \
  -d '{
    "text": "58 yo F sudden severe headache, worst headache of life, started 30 min ago. BP 180/110, alert but nauseated. No trauma."
  }'

Example Response

{
  "emergency": {
    "top_differentials": [
      {
        "diagnosis": "Subarachnoid hemorrhage (SAH)",
        "likelihood": "most likely",
        "reasoning": "Classic thunderclap headache presentation with hypertension. SAH is the most critical diagnosis to rule out.",
        "confidence": "high",
        "supporting_evidence": [
          "Sudden onset worst headache of life (thunderclap)",
          "No trauma history",
          "Hypertensive (180/110)",
          "Nausea/vomiting common with SAH"
        ]
      },
      {
        "diagnosis": "Hypertensive emergency",
        "likelihood": "possible",
        "reasoning": "Severely elevated BP could cause headache, but thunderclap presentation more concerning for SAH.",
        "confidence": "medium",
        "supporting_evidence": [
          "BP 180/110 mmHg (hypertensive urgency/emergency range)"
        ]
      },
      {
        "diagnosis": "Posterior reversible encephalopathy syndrome (PRES)",
        "likelihood": "possible",
        "reasoning": "Hypertension-related, but typically has seizures or visual changes.",
        "confidence": "low",
        "supporting_evidence": [
          "Severe hypertension"
        ]
      }
    ],
    "red_flags": [
      "Thunderclap headache (sudden, severe, peak intensity within seconds) — SUBARACHNOID HEMORRHAGE UNTIL PROVEN OTHERWISE",
      "Severe hypertension (BP 180/110) — risk of hypertensive emergency or secondary to intracranial pathology",
      "Nausea/vomiting with severe headache — concerning for increased intracranial pressure"
    ],
    "call_to_action": "IMMEDIATE: Non-contrast CT head STAT to rule out SAH. If CT negative and high suspicion, proceed to lumbar puncture. Neurosurgery consultation. Do NOT give BP medications until imaging complete (could worsen cerebral perfusion if mass lesion present).",
    "esi_score": 1,
    "safety_flags": [
      "Do NOT lower BP aggressively before CT head — if SAH or stroke present, rapid BP lowering can worsen cerebral perfusion.",
      "If CT shows SAH, activate neurosurgery immediately — time-critical for aneurysm securing."
    ],
    "latency_ms": 3240
  }
}

Error Responses

400 Bad Request

{
  "detail": "Must provide text for emergency mode"
}

500 Internal Server Error

{
  "detail": "Emergency analysis failed: [error details]"
}

Use Cases

Triage Support

Rapid assessment of ED patients for acuity scoring

Red Flag Detection

Identify critical findings requiring immediate action

Telemedicine

Quick assessment for remote consultations

Training

Educational tool for emergency medicine residents

Notes

Emergency mode uses a streamlined prompt optimized for speed and red flag detection. It does not perform literature review, multi-agent debate, or medication safety panels.
ESI scores generated by the AI should be validated by clinical judgment. ClinicalPilot is a decision-support tool, not a replacement for clinical assessment.

Comparison: Emergency vs Full Analysis

FeatureEmergency ModeFull Analysis
Latency<5 seconds15-30 seconds
AgentsSingle (Clinical)4 (Clinical, Literature, Safety, Critic)
Literature ReviewNoYes (PubMed search)
Safety PanelNoYes (drug interactions, contraindications)
Output FormatEmergencyOutputSOAPNote + DebateState
Use CaseTime-critical triageComprehensive analysis
Red FlagsYesYes
ESI ScoreYesNo
SOAP NoteNoYes

Build docs developers (and LLMs) love