

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

# 创建 FHIR 资源
<a name="managing-fhir-resources-create"></a>

FHIR `create` 交互会在 HealthLake 数据存储中创建新的 FHIR 资源。有关更多信息，请参阅 **FHIR R4 RESTful API** 文档[https://hl7.org/fhir/R4/http.html#create](https://hl7.org/fhir/R4/http.html#create)中的。

**创建 FHIR 资源**  


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

1. 确定要创建的 FHIR `Resource` 的类型。有关更多信息，请参阅 [资源类型](reference-fhir-resource-types.md)。

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

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

1. 为请求构建 JSON 正文，指定新资源的 FHIR 数据。出于本过程的目的，我们使用的是 FHIR `Patient` 资源，因此请将文件另存为`create-patient.json`。

   ```
   {
       "resourceType": "Patient",
       "identifier": [
           {
               "system": "urn:oid:1.2.36.146.595.217.0.1",
               "value": "12345"
           }
       ],
       "name": [
           {
               "family": "Silva",
               "given": [
                   "Ana",
                   "Carolina"
               ]
           }
       ],
       "gender": "female",
       "birthDate": "1992-02-10"
   }
   ```

1. 发送 请求。FHIR `create` 交互在 FHIR 授权上使用[AWS 签名版本 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html) 或 SMART 的`POST`请求。以下示例 HealthLake 使用 curl 或控制台在中创建 FHIR `Patient` 资源。 HealthLake 要查看整个示例，请滚动到 “复**制**” 按钮。

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

   Sigv4 授权

   ```
   curl --request POST \
     'https://healthlake.region.amazonaws.com/datastore/datastore-id/r4/Patient' \
     --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' \
     --data @create-patient.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)。

------
#### [ AWS Console ]

**注意**  
 HealthLake 控制台仅支持 [AWS SigV4 授权](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)。

   1. 登录 HealthLake 控制台上的 “[运行查询](https://console.aws.amazon.com/healthlake/home#/crud)” 页面。

   2. 在 **“查询设置”** 部分下，进行以下选择。
   + **数据存储 ID**-选择数据存储 ID 以生成查询字符串。
   + **查询类型**-选择`Create`。
   + **资源类型**-选择要创建的 FHIR [资源类型](reference-fhir-resource-types.md)。
   + **请求正文** — 为请求构建 JSON 正文，指定新资源的 FHIR 数据。

   3. 选择**运行查询**。

------

**为资源创建配置验证级别**  


创建 FHIR 资源时，您可以选择指定 `x-amzn-healthlake-fhir-validation-level` HTTP 标头来配置资源的验证级别。 AWS HealthLake 目前支持以下验证级别：
+ `strict`：根据资源的配置文件元素对资源进行验证，如果不存在配置文件，则根据R4规格进行验证。这是的默认验证级别 AWS HealthLake。
+ `structure-only`：根据 R4 对资源进行验证，忽略任何引用的配置文件。
+ `minimal`：资源经过最低限度的验证，忽略了某些 R4 规则。未通过所需的结构检查的资源 search/analytics 将进行更新，以包括审计警告。

尽管搜索索引需要验证失败，但使用最低验证级别创建的资源仍可能被提取到数据存储中。在这种情况下，将更新资源，以包括专门用于记录上述故障的 Healthlake 扩展程序：

```
{
    "url": "http://healthlake.amazonaws.com/fhir/StructureDefinition/validation-issue",
    "valueString": "{\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"error\",\"code\":\"processing\",\"details\":{\"text\":\"FHIR resource in payload failed FHIR validation rules.\"},\"diagnostics\":\"FHIR resource in payload failed FHIR validation rules.\"}]}"
}
```

此外，将包含以下 HTTP 响应标头，其值为 “true”：

```
x-amzn-healthlake-validation-issues : true
```

**注意**  
如果存在这些错误，则根据 R4 规范提取的数据可能无法按预期进行搜索。