

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

# 建立 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. 決定`Resource`要建立的 FHIR 類型。如需詳細資訊，請參閱[資源類型](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`互動使用具有[AWS 簽章第 4 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)版或 FHIR 授權上的 SMART 的`POST`請求。下列範例會使用 curl 或 HealthLake 主控台在 HealthLake 中建立 FHIR `Patient` 資源。若要檢視整個範例，請捲動至**複製**按鈕。

------
#### [ 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) 資料類型的 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)。

------
#### [ 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. 選擇 **Run query** (執行查詢)。

------

**設定資源建立的驗證層級**  


建立 FHIR 資源時，您可以選擇指定 `x-amzn-healthlake-fhir-validation-level` HTTP 標頭來設定資源的驗證層級。 AWS HealthLake 目前支援下列驗證層級：
+ `strict`：資源會根據資源的設定檔元素進行驗證，如果沒有設定檔，則為 R4 規格。這是 的預設驗證層級 AWS HealthLake。
+ `structure-only`：資源會根據 R4 驗證，忽略任何參考的設定檔。
+ `minimal`：最少驗證資源，忽略某些 R4 規則。搜尋/分析所需的結構檢查失敗的資源將更新為包含稽核警告。

雖然搜尋索引所需的驗證失敗，但使用最低驗證層級建立的資源仍可能會擷取至資料存放區。在這種情況下，資源將更新為包含 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 規格格式不正確擷取的資料。