feat(escort): 病历与诉求支持多材料解析为四段摘要
新增独立病历整理 Agent 与异步解析任务,支持 PDF 文本、图片 OCR、 语音 ASR 与文字输入,统一整理为基础健康、检查治疗、用药和问诊诉求。 Agent 只产出草稿,订单本人在编辑页核对确认后才写入当前订单; 原件在任务结束、失败或取消时立即清除。 inquiry 增加三段规范字段,medicalHistory 保留为旧版兼容摘要, 并兼容旧客户端只写 medicalHistory 的更新方式。
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
export const INQUIRY_FIELDS = ["basicHealth", "treatmentHistory", "medications", "demand"];
|
||||
export const INQUIRY_TEXT_LIMIT = 2000;
|
||||
|
||||
export function cleanInquiryText(value, maxLength = INQUIRY_TEXT_LIMIT) {
|
||||
return String(value ?? "").trim().slice(0, maxLength);
|
||||
}
|
||||
|
||||
export function normalizeInquiry(input = {}) {
|
||||
return Object.fromEntries(
|
||||
INQUIRY_FIELDS.map((field) => [field, cleanInquiryText(input?.[field])])
|
||||
);
|
||||
}
|
||||
|
||||
export function buildLegacyMedicalHistory(inquiry = {}) {
|
||||
const sections = [
|
||||
["基础健康与基础疾病", inquiry.basicHealth],
|
||||
["检查与治疗病历", inquiry.treatmentHistory],
|
||||
["用药情况", inquiry.medications],
|
||||
];
|
||||
return sections
|
||||
.map(([label, value]) => ({ label, text: cleanInquiryText(value) }))
|
||||
.filter(({ text }) => text)
|
||||
.map(({ label, text }) => `${label}:\n${text}`)
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
// 老订单只有 medicalHistory:读取时归入“检查与治疗病历”,不写回数据库。
|
||||
export function normalizeInquiryView(inquiry = {}) {
|
||||
const normalized = normalizeInquiry(inquiry);
|
||||
if (!normalized.basicHealth && !normalized.treatmentHistory && !normalized.medications) {
|
||||
normalized.treatmentHistory = cleanInquiryText(inquiry.medicalHistory);
|
||||
}
|
||||
return {
|
||||
...normalized,
|
||||
medicalHistory: cleanInquiryText(inquiry.medicalHistory, 6500) || buildLegacyMedicalHistory(normalized),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildInquiryUpdate(input = {}) {
|
||||
const inquiry = normalizeInquiry(input);
|
||||
const update = Object.fromEntries(
|
||||
INQUIRY_FIELDS.map((field) => [`inquiry.${field}`, inquiry[field]])
|
||||
);
|
||||
update["inquiry.medicalHistory"] = buildLegacyMedicalHistory(inquiry);
|
||||
return update;
|
||||
}
|
||||
Reference in New Issue
Block a user