Emergency Bridge

Mobile-First Progressive Web App for Preserving and Transferring Critical Information Across the Emergency Care Chain


Problem

During an acute emergency, a critical information-loss gap exists during the period between: $$\text{Emergency} \longrightarrow \text{Bystander} \longrightarrow \text{Emergency Services} \longrightarrow \text{Hospital}$$

Bystanders are highly stressed, patient medical details are fragmented or unknown, and various responders frequently receive conflicting versions of what occurred. Crucial data—such as time of consciousness loss, onset of heavy bleeding, recovery position interventions, and known severe allergies—is frequently lost before clinical triage begins.


Solution

Emergency Bridge creates a temporary, lightweight digital emergency case with:

  1. Real-time Chronological Incident Timeline: Timestamped events from bystanders, responders, and dispatchers synchronized live via WebSockets.
  2. AI-Assisted Handover Summary: Converts unstructured bystander notes and observations into structured clinical handovers strictly without inventing data or diagnosing conditions.
  3. Cryptographically Secure Temporary Access: SHA-256 hashed temporary access links and QR codes that grant scoped access to emergency contacts, first responders, and hospital staff with instant revocation capabilities.

Features

  • Rapid 3-Step Emergency Creation: Start a case in under 5 seconds with zero required typing.
  • Single-Hand Mobile UX: Large touch targets (44px+ minimum), high contrast, and bottom-sheet controls optimized for 360px–430px smartphone viewports.
  • Guided Bystander Observations: 5-question neutral observation flow ("Is the person breathing normally?", "Is the person responding?", "Is there heavy bleeding?", "Can they move normally?", "Is the area dangerous?") recorded strictly as bystander reports, never medical diagnoses.
  • Real-Time Multi-Client Synchronization: WebSocket-powered live updates with visible ● LIVE connection badges and automated exponential reconnection backoff (▲ RECONNECTING...).
  • Configurable Emergency Dispatcher: Emergency call trigger supporting regional emergency codes (112, 911, 999, 000) that automatically logs call timestamps to the timeline.
  • AI Handover Engine with Local Fallback: Supports Google Gemini API (@google/genai) with automatic fallback to a deterministic rules engine (DEMO AI MODE) when no API key is set.
  • Role-Based Dashboards: Dedicated consoles for Bystanders, Ambulance/First Responders, and Hospital ER Triage teams.
  • Privacy Center & Field Masking: Granular patient profile sharing toggles ("Share with Responders", "Share with Hospital") and one-tap emergency case purging.
  • Progressive Web App (PWA): Installable on iOS/Android, service worker caching, and offline status banner with local saving warning.
  • Audit Logging: Immutable security event trail with sanitized metadata that strictly strips patient health information (PHI).

Architecture

┌────────────────────────────────────────────────────────────────────────┐
│                          EMERGENCY BRIDGE PWA                          │
│                                                                        │
│  ┌────────────────────┐ ┌──────────────────────┐ ┌───────────────────┐  │
│  │   Bystander Flow   │ │ Responder Dashboard  │ │Hospital Dashboard │  │
│  │ (Mobile-First 44px)│ │  (En Route / Triage) │ │ (Desktop / Tablet)│  │
│  └─────────┬──────────┘ └──────────┬───────────┘ └─────────┬─────────┘  │
│            │                       │                       │            │
│            ▼                       ▼                       ▼            │
│   React 18 + Tailwind CSS + Lucide Icons + Vite PWA Service Worker     │
│   Real-time WebSocket Hook (useRealtimeCase: LIVE / RECONNECTING)      │
└────────────────────────────────────┬───────────────────────────────────┘
                                     │ HTTP REST + WebSockets (ws)
┌────────────────────────────────────▼───────────────────────────────────┐
│                           BACKEND SERVER                               │
│                                                                        │
│  ┌──────────────────┐  ┌───────────────────┐  ┌─────────────────────┐  │
│  │ REST API Routes  │  │ WebSocket Gateway │  │ AI Handover Engine  │  │
│  │ (Cases, Events,  │  │ (Room broadcast  │  │ (Gemini 2.5 Flash   │  │
│  │  Access, Patient)│  │  per Case ID)     │  │  + Deterministic)   │  │
│  └─────────┬────────┘  └─────────┬─────────┘  └──────────┬──────────┘  │
│            │                     │                       │             │
│            ▼                     ▼                       ▼             │
│   Role-Based Authorization & Token Hashing (SHA-256) & Audit Logger    │
│                                   │                                    │
│                                   ▼                                    │
│   SQLite Database (better-sqlite3) & Supabase / PostgreSQL Migrations  │
└────────────────────────────────────────────────────────────────────────┘
  • Frontend: React 18, TypeScript, Tailwind CSS, Lucide Icons, Vite, vite-plugin-pwa.
  • Backend: Express.js, ws (WebSockets), better-sqlite3 (WAL mode enabled), @google/genai.
  • Cloud/PostgreSQL: Supabase migration script (supabase/migrations/00001_initial_schema.sql) with Row-Level Security (RLS) policies and seed data (supabase/seed.sql).

Database Schema

