Smart-MRI Router is an AI-powered spatial load-balancing platform designed to resolve extreme patient queue bottlenecks at hospital MRI facilities. The system intelligently distributes patient loads from a central Hub hospital to nearby Spoke hospitals in real-time.
Disclaimer: All patient queue numbers, occurrences, and medical datasets presented in this application are strictly simulated (dummy data) designed specifically for academic prototyping and system workflow demonstration.
MRI facilities frequently experience severe patient bottlenecks at main referral hospitals, leaving MRI capacities at surrounding satellite hospitals underutilized. Prolonged waiting times can be critical for urgent-care patients.
This application implements a Hub & Spoke architecture:
- Hub (Load Center): RSUP Fatmawati
- Spokes (Distribution Nodes): RS Mayapada, RS Siloam, RS Pondok Indah, RSUD Pasar Minggu
When the AI detects a queue surge at the Hub, the system automatically calculates the fastest spatial routes and machine availability at the Spokes to efficiently relocate patients.
- Time-Series Queue Forecasting: Utilizes SARIMAX Machine Learning models (
arima_model.joblib) to predict MRI machine load patterns based on cumulative historical data. - Real-Time Spatial Routing: Integrates with the Microsoft Azure Maps API to calculate precise distances, routing latencies, and ETAs (Estimated Time of Arrival) for patient transfers.
- Secure Proxy Architecture: Implements Next.js edge rewrites to handle asynchronous communication securely between the Vercel Serverless network and Hugging Face Spaces (Port 7860), eliminating CORS policy blocks.
- Auto-Seeding Database Engine: A robust backend initialization script that automatically populates the PostgreSQL database with spatial hospital datasets and initial queue states upon server startup.
The dashboard is designed to simulate two distinct scenarios: Normal Load and Overload Crisis.
- Initial State & Server Warm-Up: Upon loading, the dashboard establishes a connection with the cloud backend (displaying a temporary cold-start indicator if waking from sleep) and presents the system date, a 2-card KPI summary (40 monitored network hospitals and RSUP Fatmawati Hub capacity of 55 MRI slots), a scrollable 40-hospital directory, and an interactive Azure Maps view.
- Demand Forecasting (
Step 1): The user selects a target date from the date picker and clicks1 Prediksi AIto run the SARIMAX model. Quadrant 4 displays two distinct cards: an AI Analytical Insight (evaluating predicted patient volume against the 55-slot Hub limit) and a Next-Step Action Guide. - Time Travel & Capacity Evaluation (
Step 2): Clicking2 Time-Travelsynchronizes real-time occupancy across all 40 hospitals to the selected target date:- Safe Capacity (
< 55patients): The dashboard shifts to a Green (SAFE CAPACITY) theme, confirming sufficient free MRI slots at RSUP Fatmawati. - Full Capacity (
=== 55patients): The dashboard shifts to an Amber (FULL CAPACITY) standby theme, indicating 100% slot utilization with zero excess patients.
- Safe Capacity (
- No Unnecessary Rerouting: Because no capacity breach occurs (
≤ 55patients), the3 Eksekusi Spatial Routerbutton remains hidden, preventing redundant rerouting operations.
- Triggering Surge Scenario: In Quadrant 3, the user clicks
Simulate Surge (Lonjakan)to inject an artificial emergency patient surge into the RSUP Fatmawati database (or selects a high-demand peak date), resetting the pipeline toStep 0/3for end-to-end validation. - Capacity Breach Detection (
Step 1→Step 2): After running1 Prediksi AIand2 Time-Travel, the system detects that Hub occupancy exceeds its 55-patient threshold (> 55). The entire interface transitions into a Red (CRISIS MODE) alert state and unlocks the3 Eksekusi Spatial Routeraction button. - Spatial Load Balancing & Patient Audit Log (
Step 3): Clicking3 Eksekusi Spatial Routerexecutes the road-network routing algorithm, transitioning the dashboard to a Green (ROUTER ACTIVE) state that:- Draws green evacuation routes from RSUP Fatmawati to the nearest available spoke hospitals on the Azure Maps canvas.
- Displays a Distribution Summary per destination hospital alongside a scrollable Patient Transfer Log table detailing each reassigned patient and their target facility.
- Frontend: Next.js (App Router), React, Tailwind CSS, Vercel
- Backend: Python, FastAPI, Uvicorn, Docker, Hugging Face Spaces
- Machine Learning: Scikit-Learn, Statsmodels (ARIMA/SARIMAX), Joblib
- Geospatial & Database: Microsoft Azure Maps API, PostgreSQL (Supabase)
For judges, recruiters, or developers who wish to run and test the application locally, follow these steps to deploy the environment using Docker:
Open your terminal and clone the source code:
git clone [https://github.com/amdihsann/MRI-Smart-Router.git](https://github.com/amdihsann/MRI-Smart-Router.git)
cd MRI-Smart-RouterCreate a new file named .env in the root directory of the project (alongside the docker-compose.yml file). Copy and paste the following configuration, replacing the values with your actual credentials:
# ==========================================
# FRONTEND CONFIGURATION (Next.js)
# ==========================================
NEXT_PUBLIC_AZURE_MAPS_KEY=your_azure_maps_primary_key_here
BACKEND_URL=http://localhost:8000
# ==========================================
# BACKEND CONFIGURATION (FastAPI & Database)
# ==========================================
DB_USER=mri_admin
DB_PASSWORD=mri_password_secure
DB_NAME=smart_mri_db
DB_PORT=5432Ensure Docker Desktop is running in the background. Open your integrated terminal in the project root and execute the following command to build and run the containers in detached mode:
docker compose up --build -dOnce the containers display a healthy/running status in Docker Desktop, you can access the application through your web browser:
- Frontend UI (Dashboard): http://localhost:3000
- Backend API (Swagger Docs): http://localhost:8000