Source Code:
hub/agents/python/emr/This is Part 2 of 3. If you haven’t completed Part 1, start there: Part 1: Getting Started
- Time to complete: 20-25 minutes
- What you’ll build: A React dashboard with real-time SSE updates
- What you’ll learn: FastAPI integration, SSE streaming, React state management
- Platform: Runs locally on AI PCs with Ryzen AI (NPU/iGPU acceleration)
Why Build a Dashboard?
The CLI is great for developers, but healthcare staff need a visual interface. The dashboard provides:- Real-time monitoring - Watch forms process as they arrive
- Patient management - Search, filter, and view patient records
- Alert handling - Acknowledge critical allergies and missing fields
- Efficiency metrics - Track time savings and ROI
Dashboard Architecture
Data flow:- New file arrives → Agent processes it
- Agent emits event → FastAPI broadcasts via SSE
- React receives event → Updates UI in real-time
- No polling required!
Quick Start
Launch the Dashboard
Launch Options
Dashboard Views
The dashboard has four main views accessible via navigation tabs.Dashboard View (Home)
The main monitoring view with live updates.
Watch Folder Panel Features:
- Status indicators with color-coded dots:
- 🟢 Green - Processed files
- 🔴 Red (flashing) - Currently processing
- 🟠 Orange - Queued for processing
- Drag-and-drop upload - Drop files directly onto the panel to upload
- File type icons - Visual indicators for PDFs vs images
- Click to navigate - Click processed files to view patient details
- Forms Processed - Total count of successfully extracted forms
- Manual Would Take - Cumulative estimated time for manual data entry
- AI Processing Time - Cumulative actual VLM processing time
- Time Saved - Running total of time saved (resets with database)
- File detection events
- Step-by-step progress (Reading file → Checking duplicates → Extracting data → Saving)
- Processing times and success/error states
Patient Database View
Searchable patient list with filtering.Patient Detail View
Complete patient information and workflow history.When deleting a patient, you can choose to also delete the source intake form file. This keeps the watched directory in sync with the database.
Chat View
Natural language interface for querying patients.
Example queries:
- “How many patients were processed today?”
- “Find patients with penicillin allergies”
- “Show me patients missing insurance information”
Settings View
Configuration and file upload.REST API Reference
The dashboard exposes a REST API for integration with other systems. Full API docs are available athttp://localhost:8080/docs when running.
Patient Endpoints
Query Parameters for GET
/api/patients:
Query Parameters for DELETE
/api/patients/:id:
Query Parameters for GET
/api/patients/:id/file:
Examples:
Alert Endpoints
Query Parameters for GET
/api/alerts:
Examples:
Session Endpoints
Query Parameters:
Chat Endpoint
Request Body:
Configuration Endpoints
Upload Example:
Watch Folder Endpoint
Response Example:
Stats & Health
Stats Response Example:
Server-Sent Events (SSE)
The/api/events endpoint streams real-time updates to the frontend. The server sends heartbeats every 30 seconds to keep connections alive.
Event Types
JavaScript Example
Event Payload Examples
Processing Steps
The agent emits 7 processing steps via SSE:Development Mode
For frontend development with hot reload:Terminal 1: Backend API
Terminal 2: Vite Dev Server
Project Structure
Electron Wrapper
The dashboard includes a minimal Electron wrapper for a native desktop experience:electron/main.js
- Loads automatically when running
gaia-emr dashboard - Shows a connection error page with retry if server is unavailable
- Opens external links in the default browser
- Falls back to browser mode if Electron/Node.js is not available
Building the FastAPI Server
Let’s understand how the backend is built.Basic Server Setup
server.py
Implementing SSE
server.py (continued)
Hooking Into Agent Events
server.py (continued)
Building the React Frontend
Main App Component
App.jsx
Live Feed Component
components/LiveFeed.jsx
Time Savings Calculation
The dashboard calculates time savings per-form based on extracted data (not fixed estimates). See Part 3: Architecture for the formula details. Summary: A typical 15-field form takes ~4-5 minutes to enter manually. VLM extracts it in ~30 seconds. That’s ~89% time savings.What’s Next?
Part 3: Architecture & Internals
Deep dive into database schema, processing pipeline, and system design decisions