新增独立病历整理 Agent 与异步解析任务,支持 PDF 文本、图片 OCR、 语音 ASR 与文字输入,统一整理为基础健康、检查治疗、用药和问诊诉求。 Agent 只产出草稿,订单本人在编辑页核对确认后才写入当前订单; 原件在任务结束、失败或取消时立即清除。 inquiry 增加三段规范字段,medicalHistory 保留为旧版兼容摘要, 并兼容旧客户端只写 medicalHistory 的更新方式。
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
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;
|
||
}
|