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