Patient safety evaluation harness for healthcare application deployments. Automated test suites for CDSS accuracy, PHI exposure, clinical workflow integrity, and integration compliance. Blocks deployments on safety failures.
Healthcare Eval Harness — 病患安全驗證
醫療應用程式部署的自動化驗證系統。任何一個 CRITICAL 失敗都會封鎖部署。病患安全不容妥協。
注意: 範例使用 Jest 作為參考測試執行器。請根據您的框架(Vitest、pytest、PHPUnit 等)調整指令 — 測試類別與通過門檻與框架無關。
使用時機
- 任何 EMR/EHR 應用程式部署前
- 修改 CDSS 邏輯後(藥物交互作用、劑量驗證、評分)
- 修改涉及病患資料的資料庫綱要後
- 修改身分驗證或存取控制後
- 在 CI/CD 管線中設定醫療應用程式時
- 解決臨床模組的合併衝突後
運作方式
評估工具依序執行五個測試類別。前三個(CDSS 準確性、PHI 暴露、資料完整性)是 CRITICAL 關卡,要求 100% 通過率 — 任何一個失敗都會封鎖部署。其餘兩個(臨床工作流程、整合)是 HIGH 關卡,要求 95% 以上通過率。
每個類別對應一個 Jest 測試路徑模式。CI 管線使用 --bail(遇到第一個失敗即停止)執行 CRITICAL 關卡,並使用 --coverage --coverageThreshold 強制覆蓋率門檻。
評估類別
1. CDSS 準確性(CRITICAL — 需 100%)
測試所有臨床決策支援邏輯:藥物交互作用配對(雙向)、劑量驗證規則、臨床評分與公開規格比對、無偽陰性、無靜默失敗。
npx jest --testPathPattern='tests/cdss' --bail --ci --coverage
2. PHI 暴露(CRITICAL — 需 100%)
測試受保護健康資訊洩漏:API 錯誤回應、主控台輸出、URL 參數、瀏覽器儲存、跨機構隔離、未經授權存取、服務角色金鑰缺失。
npx jest --testPathPattern='tests/security/phi' --bail --ci
3. 資料完整性(CRITICAL — 需 100%)
測試臨床資料安全:鎖定的就診記錄、稽核軌跡項目、串聯刪除保護、並行編輯處理、無孤立記錄。
npx jest --testPathPattern='tests/data-integrity' --bail --ci
4. 臨床工作流程(HIGH — 需 95% 以上)
測試端到端流程:就診生命週期、範本渲染、藥物組合、藥物/診斷搜尋、處方 PDF、紅旗警示。
tmp_json=$(mktemp)
npx jest --testPathPattern='tests/clinical' --ci --json --outputFile="$tmp_json" || true
total=$(jq '.numTotalTests // 0' "$tmp_json")
passed=$(jq '.numPassedTests // 0' "$tmp_json")
if [ "$total" -eq 0 ]; then
echo "No clinical tests found" >&2
exit 1
fi
rate=$(echo "scale=2; $passed * 100 / $total" | bc)
echo "Clinical pass rate: ${rate}% ($passed/$total)"
5. 整合合規性(HIGH — 需 95% 以上)
測試外部系統:HL7 訊息解析(v2.x)、FHIR 驗證、檢驗結果對應、格式錯誤訊息處理。
tmp_json=$(mktemp)
npx jest --testPathPattern='tests/integration' --ci --json --outputFile="$tmp_json" || true
total=$(jq '.numTotalTests // 0' "$tmp_json")
passed=$(jq '.numPassedTests // 0' "$tmp_json")
if [ "$total" -eq 0 ]; then
echo "No integration tests found" >&2
exit 1
fi
rate=$(echo "scale=2; $passed * 100 / $total" | bc)
echo "Integration pass rate: ${rate}% ($passed/$total)"
通過/失敗矩陣
| 類別 | 門檻 | 失敗時 |
|---|---|---|
| CDSS 準確性 | 100% | 封鎖部署 |
| PHI 暴露 | 100% | 封鎖部署 |
| 資料完整性 | 100% | 封鎖部署 |
| 臨床工作流程 | 95% 以上 | 警告,允許審查後部署 |
| 整合 | 95% 以上 | 警告,允許審查後部署 |
CI/CD 整合
name: Healthcare Safety Gate
on: [push, pull_request]
jobs:
safety-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
# CRITICAL 關卡 — 需 100%,遇到第一個失敗即停止
- name: CDSS Accuracy
run: npx jest --testPathPattern='tests/cdss' --bail --ci --coverage --coverageThreshold='{"global":{"branches":80,"functions":80,"lines":80}}'
- name: PHI Exposure Check
run: npx jest --testPathPattern='tests/security/phi' --bail --ci
- name: Data Integrity
run: npx jest --testPathPattern='tests/data-integrity' --bail --ci
# HIGH 關卡 — 需 95% 以上,自訂門檻檢查
- name: Clinical Workflows
run: |
TMP_JSON=$(mktemp)
npx jest --testPathPattern='tests/clinical' --ci --json --outputFile="$TMP_JSON" || true
TOTAL=$(jq '.numTotalTests // 0' "$TMP_JSON")
PASSED=$(jq '.numPassedTests // 0' "$TMP_JSON")
if [ "$TOTAL" -eq 0 ]; then
echo "::error::No clinical tests found"; exit 1
fi
RATE=$(echo "scale=2; $PASSED * 100 / $TOTAL" | bc)
echo "Pass rate: ${RATE}% ($PASSED/$TOTAL)"
if (( $(echo "$RATE < 95" | bc -l) )); then
echo "::warning::Clinical pass rate ${RATE}% below 95%"
fi
- name: Integration Compliance
run: |
TMP_JSON=$(mktemp)
npx jest --testPathPattern='tests/integration' --ci --json --outputFile="$TMP_JSON" || true
TOTAL=$(jq '.numTotalTests // 0' "$TMP_JSON")
PASSED=$(jq '.numPassedTests // 0' "$TMP_JSON")
if [ "$TOTAL" -eq 0 ]; then
echo "::error::No integration tests found"; exit 1
fi
RATE=$(echo "scale=2; $PASSED * 100 / $TOTAL" | bc)
echo "Pass rate: ${RATE}% ($PASSED/$TOTAL)"
if (( $(echo "$RATE < 95" | bc -l) )); then
echo "::warning::Integration pass rate ${RATE}% below 95%"
fi
反模式
- 因為「上次通過了」就跳過 CDSS 測試
- 將 CRITICAL 門檻設低於 100%
- 在 CRITICAL 測試套件中使用
--no-bail - 在整合測試中模擬 CDSS 引擎(必須測試真實邏輯)
- 安全關卡紅燈時仍允許部署
- 在 CDSS 套件中執行測試時未使用
--coverage
範例
範例 1:在本機執行所有 CRITICAL 關卡
npx jest --testPathPattern='tests/cdss' --bail --ci --coverage && \
npx jest --testPathPattern='tests/security/phi' --bail --ci && \
npx jest --testPathPattern='tests/data-integrity' --bail --ci
範例 2:檢查 HIGH 關卡通過率
tmp_json=$(mktemp)
npx jest --testPathPattern='tests/clinical' --ci --json --outputFile="$tmp_json" || true
jq '{
passed: (.numPassedTests // 0),
total: (.numTotalTests // 0),
rate: (if (.numTotalTests // 0) == 0 then 0 else ((.numPassedTests // 0) / (.numTotalTests // 1) * 100) end)
}' "$tmp_json"
# 預期:{ "passed": 21, "total": 22, "rate": 95.45 }
範例 3:評估報告
## Healthcare Eval: 2026-03-27 [commit abc1234]
### 病患安全:通過
| 類別 | 測試數 | 通過 | 失敗 | 狀態 |
|----------|-------|------|------|--------|
| CDSS 準確性 | 39 | 39 | 0 | 通過 |
| PHI 暴露 | 8 | 8 | 0 | 通過 |
| 資料完整性 | 12 | 12 | 0 | 通過 |
| 臨床工作流程 | 22 | 21 | 1 | 95.5% 通過 |
| 整合 | 6 | 6 | 0 | 通過 |
### 覆蓋率:84%(目標:80% 以上)
### 裁決:可安全部署






