

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 阅读 FHIR 资源历史记录
<a name="managing-fhir-resources-read-history"></a>

FHIR `history` 交互会检索数据存储中特定 FHIR 资源的历史记录。 HealthLake 使用此交互，您可以确定 FHIR 资源的内容如何随着时间的推移而发生变化。它还可用于与审计日志协调以查看修改前后的资源状态。FHIR 的交互作用`create`和`delete`结果是要保存的资源的历史版本。`update`有关更多信息，请参阅 **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`要读取的 FHIR 类型并收集相关`id`值。有关更多信息，请参阅 [资源类型](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_cn/healthlake/latest/devguide/managing-fhir-resources-read-history.html)

1. 发送 请求。FHIR `history` 交互在 FHIR 授权上使用[AWS 签名版本 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html) 或 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)数据类型的 SMART on FHIR 授权示例。

   ```
   {
       "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` 交互时（默认情况下，对于在 2024 年 10 月 25 日之后创建的数据存储或通过请求较旧的数据存储创建的数据存储），`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`。要查看完整示例，请参阅[示例捆绑包/捆绑包响应 (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`的 and `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` 交互在 FHIR 授权上使用[AWS 签名版本 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html) 或 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)数据类型的 SMART on FHIR 授权示例。

   ```
   {
       "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)。

------