From c9c6b7ea4f81cb21bb27975399206aef11172106 Mon Sep 17 00:00:00 2001 From: huxuejian Date: Thu, 6 Aug 2026 18:24:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hlw/drug-info/index.js | 27 ++++++++++++++++++++++++++- hlw/index.js | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hlw/drug-info/index.js b/hlw/drug-info/index.js index 787e789..2c746a0 100644 --- a/hlw/drug-info/index.js +++ b/hlw/drug-info/index.js @@ -30,6 +30,8 @@ module.exports = async (item, mongodb) => { return await getStoreSimilarDrugInfo(item); case "searchDrugs": return await searchDrugs(item); + case "getDrugMatchedDisease": + return await getDrugMatchedDisease(item); } }; // 药品库信息 @@ -403,7 +405,7 @@ async function getStoreSimilarDrugInfo(ctx) { drugs: medicines, similarDrugs: similarDrugs } - } catch (e) { + } catch (e) { return { success: false, message: e.message } } } @@ -430,3 +432,26 @@ async function searchDrugs(ctx) { return { success: false, message: e.message } } } + +async function getDrugMatchedDisease(ctx) { + try { + const drugIds = Array.isArray(ctx.drugIds) ? ctx.drugIds.filter(i => typeof i === 'string' && ObjectId.isValid(i)) : []; + if (drugIds.length === 0) { + return { success: false, message: "参数错误" } + } + const list = await db.collection("drug-info").find({ _id: { $in: drugIds.map(i => new ObjectId(i)) } }, { projection: { _id: 1, applicableDiagnosisIds: 1 } }).toArray(); + const ids = []; + list.forEach(i => { + if (i && Array.isArray(i.applicableDiagnosisIds)) { + ids.push(...i.applicableDiagnosisIds); + } + }) + if (ids.length === 0) { + return { success: true, message: "查询成功", list: [] } + } + const diseases = await db.collection("hlw-diagnosis").find({ _id: { $in: ids} }, { projection: { _id: 1, name: 1 } }).toArray(); + return { success: true, message: "查询成功", list: diseases.map(i => i.name) } + } catch (e) { + return { success: false, message: e.message } + } +} \ No newline at end of file diff --git a/hlw/index.js b/hlw/index.js index 24cd720..32b367b 100644 --- a/hlw/index.js +++ b/hlw/index.js @@ -55,6 +55,7 @@ module.exports = async (item, db, context) => { case "importHlwDrugInfo": case "getStoreSimilarDrugInfo": case "searchDrugs": + case "getDrugMatchedDisease": return await drugInfo(item, db); case "addPatientDescription": case "deletePatientDescription":