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

Bài 11: FHIR Data Types - Primitive, Complex và Special

Primitive types (boolean, string, uri, date, dateTime, instant, decimal, integer), Complex types (HumanName, Address, ContactPoint, Identifier, CodeableConcept, Coding, Quantity, Period, Reference, Narrative), BackboneElement, Element. Extensions trên data types.

🏗️ Kiến trúc — Bài 11 Bài 11: FHIR Data Types - Primitive, Complex và Special

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

Phần 4: Data Types, Terminologies và Profiles

xdev.asia

Xem bản video

1. Primitive Types

Primitive types là các giá trị đơn giản, "nguyên tử" trong FHIR.

TypeMô tảVí dụ
booleantrue/falsetrue
integerSố nguyên 32-bit42
integer64Số nguyên 64-bit (R5 mới)9223372036854775807
stringChuỗi Unicode (≤ 1MB)"Nguyễn Văn A"
decimalSố thực (precision tùy ý)3.14159
uriURI (RFC 3986)"http://loinc.org"
urlURL"https://fhir.example.com"
canonicalURL đến conformance resource"http://hl7.org/fhir/StructureDefinition/Patient"
uuidUUID (RFC 4122)"urn:uuid:c757873d-ec9a-4326-a141-556f43239520"
idResource ID (1-64 chars, [A-Za-z0-9\-.])"patient-001"
dateNgày (YYYY, YYYY-MM, YYYY-MM-DD)"2025-01-15"
dateTimeNgày giờ với timezone"2025-01-15T10:30:00+07:00"
instantThời điểm chính xác (xs:dateTime)"2025-01-15T10:30:00.000Z"
timeGiờ trong ngày"10:30:00"
codeGiá trị từ ValueSet"male"
oidOID (ISO)"urn:oid:2.16.840.1.113883.6.1"
markdownMarkdown text"**Bold** and *italic*"
base64BinaryBase64 encodedBinary data
positiveIntSố nguyên > 01
unsignedIntSố nguyên ≥ 00

Extensions trên Primitive

Ngay cả primitives cũng có thể mang extensions (sử dụng underscore convention):

{
  "birthDate": "1990-05-15",
  "_birthDate": {
    "extension": [
      {
        "url": "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
        "valueDateTime": "1990-05-15T14:30:00+07:00"
      }
    ]
  }
}

2. Complex Types — General-Purpose

Identifier

{
  "use": "official",
  "type": {
    "coding": [
      {
        "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
        "code": "NI",
        "display": "National unique individual identifier"
      }
    ],
    "text": "CCCD"
  },
  "system": "http://cccd.gov.vn",
  "value": "012345678901",
  "period": {
    "start": "2021-01-01",
    "end": "2036-01-01"
  },
  "assigner": {
    "display": "Bộ Công an"
  }
}

HumanName

{
  "use": "official",
  "text": "Nguyễn Văn A",
  "family": "Nguyễn",
  "given": ["Văn", "A"],
  "prefix": ["BS."],
  "suffix": ["ThS."],
  "period": {
    "start": "1990-05-15"
  }
}

Address

{
  "use": "home",
  "type": "physical",
  "text": "123 Đường Lê Lợi, Phường Bến Nghé, Quận 1, TP.HCM",
  "line": ["123 Đường Lê Lợi"],
  "city": "Hồ Chí Minh",
  "district": "Quận 1",
  "state": "TP.HCM",
  "postalCode": "700000",
  "country": "VN"
}

ContactPoint

[
  {
    "system": "phone",
    "value": "+84901234567",
    "use": "mobile",
    "rank": 1
  },
  {
    "system": "email",
    "value": "[email protected]",
    "use": "home"
  }
]

Coding và CodeableConcept

// Coding — một mã duy nhất
{
  "system": "http://loinc.org",
  "version": "2.77",
  "code": "8480-6",
  "display": "Systolic blood pressure"
}

