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

第 10 課:搜尋參數和進階搜尋

搜尋參數類型(字串、標記、引用、日期、數字、數量、uri)、修飾符(:exact、:contains、:missing、:not)、連結、反向連結 (_has)、_include、_revinclude、_summary、_elements、_count、分頁、複合搜尋參數、自訂 SearchParameter。

🏗️ 建築 — 第 10 課 第 10 課:搜尋參數和進階搜尋 高

HL7 FHIR - 基礎到進階醫療資料標準

第 3 部分:FHIR RESTful API 和資料交換

亞洲開發網

1. 搜尋參數類型

類型描述例如
字串.字串搜尋文字患者?姓名=Nguyen
代幣代碼/標識符患者?性別=男
參考。參考參考另一個資源觀察?受試者=患者/123
日期。日期日期患者?出生日期=1990-05-15
數量。數量否風險評估?機率=gt0.8
數量。數量數量+單位觀察?值-量=gt5.4|http://unitsofmeasure.org|mg
烏裡統一資源標識符值集?url=http://hl7.org/fhir/ValueSet/example
複合材料組合多個參數觀察?代碼值數量=...
特別的尤其是位置?附近=42.2|-71.0|10|公里
# Default: starts-with, case-insensitive
GET /Patient?name=Nguyen

# Exact match
GET /Patient?name:exact=Nguyễn

# Contains
GET /Patient?name:contains=van

# Text (full-text search trên narrative)
GET /Patient?_text=hypertension
# Chỉ code
GET /Patient?gender=male

# System + code
GET /Condition?code=http://hl7.org/fhir/sid/icd-10|I10

# Chỉ system (tìm tất cả codes trong system)
GET /Condition?code=http://snomed.info/sct|

# Identifier
GET /Patient?identifier=http://hospital.vn/mrn|MRN12345

# :not modifier
GET /Patient?gender:not=male

# :text modifier (tìm trên display text)
GET /Condition?code:text=hypertension
# Exact date
GET /Patient?birthdate=1990-05-15

# Prefixes: eq, ne, gt, lt, ge, le, sa (starts after), eb (ends before)
GET /Patient?birthdate=gt1990-01-01
GET /Encounter?date=ge2025-01-01&date=le2025-01-31
GET /Observation?date=sa2025-01-01T00:00:00Z

# Precision matters
GET /Patient?birthdate=1990      # born in 1990
GET /Patient?birthdate=1990-05   # born in May 1990
# Relative reference
GET /Observation?subject=Patient/patient-001

# Chỉ ID (nếu type rõ ràng)
GET /Observation?subject=patient-001

# Absolute reference
GET /Observation?subject=https://fhir-server.example.com/fhir/r5/Patient/patient-001

# Identifier trên referenced resource
GET /Observation?subject:identifier=http://hospital.vn/mrn|MRN12345

6. 連結-搜尋參考文獻

# Tìm Observation của Patient có tên "Nguyen"
GET /Observation?subject:Patient.name=Nguyen

# Chain sâu hơn
GET /Observation?subject:Patient.organization.name=Bach%20Mai

# Tìm MedicationRequest kê bởi Practitioner chuyên khoa Tim mạch
GET /MedicationRequest?requester:Practitioner.qualification=cardiology

7. 反向連結(_has)

# Tìm Patient có Observation với code=hba1c và value>7
GET /Patient?_has:Observation:subject:code=4548-4&_has:Observation:subject:value-quantity=gt7

# Tìm Patient có Condition "hypertension" active
GET /Patient?_has:Condition:subject:code=I10&_has:Condition:subject:clinical-status=active

# Tìm Practitioner có ít nhất 1 Encounter
GET /Practitioner?_has:Encounter:participant:date=ge2025-01-01

8. _include 和 _revinclude

# _include: kéo theo referenced resources
# Tìm Encounter VÀ Patient của Encounter đó
GET /Encounter?date=ge2025-01-15&_include=Encounter:subject

# Multiple includes
GET /MedicationRequest?status=active
  &_include=MedicationRequest:subject
  &_include=MedicationRequest:requester
  &_include=MedicationRequest:medication

# _revinclude: kéo theo resources reference ngược lại
# Tìm Patient VÀ tất cả Observation, Condition reference đến Patient
GET /Patient?_id=patient-001
  &_revinclude=Observation:subject
  &_revinclude=Condition:subject

# :iterate — recursive include
GET /MedicationRequest?_include:iterate=MedicationRequest:medication

9. 結果參數

# _count — số entry per page
GET /Patient?name=Nguyen&_count=20

# _sort — sắp xếp
GET /Observation?subject=Patient/patient-001&_sort=-date  # descending
GET /Patient?_sort=family,given                            # multi-sort

# _summary — trả về tóm tắt
GET /Patient?_summary=true      # chỉ `mandatory` elements
GET /Patient?_summary=count     # chỉ count, không trả resources
GET /Patient?_summary=text      # text + id + meta + mandatory

# _elements — chọn elements cụ thể
GET /Patient?_elements=name,birthDate,gender,identifier

# _total — kiểm soát tính total
GET /Patient?_total=accurate    # tính chính xác total
GET /Patient?_total=none        # không tính total (nhanh hơn)

10. 尋呼

{
  "resourceType": "Bundle",
  "type": "searchset",
  "total": 150,
  "link": [
    {"relation": "self",     "url": "...?_count=10&_offset=0"},
    {"relation": "first",    "url": "...?_count=10&_offset=0"},
    {"relation": "next",     "url": "...?_count=10&_offset=10"},
    {"relation": "last",     "url": "...?_count=10&_offset=140"}
  ]
}

客戶端點擊連結 接下來。下一個 獲取下一頁。 不要創建您自己的 URL — 始終使用伺服器回應中的連結。

11.自訂搜尋參數

{
  "resourceType": "SearchParameter",
  "url": "http://hospital.vn/fhir/SearchParameter/patient-cccd",
  "name": "cccd",
  "status": "active",
  "description": "Tìm Patient theo số CCCD",
  "code": "cccd",
  "base": ["Patient"],
  "type": "token",
  "expression": "Patient.identifier.where(system='http://hospital.vn/cccd')"
}
# Sử dụng custom search parameter
GET /Patient?cccd=012345678901

12. 總結

  • 9種參數類型 — 字串、標記、參考、日期、數字、數量、uri、複合、特殊

  • 修飾符 — :精確、:包含、:缺失、:不、:文字、:標識符

  • 連結 — 搜尋鏈參考(主題:Patient.name)

  • _有 — 反向鏈接,尋找其他資源引用的資源

  • _include / _revinclude — 將引用的資源拖曳到結果中

  • _summary、_elements、_sort、_count — 控制響應