Adds a substantial layer of data-backed statistics (all grounded in verified, clean source data — no fabricated metrics). Backend (new routers/statistics.py, prefix /api/stats; +106 pytest still green): - /inpatient-clinical: LOS dist + by-disease quartiles, cost dist + by-disease + cost-vs-LOS, outcome counts, admission-route counts, BMI-by-age, KPIs (5822 admissions, median LOS 4d, mean ¥6294, cure 99.1%, emergency 47%) - /symptoms: 主诉 keyword frequencies (发热/咳嗽/肺炎…) + revisit ratio (36%) - /incidence-rate: per-10k-population standardized rate by district (cases ÷ pop) - /env-correlation: pollutant×cases Pearson + 7×7 pairwise matrix + PM2.5 scatter - /temporal: weekday distribution (+ month/yoy returned but UI omits them — data is December-only, so seasonality/YoY would be misleading) Frontend: - NEW 住院临床分析 page (/analysis/clinical, nav 临床分析): 9 charts + KPI row — LOS histogram + box-by-disease, cost histogram + scatter + by-disease, outcome donut (severity-colored), admission-route donut, age-band BMI box - DiseaseAnalysis: 主诉症状词频 horizontal bar + revisit ratio - DistrictComparison: 标化发病率(每万人)with 病例数↔发病率 toggle (rate is epidemiologically correct; raw counts mislead by population) - EnvironmentalHealth: pollutant-cases correlation bar + 7×7 correlation heatmap + PM2.5×cases scatter with least-squares regression line - TrendAnalysis: 星期就诊分布 + honest "data is December-only" note - statsApi client + types Gates: tsc 0 · build ok · functional e2e 43/43 (incl 2 new clinical) · verified live against real backend data via dev proxy Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
"""
|
|
FastAPI application entry point with CORS configuration
|
|
"""
|
|
import logging
|
|
import os
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.middleware.gzip import GZipMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from logging_config import setup_logging
|
|
from middleware.request_logger import RequestLoggerMiddleware
|
|
from auth.router import router as auth_router
|
|
from auth.service import seed_default_admin
|
|
from routers import risk, alerts, analysis, insights, reports, cases, geocoded, grid, chat, environment, statistics
|
|
|
|
|
|
setup_logging()
|
|
seed_default_admin()
|
|
|
|
|
|
app = FastAPI(
|
|
title="CBPOA Risk Assessment API",
|
|
description="API for CBPOA health risk assessment and alert management",
|
|
version="1.0.0",
|
|
)
|
|
|
|
app.add_middleware(RequestLoggerMiddleware)
|
|
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=1)
|
|
|
|
logger = logging.getLogger("cbpoa.main")
|
|
|
|
|
|
@app.exception_handler(Exception)
|
|
async def global_exception_handler(request: Request, exc: Exception):
|
|
logger.exception("Unhandled exception on %s %s", request.method, request.url.path)
|
|
return JSONResponse(status_code=500, content={"detail": "Internal server error"})
|
|
|
|
cors_origins = os.getenv("CORS_ORIGINS", "http://localhost:3000,http://localhost:5173,http://127.0.0.1:3000,http://127.0.0.1:5173").split(",")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
app.include_router(auth_router)
|
|
app.include_router(risk.router)
|
|
app.include_router(alerts.router)
|
|
app.include_router(analysis.router)
|
|
app.include_router(insights.router)
|
|
app.include_router(reports.router)
|
|
app.include_router(cases.router)
|
|
app.include_router(geocoded.router)
|
|
app.include_router(grid.router)
|
|
app.include_router(chat.router)
|
|
app.include_router(environment.router)
|
|
app.include_router(statistics.router)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""Root endpoint - API health check"""
|
|
return {
|
|
"message": "CBPOA Risk Assessment API",
|
|
"version": "1.0.0",
|
|
"status": "running"
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""Health check endpoint for monitoring"""
|
|
return {"status": "healthy"}
|