---
# System prepended metadata

title: Clinical Reasoning - HAPI FHIR
tags: [HAPI, FHIR, CQL]

---

Clinical Reasoning - HAPI FHIR
===

相較於Firely最近發表的firely-cql-sdk`https://github.com/FirelyTeam/firely-cql-sdk#getting-started`，著重做Client端的程式開發，HAPI FHIR的重點則是在Server端應用。HAPI FHIR內建cql engine和Quality Measure engine可以透過FHIR operation實作CQL相關應用。

HAPI FHIR設定
---
要使用Clinical Reasoning相關功能，必須修改application.yaml檔案(或docker-compose.yaml)中參數設定`fhir.cr.enable=true`( 預設值為false)，詳細可參考[HPAI FHIR測試環境建立](https://hackmd.io/@hongyu0324/hapi-test-environment)。


使用案例
---
- Prospective/Retrospective Analytics
  - Quality Measures
  - Gaps in Care
- Clinical Decision Support
- Payer/Provider Data Exchange
- Prior Authorization

Quality Measurement Walkthrough
---
例如，乳癌篩檢的衡量標準可定義initial population為「所有女性」（使用CQL Expression）。「35歲以上女性」為分母以及「過去的一年35歲以上在該地區接受過乳癌篩檢的女性」為分子。 如果該措施針對 100 名女性進行評估，其中50名女性年齡超過35歲，25名女性在過去一年中接受過乳癌篩檢，則最終得分將為 50%(分子/分母）。

關於Quality Measure，FHIR Clinical Reasoning Module定義Measure Resource `https://www.hl7.org/fhir/measure.html`與數個相關的operation。Electronic Clinical Quality Measures (eCQMs)可以使用FHIR Measure Resource表示，內容包含metadata、terminology、population criteria section以及至少一個FHIR Library resource。FHIR Library Resource則包含一data criteria section 以及定義population criteria的相關邏輯。

目前HAPI FHIR支援 `$evaluate-measure`。相關測試資料可從`https://github.com/cqframework/ecqm-content-r4/tree/master/bundles/measure`下載後POST至HAPI FHIR Server。

例如：`POST http://your-server-base/fhir BreastCancerScreeningFHIR-bundle.json`

測試資料匯入後，可執行FHIR Operation - `$evaluate-measure`

```
GET http://your-server-base/fhir/Measure/BreastCancerScreeningFHIR/$evaluate-measure?periodStart=2019-01-01&periodEnd=2019-12-31&reportType=subject
```
  **相關參數**
  ----
| 名稱 | 範例 | 說明 |
| -------- | -------- | -------- |
| periodStart | 2019-01-01 | Report Period(對應CQL所定義之Measurement Period) - 開始|
| periodEnd | 2019-12-31 | Report Period(對應CQL所定義之Measurement Period) - 結束|
| subject | Patient/123 | 統計的對象(Patient(目前支援), Practitioner, Organization, Location, Device)|
| reportType | subject | 資料回傳的範圍，可為單一(subject)、清單(subjet-list)或統計(population)|

  **測試資料**
  ----
- 資料下載點是ecqm-content-r4，內容為2020年五月，CMS所公布，適用於2021(reporting year)以FHIR為基礎之eCQM。
- 測試資料包含多個Library，必要的Value set以及兩筆Patient與其Encounter等資料。
- Library清單如下：
  - BreastCancerScreeningFHIR
  - MATGlobalCommonFunctionsFHIR4
  - HospiceFHIR4
  - FHIRHelpers
  - SupplementalDataElementsFHIR4
  - AdvancedIllnessandFrailtyExclusionECQMFHIR4
  - AdultOutpatientEncountersFHIR4
- 主要的計算邏輯為BreastCancerScreeningFHIR，其他為運算過程中所使用的模組。Library.content是用來儲存運算邏輯的地方。以測試資料為例，提供三種形式的運算邏輯，分別是：cql、elm+xlm與elm+json。資料為base64字串，以CQL為例，轉碼後即可得內容如下：
```
library BreastCancerScreeningFHIR version '2.0.003'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.001' called FHIRHelpers
include SupplementalDataElementsFHIR4 version '2.0.000' called SDE
include MATGlobalCommonFunctionsFHIR4 version '6.0.000' called Global
include AdultOutpatientEncountersFHIR4 version '2.0.000' called AdultOutpatientEncounters
include HospiceFHIR4 version '2.0.000' called Hospice
include AdvancedIllnessandFrailtyExclusionECQMFHIR4 version '5.12.000' called Frailty

codesystem "LOINC": 'http://loinc.org'
codesystem "SNOMEDCT": 'http://snomed.info/sct'

...
```
  **測試結果**
  ----
資料回傳為MeasureReport格式`https://www.hl7.org/fhir/R4/measurereport.html`，主要測試結果可從group讀取，以測試資料為例，由於只有兩筆Patient資料，計算結果如下：
- Initial Population：２
- Denominator：２
- Denominator Exclusion：０
- Numerator：１
- measureScore：0.5

詳細內容如下：

```
...
"group": [ {
    "id": "group-1",
    "population": [ {
      "id": "3D2DD734-0712-484A-BE23-B1D2FF96D83A",
      "code": {
        "coding": [ {
          "system": "http://terminology.hl7.org/CodeSystem/measure-population",
          "code": "initial-population",
          "display": "Initial Population"
        } ]
      },
      "count": 2
    }, {
      "id": "C4B18753-73BC-4D48-801E-82AB55A70139",
      "code": {
        "coding": [ {
          "system": "http://terminology.hl7.org/CodeSystem/measure-population",
          "code": "denominator",
          "display": "Denominator"
        } ]
      },
      "count": 2
    }, {
      "id": "7C770CA2-5177-4C5F-A976-7F57EC9BC311",
      "code": {
        "coding": [ {
          "system": "http://terminology.hl7.org/CodeSystem/measure-population",
          "code": "denominator-exclusion",
          "display": "Denominator Exclusion"
        } ]
      },
      "count": 0
    }, {
      "id": "57BC5171-93A7-4D9B-AA42-18A344C8623B",
      "code": {
        "coding": [ {
          "system": "http://terminology.hl7.org/CodeSystem/measure-population",
          "code": "numerator",
          "display": "Numerator"
        } ]
      },
      "count": 1
    } ],
    "measureScore": {
      "value": 0.5
    }
  } ],
...
```


