添加后端API和前端项目的初始目录结构,包括应用层模块、工具模块和模型定义 配置前后端的.dockerignore文件以排除开发环境文件 添加前端样式文件,包括字体、Tailwind CSS和主题配置 初始化Python虚拟环境中的类型标记文件
97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
import logging
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from app.middleware.auth import get_current_user
|
|
from app.models.report import Report
|
|
from app.models.user import User
|
|
from app.services.ai_service import generate_doctor_questions
|
|
from app.utils.helpers import parse_object_id
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
|
|
# 预设医生列表
|
|
DOCTORS = [
|
|
{
|
|
"id": "1",
|
|
"name": "王丽华",
|
|
"title": "主任医师",
|
|
"hospital": "北京协和医院",
|
|
"specialty": "高危妊娠、产前诊断",
|
|
"experience": "25年",
|
|
"rating": 4.9,
|
|
"review_count": 1280,
|
|
"consult_count": 5600,
|
|
"response_time": "30分钟内",
|
|
"price": {"text": 50, "video": 200, "urgent": 100},
|
|
"tags": ["高危妊娠", "产前诊断", "遗传咨询"],
|
|
},
|
|
{
|
|
"id": "2",
|
|
"name": "张美琳",
|
|
"title": "副主任医师",
|
|
"hospital": "上海第一妇婴保健院",
|
|
"specialty": "孕期营养、妊娠期糖尿病",
|
|
"experience": "18年",
|
|
"rating": 4.8,
|
|
"review_count": 960,
|
|
"consult_count": 3800,
|
|
"response_time": "1小时内",
|
|
"price": {"text": 40, "video": 180, "urgent": 80},
|
|
"tags": ["孕期营养", "妊娠糖尿病", "体重管理"],
|
|
},
|
|
{
|
|
"id": "3",
|
|
"name": "刘晓芳",
|
|
"title": "主任医师",
|
|
"hospital": "广州市妇女儿童医疗中心",
|
|
"specialty": "超声诊断、胎儿医学",
|
|
"experience": "20年",
|
|
"rating": 4.9,
|
|
"review_count": 1100,
|
|
"consult_count": 4200,
|
|
"response_time": "2小时内",
|
|
"price": {"text": 45, "video": 190, "urgent": 90},
|
|
"tags": ["超声诊断", "胎儿医学", "产前筛查"],
|
|
},
|
|
]
|
|
|
|
|
|
@router.get("/questions/{report_id}")
|
|
async def get_doctor_questions(
|
|
report_id: str, user: User = Depends(get_current_user)
|
|
):
|
|
"""生成问诊清单"""
|
|
oid = parse_object_id(report_id)
|
|
report = await Report.get(oid)
|
|
if not report or report.user_id != user.id:
|
|
raise HTTPException(status_code=404, detail="报告不存在")
|
|
|
|
try:
|
|
result = await generate_doctor_questions(report, user)
|
|
except Exception:
|
|
logger.exception("问诊清单生成失败 report_id=%s", report_id)
|
|
raise HTTPException(status_code=502, detail="AI 服务暂时不可用,请稍后重试")
|
|
|
|
return {
|
|
"report_id": report_id,
|
|
"questions": result.get("questions", []),
|
|
}
|
|
|
|
|
|
@router.get("/experts")
|
|
async def list_experts():
|
|
"""获取专家医生列表"""
|
|
return {"doctors": DOCTORS}
|
|
|
|
|
|
@router.get("/experts/{doctor_id}")
|
|
async def get_expert_detail(doctor_id: str):
|
|
"""获取医生详情"""
|
|
for doc in DOCTORS:
|
|
if doc["id"] == doctor_id:
|
|
return doc
|
|
raise HTTPException(status_code=404, detail="医生不存在")
|