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

Bài 14: FHIR Documents và Messaging

FHIR Documents (Composition resource, Document Bundle, signatures), FHIR Messaging (MessageHeader, MessageDefinition, message events), so sánh REST vs Messaging vs Documents, use cases cho từng paradigm.

🏗️ Kiến trúc — Bài 14 Bài 14: FHIR Documents và Messaging

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

Phần 5: Tích hợp, Messaging và Security

xdev.asia

Xem bản video

1. Ba Paradigm trao đổi dữ liệu trong FHIR

ParadigmMô tảUse case
RESTful APICRUD operations trên từng ResourceỨng dụng tương tác real-time
DocumentsBộ sưu tập Resources tạo thành "document" hoàn chỉnhTóm tắt xuất viện, giấy chuyển viện, hồ sơ y tế
MessagingEvent-driven, gửi message giữa hệ thốngThông báo nhập viện, kết quả xét nghiệm, orders

2. FHIR Documents

FHIR Document là Bundle type "document", entry đầu tiên phải là Composition, theo sau là tất cả Resources được reference.

Composition Resource

{
  "resourceType": "Composition",
  "id": "comp-discharge-001",
  "status": "final",
  "type": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "18842-5",
        "display": "Discharge summary"
      }
    ],
    "text": "Tóm tắt xuất viện"
  },
  "subject": {
    "reference": "Patient/patient-001",
    "display": "Nguyễn Văn A"
  },
  "encounter": {
    "reference": "Encounter/encounter-inpatient-001"
  },
  "date": "2025-01-20T16:00:00+07:00",
  "author": [
    {
      "reference": "Practitioner/practitioner-001",
      "display": "BS. Trần Thị B"
    }
  ],
  "title": "Tóm tắt xuất viện - Nguyễn Văn A",
  "custodian": {
    "reference": "Organization/org-bvdk-001"
  },
  "section": [
    {
      "title": "Chẩn đoán",
      "code": {
        "coding": [
          {
            "system": "http://loinc.org",
            "code": "11535-2",
            "display": "Hospital discharge Dx Narrative"
          }
        ]
      },
      "text": {
        "status": "generated",
        "div": "

Tăng huyết áp độ 2, Đái tháo đường type 2

" }, "entry": [ {"reference": "Condition/cond-hypertension-001"}, {"reference": "Condition/cond-diabetes-001"} ] }, { "title": "Thuốc kê đơn khi xuất viện", "code": { "coding": [ { "system": "http://loinc.org", "code": "10183-2", "display": "Hospital discharge medications" } ] }, "entry": [ {"reference": "MedicationRequest/mr-amlodipine-001"}, {"reference": "MedicationRequest/mr-metformin-001"} ] }, { "title": "Kết quả xét nghiệm", "code": { "coding": [ { "system": "http://loinc.org", "code": "30954-2", "display": "Relevant diagnostic tests/lab data" } ] }, "entry": [ {"reference": "DiagnosticReport/dr-cbc-001"}, {"reference": "Observation/obs-hba1c-001"} ] } ] }

Document Bundle

{
  "resourceType": "Bundle",
  "type": "document",
  "identifier": {
    "system": "http://hospital.vn/documents",
    "value": "DOC-20250120-001"
  },
  "timestamp": "2025-01-20T16:00:00+07:00",
  "entry": [
    {
      "fullUrl": "urn:uuid:comp-001",
      "resource": {
        "resourceType": "Composition"
      }
    },
    {
      "fullUrl": "urn:uuid:patient-001",
      "resource": {
        "resourceType": "Patient"
      }
    },
    {
      "fullUrl": "urn:uuid:cond-001",
      "resource": {
        "resourceType": "Condition"
      }
    }
  ]
}

Document Rules

  1. Bundle.type = "document"
  2. Entry đầu tiên PHẢI là Composition
  3. Tất cả Resources referenced từ Composition PHẢI có trong Bundle
  4. Document là immutable sau khi ký
  5. Có thể ký số (signature trong Bundle hoặc Provenance)

3. FHIR Messaging

Messaging sử dụng Bundle type "message" với MessageHeader làm entry đầu tiên.

MessageHeader Resource

{
  "resourceType": "MessageHeader",
  "id": "msg-admission-001",
  "eventCoding": {
    "system": "http://terminology.hl7.org/CodeSystem/message-events",
    "code": "admin-notify"
  },
  "source": {
    "name": "HIS Bệnh viện ĐK TW",
    "endpoint": "https://his.bvdk.vn/fhir/$process-message"
  },
  "destination": [
    {
      "name": "Hệ thống BHXH",
      "endpoint": "https://api.bhxh.gov.vn/fhir/$process-message"
    }
  ],
  "focus": [
    {
      "reference": "Encounter/encounter-inpatient-001"
    },
    {
      "reference": "Patient/patient-001"
    }
  ],
  "reason": {
    "coding": [
      {
        "system": "http://terminology.hl7.org/CodeSystem/message-reasons-encounter",
        "code": "admit"
      }
    ],
    "text": "Thông báo nhập viện"
  }
}

Message Bundle

{
  "resourceType": "Bundle",
  "type": "message",
  "timestamp": "2025-01-15T14:30:00+07:00",
  "entry": [
    {
      "fullUrl": "urn:uuid:msg-001",
      "resource": {
        "resourceType": "MessageHeader"
      }
    },
    {
      "fullUrl": "urn:uuid:encounter-001",
      "resource": {
        "resourceType": "Encounter"
      }
    },
    {
      "fullUrl": "urn:uuid:patient-001",
      "resource": {
        "resourceType": "Patient"
      }
    }
  ]
}

Gửi Message

POST /fhir/$process-message HTTP/1.1
Content-Type: application/fhir+json

{
  "resourceType": "Bundle",
  "type": "message",
  ...
}

4. So sánh ba paradigms

Tiêu chíRESTDocumentsMessaging
Mô hìnhRequest/Response CRUDImmutable packageEvent-driven
CouplingLooseNone (self-contained)Loose
AtomicityTransaction bundleToàn bộ documentToàn bộ message
RoutingURL-basedN/AEndpoint-based
TimingSynchronousN/AAsync hoặc sync
Tương thích HL7 v2Khác mô hìnhTương tự CDATương tự HL7 v2 messages

5. Tổng kết

  • Documents — Composition + Bundle "document", self-contained, immutable, signable

  • Messaging — MessageHeader + Bundle "message", event-driven, $process-message

  • REST vẫn là paradigm phổ biến nhất, nhưng Documents và Messaging cần thiết cho nhiều use cases y tế truyền thống