Files
vueapp/api/chat.ts
T
2026-05-29 17:40:10 +08:00

107 lines
2.9 KiB
TypeScript

import type { ClinicalCase } from './cases'
export type ChatRole = 'patient' | 'mentor' | 'doctor'
export type ChatMessage = {
id: string
role: ChatRole
content: string
label: string
}
export type ChatSession = {
patient: {
name: string
gender: string
age: number
department: string
chiefComplaint: string
}
stages: Array<{
key: string
label: string
active: boolean
}>
messages: ChatMessage[]
}
const defaultCase: ClinicalCase = {
id: 'case-1006004',
title: '持续胸痛3小时',
patientName: '陈先生',
gender: '男',
age: 60,
department: '心血管内科',
scene: '住院部',
caseNo: '1006004',
tone: 'orange'
}
export function createMockChatSession(caseItem?: ClinicalCase | null): Promise<ChatSession> {
const currentCase = caseItem || defaultCase
const patientName = currentCase.patientName === '毕波涛' ? '陈先生' : currentCase.patientName
return Promise.resolve({
patient: {
name: patientName,
gender: currentCase.gender,
age: currentCase.age,
department: currentCase.department,
chiefComplaint: currentCase.title
},
stages: [
{ key: 'history', label: '病史采集', active: true },
{ key: 'diagnosis', label: '初步诊断', active: false },
{ key: 'treatment', label: '治疗方案', active: false }
],
messages: [
{
id: 'patient-initial',
role: 'patient',
content: currentCase.department === '心血管内科'
? '医生,我心口这儿针扎一样疼了两个小时了,现在感觉喘气都费劲。'
: `医生,我这次主要是${currentCase.title},有点担心。`,
label: '患者'
},
{
id: 'mentor-initial',
role: 'mentor',
content: '观察患者的面部表情和生命体征。你的第一个问题应该如何询问,以明确疼痛的性质?',
label: '王主任'
}
]
})
}
export function sendMockChatMessage(content: string): Promise<ChatMessage[]> {
const normalized = content.trim()
const patientReply = normalized.includes('出冷汗') || normalized.includes('恶心')
? '有,刚才疼得厉害的时候出了一身冷汗,还有点恶心,但没有吐。'
: normalized.includes('体格检查')
? '患者面色苍白,额部出汗,心率偏快,血压较入院时略低。'
: normalized.includes('辅助检查')
? '心电图提示下壁导联 ST 段抬高,肌钙蛋白待回报。'
: '疼痛主要在胸骨后,像压榨一样,休息后也没有明显缓解。'
return Promise.resolve([
{
id: `doctor-${Date.now()}`,
role: 'doctor',
content: normalized,
label: '我'
},
{
id: `patient-${Date.now() + 1}`,
role: 'patient',
content: patientReply,
label: '患者'
},
{
id: `mentor-${Date.now() + 2}`,
role: 'mentor',
content: '很好,继续围绕 OPQRST 思路追问疼痛诱因、部位、性质、放射、持续时间和缓解因素,同时关注危险信号。',
label: '王主任'
}
])
}