working server for real mock data

This commit is contained in:
2025-10-18 16:48:05 -04:00
parent e178eba0af
commit aa789b3431
2 changed files with 138 additions and 91 deletions
+40 -29
View File
@@ -8,11 +8,35 @@ from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import List, Dict, Optional
from datetime import datetime, timedelta
from contextlib import asynccontextmanager
import asyncio
import json
from collections import defaultdict
app = FastAPI(title="VitalLink API", version="1.0.0")
# ============================================================================
# LIFESPAN MANAGEMENT (Modern FastAPI Way)
# ============================================================================
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
print("=" * 80)
print("VitalLink Backend API Started")
print("=" * 80)
print("API Documentation: http://localhost:8000/docs")
print("WebSocket Endpoint: ws://localhost:8000/ws")
print("=" * 80)
yield
# Shutdown
print("\nVitalLink Backend API Shutting Down")
# ============================================================================
# APP INITIALIZATION
# ============================================================================
app = FastAPI(title="VitalLink API", version="1.0.0", lifespan=lifespan)
# CORS middleware for frontend
app.add_middleware(
@@ -151,6 +175,17 @@ def calculate_priority_score(patient: Patient) -> float:
# ============================================================================
@app.get("/")
async def root():
"""Root endpoint"""
return {
"message": "VitalLink Backend API",
"version": "1.0.0",
"docs": "/docs",
"status": "running",
}
@app.post("/api/checkin")
async def check_in_patient(data: PatientCheckIn):
"""Register a new patient and assign wristband"""
@@ -362,34 +397,10 @@ async def broadcast_update(message: dict):
# ============================================================================
# STARTUP / SHUTDOWN
# RUN SERVER
# ============================================================================
if __name__ == "__main__":
import uvicorn
@app.on_event("startup")
async def startup_event():
print("=" * 80)
print("VitalLink Backend API Started")
print("=" * 80)
print("API Documentation: http://localhost:8000/docs")
print("WebSocket Endpoint: ws://localhost:8000/ws")
print("=" * 80)
# ============================================================================
# INTEGRATION WITH SIMULATOR
# ============================================================================
async def simulator_integration_task():
"""
Background task to integrate with wristband simulator
In production, this receives data from actual base station
"""
# This would be replaced with actual base station connection
# For now, shows how to integrate the simulator
pass
# Run with: uvicorn vitalink_backend:app --reload
# Then access at http://localhost:8000
uvicorn.run(app, host="0.0.0.0", port=8000)