// CodeableConcept — nhiều Codings + text
{
  "coding": [
    {
      "system": "http://hl7.org/fhir/sid/icd-10",
      "code": "I10",
      "display": "Essential (primary) hypertension"
    },
    {
      "system": "http://snomed.info/sct",
      "code": "38341003",
      "display": "Hypertensive disorder"
    }
  ],
  "text": "Tăng huyết áp nguyên phát"
}

CodeableConcept cho phép biểu diễn cùng một khái niệm bằng nhiều CodeSystems khác nhau — hỗ trợ interoperability.

Quantity

{
  "value": 145,
  "comparator": ">=",
  "unit": "mmHg",
  "system": "http://unitsofmeasure.org",
  "code": "mm[Hg]"
}

Period và Timing

// Period
{
  "start": "2025-01-15T08:00:00+07:00",
  "end": "2025-01-15T08:45:00+07:00"
}

// Timing (cho medication dosage)
{
  "repeat": {
    "frequency": 2,
    "period": 1,
    "periodUnit": "d",
    "when": ["ACM", "ACV"],
    "boundsPeriod": {
      "start": "2025-01-15",
      "end": "2025-02-15"
    }
  },
  "code": {
    "text": "Ngày 2 lần, sáng và tối sau ăn"
  }
}

Reference

{
  "reference": "Patient/patient-001",
  "type": "Patient",
  "identifier": {
    "system": "http://hospital.vn/mrn",
    "value": "MRN12345"
  },
  "display": "Nguyễn Văn A"
}

Reference có thể chứa reference (literal URL), identifier (logical reference), hoặc cả hai.

3. Narrative (Human-Readable)

{
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>Bệnh nhân: Nguyễn Văn A, Nam, sinh ngày 15/05/1990</p></div>"
  }
}
StatusMô tả
generatedTạo tự động từ structured data
extensionsCó thông tin từ extensions không có trong structured data
additionalCó thông tin bổ sung không có trong structured data
emptyKhông có text (narrative trống)

4. BackboneElement

BackboneElement là complex type chỉ tồn tại bên trong resource cha, không thể dùng lại ở nơi khác. Ví dụ: Patient.contact, Encounter.participant, Encounter.diagnosis.

{
  "resourceType": "Patient",
  "contact": [
    {
      "relationship": [
        {
          "coding": [
            {
              "system": "http://terminology.hl7.org/CodeSystem/v2-0131",
              "code": "N",
              "display": "Next-of-Kin"
            }
          ]
        }
      ],
      "name": {
        "text": "Nguyễn Thị B (vợ)"
      },
      "telecom": [
        {
          "system": "phone",
          "value": "+84907654321"
        }
      ]
    }
  ]
}

5. Choice Types [x]

Một số elements cho phép nhiều data types — ký hiệu bằng [x]:

Element definitionSử dụng thực tế
value[x]valueQuantity, valueString, valueCodeableConcept, valueBoolean, ...
onset[x]onsetDateTime, onsetAge, onsetPeriod, onsetRange, onsetString
effective[x]effectiveDateTime, effectivePeriod, effectiveInstant, effectiveTiming
deceased[x]deceasedBoolean, deceasedDateTime
multipleBirth[x]multipleBirthBoolean, multipleBirthInteger
// Observation value dạng Quantity
{"valueQuantity": {"value": 37.2, "unit": "°C"}}

// Observation value dạng CodeableConcept
{"valueCodeableConcept": {"coding": [{"code": "positive"}]}}

// Observation value dạng string
{"valueString": "Bình thường"}

6. Tổng kết

  • Primitive types — 20+ types cơ bản (string, date, code, uri, ...), hỗ trợ extensions

  • Complex types — HumanName, Address, Identifier, CodeableConcept, Quantity, Reference, ...

  • CodeableConcept — Quan trọng nhất, cho phép multi-coding cho interoperability

  • Narrative — Human-readable XHTML trong mọi DomainResource

  • BackboneElement — Complex type nội bộ resource

  • Choice types [x] — Linh hoạt chọn data type phù hợp