|
@@ -21,7 +21,10 @@ router = APIRouter(prefix="/graph", tags=["Knowledge Graph"])
|
|
|
|
|
|
@router.get("/nodes/recommend", response_model=StandardResponse)
|
|
|
async def recommend(
|
|
|
- chief: str
|
|
|
+ chief: str,
|
|
|
+ sex: Optional[str] = None,
|
|
|
+ age: Optional[int] = None,
|
|
|
+ department: Optional[str] = None,
|
|
|
):
|
|
|
start_time = time.time()
|
|
|
app_id = "256fd853-60b0-4357-b11b-8114b4e90ae0"
|
|
@@ -29,7 +32,7 @@ async def recommend(
|
|
|
result = call_chat_api(app_id, conversation_id, chief)
|
|
|
json_data = json.loads(result)
|
|
|
keyword = " ".join(json_data["symptoms"])
|
|
|
- result = await neighbor_search(keyword=keyword, neighbor_type='Check', limit=10)
|
|
|
+ result = await neighbor_search(keyword=keyword,sex=sex,age=age, neighbor_type='Check', limit=10)
|
|
|
end_time = time.time()
|
|
|
print(f"recommend执行完成,耗时:{end_time - start_time:.2f}秒")
|
|
|
return result;
|
|
@@ -38,6 +41,9 @@ async def recommend(
|
|
|
@router.get("/nodes/neighbor_search", response_model=StandardResponse)
|
|
|
async def neighbor_search(
|
|
|
keyword: str = Query(..., min_length=2),
|
|
|
+ sex: Optional[str] = None,
|
|
|
+ age: Optional[int] = None,
|
|
|
+ department: Optional[str] = None,
|
|
|
limit: int = Query(10, ge=1, le=100),
|
|
|
node_type: Optional[str] = Query(None),
|
|
|
neighbor_type: Optional[str] = Query(None),
|
|
@@ -52,14 +58,18 @@ async def neighbor_search(
|
|
|
keywords = keyword.split(" ")
|
|
|
|
|
|
record = CDSSInput(
|
|
|
- #pat_age=CDSSInt(type="month", value=24),
|
|
|
- #pat_sex=CDSSText(type="sex", value="女"),
|
|
|
+ pat_age=CDSSInt(type="month", value=age),
|
|
|
+ pat_sex=CDSSText(type="sex", value=sex),
|
|
|
chief_complaint=keywords,
|
|
|
+ department=CDSSText(type='department', value=department)
|
|
|
)
|
|
|
# 使用从main.py导入的capability实例处理CDSS逻辑
|
|
|
output = capability.process(input=record)
|
|
|
+
|
|
|
+ output.diagnosis.value = [{"name":key,"score":value["score"],"count":value["count"],
|
|
|
+ "hasInfo": 1,
|
|
|
+ "type": 1} for key,value in output.diagnosis.value.items()]
|
|
|
|
|
|
- print(output.diagnosis.value)
|
|
|
return StandardResponse(
|
|
|
success=True,
|
|
|
data={"可能诊断":output.diagnosis.value,"症状":keywords,"推荐检验":output.checks.value}
|