醫療保健 CDSS 開發模式 是做什麼的?
用於建構可整合至 EMR 工作流程的臨床決策支援系統(CDSS)的模式。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 行為 | 臨床醫師需採取的動作 |
|---|---|---|
| 重大 (Critical) | 封鎖動作。不可關閉的模態視窗。紅色。 | 必須記錄覆寫原因才能繼續 |
| 主要 (Major) | 內聯警告橫幅。橙色。 | 必須確認才能繼續 |
| 次要 (Minor) | 內聯資訊提示。黃色。 | 僅需知悉,無需動作 |
重大警報絕對不得自動關閉或以滑出通知(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。' }