動作
Feature #150
已結束
SC
SC
實作基於 Ollama 的 ICD-10 Extraction API
Feature #150:
實作基於 Ollama 的 ICD-10 Extraction API
概述
於 Backend 建立一個新的 API Endpoint,功能為接收外傷病歷敘述 (Trauma Note),並利用本地運行的 LLM (Ollama) 自動提取並建議對應的 ICD-10-CM 診斷碼。
技術實作細節 (Technical Implementation)
- 套件安裝: 在 Backend 環境中安裝 ollama python library 以進行模型串接。
- API Endpoint:
- 路徑: POST /predict_icd10
- 框架: FastAPI
- Data Validation (Pydantic):
- 建立 TraumaNote model,包含欄位 text (str) 作為輸入。
- LLM 整合邏輯:
- 使用 ollama.chat 呼叫本地模型 (Llama 3)。
- System Prompt 設計:
- 定義角色為 "Professional Medical Coder"。
- 要求分析傷勢並映射至最具體之 ICD-10-CM codes。
- 預設使用 "Initial encounter" (XXA) 後綴。
- 輸出格式: 強制要求為 Strict JSON 格式。
輸入/輸出規格 (I/O Specification)
- Request Payload:
{
"text": "Patient with 5cm laceration on right forehead."
}
- Response (JSON): 需包含代碼、英文描述以及繁體中文翻譯。
{
"results": [
{
"code": "S01.81XA",
"description_en": "Laceration without foreign body of other part of head, initial encounter",
"description_zh": "頭部其他部位撕裂傷,無異物,初次遭遇"
}
]
}
驗收標準 (Acceptance Criteria)
API 能成功接收字串並回傳符合 Schema 的 JSON。¶
回傳內容包含正確的 ICD-10 Code 格式。¶
回傳內容包含繁體中文翻譯 (description_zh)。¶
動作