

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 讀取 FHIR 資源歷史記錄
<a name="managing-fhir-resources-read-history"></a>

FHIR `history`互動會擷取 HealthLake 資料存放區中特定 FHIR 資源的歷史記錄。使用此互動，您可以判斷 FHIR 資源的內容如何隨時間變更。在協調稽核日誌時，查看修改前後的資源狀態也很有用。FHIR 互動 `create`、 `update`和 `delete`會產生要儲存的歷史資源版本。如需詳細資訊，請參閱 **FHIR R4 RESTful API 文件**[https://hl7.org/fhir/R4/http.html#history](https://hl7.org/fhir/R4/http.html#history)中的 。

**注意**  
您可以選擇不`history`接收特定 FHIR 資源類型。若要選擇退出，請使用 建立案例[AWS Support Center Console](https://console.aws.amazon.com/support/home#/)。若要建立您的案例，請登入您的 AWS 帳戶 ，然後選擇**建立案例**。

**讀取 FHIR 資源歷史記錄**  


1. 收集 HealthLake `region`和 `datastoreId` 值。如需詳細資訊，請參閱[取得資料存放區屬性](managing-data-stores-describe.md)。

1. 決定`Resource`要讀取和收集相關聯`id`值的 FHIR 類型。如需詳細資訊，請參閱[資源類型](reference-fhir-resource-types.md)。

1. 使用 HealthLake `region`和 的收集值來建構請求的 URL`datastoreId`。也包括 FHIR `Resource`類型、其相關聯的 `id`，以及選用的搜尋參數。若要在下列範例中檢視整個 URL 路徑，請捲動至**複製**按鈕。

   ```
   GET https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Resource/id/_history{?[parameters]}
   ```  
**HealthLake 支援的 FHIR `history`互動搜尋參數**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/healthlake/latest/devguide/managing-fhir-resources-read-history.html)

1. 傳送 請求。FHIR `history`互動使用具有[AWS 簽章第 4 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)版或 FHIR 授權上的 SMART 的`GET`請求。下列`curl`範例使用`_count`搜尋參數，針對 HealthLake 中的 FHIR `Patient` 資源傳回每頁 100 個歷史搜尋結果。若要檢視整個範例，請捲動至**複製**按鈕。

------
#### [ SigV4 ]

   SigV4 授權

   ```
   curl --request GET \
     'https://healthlake.region.amazonaws.com/datastore/datastore-id/r4/Patient/id/_history?_count=100' \
     --aws-sigv4 'aws:amz:region:healthlake' \
     --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
     --header "x-amz-security-token:$AWS_SESSION_TOKEN" \
     --header 'Accept: application/json'
   ```

------
#### [ SMART on FHIR ]

   [https://docs.aws.amazon.com/healthlake/latest/APIReference/API_IdentityProviderConfiguration.html](https://docs.aws.amazon.com/healthlake/latest/APIReference/API_IdentityProviderConfiguration.html) 資料類型的 FHIR 上的 SMART 授權範例。

   ```
   {
       "AuthorizationStrategy": "SMART_ON_FHIR",
       "FineGrainedAuthorizationEnabled": true,
       "IdpLambdaArn": "arn:aws:lambda:your-region:your-account-id:function:your-lambda-name",
       "Metadata": "{\"issuer\":\"https://ehr.example.com\", \"jwks_uri\":\"https://ehr.example.com/.well-known/jwks.json\",\"authorization_endpoint\":\"https://ehr.example.com/auth/authorize\",\"token_endpoint\":\"https://ehr.token.com/auth/token\",\"token_endpoint_auth_methods_supported\":[\"client_secret_basic\",\"foo\"],\"grant_types_supported\":[\"client_credential\",\"foo\"],\"registration_endpoint\":\"https://ehr.example.com/auth/register\",\"scopes_supported\":[\"openId\",\"profile\",\"launch\"],\"response_types_supported\":[\"code\"],\"management_endpoint\":\"https://ehr.example.com/user/manage\",\"introspection_endpoint\":\"https://ehr.example.com/user/introspect\",\"revocation_endpoint\":\"https://ehr.example.com/user/revoke\",\"code_challenge_methods_supported\":[\"S256\"],\"capabilities\":[\"launch-ehr\",\"sso-openid-connect\",\"client-public\",\"permission-v2\"]}"
   }
   ```

   發起人可以在授權 lambda 中指派許可。如需詳細資訊，請參閱[OAuth 2.0 範圍](reference-smart-on-fhir-oauth-scopes.md)。

------

   `history` 互動的傳回內容包含在 FHIR 資源 中`Bundle`，類型設定為 `history`。它包含指定的版本歷史記錄，最後以最舊的版本排序，並包含已刪除的資源。如需詳細資訊，請參閱 **FHIR R4 文件**[https://hl7.org/fhir/R4/bundle.html](https://hl7.org/fhir/R4/bundle.html)中的 。

## 讀取版本特定的 FHIR 資源歷史記錄
<a name="managing-fhir-data-get-version-specific-resource"></a>

FHIR `vread`互動會對 HealthLake 資料存放區中的資源執行版本特定讀取。使用此互動，您可以像過去特定時間一樣檢視 FHIR 資源的內容。

**注意**  
如果您在*不使用* 的情況下使用 FHIR `history`互動`vread`，HealthLake 一律會傳回資源中繼資料的最新版本。

HealthLake 宣告支援[https://hl7.org/fhir/R4/capabilitystatement-definitions.html#CapabilityStatement.rest.resource.versioning](https://hl7.org/fhir/R4/capabilitystatement-definitions.html#CapabilityStatement.rest.resource.versioning)針對每個支援的資源在 中進行版本控制。所有 HealthLake 資料存放區在所有資源上都包含 `Resource.meta.versionId`(`vid`)。

啟用 FHIR `history`互動時 （預設為 10/25/2024 之後建立的資料存放區，或請求較舊的資料存放區），`Bundle`回應會包含 `vid`作為 [https://hl7.org/fhir/R4/bundle-definitions.html#Bundle.entry.response.location](https://hl7.org/fhir/R4/bundle-definitions.html#Bundle.entry.response.location)元素的一部分。在下列範例中， `vid`會顯示為數字 `1`。若要檢視完整範例，請參閱 [Bundle/bundle-response (JSON) 範例](https://build.fhir.org/bundle-response.json.html)。

```
"response" : {
    "status" : "201 Created",
    "location" : "Patient/12423/_history/1",
    ...}
```

**讀取版本特定的 FHIR 資源歷史記錄**  


1. 收集 HealthLake `region`和 `datastoreId` 值。如需詳細資訊，請參閱[取得資料存放區屬性](managing-data-stores-describe.md)。

1. 決定要讀取和收集相關聯 `id` 和 `vid`值的 FHIR `Resource`類型。如需詳細資訊，請參閱[資源類型](reference-fhir-resource-types.md)。

1. 使用針對 HealthLake 和 FHIR 收集的值來建構請求的 URL。若要在下列範例中檢視整個 URL 路徑，請捲動至**複製**按鈕。

   ```
   GET https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Resource/id/_history/vid
   ```

1. 傳送 請求。FHIR `history`互動使用具有[AWS 簽章第 4 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)版或 FHIR 授權上的 SMART 的`GET`請求。下列`vread`互動會針對 指定的資源中繼資料版本，傳回具有 FHIR `Patient` 資源指定內容的單一執行個體`vid`。若要在下列範例中檢視整個 URL 路徑，請捲動至**複製**按鈕。

------
#### [ SigV4 ]

   SigV4 授權

   ```
   curl --request GET \
     'https://healthlake.region.amazonaws.com/datastore/datastore-id/r4/Patient/id/_history/vid' \
     --aws-sigv4 'aws:amz:region:healthlake' \
     --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
     --header "x-amz-security-token:$AWS_SESSION_TOKEN" \
     --header 'Accept: application/json'
   ```

------
#### [ SMART on FHIR ]

   [https://docs.aws.amazon.com/healthlake/latest/APIReference/API_IdentityProviderConfiguration.html](https://docs.aws.amazon.com/healthlake/latest/APIReference/API_IdentityProviderConfiguration.html) 資料類型的 FHIR 上的 SMART 授權範例。

   ```
   {
       "AuthorizationStrategy": "SMART_ON_FHIR",
       "FineGrainedAuthorizationEnabled": true,
       "IdpLambdaArn": "arn:aws:lambda:your-region:your-account-id:function:your-lambda-name",
       "Metadata": "{\"issuer\":\"https://ehr.example.com\", \"jwks_uri\":\"https://ehr.example.com/.well-known/jwks.json\",\"authorization_endpoint\":\"https://ehr.example.com/auth/authorize\",\"token_endpoint\":\"https://ehr.token.com/auth/token\",\"token_endpoint_auth_methods_supported\":[\"client_secret_basic\",\"foo\"],\"grant_types_supported\":[\"client_credential\",\"foo\"],\"registration_endpoint\":\"https://ehr.example.com/auth/register\",\"scopes_supported\":[\"openId\",\"profile\",\"launch\"],\"response_types_supported\":[\"code\"],\"management_endpoint\":\"https://ehr.example.com/user/manage\",\"introspection_endpoint\":\"https://ehr.example.com/user/introspect\",\"revocation_endpoint\":\"https://ehr.example.com/user/revoke\",\"code_challenge_methods_supported\":[\"S256\"],\"capabilities\":[\"launch-ehr\",\"sso-openid-connect\",\"client-public\",\"permission-v2\"]}"
   }
   ```

   發起人可以在授權 lambda 中指派許可。如需詳細資訊，請參閱[OAuth 2.0 範圍](reference-smart-on-fhir-oauth-scopes.md)。

------