ai review

This commit is contained in:
lik
2026-09-01 21:49:17 +08:00
parent 390c871d35
commit 98c9026485
14 changed files with 288 additions and 262 deletions
+33 -15
View File
@@ -7,7 +7,7 @@ import mongoose from "mongoose";
*
* 用于记录和管理陪诊服务全流程数据,包含以下主要分类:
* - 基础信息:userId(订单提交用户)、healthProfileId(关联健康档案ID
* - 患者信息:patient(姓名、电话、性别、年龄、身份证号)
* - 患者信息:patient(姓名、电话、性别、出生年月、身份证号)
* - 陪诊服务:escort(服务ID、服务名称)
* - 就诊信息:hospital(医院省份、名称、地址、科室、医生、病历号)
* - 时间安排:schedule(预约时间、开始时间、结束时间、时长)
@@ -50,7 +50,7 @@ const EscortRecordSchema = mongoose.Schema(
name: { type: String, default: "", comment: "患者姓名" },
mobile: { type: String, default: "", index: true, comment: "患者联系电话" },
sex: { type: String, enum: ["male", "female"], comment: "患者性别" },
age: { type: Number, default: 0, comment: "患者年龄" },
birth: { type: String, default: "", comment: "患者出生年月(YYYY-MM-DD" },
weight: { type: Number, default: 0, comment: "患者体重(kg" },
height: { type: Number, default: 0, comment: "患者身高(cm" },
idnumber: { type: String, default: "", comment: "患者身份证号" },
@@ -193,6 +193,34 @@ EscortRecordSchema.statics.findRecords = async function (options = {}, cb) {
.exec(cb);
};
/**
* 查找陪诊员的陪诊记录
*
* @param {ObjectId|string} attendantId - 陪诊员用户ID
* @param {Object} options - 查询选项
* @param {number} [options.page=1] - 页码
* @param {number} [options.pageSize=20] - 每页数量
* @param {string} [options.status] - 状态筛选(可选)
* @param {Function} [cb] - 可选的回调函数
* @returns {Promise<Array>} 陪诊记录列表(按预约日期倒序)
*/
EscortRecordSchema.statics.findRecordsByAttendant = async function (attendantId, options = {}, cb) {
const { page = 1, pageSize = 20, status } = options;
const filter = { "attendant.id": attendantId };
if (status) {
filter.status = status;
}
const skip = (page - 1) * pageSize;
return await this.find(filter)
.sort({ "schedule.date": -1 })
.skip(skip)
.limit(pageSize)
.exec(cb);
};
/**
* 创建陪诊记录
*
@@ -219,13 +247,8 @@ EscortRecordSchema.statics.createRecord = async function (record, cb) {
* @returns {Promise<Object|null>} 更新后的记录,失败返回null
*/
EscortRecordSchema.statics.updateRecord = async function (id, update, cb) {
try {
update["meta.updatetime"] = Date.now();
return await this.findByIdAndUpdate(id, { $set: update }, { new: true }, cb);
} catch (error) {
console.error("更新陪诊记录失败:", error);
return null;
}
const $set = { ...update, "meta.updatetime": Date.now() };
return await this.findByIdAndUpdate(id, { $set }, { new: true }, cb);
};
/**
@@ -268,12 +291,7 @@ EscortRecordSchema.statics.findRecordsByStatus = async function (status, options
* @returns {Promise<Object|null>} 删除的记录,失败返回null
*/
EscortRecordSchema.statics.deleteRecord = async function (id, cb) {
try {
return await this.findByIdAndDelete(id, cb);
} catch (error) {
console.error("删除陪诊记录失败:", error);
return null;
}
return await this.findByIdAndDelete(id, cb);
};
// ==================== 索引定义 ====================