"""FastAPI application for OMOP Pipeline.""" from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager import logging from .routers import etl, schema, stats, logs, validation from ..utils.config import Config logger = logging.getLogger(__name__) @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan manager.""" logger.info("Starting OMOP Pipeline API") yield logger.info("Shutting down OMOP Pipeline API") app = FastAPI( title="OMOP Pipeline API", description="API for managing OMOP CDM 5.4 ETL pipeline", version="1.0.0", lifespan=lifespan ) # CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["http://localhost:4400", "http://localhost:3000", "http://localhost:5173"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(etl.router, prefix="/api/etl", tags=["ETL"]) app.include_router(schema.router, prefix="/api/schema", tags=["Schema"]) app.include_router(stats.router, prefix="/api/stats", tags=["Statistics"]) app.include_router(logs.router, prefix="/api/logs", tags=["Logs"]) app.include_router(validation.router, prefix="/api/validation", tags=["Validation"]) @app.get("/") async def root(): """Root endpoint.""" return { "message": "OMOP Pipeline API", "version": "1.0.0", "docs": "/docs" } @app.get("/health") async def health(): """Health check endpoint.""" return {"status": "healthy"}