feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
"""
|
|
|
|
|
|
医疗病例数据 API 路由
|
|
|
|
|
|
|
|
|
|
|
|
提供门诊和住院数据的统计、趋势、区域分布等接口
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, HTTPException, Query
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
from datetime import datetime, date
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
import asyncio
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
import pandas as pd
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
from data.case_loader import load_data, get_combined_data, get_outpatient_data, get_inpatient_data, get_diagnoses, WUHAN_DISTRICTS, DATE_PATTERN
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api/cases", tags=["cases"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Response Models ==============
|
|
|
|
|
|
|
|
|
|
|
|
class StatsResponse(BaseModel):
|
|
|
|
|
|
"""统计数据响应"""
|
|
|
|
|
|
total_outpatient: int
|
|
|
|
|
|
total_inpatient: int
|
|
|
|
|
|
date_range: dict
|
|
|
|
|
|
top_districts: list
|
|
|
|
|
|
top_diagnoses: list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TrendPoint(BaseModel):
|
|
|
|
|
|
"""趋势数据点"""
|
|
|
|
|
|
date: str
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TrendResponse(BaseModel):
|
|
|
|
|
|
"""趋势数据响应"""
|
|
|
|
|
|
trend: list[TrendPoint]
|
|
|
|
|
|
summary: dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DistrictData(BaseModel):
|
|
|
|
|
|
"""区域数据"""
|
|
|
|
|
|
district: str
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
outpatient_ratio: float
|
|
|
|
|
|
inpatient_ratio: float
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DistrictsResponse(BaseModel):
|
|
|
|
|
|
"""区域分布响应"""
|
|
|
|
|
|
districts: list[DistrictData]
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RealtimeData(BaseModel):
|
|
|
|
|
|
"""实时数据"""
|
|
|
|
|
|
today_outpatient: int
|
|
|
|
|
|
today_inpatient: int
|
|
|
|
|
|
today_total: int
|
|
|
|
|
|
last_7d_avg: int
|
|
|
|
|
|
change_ratio: float
|
|
|
|
|
|
status: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== API Endpoints ==============
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/stats", response_model=StatsResponse, summary="获取病例统计数据")
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
async def get_cases_stats(
|
|
|
|
|
|
diagnosis: Optional[str] = Query(None, description="Filter to single disease stats"),
|
|
|
|
|
|
):
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
"""
|
|
|
|
|
|
获取病例总体统计信息
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
- 总门诊量、总住院量
|
|
|
|
|
|
- 数据日期范围
|
|
|
|
|
|
- 就诊量前 10 的区域
|
|
|
|
|
|
- 最常见诊断前 10
|
|
|
|
|
|
"""
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
load_data()
|
|
|
|
|
|
|
|
|
|
|
|
df_out = get_outpatient_data()
|
|
|
|
|
|
df_in = get_inpatient_data()
|
|
|
|
|
|
|
|
|
|
|
|
# 诊断过滤
|
|
|
|
|
|
if diagnosis:
|
|
|
|
|
|
df_out = df_out[df_out['初诊'].str.contains(diagnosis, na=False, case=False)]
|
|
|
|
|
|
df_in = df_in[df_in['诊断名称'].str.contains(diagnosis, na=False, case=False)]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 计算统计
|
|
|
|
|
|
total_outpatient = len(df_out)
|
|
|
|
|
|
total_inpatient = len(df_in)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
|
|
|
|
|
# 日期范围(过滤后可能为空,需防御 NaT)
|
|
|
|
|
|
all_dates = pd.concat([df_out['date'], df_in['date']]).dropna()
|
|
|
|
|
|
date_start = all_dates.min().strftime("%Y-%m-%d") if len(all_dates) else ""
|
|
|
|
|
|
date_end = all_dates.max().strftime("%Y-%m-%d") if len(all_dates) else ""
|
|
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 区域统计
|
|
|
|
|
|
out_districts = df_out[df_out['district'] != '未知']['district'].value_counts().head(10)
|
|
|
|
|
|
in_districts = df_in[df_in['district'] != '其他']['district'].value_counts().head(10)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
combined_districts = pd.concat([out_districts, in_districts]).groupby(level=0).sum().nlargest(10)
|
|
|
|
|
|
top_districts = [{"district": d, "count": int(c)} for d, c in combined_districts.items()]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 诊断统计
|
|
|
|
|
|
out_diagnoses = df_out['初诊'].value_counts().head(10)
|
|
|
|
|
|
in_diagnoses = df_in['诊断名称'].value_counts().head(10)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
top_diagnoses = [
|
|
|
|
|
|
{"diagnosis": str(d), "outpatient": int(out_diagnoses.get(d, 0)), "inpatient": int(in_diagnoses.get(d, 0))}
|
|
|
|
|
|
for d in set(list(out_diagnoses.index[:5]) + list(in_diagnoses.index[:5]))
|
|
|
|
|
|
][:10]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
return StatsResponse(
|
|
|
|
|
|
total_outpatient=total_outpatient,
|
|
|
|
|
|
total_inpatient=total_inpatient,
|
|
|
|
|
|
date_range={
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
"start": date_start,
|
|
|
|
|
|
"end": date_end
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
top_districts=top_districts,
|
|
|
|
|
|
top_diagnoses=top_diagnoses
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/trend", response_model=TrendResponse, summary="获取病例趋势数据")
|
|
|
|
|
|
async def get_cases_trend(
|
|
|
|
|
|
start_date: Optional[str] = Query(None, description="开始日期 (YYYY-MM-DD)"),
|
|
|
|
|
|
end_date: Optional[str] = Query(None, description="结束日期 (YYYY-MM-DD)"),
|
|
|
|
|
|
group_by: str = Query("day", description="分组粒度:day, week, month"),
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
diagnosis: Optional[str] = Query(None, description="Filter by diagnosis name"),
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
):
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取病例时间趋势数据
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
- 支持按日、周、月分组
|
|
|
|
|
|
- 可指定日期范围
|
|
|
|
|
|
- 返回门诊、住院、总计趋势
|
|
|
|
|
|
"""
|
|
|
|
|
|
if start_date and not DATE_PATTERN.match(start_date):
|
|
|
|
|
|
raise HTTPException(status_code=400, detail="Invalid start_date format. Use YYYY-MM-DD")
|
|
|
|
|
|
if end_date and not DATE_PATTERN.match(end_date):
|
|
|
|
|
|
raise HTTPException(status_code=400, detail="Invalid end_date format. Use YYYY-MM-DD")
|
|
|
|
|
|
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
df = get_combined_data().copy()
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
|
|
|
|
|
|
# 日期过滤
|
|
|
|
|
|
if start_date:
|
|
|
|
|
|
df = df[df['date'] >= pd.to_datetime(start_date)]
|
|
|
|
|
|
if end_date:
|
|
|
|
|
|
df = df[df['date'] <= pd.to_datetime(end_date)]
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
|
|
|
|
|
|
# 诊断过滤
|
|
|
|
|
|
if diagnosis:
|
|
|
|
|
|
df = df[df['diagnosis'].str.contains(diagnosis, na=False, case=False)]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 分组
|
|
|
|
|
|
if group_by == "week":
|
|
|
|
|
|
df['period'] = df['date'].dt.to_period('W').dt.start_time
|
|
|
|
|
|
elif group_by == "month":
|
|
|
|
|
|
df['period'] = df['date'].dt.to_period('M').dt.start_time
|
|
|
|
|
|
else:
|
|
|
|
|
|
df['period'] = df['date'].dt.date
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 聚合
|
|
|
|
|
|
out_trend = df[df['type'] == 'outpatient'].groupby('period').size()
|
|
|
|
|
|
in_trend = df[df['type'] == 'inpatient'].groupby('period').size()
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
periods = sorted(set(out_trend.index.tolist() + in_trend.index.tolist()))
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
trend = []
|
|
|
|
|
|
total_out = total_in = 0
|
|
|
|
|
|
for p in periods:
|
|
|
|
|
|
out_count = int(out_trend.get(p, 0))
|
|
|
|
|
|
in_count = int(in_trend.get(p, 0))
|
|
|
|
|
|
total_out += out_count
|
|
|
|
|
|
total_in += in_count
|
|
|
|
|
|
trend.append(TrendPoint(
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
date=str(p).split(' ')[0] if hasattr(p, 'strftime') else str(p)[:10],
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
outpatient=out_count,
|
|
|
|
|
|
inpatient=in_count,
|
|
|
|
|
|
total=out_count + in_count
|
|
|
|
|
|
))
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
return TrendResponse(
|
|
|
|
|
|
trend=trend,
|
|
|
|
|
|
summary={
|
|
|
|
|
|
"total_outpatient": total_out,
|
|
|
|
|
|
"total_inpatient": total_in,
|
|
|
|
|
|
"period_count": len(periods),
|
|
|
|
|
|
"avg_daily_outpatient": round(total_out / max(len(periods), 1), 2),
|
|
|
|
|
|
"avg_daily_inpatient": round(total_in / max(len(periods), 1), 2),
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
def _compute_cases_districts(
|
|
|
|
|
|
case_type: Optional[str],
|
|
|
|
|
|
min_count: int,
|
|
|
|
|
|
diagnosis: Optional[str],
|
|
|
|
|
|
start_date: Optional[str] = None,
|
|
|
|
|
|
end_date: Optional[str] = None,
|
|
|
|
|
|
) -> DistrictsResponse:
|
|
|
|
|
|
"""Run the full pandas aggregation pipeline (called in thread pool)."""
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
df = get_combined_data()
|
|
|
|
|
|
|
|
|
|
|
|
# 诊断过滤
|
|
|
|
|
|
if diagnosis:
|
|
|
|
|
|
df = df[df['diagnosis'].str.contains(diagnosis, na=False, case=False)]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
|
|
|
|
|
# 日期过滤
|
|
|
|
|
|
if start_date:
|
|
|
|
|
|
df = df[df['date'] >= pd.to_datetime(start_date)]
|
|
|
|
|
|
if end_date:
|
|
|
|
|
|
df = df[df['date'] <= pd.to_datetime(end_date)]
|
|
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 类型过滤
|
|
|
|
|
|
if case_type == "outpatient":
|
|
|
|
|
|
df = df[df['type'] == 'outpatient']
|
|
|
|
|
|
elif case_type == "inpatient":
|
|
|
|
|
|
df = df[df['type'] == 'inpatient']
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 过滤未知区域
|
|
|
|
|
|
df = df[(df['district'] != '未知') & (df['district'] != '其他')]
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 聚合
|
|
|
|
|
|
district_stats = df.groupby(['district', 'type']).size().unstack(fill_value=0)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
if 'outpatient' not in district_stats.columns:
|
|
|
|
|
|
district_stats['outpatient'] = 0
|
|
|
|
|
|
if 'inpatient' not in district_stats.columns:
|
|
|
|
|
|
district_stats['inpatient'] = 0
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
district_stats['total'] = district_stats['outpatient'] + district_stats['inpatient']
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 过滤
|
|
|
|
|
|
district_stats = district_stats[district_stats['total'] >= min_count]
|
|
|
|
|
|
district_stats = district_stats.sort_values('total', ascending=False)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
total = int(district_stats['total'].sum())
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
districts = []
|
|
|
|
|
|
for district, row in district_stats.iterrows():
|
|
|
|
|
|
districts.append(DistrictData(
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
district=str(district),
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
outpatient=int(row['outpatient']),
|
|
|
|
|
|
inpatient=int(row['inpatient']),
|
|
|
|
|
|
total=int(row['total']),
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
outpatient_ratio=round(float(row['outpatient']) / float(row['total']) * 100, 2) if row['total'] > 0 else 0,
|
|
|
|
|
|
inpatient_ratio=round(float(row['inpatient']) / float(row['total']) * 100, 2) if row['total'] > 0 else 0
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
))
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
return DistrictsResponse(districts=districts, total=total)
|
|
|
|
|
|
|
|
|
|
|
|
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
@router.get("/districts", response_model=DistrictsResponse, summary="获取区域分布数据")
|
|
|
|
|
|
async def get_cases_districts(
|
|
|
|
|
|
case_type: Optional[str] = Query(None, description="病例类型:outpatient, inpatient, all"),
|
|
|
|
|
|
min_count: int = Query(10, description="最小病例数过滤"),
|
|
|
|
|
|
diagnosis: Optional[str] = Query(None, description="Filter by diagnosis name"),
|
|
|
|
|
|
start_date: Optional[str] = Query(None, description="开始日期 (YYYY-MM-DD)"),
|
|
|
|
|
|
end_date: Optional[str] = Query(None, description="结束日期 (YYYY-MM-DD)"),
|
|
|
|
|
|
):
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取病例区域分布数据
|
|
|
|
|
|
|
|
|
|
|
|
- 支持按病例类型筛选
|
|
|
|
|
|
- 可设置最小病例数过滤
|
|
|
|
|
|
- 支持日期范围过滤
|
|
|
|
|
|
- 返回各区门诊、住院量及占比
|
|
|
|
|
|
|
|
|
|
|
|
Pandas processing runs in a thread pool to avoid blocking the async event loop.
|
|
|
|
|
|
"""
|
|
|
|
|
|
return await asyncio.to_thread(
|
|
|
|
|
|
_compute_cases_districts, case_type, min_count, diagnosis, start_date, end_date
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
@router.get("/realtime", response_model=RealtimeData, summary="获取实时数据")
|
|
|
|
|
|
async def get_cases_realtime():
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取实时病例数据
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
- 今日就诊量
|
|
|
|
|
|
- 近 7 日平均值
|
|
|
|
|
|
- 变化率
|
|
|
|
|
|
- 状态评估 (正常/偏高/偏低)
|
|
|
|
|
|
"""
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
df = get_combined_data()
|
|
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
today = pd.Timestamp.today().normalize()
|
|
|
|
|
|
last_7d = today - pd.Timedelta(days=7)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 今日数据
|
|
|
|
|
|
today_data = df[df['date'] >= today]
|
|
|
|
|
|
today_total = len(today_data)
|
|
|
|
|
|
today_out = len(today_data[today_data['type'] == 'outpatient'])
|
|
|
|
|
|
today_in = len(today_data[today_data['type'] == 'inpatient'])
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 近 7 日平均
|
|
|
|
|
|
last_7d_data = df[(df['date'] >= last_7d) & (df['date'] < today)]
|
|
|
|
|
|
last_7d_avg = round(len(last_7d_data) / 7, 2) if len(last_7d_data) > 0 else 0
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 变化率
|
|
|
|
|
|
if last_7d_avg > 0:
|
|
|
|
|
|
change_ratio = round((today_total - last_7d_avg) / last_7d_avg * 100, 2)
|
|
|
|
|
|
else:
|
|
|
|
|
|
change_ratio = 0.0
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
# 状态评估
|
|
|
|
|
|
if change_ratio > 20:
|
|
|
|
|
|
status = "偏高"
|
|
|
|
|
|
elif change_ratio < -20:
|
|
|
|
|
|
status = "偏低"
|
|
|
|
|
|
else:
|
|
|
|
|
|
status = "正常"
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
return RealtimeData(
|
|
|
|
|
|
today_outpatient=today_out,
|
|
|
|
|
|
today_inpatient=today_in,
|
|
|
|
|
|
today_total=today_total,
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
last_7d_avg=int(last_7d_avg),
|
feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.
Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.
Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review
Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00
|
|
|
|
change_ratio=change_ratio,
|
|
|
|
|
|
status=status
|
|
|
|
|
|
)
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiagnosesResponse(BaseModel):
|
|
|
|
|
|
"""诊断列表响应"""
|
|
|
|
|
|
diagnoses: list[str]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/diagnoses", response_model=DiagnosesResponse, summary="获取所有诊断名称列表")
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
async def get_diagnoses_list():
|
|
|
|
|
|
"""Returns deduplicated, sorted list of unique diagnosis names (cached, fast)."""
|
|
|
|
|
|
diagnoses = get_diagnoses()
|
feat: add reports center, admin drill-down, disease filter + bug fixes + perf optimization
Frontend features:
- 报表中心 (ReportsCenter): list/detail views, diagnosis breakdown chart, CSV export
- 多级行政下钻 (AdminBreadcrumb): 湖北省→武汉市→区→街道 hierarchical drill-down
- 按病种筛选 (DiseaseFilter): multi-select diagnosis filter on monitoring + reports pages
Backend:
- Add /forecast/{days} endpoint, diagnosis filter params on cases endpoints
- Add /streets aggregation endpoint, enrich reports with real case data
- Extract shared case_loader module
Bug fixes (14):
- Fix missing /risk/forecast route (404), historyApi pointing to non-existent router
- Fix min_risk filter silently ignored in insights/hotspots
- Fix type mismatches: CaseTrendResponse, CaseStatsResponse shapes
- Fix silent .catch(() => {}) swallowing errors, fetchAlerts not clearing stale state
- Fix lru_cache caching exceptions, generateReport used cachedGet for write op
- Fix missing useEffect deps in Insights, DistrictComparison, ReportsCenter
Performance (9):
- Zustand selectors across 9 components (eliminate re-render cascades)
- Fix districtCases.sort() mutating store state, inline IIFE → memo'd component
- CaseLocationMap: React.memo, race protection, correct deps
- AlertCard: stable callbacks, TimelinePlayer: useMemo, TopNav: clock isolation
- SideNav: modules array to module scope, DiseaseFilter: memoized filter
2026-06-08 18:40:08 +08:00
|
|
|
|
return DiagnosesResponse(diagnoses=diagnoses)
|
feat: add analysis pages and raster risk map
Ship a new app version with broader analytics, restructured
dashboards, and a server-rendered risk map.
Frontend:
- Add Overview, Demographic, Disease, and Environmental Health
analysis pages
- Add AnomalyMarkers, CalendarHeatmap, and MetricHeatmapTable
components
- Rebuild Alerts map onto server-rendered raster risk tiles;
expand Monitoring, Trend, and District Comparison views
- Extend API client, stores, and TypeScript types
Backend:
- Add environment router (pollutants, lag correlations)
- Add risk_raster util serving XYZ 100m risk tiles
- Expand cases endpoints (demographics, seasonality, diagnoses)
and insights; harden auth and file-based loaders
Data & tooling:
- Add processed outpatient/inpatient/combined case parquet (LFS)
- Add nested CLAUDE.md guides, pyrightconfig, and test updates
2026-06-21 17:35:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Seasonal & Distribution Endpoints ==============
|
|
|
|
|
|
|
|
|
|
|
|
class SeasonalPoint(BaseModel):
|
|
|
|
|
|
"""月度聚合数据点"""
|
|
|
|
|
|
month: int # 1-12
|
|
|
|
|
|
month_label: str # "1月", "2月", ...
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SeasonalResponse(BaseModel):
|
|
|
|
|
|
"""月度季节性响应"""
|
|
|
|
|
|
monthly: list[SeasonalPoint]
|
|
|
|
|
|
period_years: list[int] # e.g. [2022, 2023, 2024]
|
|
|
|
|
|
total_cases: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiagnosisDistributionItem(BaseModel):
|
|
|
|
|
|
"""诊断分布数据项"""
|
|
|
|
|
|
diagnosis: str
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
percentage: float
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiagnosisDistributionResponse(BaseModel):
|
|
|
|
|
|
"""诊断分布响应"""
|
|
|
|
|
|
diagnoses: list[DiagnosisDistributionItem]
|
|
|
|
|
|
total_cases: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Demographics Models ==============
|
|
|
|
|
|
|
|
|
|
|
|
class AgeBin(BaseModel):
|
|
|
|
|
|
"""年龄分段数据"""
|
|
|
|
|
|
age_bin: int # 0-17
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GenderSplit(BaseModel):
|
|
|
|
|
|
"""性别拆分数据"""
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GenderSplitData(BaseModel):
|
|
|
|
|
|
"""性别分布响应内层"""
|
|
|
|
|
|
male: GenderSplit
|
|
|
|
|
|
female: GenderSplit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AgeDiagnosisMatrixItem(BaseModel):
|
|
|
|
|
|
"""年龄-诊断矩阵项"""
|
|
|
|
|
|
age_group: str # "0-1", "1-3", "3-6", "6-12", "12-18"
|
|
|
|
|
|
diagnosis: str
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DemographicsResponse(BaseModel):
|
|
|
|
|
|
"""人口统计响应"""
|
|
|
|
|
|
age_distribution: list[AgeBin]
|
|
|
|
|
|
gender_split: GenderSplitData
|
|
|
|
|
|
age_diagnosis_matrix: list[AgeDiagnosisMatrixItem]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Disease Seasonality Models ==============
|
|
|
|
|
|
|
|
|
|
|
|
class DiseaseSeasonalityPoint(BaseModel):
|
|
|
|
|
|
"""疾病月度季节性数据点"""
|
|
|
|
|
|
diagnosis: str
|
|
|
|
|
|
month: int # 1-12
|
|
|
|
|
|
month_label: str # "1月"-"12月"
|
|
|
|
|
|
outpatient: int
|
|
|
|
|
|
inpatient: int
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiseaseDistrictItem(BaseModel):
|
|
|
|
|
|
"""单个诊断的区域分布(按病例数排序的前若干区)"""
|
|
|
|
|
|
diagnosis: str
|
|
|
|
|
|
district: str
|
|
|
|
|
|
total: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiseaseSeasonalityResponse(BaseModel):
|
|
|
|
|
|
"""疾病季节性响应"""
|
|
|
|
|
|
seasonality: list[DiseaseSeasonalityPoint]
|
|
|
|
|
|
diagnoses: list[str]
|
|
|
|
|
|
# 每个诊断的真实区域分布(按区聚合),使前端可为每个诊断显示其各自的"主要区域"
|
|
|
|
|
|
diagnosis_districts: list[DiseaseDistrictItem]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/seasonal", response_model=SeasonalResponse, summary="获取季节性月度聚合数据")
|
|
|
|
|
|
async def get_cases_seasonal(
|
|
|
|
|
|
diagnosis: Optional[str] = Query(None, description="Filter by diagnosis name"),
|
|
|
|
|
|
):
|
|
|
|
|
|
"""
|
|
|
|
|
|
按月聚合所有年份的病例数据
|
|
|
|
|
|
|
|
|
|
|
|
- 返回 1-12 月各月门诊/住院/总计均值
|
|
|
|
|
|
- 支持诊断过滤
|
|
|
|
|
|
- 用于季节性分解图表
|
|
|
|
|
|
"""
|
|
|
|
|
|
df = get_combined_data()
|
|
|
|
|
|
|
|
|
|
|
|
if diagnosis:
|
|
|
|
|
|
df = df[df['diagnosis'].str.contains(diagnosis, na=False, case=False)]
|
|
|
|
|
|
|
|
|
|
|
|
# Extract month and aggregate
|
|
|
|
|
|
df = df.copy()
|
|
|
|
|
|
df['month'] = df['date'].dt.month
|
|
|
|
|
|
years = sorted(df['date'].dt.year.unique().tolist())
|
|
|
|
|
|
|
|
|
|
|
|
out_monthly = df[df['type'] == 'outpatient'].groupby('month').size()
|
|
|
|
|
|
in_monthly = df[df['type'] == 'inpatient'].groupby('month').size()
|
|
|
|
|
|
|
|
|
|
|
|
month_labels = ['1月', '2月', '3月', '4月', '5月', '6月',
|
|
|
|
|
|
'7月', '8月', '9月', '10月', '11月', '12月']
|
|
|
|
|
|
|
|
|
|
|
|
monthly = []
|
|
|
|
|
|
total_cases = 0
|
|
|
|
|
|
for m in range(1, 13):
|
|
|
|
|
|
out_count = int(out_monthly.get(m, 0))
|
|
|
|
|
|
in_count = int(in_monthly.get(m, 0))
|
|
|
|
|
|
total_cases += out_count + in_count
|
|
|
|
|
|
monthly.append(SeasonalPoint(
|
|
|
|
|
|
month=m,
|
|
|
|
|
|
month_label=month_labels[m - 1],
|
|
|
|
|
|
outpatient=out_count,
|
|
|
|
|
|
inpatient=in_count,
|
|
|
|
|
|
total=out_count + in_count,
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
return SeasonalResponse(
|
|
|
|
|
|
monthly=monthly,
|
|
|
|
|
|
period_years=years,
|
|
|
|
|
|
total_cases=total_cases,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/diagnosis-distribution", response_model=DiagnosisDistributionResponse, summary="获取诊断分布统计")
|
|
|
|
|
|
async def get_diagnosis_distribution(
|
|
|
|
|
|
limit: int = Query(default=20, ge=1, le=50, description="Maximum diagnoses to return"),
|
|
|
|
|
|
):
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取诊断名称分布统计(门诊+住院分列)
|
|
|
|
|
|
|
|
|
|
|
|
- 返回前 N 个诊断及门诊/住院/总计/占比
|
|
|
|
|
|
- 用于诊断分布饼图、树图等
|
|
|
|
|
|
"""
|
|
|
|
|
|
df = get_combined_data()
|
|
|
|
|
|
|
|
|
|
|
|
# Compute O/I counts per diagnosis
|
|
|
|
|
|
breakdown = df.groupby(['diagnosis', 'type']).size().unstack(fill_value=0)
|
|
|
|
|
|
if 'outpatient' not in breakdown.columns:
|
|
|
|
|
|
breakdown['outpatient'] = 0
|
|
|
|
|
|
if 'inpatient' not in breakdown.columns:
|
|
|
|
|
|
breakdown['inpatient'] = 0
|
|
|
|
|
|
breakdown['total'] = breakdown['outpatient'] + breakdown['inpatient']
|
|
|
|
|
|
breakdown = breakdown.sort_values('total', ascending=False).head(limit)
|
|
|
|
|
|
|
|
|
|
|
|
grand_total = int(breakdown['total'].sum())
|
|
|
|
|
|
|
|
|
|
|
|
diagnoses = []
|
|
|
|
|
|
for diagnosis_name, row in breakdown.iterrows():
|
|
|
|
|
|
diagnoses.append(DiagnosisDistributionItem(
|
|
|
|
|
|
diagnosis=str(diagnosis_name),
|
|
|
|
|
|
outpatient=int(row['outpatient']),
|
|
|
|
|
|
inpatient=int(row['inpatient']),
|
|
|
|
|
|
total=int(row['total']),
|
|
|
|
|
|
percentage=round(float(row['total']) / float(grand_total) * 100, 2) if grand_total > 0 else 0,
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
return DiagnosisDistributionResponse(
|
|
|
|
|
|
diagnoses=diagnoses,
|
|
|
|
|
|
total_cases=grand_total,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Demographics Endpoint ==============
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/demographics", response_model=DemographicsResponse, summary="获取人口统计信息")
|
|
|
|
|
|
async def get_cases_demographics():
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取病例人口统计信息
|
|
|
|
|
|
|
|
|
|
|
|
- 年龄分布(0-17岁,按1岁分段,仅住院数据)
|
|
|
|
|
|
- 性别分布(仅住院数据)
|
|
|
|
|
|
- 年龄-诊断矩阵(按年龄段分组,仅住院数据)
|
|
|
|
|
|
|
|
|
|
|
|
注意:门诊数据不包含人口统计信息(性别/年龄),因此门诊计数均为 0。
|
|
|
|
|
|
"""
|
|
|
|
|
|
df = get_inpatient_data()
|
|
|
|
|
|
df = df.copy()
|
|
|
|
|
|
df['age_bin'] = df['年龄'].clip(0, 17).astype(int)
|
|
|
|
|
|
|
|
|
|
|
|
# --- Age distribution: 1-year bins from 0 to 17 ---
|
|
|
|
|
|
age_counts = df.groupby('age_bin').size()
|
|
|
|
|
|
age_distribution = [
|
|
|
|
|
|
AgeBin(age_bin=a, outpatient=0, inpatient=int(age_counts.get(a, 0)))
|
|
|
|
|
|
for a in range(0, 18)
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# --- Gender split ---
|
|
|
|
|
|
gender_counts = df['性别'].value_counts()
|
|
|
|
|
|
gender_split = GenderSplitData(
|
|
|
|
|
|
male=GenderSplit(outpatient=0, inpatient=int(gender_counts.get('男性', 0))),
|
|
|
|
|
|
female=GenderSplit(outpatient=0, inpatient=int(gender_counts.get('女性', 0))),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# --- Age-diagnosis matrix ---
|
|
|
|
|
|
age_bins = [
|
|
|
|
|
|
(0, 1, "0-1"), (1, 3, "1-3"), (3, 6, "3-6"),
|
|
|
|
|
|
(6, 12, "6-12"), (12, 18, "12-18"),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
matrix_rows: list[AgeDiagnosisMatrixItem] = []
|
|
|
|
|
|
for low, high, label in age_bins:
|
|
|
|
|
|
group = df[(df['年龄'] >= low) & (df['年龄'] < high)]
|
|
|
|
|
|
for diag, count in group['诊断名称'].value_counts().items():
|
|
|
|
|
|
matrix_rows.append(AgeDiagnosisMatrixItem(
|
|
|
|
|
|
age_group=label, diagnosis=str(diag),
|
|
|
|
|
|
outpatient=0, inpatient=int(count), total=int(count),
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
return DemographicsResponse(
|
|
|
|
|
|
age_distribution=age_distribution,
|
|
|
|
|
|
gender_split=gender_split,
|
|
|
|
|
|
age_diagnosis_matrix=matrix_rows,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============== Disease Seasonality Endpoint ==============
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/disease-seasonality", response_model=DiseaseSeasonalityResponse, summary="获取疾病季节性数据")
|
|
|
|
|
|
async def get_disease_seasonality(
|
|
|
|
|
|
diagnosis: Optional[str] = Query(None, description="Filter by diagnosis name"),
|
|
|
|
|
|
):
|
|
|
|
|
|
"""
|
|
|
|
|
|
获取各诊断的月度季节性分布数据
|
|
|
|
|
|
|
|
|
|
|
|
- 基于门诊+住院合并数据
|
|
|
|
|
|
- 按月聚合所有年份,返回 top 10 诊断的月度分布
|
|
|
|
|
|
- 支持可选诊断过滤
|
|
|
|
|
|
- 用于疾病季节性热力图、雷达图等
|
|
|
|
|
|
"""
|
|
|
|
|
|
df = get_combined_data()
|
|
|
|
|
|
|
|
|
|
|
|
if diagnosis:
|
|
|
|
|
|
df = df[df['diagnosis'].str.contains(diagnosis, na=False, case=False)]
|
|
|
|
|
|
|
|
|
|
|
|
# Extract month
|
|
|
|
|
|
df = df.copy()
|
|
|
|
|
|
df['month'] = df['date'].dt.month
|
|
|
|
|
|
|
|
|
|
|
|
# Get top 10 diagnoses by total case count
|
|
|
|
|
|
diag_totals = df.groupby('diagnosis').size().nlargest(10)
|
|
|
|
|
|
top_diagnoses = diag_totals.index.tolist()
|
|
|
|
|
|
|
|
|
|
|
|
month_labels = ['1月', '2月', '3月', '4月', '5月', '6月',
|
|
|
|
|
|
'7月', '8月', '9月', '10月', '11月', '12月']
|
|
|
|
|
|
|
|
|
|
|
|
# Filter to top diagnoses
|
|
|
|
|
|
df_top = df[df['diagnosis'].isin(top_diagnoses)]
|
|
|
|
|
|
|
|
|
|
|
|
# Group by diagnosis + month
|
|
|
|
|
|
breakdown = df_top.groupby(['diagnosis', 'month', 'type']).size().unstack(fill_value=0)
|
|
|
|
|
|
if 'outpatient' not in breakdown.columns:
|
|
|
|
|
|
breakdown['outpatient'] = 0
|
|
|
|
|
|
if 'inpatient' not in breakdown.columns:
|
|
|
|
|
|
breakdown['inpatient'] = 0
|
|
|
|
|
|
|
|
|
|
|
|
seasonality: list[DiseaseSeasonalityPoint] = []
|
|
|
|
|
|
for diag in top_diagnoses:
|
|
|
|
|
|
for m in range(1, 13):
|
|
|
|
|
|
row = breakdown.loc[(diag, m)] if (diag, m) in breakdown.index else None
|
|
|
|
|
|
out_count = int(row['outpatient']) if row is not None else 0
|
|
|
|
|
|
in_count = int(row['inpatient']) if row is not None else 0
|
|
|
|
|
|
seasonality.append(DiseaseSeasonalityPoint(
|
|
|
|
|
|
diagnosis=str(diag),
|
|
|
|
|
|
month=m,
|
|
|
|
|
|
month_label=month_labels[m - 1],
|
|
|
|
|
|
outpatient=out_count,
|
|
|
|
|
|
inpatient=in_count,
|
|
|
|
|
|
total=out_count + in_count,
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
# Per-diagnosis district distribution (real aggregation by diagnosis × district).
|
|
|
|
|
|
# Previously the frontend showed the same "主要区域" for every diagnosis because
|
|
|
|
|
|
# no per-diagnosis district data was exposed. Top 3 districts per diagnosis.
|
|
|
|
|
|
df_districts = df_top[(df_top['district'] != '未知') & (df_top['district'] != '其他')]
|
|
|
|
|
|
diag_district_counts = df_districts.groupby(['diagnosis', 'district']).size()
|
|
|
|
|
|
diagnosis_districts: list[DiseaseDistrictItem] = []
|
|
|
|
|
|
for diag in top_diagnoses:
|
|
|
|
|
|
if diag not in diag_district_counts.index.get_level_values('diagnosis'):
|
|
|
|
|
|
continue
|
|
|
|
|
|
top_d = diag_district_counts.loc[diag].sort_values(ascending=False).head(3)
|
|
|
|
|
|
for district_name, count in top_d.items():
|
|
|
|
|
|
diagnosis_districts.append(DiseaseDistrictItem(
|
|
|
|
|
|
diagnosis=str(diag),
|
|
|
|
|
|
district=str(district_name),
|
|
|
|
|
|
total=int(count),
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
return DiseaseSeasonalityResponse(
|
|
|
|
|
|
seasonality=seasonality,
|
|
|
|
|
|
diagnoses=[str(d) for d in top_diagnoses],
|
|
|
|
|
|
diagnosis_districts=diagnosis_districts,
|
|
|
|
|
|
)
|