Skip to content

NishnathPolav/SwiftER

Repository files navigation

SwiftER - Smart Ambulance–Hospital Coordination System

An intelligent system for real-time ambulance routing based on patient condition, location, and hospital capacity using AI-powered decision making.

🎯 Overview

SwiftER connects ambulances with hospitals through an intelligent coordination system that:

  1. Captures voice reports from EMTs and converts them to structured patient data
  2. Analyzes patient condition, severity, and required capabilities
  3. Evaluates real-time hospital capacity and specializations
  4. Routes ambulances to the optimal hospital using AI (Wood Wide AI)
  5. Tracks ambulance locations in real-time on an interactive map

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                              AMBULANCE APP                                   │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐              │
│  │   Wispr STT     │→ │  Patient Form   │→ │  Navigation     │              │
│  │  (Voice Input)  │  │  (Structured)   │  │  (Turn-by-turn) │              │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘              │
│           │                    │                    │                        │
│           └────────────────────┼────────────────────┘                        │
│                                ↓                                             │
└────────────────────────────────┼─────────────────────────────────────────────┘
                                 │ Location Updates
                                 ↓
┌─────────────────────────────────────────────────────────────────────────────┐
│                              SUPABASE                                        │
│  ┌─────────────────────────┐    ┌─────────────────────────┐                 │
│  │   patient_incidents     │    │       hospitals         │                 │
│  │  (Patient data, GPS)    │    │  (Capacity, Resources)  │                 │
│  └─────────────────────────┘    └─────────────────────────┘                 │
└────────────────────────────────────────────────────────────────────────────┘
           │                                         │
           ↓                                         ↓
┌─────────────────────────────────────────────────────────────────────────────┐
│                           BACKEND SERVICES                                   │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────────────┐  │
│  │ Reasoning Agent │  │ Capacity Agent  │  │ Woodwide Reasoning Agent    │  │
│  │ (NLP Extraction)│  │(Hospital Status)│  │ (AI Routing via Wood Wide)  │  │
│  │   Port 8000     │  │                 │  │        Port 8001            │  │
│  └─────────────────┘  └─────────────────┘  └─────────────────────────────┘  │
└────────────────────────────────────────────────────────────────────────────┘
                                 │
                                 ↓ Routing Decision
┌─────────────────────────────────────────────────────────────────────────────┐
│                            FRONTEND APPS                                     │
│  ┌──────────────────────────┐    ┌────────────────────────────────────────┐ │
│  │     Maps Dashboard       │    │        Hospital Dashboards             │ │
│  │  (Real-time tracking)    │    │   (Presbyterian, Mercy, etc.)          │ │
│  │      Port 5173           │    │      Ports 3001, 3002                  │ │
│  └──────────────────────────┘    └────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘

📁 Project Structure

SwiftER/
├── apps/                           # Frontend Applications
│   ├── ambulance/                  # EMT tablet app
│   │   ├── src/components/         # Wispr STT, Navigation, Patient Form
│   │   └── src/services/           # API client, Supabase client
│   │
│   ├── maps-dashboard/             # Real-time ambulance tracking
│   │   ├── src/services/           # Ambulance service, Hospital API
│   │   └── src/hooks/              # Real-time location hooks
│   │
│   ├── hospital-dashboard-presbyterian/  # UPMC Presbyterian dashboard
│   └── hospital-dashboard-mercy/         # UPMC Mercy dashboard
│
├── services/                       # Backend Microservices
│   └── agents/
│       ├── reasoning-agent/        # Transcription → Structured data
│       ├── capacity-agent/         # Hospital capacity management
│       └── woodwide-reasoning-agent/  # AI-powered routing decisions
│
├── infrastructure/                 # Database schemas, Docker configs
├── shared/                         # Shared domain models
└── docs/                           # Documentation

🚀 Quick Start

Prerequisites

  • Node.js 18+
  • Python 3.10+
  • Supabase account (for database)
  • Wood Wide AI API key (for routing)
  • Wispr API key (for voice transcription)

1. Clone and Install

git clone <repository-url>
cd SwiftER

2. Set Up Backend Services

Reasoning Agent (Port 8000)

cd services/agents/reasoning-agent
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp env.example .env
# Edit .env with your OPENAI_API_KEY, SUPABASE_URL, SUPABASE_ANON_KEY
python main.py

Woodwide Reasoning Agent (Port 8001)

cd services/agents/woodwide-reasoning-agent
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp env.example .env
# Edit .env with WOODWIDE_API_KEY, SUPABASE_URL, SUPABASE_ANON_KEY, ROUTING_MODEL_ID
python run.py

