hospital_info_list/query/set 改为读写 hospital 集合,适配 entityName/nicknames/fudanRank;医院子代理与提示词同步字段口径;health_profile_set 更新启用 schema 校验;escort_record_set 限制线下收款方式,存在未支付流水时禁止改价。
94 lines
3.5 KiB
JavaScript
94 lines
3.5 KiB
JavaScript
import { tool } from "@langchain/core/tools";
|
||
import { z } from "zod";
|
||
import { DBModel } from "../../../../../models/index.js";
|
||
import { parseObjectId } from "../utils.js";
|
||
|
||
// 医院基础信息字段:新 hospital 集合没有 overview/doctors/guides/photos
|
||
function toHospitalView(hospital) {
|
||
return {
|
||
id: hospital._id,
|
||
name: hospital.name ?? "",
|
||
entityName: hospital.entityName ?? "",
|
||
nicknames: hospital.nicknames ?? [],
|
||
province: hospital.province ?? "",
|
||
city: hospital.city ?? "",
|
||
address: hospital.address ?? "",
|
||
phone: hospital.phone ?? "",
|
||
level: hospital.level ?? "",
|
||
departments: hospital.departments ?? [],
|
||
fudanRank: hospital.fudanRank ?? null,
|
||
updatedAt: hospital.meta?.updatetime ?? null,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 医院基础信息查询工具
|
||
*
|
||
* 两种用法:
|
||
* - 传 hospitalId:返回该院完整档案(id 可先用 hospital_info_list 获取);
|
||
* - 传 hospitalName:按名称/主体名称/拼音/昵称模糊查询,并可按科室名过滤。
|
||
*/
|
||
const hospitalInfoQueryTool = tool(
|
||
async ({ hospitalId, hospitalName, department }) => {
|
||
try {
|
||
if (hospitalId) {
|
||
const id = parseObjectId(hospitalId);
|
||
if (!id) {
|
||
return { success: false, error: `Invalid hospital ID: ${hospitalId}` };
|
||
}
|
||
const hospital = await DBModel.Hospital.findHospitalById(id);
|
||
if (!hospital) {
|
||
return { success: false, error: `未找到 id 为「${hospitalId}」的医院` };
|
||
}
|
||
return { success: true, total: 1, data: [toHospitalView(hospital)] };
|
||
}
|
||
|
||
if (!hospitalName) {
|
||
return { success: false, error: "请提供 hospitalId 或 hospitalName" };
|
||
}
|
||
|
||
// 医院总量有限,一次最多取 10 家,命中过多时由调用方细化名称
|
||
const result = await DBModel.Hospital.findHospitals({
|
||
page: 1,
|
||
pageSize: 10,
|
||
keyword: hospitalName,
|
||
});
|
||
if (result.total === 0) {
|
||
return { success: false, error: `未找到名称包含「${hospitalName}」的医院` };
|
||
}
|
||
|
||
const keyword = String(department ?? "").trim();
|
||
const data = result.list.map((hospital) => {
|
||
const view = toHospitalView(hospital);
|
||
if (!keyword) return view;
|
||
return {
|
||
...view,
|
||
departments: view.departments.filter((name) => String(name).includes(keyword)),
|
||
};
|
||
});
|
||
|
||
return { success: true, total: result.total, data };
|
||
} catch (error) {
|
||
return { success: false, error: error.message };
|
||
}
|
||
},
|
||
{
|
||
name: "hospital_info_query",
|
||
description:
|
||
"查询医院基础信息(省市、地址、电话、等级、科室名称列表、复旦榜档位与昵称)。传 hospitalId 返回该院完整档案;传 hospitalName 按名称/主体名称/拼音/昵称模糊查询,可再按科室名过滤;最多返回 10 家医院。资料库不含医生出诊、挂号流程与就医指南,问到这些需说明库中没有并用 web_search / web_fetch 查官方信息。",
|
||
schema: z.object({
|
||
hospitalId: z
|
||
.string()
|
||
.optional()
|
||
.describe("医院 id(MongoDB ObjectId,来自 hospital_info_list),提供时忽略其他查询条件"),
|
||
hospitalName: z
|
||
.string()
|
||
.optional()
|
||
.describe("医院名称/主体名称/拼音/昵称,支持模糊匹配(如 协和、xiehe、陆总)"),
|
||
department: z.string().optional().describe("科室名称过滤(如 风湿免疫科、放射科)"),
|
||
}),
|
||
}
|
||
);
|
||
|
||
export { hospitalInfoQueryTool };
|