

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

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

您可以使用 FHIR [https://hl7.org/fhir/R4/search.html](https://hl7.org/fhir/R4/search.html)互動與 `POST` 請求來搜尋 HealthLake 資料存放區。使用 時`POST`，HealthLake 支援 URL 或請求內文中的搜尋參數，但您無法在單一請求中使用兩者。

**Important (重要)**  
對於涉及個人身分識別資訊 (PII) 或受保護醫療資訊 (PHI) 的搜尋，安全最佳實務會使用 `POST` 請求，因為 PII 和 PHI 會新增為請求內文的一部分，並在傳輸中加密。

以下程序後面是使用 FHIR R4 與 `search`互動`POST`來搜尋 HealthLake 資料存放區的範例。這些範例示範如何在 JSON 請求內文中指定搜尋參數。

**使用 搜尋 HealthLake 資料存放區 `POST`**  


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

1. 決定要搜尋的 FHIR 資源類型，並收集相關聯的`id`值。如需詳細資訊，請參閱[資源類型](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`互動使用`GET`請求搭配 [AWS Signature 第 4 版](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)或 FHIR 上的 SMART 授權。
**注意**  
在`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) 資料類型的 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)。

------

## 範例：使用 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`。

您必須指定請求 URL 和請求內文。以下是請求 URL 的範例。

```
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 資料存放區中包含城市名稱 Boston 做為地址一部分的位置。

您必須指定請求 URL 和請求內文。以下是請求 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
```

若要指定狀態，請在 JSON 內文`value-concept=266919005`中設定 `Never smoker` 。

```
value-concept=266919005
```

------