医疗CDSS开发模式 是做什么的?
构建集成到EMR工作流中的临床决策支持系统的模式。CDSS模块对患者安全至关重要——零容忍漏报。
适用场景
- 实现药物相互作用检查
- 构建剂量验证引擎
- 实现临床评分系统(NEWS2、qSOFA、APACHE、GCS)
- 设计异常临床值的警报系统
- 构建带有安全检查的药物处方录入
- 结合临床背景解读检验结果
工作原理
CDSS引擎是一个纯函数库,无副作用。输入临床数据,输出警报。这使得它完全可测试。
三个主要模块:
checkInteractions(newDrug, currentMeds, allergies)—— 检查新药与当前用药及已知过敏的相互作用。返回按严重性排序的InteractionAlert[]。使用DrugInteractionPair数据模型。validateDose(drug, dose, route, weight, age, renalFunction)—— 根据体重、年龄和肾功能调整规则验证处方剂量。返回DoseValidationResult。calculateNEWS2(vitals)—— 基于NEWS2Input计算国家早期预警评分2。返回包含总分、风险等级和升级指导的NEWS2Result。
EMR UI
↓ (用户输入数据)
CDSS引擎(纯函数,无副作用)
├── 药物相互作用检查器
├── 剂量验证器
├── 临床评分(NEWS2、qSOFA等)
└── 警报分类器
↓ (返回警报)
EMR UI(内联显示警报,关键警报阻断操作)
药物相互作用检查
interface DrugInteractionPair {
drugA: string; // 通用名
drugB: string; // 通用名
severity: 'critical' | 'major' | 'minor';
mechanism: string;
clinicalEffect: string;
recommendation: string;
}
function checkInteractions(
newDrug: string,
currentMedications: string[],
allergyList: string[]
): InteractionAlert[] {
if (!newDrug) return [];
const alerts: InteractionAlert[] = [];
for (const current of currentMedications) {
const interaction = findInteraction(newDrug, current);
if (interaction) {
alerts.push({ severity: interaction.severity, pair: [newDrug, current],
message: interaction.clinicalEffect, recommendation: interaction.recommendation });
}
}
for (const allergy of allergyList) {
if (isCrossReactive(newDrug, allergy)) {
alerts.push({ severity: 'critical', pair: [newDrug, allergy],
message: `与记录的过敏交叉反应:${allergy}`,
recommendation: '未经过敏会诊不得处方' });
}
}
return alerts.sort((a, b) => severityOrder(a.severity) - severityOrder(b.severity));
}
相互作用对必须是双向的:如果药物A与药物B相互作用,则药物B也与药物A相互作用。
剂量验证
interface DoseValidationResult {
valid: boolean;
message: string;
suggestedRange: { min: number; max: number; unit: string } | null;
factors: string[];
}
function validateDose(
drug: string,
dose: number,
route: 'oral' | 'iv' | 'im' | 'sc' | 'topical',
patientWeight?: number,
patientAge?: number,
renalFunction?: number
): DoseValidationResult {
const rules = getDoseRules(drug, route);
if (!rules) return { valid: true, message: '无可用验证规则', suggestedRange: null, factors: [] };
const factors: string[] = [];
// 安全:如果规则需要体重但体重缺失,则阻断(不通过)
if (rules.weightBased) {
if (!patientWeight || patientWeight <= 0) {
return { valid: false, message: `需要体重来计算${drug}(mg/kg 剂量)`,
suggestedRange: null, factors: ['weight_missing'] };
}
factors.push('weight');
const maxDose = rules.maxPerKg * patientWeight;
if (dose > maxDose) {
return { valid: false, message: `剂量超过${patientWeight}kg体重的最大值`,
suggestedRange: { min: rules.minPerKg * patientWeight, max: maxDose, unit: rules.unit }, factors };
}
}
// 年龄调整(当规则定义了年龄区间且提供了年龄时)
if (rules.ageAdjusted && patientAge !== undefined) {
factors.push('age');
const ageMax = rules.getAgeAdjustedMax(patientAge);
if (dose > ageMax) {
return { valid: false, message: `超过${patientAge}岁的年龄调整最大值`,
suggestedRange: { min: rules.typicalMin, max: ageMax, unit: rules.unit }, factors };
}
}
// 肾功能调整(当规则定义了eGFR区间且提供了eGFR时)
if (rules.renalAdjusted && renalFunction !== undefined) {
factors.push('renal');
const renalMax = rules.getRenalAdjustedMax(renalFunction);
if (dose > renalMax) {
return { valid: false, message: `超过eGFR ${renalFunction}的肾功能调整最大值`,
suggestedRange: { min: rules.typicalMin, max: renalMax, unit: rules.unit }, factors };
}
}
// 绝对最大值
if (dose > rules.absoluteMax) {
return { valid: false, message: `超过绝对最大值 ${rules.absoluteMax}${rules.unit}`,
suggestedRange: { min: rules.typicalMin, max: rules.absoluteMax, unit: rules.unit },
factors: [...factors, 'absolute_max'] };
}
return { valid: true, message: '范围内',
suggestedRange: { min: rules.typicalMin, max: rules.typicalMax, unit: rules.unit }, factors };
}
临床评分:NEWS2
interface NEWS2Input {
respiratoryRate: number; oxygenSaturation: number; supplementalOxygen: boolean;
temperature: number; systolicBP: number; heartRate: number;
consciousness: 'alert' | 'voice' | 'pain' | 'unresponsive';
}
interface NEWS2Result {
total: number; // 0-20
risk: 'low' | 'low-medium' | 'medium' | 'high';
components: Record<string, number>;
escalation: string;
}
评分表必须完全符合英国皇家内科医师学会的规范。
警报严重性与UI行为
| 严重性 | UI行为 | 临床医生需要采取的操作 |
|---|---|---|
| 关键 | 阻断操作。不可关闭的模态框。红色。 | 必须记录否决理由才能继续 |
| 主要 | 内联警告横幅。橙色。 | 必须确认后才能继续 |
| 次要 | 内联信息提示。黄色。 | 仅需知晓,无需操作 |
关键警报绝不能自动关闭或作为Toast通知实现。否决理由必须存储在审计跟踪中。
测试CDSS(零容忍漏报)
describe('CDSS — 患者安全', () => {
INTERACTION_PAIRS.forEach(({ drugA, drugB, severity }) => {
it(`检测 ${drugA} + ${drugB}(${severity})`, () => {
const alerts = checkInteractions(drugA, [drugB], []);
expect(alerts.length).toBeGreaterThan(0);
expect(alerts[0].severity).toBe(severity);
});
it(`检测 ${drugB} + ${drugA}(反向)`, () => {
const alerts = checkInteractions(drugB, [drugA], []);
expect(alerts.length).toBeGreaterThan(0);
});
});
it('当体重缺失时阻断mg/kg药物', () => {
const result = validateDose('gentamicin', 300, 'iv');
expect(result.valid).toBe(false);
expect(result.factors).toContain('weight_missing');
});
it('优雅处理格式错误的药物数据', () => {
expect(() => checkInteractions('', [], [])).not.toThrow();
});
});
通过标准:100%。一次遗漏的相互作用即构成患者安全事件。
反模式
- 使CDSS检查可选项或可跳过,且无文件记录的理由
- 将相互作用检查实现为Toast通知
- 对药物或临床数据使用
any类型 - 硬编码相互作用对,而非使用可维护的数据结构
- 在CDSS引擎中静默捕获错误(必须响亮地暴露失败)
- 当体重不可用时跳过基于体重的验证(必须阻断,而非通过)
示例
示例1:药物相互作用检查
const alerts = checkInteractions('warfarin', ['aspirin', 'metformin'], ['penicillin']);
// [{ severity: 'critical', pair: ['warfarin', 'aspirin'],
// message: '出血风险增加', recommendation: '避免联用' }]
示例2:剂量验证
const ok = validateDose('paracetamol', 1000, 'oral', 70, 45);
// { valid: true, suggestedRange: { min: 500, max: 4000, unit: 'mg' } }
const bad = validateDose('paracetamol', 5000, 'oral', 70, 45);
// { valid: false, message: '超过绝对最大值 4000mg' }
const noWeight = validateDose('gentamicin', 300, 'iv');
// { valid: false, factors: ['weight_missing'] }
示例3:NEWS2评分
const result = calculateNEWS2({
respiratoryRate: 24, oxygenSaturation: 93, supplementalOxygen: true,
temperature: 38.5, systolicBP: 100, heartRate: 110, consciousness: 'voice'
});
// { total: 13, risk: 'high', escalation: '紧急临床复查。考虑ICU。' }