Try   HackMD

FHIR RESRful API介紹

基本CRUD操作

以下內容參考Abel Enthoven - FHIR REST API | DevDays 2023 Amsterdam
https://www.youtube.com/watch?v=dWnHFf8jJJM&list=PLKuZNI94tzWY1J988TdEGhJ69r4DnTiAN&index=112

  • Create a Resource:使用POST,JSON檔案(id由FHIR Server決定)
  • Upsert a Resource:使用PUT,JSON檔案(可自行定義id)
  • Partially update a resource : 使用PATCH(不建議使用,並非所有FHIR Server都有實作PATCH)
  • Delete a Resource : 使用DELETE(歷史資料並不會同時被刪除)
  • POST a Bundle : Bundle包含collection of resource,所有的request依序執行,若bundle的type為batch,表示不自動執行,必須是transaction才能自動執行。Bundle包含多個Entry,每一個Entry包含resource與request(執行方法)
  • Resource Validation
    • 基本格式檢查(內容符合JSON檔案格式)
    • FHIR Basic(欄位名稱符合FHIR的定義)
    • FHIR Resource Type(欄位名稱包含在特定Resource之中,resource定義必填的欄位是否存在)
    • FHIR Profile(資料符合特定IG/Profile的規定,Profile所定義的資料格式必須完全符合)
  • Concurrency : 根據timestamp/Etag判斷資料是否被修改,有些FHIR Server會提供類似data lock的功能,但並非全部支援。
  • Fetch a Resource by id : 回傳Bundle
  • Search的語法
    • using URL parameters:GTE(URL可能被記錄)
      GET /Patient?family=Enthoven&birthdate=1975-12-21
    • using a form post
      POST /Patient/_search Content-type:application/x-www-form-urlencoded
      with content:
      family=family=Enthoven&birthdate=1975-12-21
  • search parameter
    • FHIR標準之所有resource都提供:_id,_profile,_type
    • 特定的resource定義或客製化:Patient.name, Observtion.code,Patient.my_search_param
    • multiple paramete types
    • modifiers:對搜尋結果增加限制(例如:exact,missing)
      GET /Patient?family:exact =Enthoven
      GET /Observation?patient:missing =true
    • prefixes:邏輯搜尋條件,僅限於number, date, qualitity(例如:ge,lt)
      GET /Patient?birthdate =ge1975-01-01
      GET /Observation?patient =1&value quantity=lt4.6

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

FHIR searh同時提供進階版本的search,以資料庫的master-detail觀念會比較容易了解。還傳值為Bundle型態,因此對於程式撰寫來說,一般需要對Bundle做後處理才能得到真正想要的答案。

  • Forward Chaining
    條件一:Resource A的search parameter包含一類型為reference(Resource B)
    條件二:以類型B的任一Search parameter當作搜尋條件。
    舉例:Encounter的search parameter中,Patient為reference,即可使用Patient的search parameter "NAME",尋找符合姓名搜尋條件之所有Encounter資料。(實務上,這是一個Master-Detail的觀念,一般假設搜尋結果為一對多;若搜尋結果為多對多,則後續必須針對搜尋結果作後處理。例如一個Patient有多個Encounter,一個Encounter有多個Condition)
GET [base]/Encounter?date=2023-02-03&patient.name=Sanford861, Maile198
  • Reverse Chaining
    Reverse Chaining為Forward Chaining的反向操作, FHIR API使用"_has"實作。使用情境為指定Detail狀態,取得符合該狀態的Master清單。例如想知道符合Condition code為314529007(SNOMED-CT 代碼系統中的 “藥物審查到期” - Medication review due)的病患清單,即可使用reverse chaining. 由於HAPI FHIR Java SDK並未實作"_has",因此使用Plain URL為替代方案。
GET [base]/Patient?_has:Condition:patient:code:314529007
  • Include
    選擇特定的Detail,並將一或多個Master資料一併回傳,通常為多對多,則需要後續處理。
    舉例:取得Condition的code為314529007的Condition資料,並且包含patient資料
GET [base]/Condition?code=314529007&_include =Condition:patient
  • Revese Includes
    選擇特定的Master,並將一或多個Detail資料一併回傳,最好為一對多;若狀況為多對多,則需要後續處理。
    舉例:取得Patient的name為Sanford861的資料,同時取得其Encounter,Condition資料
GET [base]/ Patient?name=Sanford861&name=Maile198&_revinclude=Encounter:patient&_revinclude=Condition:patient