File size: 1,499 Bytes
05cb41b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import auth_routes

from app.core.rag import rag_engine
from app.api import claims

@asynccontextmanager
async def lifespan(app: FastAPI):
    """
    Handles startup and shutdown events asynchronously.
    This guarantees our DB and AI memory are ready before the first request arrives.
    """
    # --- Startup ---
    rag_engine.initialize()
    yield
    # --- Shutdown ---

# Initialize the FastAPI application
app = FastAPI(
    title="Plum OPD Adjudication Engine",
    description="AI-powered automation tool for processing OPD medical claims.",
    version="1.0.0",
    lifespan=lifespan
)

# Configure Cross-Origin Resource Sharing (CORS)
# This allows your frontend (e.g., React on port 3000) to talk to this API
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # In production, replace "*" with your Vercel frontend URL
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Register our API routes
app.include_router(claims.router, prefix="/api")

app.include_router(auth_routes.router, prefix="/api")

@app.get("/")
async def health_check():
    """Simple endpoint to verify the server is running."""
    return {
        "status": "online",
        "service": "Plum OPD Adjudication Engine",
        "database": "connected",
        "rag_memory": "loaded" if rag_engine.vector_store else "offline"
    }