feat(org): 平铺就医信息并支持分院/院区

This commit is contained in:
lik
2026-11-03 16:59:52 +08:00
parent 47fdb91dbe
commit 07d4ce27bf
7 changed files with 390 additions and 101 deletions
+35 -37
View File
@@ -5,17 +5,27 @@ import { pinyin } from "pinyin-pro";
/**
* Organization Schema
* 组织/机构基础信息,支持医院、诊所、体检中心等多种机构类型
* 组织/机构基础信息,支持医院、诊所、体检中心等多种机构类型;
* 分院/院区用 parentId 指向总院,先只做一层,更多层级按需再加
*/
const OrganizationSchema = mongoose.Schema(
{
// 基础信息
name: { type: String, required: true, index: true, comment: "机构名称" },
shortName: { type: String, default: "", comment: "机构简称" },
name: { type: String, required: true, index: true, comment: "机构全称;分院/院区需带总院名,如 北京协和医院西单院区" },
shortName: { type: String, default: "", comment: "机构简称/别名,如 协和西院" },
pinyin: { type: String, default: "", index: true, comment: "机构名称全拼(小写无分隔,用于搜索)" },
pinyinFL: { type: String, default: "", index: true, comment: "机构名称拼音首字母(用于搜索)" },
code: { type: String, unique: true, sparse: true, comment: "机构编码(不填时字段缺省,避免与 unique sparse 索引冲突)" },
// 层级:分院/院区指向总院,总院为空。够用先只做一层,更多层级按需再加
parentId: {
type: mongoose.Schema.Types.ObjectId,
ref: "organization",
default: null,
index: true,
comment: "上级机构ID(分院/院区指向总院,总院为空)",
},
// 机构类型
type: {
type: String,
@@ -67,38 +77,26 @@ const OrganizationSchema = mongoose.Schema(
description: { type: String, default: "", comment: "机构简介" },
remark: { type: String, default: "", comment: "备注" },
// 就医信息(agent-first:少字段、大文本;由 AI 助手录入维护,供查询与看病指导)
forAgent: {
updatedAt: { type: Date, comment: "最近更新时间" },
updatedBy: { type: String, default: "", comment: "最近更新人" },
// 医院级总览:门诊时间、挂号渠道、缴费、医保、异地备案、交通停车,一个文本块全包含
overview: { type: String, default: "", comment: "医院级信息全文(门诊/挂号/缴费/医保/交通)" },
// 医院/导引照片
photos: [{
url: { type: String, default: "", comment: "图片链接" },
caption: { type: String, default: "", comment: "说明(医院照片/导引照片 + 描述)" },
}],
// 科室:name 是锚点;detail 包含位置/电话/临床还是医技/就诊提示全文
departments: [{
name: { type: String, comment: "科室名称(锚点)" },
detail: { type: String, default: "", comment: "科室信息全文(位置/电话/类型/就诊提示)" },
photo: { type: String, default: "", comment: "科室位置导引照片链接" },
}],
// 医生:name+department 是锚点;detail 包含职称/擅长/号别/坐班停诊全文
doctors: [{
name: { type: String, comment: "医生姓名(锚点)" },
department: { type: String, comment: "所属科室(锚点)" },
detail: { type: String, default: "", comment: "医生信息全文(职称/擅长/号别/坐班停诊)" },
photo: { type: String, default: "", comment: "医生照片链接" },
}],
// 场景指南:初诊/复诊/住院/检查须知/老人服务等,键为场景名,值为文本,结构自由演化
guides: { type: mongoose.Schema.Types.Mixed, comment: "场景指南(键为场景名,值为文本)" },
},
// 就医信息:agent-first,字段已平铺,先保留够用的部分,后续按需增加
overview: { type: String, default: "", comment: "医院级信息全文(门诊/挂号/缴费/医保/交通)" },
photos: [{
url: { type: String, default: "", comment: "图片链接" },
caption: { type: String, default: "", comment: "说明(医院照片/导引照片 + 描述)" },
}],
departments: [{
name: { type: String, comment: "科室名称(锚点)" },
detail: { type: String, default: "", comment: "科室信息全文(位置/电话/类型/就诊提示)" },
photo: { type: String, default: "", comment: "科室位置导引照片链接" },
}],
doctors: [{
name: { type: String, comment: "医生姓名(锚点)" },
department: { type: String, comment: "所属科室(锚点)" },
detail: { type: String, default: "", comment: "医生信息全文(职称/擅长/号别/坐班停诊)" },
photo: { type: String, default: "", comment: "医生照片链接" },
}],
guides: { type: mongoose.Schema.Types.Mixed, comment: "场景指南(键为场景名,值为文本)" },
infoUpdatedAt: { type: Date, comment: "就医信息最近更新时间" },
infoUpdatedBy: { type: String, default: "", comment: "就医信息最近更新人" },
// 元数据
meta: {
@@ -141,14 +139,14 @@ OrganizationSchema.pre("save", function (next) {
// ==================== 静态方法 ====================
/**
* 根据名称/拼音/拼音首字母模糊查询机构
* 根据名称/简称/拼音/拼音首字母模糊查询机构
*/
OrganizationSchema.statics.findByName = async function (name, options = {}) {
const { page = 1, pageSize = 20 } = options;
const skip = (page - 1) * pageSize;
const escaped = String(name).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = { $regex: escaped, $options: "i" };
return await this.find({ $or: [{ name: re }, { pinyin: re }, { pinyinFL: re }] })
return await this.find({ $or: [{ name: re }, { shortName: re }, { pinyin: re }, { pinyinFL: re }] })
.skip(skip)
.limit(pageSize)
.exec();