109 lines
2.6 KiB
Python
109 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any, Literal, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class Detection(BaseModel):
|
|
label: str
|
|
confidence: float
|
|
bbox: list[float] = Field(description="[x1, y1, x2, y2] 像素坐标")
|
|
label_zh: Optional[str] = None
|
|
|
|
|
|
class ImagingAnalyzeResponse(BaseModel):
|
|
detections: list[Detection] = []
|
|
annotated_image_base64: Optional[str] = None
|
|
preliminary_diagnosis: str
|
|
findings: str
|
|
recommendations: str
|
|
confidence: float
|
|
model_version: str
|
|
mode: Literal["demo", "real"] = "demo"
|
|
full_report: Optional[str] = None
|
|
disclaimer: str = "本结果仅供辅助决策,不能替代执业医师诊断。"
|
|
|
|
|
|
class ImagingReportRequest(BaseModel):
|
|
study_type: str = "CT"
|
|
body_part: str = ""
|
|
patient_summary: str = ""
|
|
preliminary_diagnosis: str = ""
|
|
findings: str = ""
|
|
detections: list[Detection] = []
|
|
confidence: float = 0.85
|
|
|
|
|
|
class ImagingReportResponse(BaseModel):
|
|
findings: str
|
|
impression: str
|
|
recommendations: str
|
|
full_report: str
|
|
model_version: str = "report-v1"
|
|
|
|
|
|
class PatientInfo(BaseModel):
|
|
age: Optional[int] = None
|
|
gender: Optional[str] = None
|
|
name: Optional[str] = None
|
|
|
|
|
|
class DecisionRequest(BaseModel):
|
|
chief_complaint: str = ""
|
|
history: str = ""
|
|
exam_findings: str = ""
|
|
diagnosis: str = ""
|
|
medications: str = ""
|
|
imaging_summary: str = ""
|
|
patient: Optional[PatientInfo] = None
|
|
|
|
|
|
class RiskItem(BaseModel):
|
|
type: str
|
|
description: str
|
|
level: str = "中"
|
|
confidence: float = 0.8
|
|
|
|
|
|
class SourceRef(BaseModel):
|
|
title: str
|
|
snippet: str = ""
|
|
category: str = ""
|
|
score: float = 0.0
|
|
|
|
|
|
class DecisionResponse(BaseModel):
|
|
treatment_suggestions: list[dict[str, Any]] = []
|
|
medication_suggestions: list[dict[str, Any]] = []
|
|
nursing_advice: list[str] = []
|
|
follow_up_plan: list[str] = []
|
|
risks: list[RiskItem] = []
|
|
conflicts: list[str] = []
|
|
sources: list[SourceRef] = []
|
|
full_text: str = ""
|
|
engine: str = "fastapi-rag"
|
|
disclaimer: str = "本结果仅供辅助决策,不能替代执业医师诊断。"
|
|
|
|
|
|
class RagQueryRequest(BaseModel):
|
|
query: str
|
|
top_k: int = 4
|
|
context: str = ""
|
|
|
|
|
|
class RagQueryResponse(BaseModel):
|
|
answer: str
|
|
sources: list[SourceRef] = []
|
|
engine: str = "langchain-rag"
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str = "ok"
|
|
yolo_available: bool = False
|
|
monai_available: bool = False
|
|
langchain_available: bool = False
|
|
llm_configured: bool = False
|
|
demo_mode: str = "auto"
|
|
knowledge_docs: int = 0
|