更新
This commit is contained in:
@@ -90,6 +90,49 @@ export function parsePartialDietPlainText(text) {
|
||||
return out
|
||||
}
|
||||
|
||||
/** 从流式纯文本中提取血糖照护建议(支持未写完的最后一行) */
|
||||
export function parsePartialBloodCarePlainText(text) {
|
||||
const out = {}
|
||||
if (!text) return out
|
||||
|
||||
const lineRe = /^(总评|血糖|中医|留意|复诊)[::]\s*(.*)$/gm
|
||||
let match
|
||||
while ((match = lineRe.exec(text)) !== null) {
|
||||
const key = {
|
||||
'总评': 'summary',
|
||||
'血糖': 'blood_advice',
|
||||
'中医': 'tcm_plan',
|
||||
'留意': 'watch_points',
|
||||
'复诊': 'next_steps'
|
||||
}[match[1]]
|
||||
const val = (match[2] || '').trim()
|
||||
if (key === 'watch_points') {
|
||||
out.watch_points = val.split(/[、,,;;\s]+/).map((s) => s.trim()).filter(Boolean)
|
||||
} else {
|
||||
out[key] = val
|
||||
}
|
||||
}
|
||||
|
||||
const tail = text.match(/(?:^|\n)(总评|血糖|中医|留意|复诊)[::]\s*([^\n]*)$/)
|
||||
if (tail) {
|
||||
const key = {
|
||||
'总评': 'summary',
|
||||
'血糖': 'blood_advice',
|
||||
'中医': 'tcm_plan',
|
||||
'留意': 'watch_points',
|
||||
'复诊': 'next_steps'
|
||||
}[tail[1]]
|
||||
const val = (tail[2] || '').trim()
|
||||
if (key === 'watch_points') {
|
||||
if (val) out.watch_points = val.split(/[、,,;;\s]+/).map((s) => s.trim()).filter(Boolean)
|
||||
} else {
|
||||
out[key] = val
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
/** @deprecated 使用 parsePartialDietPlainText */
|
||||
export function parsePartialDietJson(text) {
|
||||
return parsePartialDietPlainText(text)
|
||||
|
||||
Reference in New Issue
Block a user