feat(escort): 病历与诉求支持多材料解析为四段摘要

新增独立病历整理 Agent 与异步解析任务,支持 PDF 文本、图片 OCR、
语音 ASR 与文字输入,统一整理为基础健康、检查治疗、用药和问诊诉求。
Agent 只产出草稿,订单本人在编辑页核对确认后才写入当前订单;
原件在任务结束、失败或取消时立即清除。

inquiry 增加三段规范字段,medicalHistory 保留为旧版兼容摘要,
并兼容旧客户端只写 medicalHistory 的更新方式。
This commit is contained in:
lik
2026-11-16 20:44:46 +08:00
parent 77a201c0b3
commit 6d2fc04424
17 changed files with 901 additions and 12 deletions
+3
View File
@@ -11,6 +11,7 @@ import { TrainingApplicationSchema } from "./schema/training_application.js"
import { AttendantApplicationSchema } from "./schema/attendant_application.js"
import { PaymentRecordSchema } from "./schema/payment_record.js"
import { RefundRecordSchema } from "./schema/refund_record.js"
import { InquiryParseJobSchema } from "./schema/inquiry_parse_job.js"
import config from '../config.js';
import logger from '../utils/logger.js';
@@ -27,6 +28,7 @@ class MongoDBSchema {
this.AttendantApplication = null;
this.PaymentRecord = null;
this.RefundRecord = null;
this.InquiryParseJob = null;
}
init() {
@@ -62,6 +64,7 @@ class MongoDBSchema {
this.AttendantApplication = this.dbConnection.model('attendant_application', AttendantApplicationSchema)
this.PaymentRecord = this.dbConnection.model('payment_record', PaymentRecordSchema)
this.RefundRecord = this.dbConnection.model('refund_record', RefundRecordSchema)
this.InquiryParseJob = this.dbConnection.model('inquiry_parse_job', InquiryParseJobSchema)
// 索引创建失败(如唯一索引遇到存量重复)时 mongoose 会 emit('error'),
// 而 EventEmitter 对没有监听器的 'error' 事件会直接抛未捕获异常,
+15 -1
View File
@@ -185,7 +185,11 @@ const EscortRecordSchema = mongoose.Schema(
* 问诊信息 - 就诊人补充的病历与诉求,与下单备注分开
*/
inquiry: {
medicalHistory: { type: String, default: "", comment: "病历" },
// 四段为规范字段;medicalHistory 由前三段生成,保留给旧版客户端展示。
basicHealth: { type: String, default: "", comment: "基础健康状况与基础疾病" },
treatmentHistory: { type: String, default: "", comment: "检查与治疗病历" },
medications: { type: String, default: "", comment: "用药情况" },
medicalHistory: { type: String, default: "", comment: "病历兼容摘要" },
demand: { type: String, default: "", comment: "诉求" },
},
@@ -471,6 +475,16 @@ EscortRecordSchema.statics.updateRecord = async function (id, update, cb) {
);
};
// 解析草稿确认必须基于创建任务时的订单版本,避免覆盖解析期间的其他修改。
EscortRecordSchema.statics.updateRecordIfUnchanged = async function (id, expectedUpdatedAt, update) {
if (!expectedUpdatedAt) return null;
return await this.findOneAndUpdate(
{ _id: id, deletedAt: null, "meta.updatetime": new Date(expectedUpdatedAt) },
{ $set: { ...update, "meta.updatetime": Date.now() } },
{ new: true, runValidators: true }
);
};
// 状态迁移必须仍以读取时的状态为条件,避免并发请求重复取消或跨过服务阶段。
EscortRecordSchema.statics.updateRecordStatus = async function (id, fromStatus, update) {
return await this.findOneAndUpdate(
+48
View File
@@ -0,0 +1,48 @@
import mongoose from "mongoose";
const InquiryParseJobSchema = mongoose.Schema(
{
recordId: { type: mongoose.Schema.Types.ObjectId, ref: "escort_record", required: true, index: true },
userId: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true, index: true },
status: {
type: String,
enum: ["queued", "processing", "waiting_confirmation", "failed", "confirmed", "cancelled"],
default: "queued",
index: true,
},
// 原始 base64 仅在解析期间保留;任务完成、失败或取消时立即 $unset。
inputs: { type: Object, select: false, default: null },
active: { type: Boolean, default: true },
baseUpdatedAt: { type: Date, default: null },
draft: {
basicHealth: { type: String, default: "" },
treatmentHistory: { type: String, default: "" },
medications: { type: String, default: "" },
demand: { type: String, default: "" },
},
uncertainties: { type: [String], default: [] },
errorMessage: { type: String, default: "" },
expiresAt: { type: Date, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
},
{ minimize: false, strict: true, collection: "inquiry_parse_job", timestamps: false }
);
InquiryParseJobSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
InquiryParseJobSchema.index({ recordId: 1, userId: 1, createdAt: -1 });
InquiryParseJobSchema.index(
{ recordId: 1, userId: 1 },
{ unique: true, partialFilterExpression: { active: true }, name: "one_active_inquiry_job" }
);
InquiryParseJobSchema.pre("updateOne", function (next) {
this.set({ updatedAt: new Date() });
next();
});
InquiryParseJobSchema.pre("findOneAndUpdate", function (next) {
this.set({ updatedAt: new Date() });
next();
});
export { InquiryParseJobSchema };