1. FHIR 上的 SMART 概述
智慧 FHIR 上的(可替代醫療應用程式、可重複使用技術)是一個框架,允許第三方醫療應用程式透過 OAuth 2.0 + FHIR 與 EHR/EMR 安全整合。
┌─────────────┐ ┌─────────────┐
│ SMART App │ OAuth 2.0 flow │ EHR/EMR │
│ (web/ │ ◀────────────────▶ │ (FHIR │
│ mobile) │ FHIR API calls │ Server) │
└─────────────┘ └─────────────┘
│ │
│ ┌──────────────┐ │
└───────▶│ Auth Server │◀─────────┘
│ (OAuth 2.0) │
└──────────────┘
2. 啟動類型
電子病歷發布
應用程式已打開 從電子病歷內部 — EHR 傳遞背景資訊(病人、遭遇)。
1. Bác sĩ click "Open App" trong EHR
2. EHR redirect → App với launch parameter
3. App → Authorization Server (authorize endpoint)
4. User đồng ý → Auth Server trả code
5. App đổi code → access_token + id_token
6. App gọi FHIR API với access_token
GET https://smart-app.example.com/launch
?iss=https://fhir-server.hospital.vn/fhir/r5
&launch=xyz123
獨立啟動
應用程式運行 獨立的,自己找到FHIR伺服器並請求許可。
GET https://fhir-server.hospital.vn/fhir/r5/.well-known/smart-configuration
{
"authorization_endpoint": "https://auth.hospital.vn/authorize",
"token_endpoint": "https://auth.hospital.vn/token",
"capabilities": [
"launch-ehr",
"launch-standalone",
"client-public",
"client-confidential-symmetric",
"sso-openid-connect",
"context-ehr-patient",
"permission-v2"
],
"scopes_supported": [
"openid",
"fhirUser",
"launch",
"launch/patient",
"patient/*.rs",
"user/*.cruds"
]
}
3. 臨床範圍(SMART v2)
SMART 範圍控制允許應用程式存取的內容:
# Scope format (v2):
# [context]/[resourceType].[cruds]
# Patient-level scopes (data của patient cụ thể)
patient/Patient.rs # Read Patient + Search
patient/Observation.rs # Read + Search Observations
patient/MedicationRequest.rs
# User-level scopes (theo quyền của user đang login)
user/Patient.cruds # Full CRUD + Search on Patient
user/Encounter.rs
user/*.rs # Read + Search tất cả resources
# System-level scopes (backend services)
system/Patient.rs
system/*.rs
CRUD操作
| 人物 | 操作 |
|---|---|
| c | 創建 |
| r | 閱讀 |
| 你 | 更新 |
| d | 刪除 |
| s | 搜尋 |
4. OAuth 2.0 授權代碼流程
# Step 1: Authorization Request
GET https://auth.hospital.vn/authorize
?response_type=code
&client_id=my-smart-app
&redirect_uri=https://smart-app.example.com/callback
&scope=launch/patient openid fhirUser patient/Patient.rs patient/Observation.rs
&state=random-state-value
&aud=https://fhir-server.hospital.vn/fhir/r5
&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
&code_challenge_method=S256
# Step 2: Token Exchange
POST https://auth.hospital.vn/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=auth-code-from-callback
&redirect_uri=https://smart-app.example.com/callback
&client_id=my-smart-app
&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
{
"access_token": "eyJ...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "launch/patient openid fhirUser patient/Patient.rs patient/Observation.rs",
"id_token": "eyJ...",
"patient": "patient-001",
"encounter": "encounter-001",
"fhirUser": "Practitioner/practitioner-001"
}
# Step 3: FHIR API Calls
GET https://fhir-server.hospital.vn/fhir/r5/Patient/patient-001
Authorization: Bearer eyJ...
5. SMART後端服務(系統到系統)
無需用戶互動——使用 客戶憑證 與 JWT 斷言。
POST https://auth.hospital.vn/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&scope=system/Patient.rs system/Observation.rs
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&client_assertion=eyJ...signed_jwt...
6.CDS Hooks-臨床決策支持
CDS Hooks 允許應用程式配置 臨床建議 在 EHR 中做出決策時。
{
"hookInstance": "uuid-001",
"hook": "patient-view",
"fhirServer": "https://fhir-server.hospital.vn/fhir/r5",
"fhirAuthorization": {
"access_token": "eyJ...",
"token_type": "Bearer",
"scope": "patient/Patient.rs patient/Observation.rs"
},
"context": {
"userId": "Practitioner/practitioner-001",
"patientId": "patient-001"
}
}
CDS 回應(卡)
{
"cards": [
{
"uuid": "card-001",
"summary": "HbA1c cao — Cần điều chỉnh thuốc tiểu đường",
"detail": "HbA1c gần nhất: 8.5% (2025-01-10). Mục tiêu: < 7%. Xem xét tăng liều Metformin hoặc thêm thuốc mới.",
"indicator": "warning",
"source": {
"label": "Diabetes Management CDS",
"url": "https://cds.hospital.vn"
},
"suggestions": [
{
"label": "Kê đơn Metformin 1000mg",
"actions": [
{
"type": "create",
"description": "Tạo MedicationRequest Metformin 1000mg",
"resource": {
"resourceType": "MedicationRequest",
"status": "draft",
"intent": "proposal"
}
}
]
}
]
}
]
}
七、總結
FHIR 上的智能 — 適用於第三方健康應用程式的 OAuth 2.0 + FHIR
電子病歷發布 — 從 EHR 開啟應用程序,以取得可用的上下文
獨立啟動 — 應用程式獨立運行,自行要求權限
臨床範圍 — 具有 CRUDS 權限的病人/*、使用者/*、系統/*
後端服務 — 系統到系統,JWT 用戶端斷言
CDS 掛鉤 — 護理點決策支持