3. Set Up Frontend Apps

Maps Dashboard (Port 5173)

cd apps/maps-dashboard
npm install
cp env.example .env.local
# Edit .env.local with VITE_SUPABASE_URL, VITE_SUPABASE_ANON_KEY
npm run dev

Ambulance App (Port 5174)

cd apps/ambulance
npm install
cp env.example .env.local
# Edit .env.local with VITE_WISPR_API_KEY, VITE_SUPABASE_URL, etc.
npm run dev

Hospital Dashboards (Ports 3001, 3002)

# Presbyterian
cd apps/hospital-dashboard-presbyterian
npm install
cp env.example .env.local
npm run dev

# Mercy
cd apps/hospital-dashboard-mercy
npm install
cp env.example .env.local
npm run dev

🔧 Configuration

Environment Variables

Variable Description Used In
VITE_SUPABASE_URL Supabase project URL All frontend apps
VITE_SUPABASE_ANON_KEY Supabase anonymous key All frontend apps
VITE_WISPR_API_KEY Wispr Flow API key Ambulance app
VITE_API_BASE_URL Reasoning agent URL Ambulance app
VITE_WOODWIDE_API_BASE_URL Woodwide agent URL Ambulance app
WOODWIDE_API_KEY Wood Wide AI API key Woodwide agent
ROUTING_MODEL_ID Trained routing model ID Woodwide agent
SUPABASE_URL Supabase URL Backend agents
SUPABASE_ANON_KEY Supabase key Backend agents

🗄️ Database Schema

patient_incidents

Column Type Description
incident_id UUID Primary key
ambulance_id VARCHAR Ambulance identifier
latitude FLOAT Current GPS latitude
longitude FLOAT Current GPS longitude
status VARCHAR Hospital name (when routed)
severity_level INT 1-5 severity scale
age INT Patient age
gender VARCHAR Patient gender
timestamp TIMESTAMP Last update time

hospitals

Column Type Description
hospital_id VARCHAR Hospital identifier
hospital_name VARCHAR Hospital display name
latitude FLOAT Hospital location
longitude FLOAT Hospital location
er_beds_available INT Available ER beds
icu_beds_available INT Available ICU beds
last_updated TIMESTAMP Last capacity update

🎨 Key Features

Ambulance App

  • Voice-to-Text: Wispr Flow STT captures EMT reports
  • Patient Form: Auto-populated structured patient data
  • Live Navigation: Turn-by-turn directions to routed hospital
  • Real-time Location: GPS updates sent to Supabase every 2 seconds

Maps Dashboard

  • Interactive Map: MapLibre GL JS with Pittsburgh focus
  • Live Ambulances: Red markers showing active transports
  • Hospital Status: Color-coded capacity indicators
  • Click Details: Modal with patient/hospital information
  • Real-time Updates: Polling every 2 seconds for ambulance positions

Woodwide Reasoning Agent

  • AI-Powered Routing: Wood Wide AI for optimal hospital selection
  • Multi-factor Analysis: Distance, ETA, capacity, patient needs
  • Road Distance: OSRM integration for actual road distances (not straight-line)
  • Supabase Integration: Fetches live patient and hospital data

🛣️ Road Distance Calculation

The system uses OSRM (Open Source Routing Machine) for accurate road-based distances:

Patient Location → OSRM API → Actual Road Distance & ETA
                              (accounts for rivers, roads, traffic)

This is critical in Pittsburgh where straight-line distances can be misleading due to rivers and terrain.

📊 Routing Decision Flow

  1. EMT speaks patient report → Wispr STT → Text
  2. Text → Reasoning Agent → Structured patient data in Supabase
  3. User clicks "Submit for Routing" → Woodwide Agent:
    • Fetches patient data from Supabase
    • Fetches hospital capacity from Supabase
    • Calculates road distances via OSRM
    • Runs Wood Wide AI model for optimal hospital
    • Returns routing decision
  4. Ambulance app navigates to selected hospital
  5. Maps Dashboard shows ambulance moving in real-time

🧪 Testing

Test Routing Decision

curl -X POST http://localhost:8001/route/from-supabase/<incident_id>

Test Ambulance Location Update

# Update ambulance location in Supabase
# Maps dashboard will reflect changes within 2 seconds

📚 Documentation

🛠️ Tech Stack

Layer Technology
Frontend React, TypeScript, Vite, TailwindCSS
Maps MapLibre GL JS
Voice Wispr Flow STT
Backend Python, FastAPI
Database Supabase (PostgreSQL)
AI/ML Wood Wide AI
Routing OSRM (road distances)

📄 License

[Add license information]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors