Chuyển đến nội dung chính

Bài 2: Tổng quan FHIR R5 - Kiến trúc và nguyên tắc thiết kế

Kiến trúc FHIR (Resources, Data Types, Extensibility, RESTful API, Messaging, Documents), nguyên tắc thiết kế 80/20, FHIR Maturity Model (FMM), so sánh FHIR R4 vs R5, các modules trong specification.

🏗️ Kiến trúc — Bài 2 Bài 2: Tổng quan FHIR R5 - Kiến trúc và nguyên tắc thiết kế

HL7 FHIR - Chuẩn Dữ liệu Y tế từ Cơ bản đến Nâng cao

Phần 1: Nền tảng HL7 và FHIR

xdev.asia

Xem bản video

1. Kiến trúc tổng thể FHIR

FHIR được thiết kế như một platform — không chỉ là một chuẩn dữ liệu mà là cả một hệ sinh thái hoàn chỉnh cho trao đổi thông tin y tế. Kiến trúc FHIR bao gồm các tầng sau:

Các tầng kiến trúc

┌─────────────────────────────────────────┐
│     Implementation Guides (IGs)         │  ← Tùy chỉnh cho ngữ cảnh
├─────────────────────────────────────────┤
│   Profiles / Extensions / Terminologies │  ← Ràng buộc & mở rộng
├─────────────────────────────────────────┤
│   Exchange (REST / Messaging / Docs)    │  ← Cách trao đổi dữ liệu
├─────────────────────────────────────────┤
│          Resources (~157 loại)          │  ← Đơn vị dữ liệu
├─────────────────────────────────────────┤
│         Data Types (Primitive/Complex)  │  ← Kiểu dữ liệu
├─────────────────────────────────────────┤
│      Foundation (Infrastructure)        │  ← Nền tảng chung
└─────────────────────────────────────────┘

2. Resource — Đơn vị cơ bản của FHIR

Trong FHIR, mọi thứ được biểu diễn dưới dạng Resource. Resource là building block cơ bản — giống như "bảng" trong cơ sở dữ liệu quan hệ, nhưng linh hoạt hơn nhiều.

Đặc điểm chung của mọi Resource

Tất cả Resources đều có:

  • id — logical identifier, duy nhất trong server

  • meta — metadata (versionId, lastUpdated, profile, security, tag)

  • implicitRules — tham chiếu đến quy tắc xử lý đặc biệt (hiếm dùng)

  • language — ngôn ngữ của resource

Hầu hết Resources là DomainResource (kế thừa từ Resource), thêm:

  • text — Narrative (phần human-readable HTML)

  • contained — Resources nhúng bên trong

  • extension — dữ liệu mở rộng

  • modifierExtension — extension thay đổi ngữ nghĩa Resource

Ví dụ: Patient Resource (JSON)

{
  "resourceType": "Patient",
  "id": "example-vn",
  "meta": {
    "versionId": "1",
    "lastUpdated": "2026-03-30T10:00:00Z"
  },
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Nguyễn Văn A, Nam, 15/03/1985</div>"
  },
  "identifier": [
    {
      "system": "urn:oid:2.16.840.1.113883.4.56.10",
      "value": "001085012345"
    }
  ],
  "active": true,
  "name": [
    {
      "use": "official",
      "family": "Nguyễn",
      "given": ["Văn", "A"]
    }
  ],
  "gender": "male",
  "birthDate": "1985-03-15",
  "address": [
    {
      "use": "home",
      "line": ["123 Lê Lợi"],
      "city": "Thành phố Hồ Chí Minh",
      "country": "VN"
    }
  ]
}

157 Resources được phân loại theo modules

FHIR R5 có 157 resource types, được tổ chức thành các module:

ModuleMô tảResources tiêu biểu
FoundationHạ tầng cơ bảnBundle, OperationOutcome, Binary, Parameters
ConformanceĐặc tả conformanceCapabilityStatement, StructureDefinition, SearchParameter
TerminologyThuật ngữCodeSystem, ValueSet, ConceptMap
SecurityBảo mậtProvenance, AuditEvent, Consent, Permission
AdministrationHành chínhPatient, Practitioner, Organization, Location, Encounter
ClinicalLâm sàngCondition, Observation, AllergyIntolerance, Procedure
DiagnosticsChẩn đoánDiagnosticReport, Specimen, ImagingStudy
MedicationsThuốcMedication, MedicationRequest, Immunization
WorkflowQuy trìnhTask, Appointment, Schedule, ServiceRequest
FinancialTài chínhClaim, Coverage, ExplanationOfBenefit

3. Nguyên tắc thiết kế 80/20

FHIR áp dụng triết lý: giải quyết 80% use cases phổ biến trong chuẩn cơ bản, cho phép 20% còn lại qua extensions và profiles.

Điều này có nghĩa:

  • Resource cơ bản đủ đơn giản — không cố nhồi nhét mọi trường hợp đặc biệt

  • Extension mechanism — khi cần thêm dữ liệu, dùng Extensions thay vì thay đổi chuẩn

  • Profile — khi cần ràng buộc chặt hơn, dùng StructureDefinition

Ví dụ: Resource Patient cơ bản không có trường "số CCCD" (chỉ Việt Nam dùng), nhưng bạn có thể thêm qua Extension hoặc sử dụng identifier với system phù hợp.

4. Bốn paradigm trao đổi dữ liệu

Trang Summary của specification nêu nguyên văn: "Support for RESTful architectures, seamless exchange of information using messages or documents, and service-based architectures." Đếm lại thì đó là bốn cách, và RESTful chỉ là cách đứng đầu danh sách — không phải cách duy nhất, cũng không phải cách được specification ưu tiên hơn ba cách còn lại.

4.1. RESTful API

Cách phổ biến nhất, dựa trên HTTP methods:

# Đọc thông tin bệnh nhân
GET /Patient/123

# Tạo bệnh nhân mới
POST /Patient
Content-Type: application/fhir+json
{...}

# Cập nhật
PUT /Patient/123
{...}

# Tìm kiếm
GET /Patient?family=Nguyen&birthdate=1985-03-15

# Xóa
DELETE /Patient/123

Dùng khi: Ứng dụng web/mobile, patient portals, data queries, SMART apps.

4.2. Messaging

Gửi message giữa các hệ thống (tương tự HL7 v2 nhưng dùng FHIR Resources):

{
  "resourceType": "Bundle",
  "type": "message",
  "entry": [
    {
      "resource": {
        "resourceType": "MessageHeader",
        "eventCoding": {
          "system": "http://example.org/events",
          "code": "admit-notification"
        },
        "source": { "endpoint": "http://hospital-a.vn/fhir" }
      }
    },
    {
      "resource": {
        "resourceType": "Patient",
        "id": "123"
      }
    }
  ]
}

Dùng khi: Trao đổi event-driven (nhập viện, ra viện, kết quả xét nghiệm), tích hợp với legacy systems.

4.3. Documents

Tạo tài liệu y tế có cấu trúc (tương tự CDA nhưng dùng FHIR):

{
  "resourceType": "Bundle",
  "type": "document",
  "entry": [
    {
      "resource": {
        "resourceType": "Composition",
        "title": "Tóm tắt xuất viện",
        "type": {
          "coding": [{
            "system": "http://loinc.org",
            "code": "18842-5",
            "display": "Discharge summary"
          }]
        },
        "section": [...]
      }
    }
  ]
}

Dùng khi: Giấy ra viện, tóm tắt bệnh án, giấy chuyển tuyến, International Patient Summary.

4.4. Service-based architectures

Cách thứ tư — thường bị bỏ qua nhất khi người ta học FHIR qua REST. Khi tác vụ không map gọn vào một HTTP method trên một resource, FHIR định nghĩa operation: một endpoint có tên riêng, có tham số vào và ra khai báo bằng OperationDefinition.

# Tra một mã thuộc ValueSet nào không (terminology service)
GET /ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/observation-codes

# Kiểm một mã có hợp lệ trong ValueSet
POST /ValueSet/$validate-code

# Sinh Composition tóm tắt bệnh nhân
GET /Patient/123/$summary

# Chạy một CQL library trên dữ liệu bệnh nhân
POST /Measure/$evaluate-measure

Dùng khi: Terminology service ($expand, $lookup, $validate-code), tính toán trên nhiều resource, hoặc bất cứ tác vụ nào là một hành vi chứ không phải một phép CRUD trên một resource.

Ba paradigm 4.2 – 4.4 không phải mẹo lách REST. Chúng là thành phần chính thức của chuẩn, có luật riêng, và specification dựng sẵn chúng. Khi chọn cách tích hợp, hỏi trước: dữ liệu này là một lần đọc ghi, một tài liệu cần đóng dấu, một thông điệp cần đẩy, hay một dịch vụ cần gọi? Bốn câu trả lời dẫn tới bốn paradigm khác nhau.

5. FHIR Maturity Model (FMM)

Mỗi Resource trong FHIR có một mức độ trưởng thành (FMM) từ 0 đến Normative (N):

FMMMức độÝ nghĩa
0DraftMới đề xuất, chưa implement
1Draft (tested)Đã có ít nhất 1 implementation
2Trial UseĐã được test tại Connectathon
3Trial Use (verified)Đã có nhiều implementation thực tế
4Trial Use (agreed)Quality criteria đạt, chuẩn bị normative
5Trial Use (published)Đã published trong 2+ ballot cycles
NNormativeỔn định, backward compatible — KHÔNG thay đổi

Một số Resources đã đạt Normative trong R5:

  • Patient (N), Observation (N), Bundle (N), CapabilityStatement (N)

  • StructureDefinition (N), ValueSet (N), CodeSystem (N)

  • OperationOutcome (N), Binary (N), Parameters (N)

Khi chọn Resource cho dự án, nên ưu tiên Resources có FMM ≥ 3 hoặc Normative để đảm bảo ổn định.

6. FHIR R4 vs R5 — Những thay đổi quan trọng

R4 hiện vẫn là phiên bản được dùng nhiều nhất (vì nhiều mandate tại Mỹ dựa trên R4). R5 mang đến nhiều cải tiến:

Tính năngR4R5
SubscriptionsSubscription cơ bản (criteria-based)Topic-based Subscriptions (SubscriptionTopic)
WorkflowTask basicTransport resource mới, improved workflow patterns
Evidence-Based MedHạn chếEvidence, EvidenceVariable, ArtifactAssessment mới
New Resources—Permission, InventoryItem, InventoryReport, NutritionIntake
Observationcomponent-basedCải tiến triggeredBy, instantiatesCanonical
SearchStandardCải tiến _filter, _sort enhancements
Types—CodeableReference (mới), integer64

Khuyến nghị:

  • Dự án mới tại Mỹ: dùng R4 (vì US Core mandate)

  • Dự án mới không ràng buộc: cân nhắc R5 (mới hơn, nhiều tính năng)

  • Dự án tại Việt Nam: R4 hoặc R5 đều phù hợp (chưa có mandate cụ thể)

7. Các modules trong FHIR Specification

FHIR specification được tổ chức thành các modules chính:

Foundation Module

Nền tảng kỹ thuật: Resource definition, Data Types, Extensions, REST API, Messaging, Documents, Narrative, Compartments.

Implementer Support Module

Hỗ trợ triển khai: Downloads, testing tools, implementation guides registry, validation.

Security & Privacy Module

Bảo mật: Authorization, Authentication, Security labels, Audit, Consent, Provenance.

Conformance Module

Đặc tả conformance: CapabilityStatement, StructureDefinition, OperationDefinition, SearchParameter, Implementation Guides.

Terminology Module

Thuật ngữ: CodeSystem, ValueSet, ConceptMap, NamingSystem, terminology operations ($validate-code, $expand, $lookup, $translate).

Administration Module

Quản lý hành chính: Patient, Practitioner, Organization, Location, HealthcareService, Endpoint, Device.

Clinical Modules

Modules lâm sàng bao gồm: Clinical Summary (Condition, AllergyIntolerance, Procedure), Diagnostics (Observation, DiagnosticReport), Medications, Care Provision (CarePlan, Goal), Workflow (Task, Appointment).

Financial Module

Tài chính y tế: Coverage, Claim, ExplanationOfBenefit, Account, Invoice.

8. Resource References — Liên kết giữa Resources

Resources trong FHIR liên kết với nhau qua References. Đây là cơ chế quan trọng nhất để tạo nên mạng lưới dữ liệu y tế.

{
  "resourceType": "Observation",
  "id": "blood-pressure",
  "status": "final",
  "code": {
    "coding": [{
      "system": "http://loinc.org",
      "code": "85354-9",
      "display": "Blood pressure panel"
    }]
  },
  "subject": {
    "reference": "Patient/example-vn",
    "display": "Nguyễn Văn A"
  },
  "encounter": {
    "reference": "Encounter/visit-2026-03-30"
  },
  "performer": [{
    "reference": "Practitioner/dr-tran"
  }],
  "effectiveDateTime": "2026-03-30T09:00:00+07:00",
  "component": [
    {
      "code": {
        "coding": [{
          "system": "http://loinc.org",
          "code": "8480-6",
          "display": "Systolic blood pressure"
        }]
      },
      "valueQuantity": {
        "value": 120,
        "unit": "mmHg",
        "system": "http://unitsofmeasure.org",
        "code": "mm[Hg]"
      }
    },
    {
      "code": {
        "coding": [{
          "system": "http://loinc.org",
          "code": "8462-4",
          "display": "Diastolic blood pressure"
        }]
      },
      "valueQuantity": {
        "value": 80,
        "unit": "mmHg",
        "system": "http://unitsofmeasure.org",
        "code": "mm[Hg]"
      }
    }
  ]
}

Trong ví dụ trên:

  • subject → liên kết đến Patient

  • encounter → liên kết đến Encounter (lượt khám)

  • performer → liên kết đến Practitioner (bác sĩ đo)

9. Narrative — Phần human-readable

Mỗi DomainResource có thể chứa phần Narrative — HTML đại diện cho nội dung resource mà con người có thể đọc. Đây là tính năng quan trọng cho clinical safety:

{
  "text": {
    "status": "generated",
    "div": "<div xmlns='http://www.w3.org/1999/xhtml'><p>Huyết áp: 120/80 mmHg</p><p>Bệnh nhân: Nguyễn Văn A</p><p>Ngày đo: 30/03/2026</p></div>"
  }
}

Narrative status có thể là:

  • generated — được tạo từ structured data

  • extensions — chứa thông tin từ extensions

  • additional — có thông tin thêm không có trong structured data

  • empty — không có nội dung (trong contained resources)

10. Extensibility — Cơ chế mở rộng của FHIR

Đây là một trong những tính năng mạnh nhất của FHIR. Khi cần thêm dữ liệu không có trong chuẩn, bạn sử dụng Extensions:

{
  "resourceType": "Patient",
  "id": "vn-patient",
  "extension": [
    {
      "url": "http://fhir.vn/StructureDefinition/patient-ethnicity",
      "valueCodeableConcept": {
        "coding": [{
          "system": "http://fhir.vn/CodeSystem/vn-ethnicity",
          "code": "01",
          "display": "Kinh"
        }]
      }
    },
    {
      "url": "http://fhir.vn/StructureDefinition/patient-cccd",
      "valueString": "001085012345"
    }
  ],
  "name": [{"family": "Nguyễn", "given": ["Văn", "A"]}]
}

Hai quy tắc quan trọng:

  1. Hệ thống nhận PHẢI có thể đọc resource ngay cả khi không hiểu extension (graceful handling)

  2. Extensions KHÔNG ĐƯỢC thay đổi ngữ nghĩa của elements cơ bản (trừ modifierExtension)

11. Tóm tắt

Trong bài này, chúng ta đã tìm hiểu:

  • Kiến trúc FHIR gồm nhiều tầng: Foundation → Data Types → Resources → Exchange → Profiles → IGs

  • Resource là đơn vị cơ bản, FHIR R5 có 157 resource types

  • Nguyên tắc 80/20: chuẩn cơ bản giải quyết 80%, extensions cho 20%

  • 3 paradigm: REST (phổ biến nhất), Messaging, Documents

  • FMM: đánh giá mức trưởng thành, ưu tiên Resources Normative

  • R4 vs R5: R4 ổn định hơn, R5 nhiều tính năng mới

  • References: cách liên kết Resources thành mạng lưới dữ liệu

  • Narrative: phần HTML human-readable cho clinical safety

  • Extensibility: cơ chế mở rộng linh hoạt mà không phá vỡ chuẩn

Bài tiếp theo, chúng ta sẽ thực hành cài đặt môi trường: HAPI FHIR Server, Postman, FHIR tools — và chạy thử các thao tác CRUD đầu tiên.