FHIR IG應用開發 === "FHIR IG應用"這是自創名詞,想表達的是當開發人員拿到一個新的FHIR IG如何按部就班,了解其架構後開發相關應用程式,產生相關資料。 我們可以使用HAPI FHIR為主體,建構FHIR資料平台,使用平台成為我們打造FHIR IG應用的基礎。也就是說,可以將資料轉換成FHIR格式儲存於FHIR資料平台,並根據實際上IG規範,開發FHIR IG應用程式。換句話說,我們應用FHIR資料平台,將工作區分為兩部分:資料匯入FHIR平台,與開發FHIR IG應用程式,將所需要的資料從平台取出。 ![FHIRIG-4](https://hackmd.io/_uploads/SJeTJPFpeg.png) 由於目前所規範出來的IG主要目的還是資料交換,所以會存在一個或多個Bundle作為資料交換的主體。因此FHIR IG應用開發的主要工作會是如何產生IG所需要的Bundle。 一般而言,每一個Bundle都會存在一個主要的Profile為資料交換的主體我們稱它為Major Data,其他Profile可視為major data的佐證資料。在不同的佐證資料中,又可依其特性區分為Master Data與IG Data。兩者之間主要的區別在於Master Data是跨IG使用,而IG Data則是特別IG的專屬資料。 ![FHIRIG-5](https://hackmd.io/_uploads/HJklbwK6ex.png) 因此,我們可將開發FHIR IG應用的過程簡化為以下步驟: 1. 匯入Master Data(FHIR平台資料匯入) 2. 匯入IG Data(FHIR平台資料匯入) 3. 根據使用情境產生Major Data(FHIR平台應用程式開發) 4. 匯集所有相關資料,產生Bundle(FHIR平台應用程式開發) 接下來的問題是如何區分Master Data與IG Data?我們舉PAS與NGS兩個實際案例如下表所示: ![FHIRIG-2](https://hackmd.io/_uploads/SJRQtLK6xe.png) 有些Resource是比較難歸類的,首先是DocumentReference和Specimen,這兩個Resourcey在PAS與NGS都各自有定義,但並沒有很大的差別,將其歸類為Master Data的目的是希望在FHIR平台中只有一筆資料,不會因為不同IG應用而需要兩筆資料。 Device是另一個有較難分類的Resource,以基因檢測為例,一般都是由外部單位負責,因此Device資料需要由外部單位提供,或是從報告中取得,因次第一次資料取得的時機會是在報告匯入之時。但考量未來相關報告可能使用同一筆Device資料,我們還是將Device歸類為Master Data。 截至目前(2025/10/11)為止,[政府部門公布的IG](https://www.fhir.org/guides/registry/)共有:TW core、IDIR、PAS、EMR、NGS、CI、VACC。其中VACC並沒有在https://www.fhir.org/guides/registry 註冊,另外PAS在政府正式版本已經是1.0.8但FHIR官網顯示還是1.0.5。衛福部所公告的IG其Bundle Type與Major Profile列表如下: | IG | Bundle Type | Major Profile | | -------- | -------- | -------- | | PAS | Collection | Claim | | NGS | Document | Composition | | CI | Collection | QuestionnaireResponse | | EMR | Document | Composition | | VACC | Batch | Composition| | IDIR | Message | MessageHeader| Bundle說明 --- Bundle是一個相當特殊的Resource,[官方網站是這樣定義Bundle](https://hl7.org/fhir/R4/bundle.html):*A container for a collection of resources.* 因此,FHIR IG應用開發的主要流程即為蒐集Bundle所需要的Resource資料,並彙集成Bundle檔。 另外,Bundle的type定義了不同的使用方式,官方說明如下: *One common operation performed with resources is to gather a collection of resources into a single instance with containing context. In FHIR this is referred to as "bundling" the resources together. These resource bundles are useful for a variety of different reasons, including:* * *Returning a set of resources that meet some criteria as part of a server operation (see RESTful Search)* * *Returning a set of versions of resources as part of the history operation on a server (see History)* * *Sending a set of resources as part of a message exchange (see Messaging)* * *Grouping a self-contained set of resources to act as an exchangeable and persistable collection with clinical integrity - e.g. a clinical document (see Documents)* * *Creating/updating/deleting a set of resources on a server as a single operation (including doing so as a single atomic transaction) (see Transactions/Batch)* * *Storing a collection of resources* Bundle Type包含:document | message | transaction | transaction-response | batch | batch-response | history | searchset | collection,其中history、searchset、batch-response/transaction-response應用在REST API的回應,與資料交換相關的type為靜態的document、message和collection。以及動態的transaction和batch。 如果Bundle type為document,表示Bundle.entry的第一個Resource必須是Composition,Compositionc可視為Bundle document的"目錄",包含概述,如category、type、date、Subject(Patient)和Author(Organization),以及詳細資料Section(Bundlen所包含Resource列表)。以NGS為例,我們可以將Bundle以圖形化表示如下: ![FHIRIG-1](https://hackmd.io/_uploads/ryhjZDYTll.png) 從上圖我們可以知道,一個NGS Bundle必須包含的Resource清單以及相關限制設定。 作業流程 --- 再以NGS為例,結合上述說明,我們可以得到以下的作業流程: ![FHIRIG-3](https://hackmd.io/_uploads/B18_bvYTll.png) 也就是說,我們將必要的master/IG Data匯入FHIR資料平台後,就可以開發FHIR IG應用程式,根據實際需求,產生Composition並打包成Bundle檔。 相關開發細節可參考[FHIR平台應用程式開發](https://hackmd.io/@hongyu0324/FHIRAppDev)