feat: 联调对话功能
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { FASTAPI_BASE_URL, authHeaders, readError, type ApiEnvelope } from './session'
|
||||
|
||||
export type TreatmentDraft = {
|
||||
treatmentPrinciple: string
|
||||
treatmentMeasures: string
|
||||
riskPlan: string
|
||||
communication: string
|
||||
followUp: string
|
||||
}
|
||||
|
||||
export type TreatmentPayload = {
|
||||
treatment_principle: string
|
||||
treatment_measures: string
|
||||
risk_plan: string
|
||||
communication: string
|
||||
follow_up: string
|
||||
}
|
||||
|
||||
export async function submitTreatment(sessionId: number, draft: TreatmentDraft) {
|
||||
const payload: TreatmentPayload = {
|
||||
treatment_principle: draft.treatmentPrinciple.trim(),
|
||||
treatment_measures: draft.treatmentMeasures.trim(),
|
||||
risk_plan: draft.riskPlan.trim(),
|
||||
communication: draft.communication.trim(),
|
||||
follow_up: draft.followUp.trim()
|
||||
}
|
||||
|
||||
const response = await fetch(`${FASTAPI_BASE_URL}/sessions/${sessionId}/treatment`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders(),
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(await readError(response))
|
||||
}
|
||||
|
||||
const result = (await response.json()) as ApiEnvelope<unknown>
|
||||
if (result.code !== 'OK') {
|
||||
throw new Error(result.message || '治疗方案提交失败')
|
||||
}
|
||||
|
||||
return result.data || payload
|
||||
}
|
||||
Reference in New Issue
Block a user