Table Purpose
users Bystanders, Emergency Contacts, Responders, Hospital staff, and Admins.
emergency_cases Core incident record (case_code, status, started time, consented GPS coords, label).
patient_profiles Voluntary patient information with field-level privacy sharing permissions.
case_participants Authorized case collaborators and their role-specific access levels.
timeline_events Chronological log of incident occurrences with source and visibility.
emergency_contacts Next-of-kin contacts with notification consent flags.
case_access_tokens Cryptographic SHA-256 hashes of temporary, revocable access tokens.
handover_summaries Version-controlled AI and deterministic clinical handover documents.
audit_logs Immutable security audit trail with sanitized metadata (zero medical information).

Security & Privacy

  • Token Hashing: Raw access tokens are generated using 24 cryptographically random bytes and stored exclusively as SHA-256 hashes.
  • Revocation: Case creators can revoke individual or all active access links at any moment from the Privacy Center.
  • Data Minimization: Only information required for the emergency workflow is requested.
  • Field-Level Medical Privacy: Medical background (blood group, allergies, conditions) is concealed unless the user explicitly checks sharing permissions for that role.
  • No PHI in URLs or QR Codes: QR codes contain solely the temporary authorization token URL, never raw patient medical data.
  • Search Engine Blocking: X-Robots-Tag: noindex, nofollow headers prevent case URLs from being crawled.
  • Sanitized Audit Trails: Audit log metadata strictly strips health parameters before saving.

AI Safety Boundary

Emergency Bridge strictly adheres to non-diagnostic medical boundaries:

  • Summarizes Only: Extracts and organizes only information recorded in the case.
  • Never Diagnoses: Never claims a patient is having a heart attack, stroke, or any disease.
  • Never Prescribes: Never suggests medication doses or interventions.
  • Preserves Uncertainty: Preserves bystander uncertainty ("NOT SURE" is never converted to "YES").
  • Explicit Missing Indicators: Any unrecorded parameter is marked as "Not recorded."
  • Mandatory Medical Disclaimer: Every handover summary prominently states: > "Information in this summary is strictly based on reported bystander observations and unverified notes. Emergency Bridge does NOT diagnose conditions, prescribe medications, or recommend treatments. This document must be verified by authorized medical professionals."

Local Development Setup

Prerequisites

  • Node.js (v18+ or v20+ or v24+)
  • npm (v9+)

Installation

# 1. Clone or enter the workspace
cd "c:\Users\Laeeque Anwer\OneDrive\Desktop\EMERGENCY BRIDGE"

# 2. Install dependencies
npm install

# 3. Copy environment configuration
cp .env.example .env

Running the Application

# Start both backend server (port 3001) and Vite PWA (port 5173)
npm run dev

Open your browser at http://localhost:5173.


Environment Variables

Configure .env (optional for local testing; default settings are turnkey):

# Server Port
PORT=3001

# Gemini AI API Key (Optional: when unset, deterministic Demo AI mode is used)
GEMINI_API_KEY=your_gemini_api_key_here

# JWT Secret
JWT_SECRET=emergency-bridge-secure-local-jwt-secret-key-2026

# Configurable Emergency Services Dial Number (default: 112)
DEFAULT_EMERGENCY_NUMBER=112

# Database File Path
DATABASE_FILE=./emergency_bridge.db

Demo Mode

Emergency Bridge includes built-in fictional demo data and simulation tools:

  1. Tap View Demo (Fictional Data) or Simulator in the header.
  2. Select one of the 3 fictional cases:
    • EB-48291: Road accident (Aarav Sharma, 34, O+, Penicillin allergy) — Status: IN_TRANSIT.
    • EB-48302: Person unresponsive (Meera Kapoor, 67, B+) — Status: AT_HOSPITAL.
    • EB-48317: Breathing problem (Demo Patient, 29) — Status: ACTIVE.
  3. Open a second tab in Responder Mode or Hospital Mode.
  4. Tap SIMULATE AMBULANCE ARRIVAL or SIMULATE CLINICAL HANDOVER in the Simulator tab and watch the event appear instantaneously in real time on the other tab without refreshing!

Testing

Run the automated Vitest test suite:

npm test

Test Coverage:

  • cases.test.ts: Case creation, input validation, EB-XXXXX format validation, status transitions.
  • access.test.ts: SHA-256 token hashing, authorization verification, expired token rejection, revoked token rejection.
  • timeline.test.ts: Chronological ordering, duplicate event deduplication (5s window), bystander observation attribution.
  • ai-safety.test.ts: Handover summary non-diagnostic enforcement, uncertainty preservation, missing data handling, medical disclaimer presence.
  • privacy.test.ts: Field-level patient profile masking by role, sanitized audit logging.

Production Build & Deployment

# Build production client and typecheck
npm run build

# Run production server
npm start

For cloud deployments (Render, Fly.io, Railway, Docker, Vercel/Supabase):

  1. Execute supabase/migrations/00001_initial_schema.sql against your PostgreSQL database.
  2. Execute supabase/seed.sql to populate initial demo data if desired.
  3. Deploy the application with NODE_ENV=production.

Medical Safety Disclaimer

IMPORTANT: Emergency Bridge is an emergency communication and information-management tool, NOT a diagnostic or treatment tool. It does NOT diagnose medical conditions, prescribe treatments, or replace professional emergency services (e.g. 112, 911, 999) or certified medical personnel. If someone is in immediate medical danger, contact your local emergency response service immediately.

Share this project:

Updates