diff --git a/models/schema/escort_record.js b/models/schema/escort_record.js index 5185be6..cf2860f 100644 --- a/models/schema/escort_record.js +++ b/models/schema/escort_record.js @@ -6,7 +6,7 @@ import mongoose from "mongoose"; * 陪诊记录Schema定义 * * 用于记录和管理陪诊服务全流程数据,包含以下主要分类: - * - 基础信息:userId(订单提交用户) + * - 基础信息:userId(订单提交用户)、healthProfileId(关联健康档案ID) * - 患者信息:patient(姓名、电话、性别、年龄、身份证号) * - 陪诊服务:escort(服务ID、服务名称) * - 就诊信息:hospital(医院省份、名称、地址、科室、医生、病历号) @@ -31,6 +31,18 @@ const EscortRecordSchema = mongoose.Schema( comment: "提交订单用户ID" }, + /** + * 关联健康档案ID(可为空) + * @type {ObjectId} + * @ref health_profile + */ + healthProfileId: { + type: mongoose.Schema.Types.ObjectId, + ref: "health_profile", + default: null, + comment: "关联健康档案ID" + }, + /** * 患者信息 - 就诊患者的基本信息 */ @@ -271,6 +283,11 @@ EscortRecordSchema.statics.deleteRecord = async function (id, cb) { */ EscortRecordSchema.index({ userId: 1, "schedule.date": -1 }); +/** + * 健康档案ID索引 - 稀疏索引,用于快速按健康档案筛选记录 + */ +EscortRecordSchema.index({ healthProfileId: 1 }, { sparse: true }); + /** * 陪诊员ID索引 - 用于快速查询陪诊员的服务记录 */