- Add FastAPI routes for surgery start/end, results, pending confirmation (WAV upload), and health checks. - Implement RTSP/Hikvision capture, consumable classification, session manager, MinIO/Baidu voice resolution, and DB persistence. - Add documentation (client API, video backends, staging checklist) and sample camera/RTSP config. - Add pytest suite (API contract, session manager, voice, repositories, pipeline persistence) and httpx dev dependency. - Replace deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT. - Fix SurgeryPipeline DB reads to use an explicit transaction with autobegin disabled. Made-with: Cursor
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
import sys
|
|
from contextlib import asynccontextmanager
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from loguru import logger
|
|
|
|
from app.api import router as api_router
|
|
from app.database import check_database, engine, init_db_schema
|
|
from app.dependencies import camera_session_manager
|
|
|
|
logger.remove()
|
|
logger.add(
|
|
sys.stderr,
|
|
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan> - <level>{message}</level>",
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await check_database()
|
|
await init_db_schema()
|
|
logger.info("Database connection verified and schema ensured")
|
|
await camera_session_manager.start_archive_retry_loop()
|
|
yield
|
|
await camera_session_manager.shutdown()
|
|
await engine.dispose()
|
|
logger.info("Database engine disposed")
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
application = FastAPI(
|
|
title="Operation Room Monitor",
|
|
lifespan=lifespan,
|
|
)
|
|
application.include_router(api_router)
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
def main() -> None:
|
|
uvicorn.run(
|
|
"main:app",
|
|
host="0.0.0.0",
|
|
port=38080,
|
|
reload=True,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|