

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

# 使用 POST 搜索 FHIR 资源
<a name="searching-fhir-resources-post"></a>

您可以使用 FHIR 与`POST`请求的[https://hl7.org/fhir/R4/search.html](https://hl7.org/fhir/R4/search.html)交互来搜索HealthLake 数据存储。使用时`POST`， HealthLake 支持在 URL 或请求正文中使用搜索参数，但不能在单个请求中同时使用这两个参数。

**重要提示**  
对于涉及个人身份信息 (PII) 或受保护的健康信息 (PHI) 的搜索，安全最佳实践要求使用`POST`请求，因为 PII 和 PHI 是作为请求正文的一部分添加的，并在传输过程中进行加密。

以下过程是使用 FHIR R4 与的`search`交互`POST`来搜索 HealthLake 数据存储的示例。这些示例展示了如何在 JSON 请求正文中指定搜索参数。

**使用搜索 HealthLake 数据存储 `POST`**  


1. 收集 HealthLake `region`和`datastoreId`价值。有关更多信息，请参阅 [获取数据存储属性](managing-data-stores-describe.md)。

1. 确定要搜索和收集关联`id`值的 FHIR 资源类型。有关更多信息，请参阅 [资源类型](reference-fhir-resource-types.md)。

1. 使用收集到的 HealthLake`region`和值为请求构造一个 URL `datastoreId`。还包括 FHIR `Resource` 类型和`_search`交互作用。要查看以下示例中的整个 URL 路径，请滚动到 “**复制**” 按钮。

   ```
   POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Resource/_search
   ```

1. 为请求构建 JSON 正文，指定要搜索的 FHIR 数据。出于此手术的目的，您将搜索`Observation`资源以发现从未吸烟的患者。要指定医疗代码状态`Never smoker`，请在 JSON 请求正文`value-concept=266919005`中进行设置。将该文件保存为 `search-observation.json`。

   ```
   value-concept=266919005
   ```

1. 发送 请求。FHIR `search` 交互使用带有[AWS 签名版本 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html) 或 SMART 的 FHIR 授权`GET`请求。
**注意**  
在`POST`请求正文中使用搜索参数发出请求时，请`Content-Type: application/x-www-form-urlencoded`将其用作标头的一部分。

   以下`curl`示例对`Observation`资源类型发出基于 Post的搜索请求。该请求使用[https://hl7.org/fhir/R4/observation.html#search](https://hl7.org/fhir/R4/observation.html#search)搜索参数来查找表示值的医疗代码`266919005``Never smoker`。要查看整个示例，请滚动到 “复**制**” 按钮。

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

   Sigv4 授权

   ```
   curl --request POST \
     'https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Observation/_search' \						
     --aws-sigv4 'aws:amz:region:healthlake' \
     --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
     --header "x-amz-security-token:$AWS_SESSION_TOKEN" \
     --header "Content-Type: application/x-www-form-urlencoded"							
     --header "Accept: application/json"
     --data @search-observation.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)。

------

## 示例：使用 POST 进行搜索
<a name="searching-fhir-resources-post-examples"></a>

以下选项卡提供了使用搜索特定 FHIR 资源类型的示例。`POST`这些示例说明了如何在中指定请求 URLs。

**注意**  
 HealthLake 控制台仅支持 SigV4 授权。通过 AWS CLI 和 AWS SDKs支持 FHIR 上的 SMART 授权。  
HealthLake 支持 FHIR R4 搜索参数的子集。有关更多信息，请参阅 [搜索参数](reference-fhir-search-parameters.md)。

------
#### [ Patient (age) ]

尽管年龄不是在 FHIR 中定义的资源类型，但它被捕获为[https://hl7.org/fhir/R4/patient.html](https://hl7.org/fhir/R4/patient.html)资源类型中的一个元素。使用以下示例对`Patient`资源类型发出`POST`基于搜索的请求。以下搜索示例使用搜索[比较器来`eq`搜索](reference-fhir-search-parameters.md#search-comparators) 1997 年出生的个人。

```
POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Patient/_search
```

要在搜索中指定 1997 年，请在请求正文中添加以下元素。

```
birthdate=eq1997
```

------
#### [ Condition ]

使用以下内容对`Condition`资源类型`POST`提出请求。此搜索可在您的 HealthLake 数据存储中查找包含医疗代码的位置`72892002`。

您必须指定请求网址和请求正文。以下是请求网址的示例。

```
POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Condition/_search
```

要指定要搜索的医疗代码，请在请求正文中添加以下 JSON 元素。

```
code=72892002
```

------
#### [ DocumentReference ]

要在对 HealthLake`DocumentReference`资源类型`POST`提出请求时查看集成自然语言处理 (NLP) 的结果，请按以下方式格式化请求。

```
POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/DocumentReference/_search
```

要指定要引用的`DocumentReference`搜索参数，请参阅[搜索参数类型](reference-fhir-search-parameters.md#search-parameter-types)。以下查询字符串使用多个搜索参数搜索用于生成集成 NLP 结果的 Amazon Comprehend Medical API 操作。

```
_lastUpdated=le2021-12-19&infer-icd10cm-entity-text-concept-score;=streptococcal|0.6&infer-rxnorm-entity-text-concept-score=Amoxicillin|0.8
```

------
#### [ Location ]

使用以下示例对`Location`资源类型发出`POST`请求。搜索会在您的HealthLake 数据存储中查找地址中包含城市名称波士顿的位置。

您必须指定请求 URL 和请求正文。以下是请求网址的示例。

```
POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Location/_search
```

要在搜索`Boston`中指定，请在请求正文中添加以下元素：

```
address=Boston
```

------
#### [ Observation ]

使用以下示例对`Observation`资源类型发出`POST`基于搜索的请求。搜索使用`value-concept`搜索参数来查找医疗代码，`266919005`这表示出来`Never smoker`。

```
POST https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Observation/_search
```

要指定状态`Never smoker`，请在 JSON 的正文`value-concept=266919005`中进行设置。

```
value-concept=266919005
```

------