

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

# 建立 HealthLake 資料存放區
<a name="managing-data-stores-create"></a>

使用 `CreateFHIRDatastore`建立符合 FHIR R4 規格 AWS HealthLake 的資料存放區。HealthLake 資料存放區用於匯入、管理、搜尋和匯出 FHIR 資料。建立時，您可以選擇將 （預先載入） Synthea 開放原始碼 FHIR R4 運作狀態資料匯入資料存放區。如需詳細資訊，請參閱[預先載入的資料類型](reference-healthlake-preloaded-data-types.md)。

**Important (重要)**  
HealthLake 支援兩種類型的 FHIR 資料存放區授權策略： AWS SigV4 或 FHIR 上的 SMART。在建立 HealthLake FHIR 資料存放區之前，您必須選擇其中一個授權策略。如需詳細資訊，請參閱[資料存放區授權策略](getting-started-concepts.md#concept-data-store-authorization-strategy)。

當您建立 HealthLake 資料存放區時，可透過 RESTful API [端點](reference-healthlake-endpoints-quotas.md#reference-healthlake-endpoints)提供 FHIR 資料儲存庫。建立 HealthLake 資料存放區之後，您可以請求其[功能陳述](reference-fhir-capability-statement.md)式來尋找所有相關的 FHIR 相關功能 （行為）。

下列功能表提供 AWS CLI 和 AWS SDKs的範例，以及 的程序 AWS 管理主控台。如需詳細資訊，請參閱 *AWS HealthLake API 參考*中的 [https://docs.aws.amazon.com/healthlake/latest/APIReference/API_CreateFHIRDatastore.html](https://docs.aws.amazon.com/healthlake/latest/APIReference/API_CreateFHIRDatastore.html)。

**建立 HealthLake 資料存放區**  
根據您的存取偏好設定選擇選單 AWS HealthLake。

## AWS CLI 和 SDKs
<a name="managing-data-stores-create-cli-sdk"></a>

------
#### [ CLI ]

**AWS CLI**  
**範例 1：建立 SigV4-enabled HealthLake 資料存放區**  
下列`create-fhir-datastore`範例示範如何在 AWS HealthLake 中建立新的資料存放區。  

```
aws healthlake create-fhir-datastore \
    --datastore-type-version R4 \
    --datastore-name "FhirTestDatastore"
```
輸出：  

```
{
    "DatastoreEndpoint": "https://healthlake.us-east-1.amazonaws.com/datastore/(Data store ID)/r4/",
    "DatastoreArn": "arn:aws:healthlake:us-east-1:(AWS Account ID):datastore/(Data store ID)",
    "DatastoreStatus": "CREATING",
    "DatastoreId": "(Data store ID)"
}
```
**範例 2：在啟用 FHIR 的 HealthLake 資料存放區上建立 SMART**  
下列`create-fhir-datastore`範例示範如何在啟用 FHIR 的資料存放區上建立新的 SMART in AWS HealthLake。  

```
aws healthlake create-fhir-datastore \
    --datastore-name "your-data-store-name" \
    --datastore-type-version R4 \
    --preload-data-config PreloadDataType="SYNTHEA" \
    --sse-configuration '{ "KmsEncryptionConfig": {  "CmkType": "CUSTOMER_MANAGED_KMS_KEY", "KmsKeyId": "arn:aws:kms:us-east-1:your-account-id:key/your-key-id" } }' \
    --identity-provider-configuration  file://identity_provider_configuration.json
```
`identity_provider_configuration.json` 的內容：  

```
{
    "AuthorizationStrategy": "SMART_ON_FHIR_V1",
    "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\"]}"
}
```
輸出：  

```
{
    "DatastoreEndpoint": "https://healthlake.us-east-1.amazonaws.com/datastore/(Data store ID)/r4/",
    "DatastoreArn": "arn:aws:healthlake:us-east-1:(AWS Account ID):datastore/(Data store ID)",
    "DatastoreStatus": "CREATING",
    "DatastoreId": "(Data store ID)"
}
```
如需詳細資訊，請參閱《AWS HealthLake 開發人員指南》**中的[建立和監控 FHIR 資料存放區](https://docs.aws.amazon.com/healthlake/latest/devguide/working-with-FHIR-healthlake.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateFHIRDatastore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/create-fhir-datastore.html)。

------
#### [ Python ]

**適用於 Python 的 SDK (Boto3)**  

```
    @classmethod
    def from_client(cls) -> "HealthLakeWrapper":
        """
        Creates a HealthLakeWrapper instance with a default AWS HealthLake client.

        :return: An instance of HealthLakeWrapper initialized with the default HealthLake client.
        """
        health_lake_client = boto3.client("healthlake")
        return cls(health_lake_client)


    def create_fhir_datastore(
        self,
        datastore_name: str,
        sse_configuration: dict[str, any] = None,
        identity_provider_configuration: dict[str, any] = None,
    ) -> dict[str, str]:
        """
        Creates a new HealthLake data store.
        When creating a SMART on FHIR data store, the following parameters are required:
        - sse_configuration: The server-side encryption configuration for a SMART on FHIR-enabled data store.
        - identity_provider_configuration: The identity provider configuration for a SMART on FHIR-enabled data store.

        :param datastore_name: The name of the data store.
        :param sse_configuration: The server-side encryption configuration for a SMART on FHIR-enabled data store.
        :param identity_provider_configuration: The identity provider configuration for a SMART on FHIR-enabled data store.
        :return: A dictionary containing the data store information.
        """
        try:
            parameters = {"DatastoreName": datastore_name, "DatastoreTypeVersion": "R4"}
            if (
                sse_configuration is not None
                and identity_provider_configuration is not None
            ):
                # Creating a SMART on FHIR-enabled data store
                parameters["SseConfiguration"] = sse_configuration
                parameters[
                    "IdentityProviderConfiguration"
                ] = identity_provider_configuration

            response = self.health_lake_client.create_fhir_datastore(**parameters)
            return response
        except ClientError as err:
            logger.exception(
                "Couldn't create data store %s. Here's why %s",
                datastore_name,
                err.response["Error"]["Message"],
            )
            raise
```
下列程式碼示範啟用 FHIR 的 HealthLake 資料存放區上的 SMART 參數範例。  

```
            sse_configuration = {
                "KmsEncryptionConfig": {"CmkType": "AWS_OWNED_KMS_KEY"}
            }
            # TODO: Update the metadata to match your environment.
            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",
                ],
            }
            # TODO: Update the IdpLambdaArn.
            identity_provider_configuration = {
                "AuthorizationStrategy": "SMART_ON_FHIR_V1",
                "FineGrainedAuthorizationEnabled": True,
                "IdpLambdaArn": "arn:aws:lambda:your-region:your-account-id:function:your-lambda-name",
                "Metadata": json.dumps(metadata),
            }
            data_store = self.create_fhir_datastore(
                datastore_name, sse_configuration, identity_provider_configuration
            )
```
+  如需 API 詳細資訊，請參閱《AWS SDK for Python (Boto3) API 參考》**中的 [CreateFHIRDatastore](https://docs.aws.amazon.com/goto/boto3/healthlake-2017-07-01/CreateFHIRDatastore)。
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/healthlake#code-examples)中設定和執行。

------
#### [ SAP ABAP ]

**適用於 SAP ABAP 的開發套件**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap/services/hll#code-examples)中設定和執行。

```
    TRY.
        " iv_datastore_name = 'MyHealthLakeDataStore'
        oo_result = lo_hll->createfhirdatastore(
          iv_datastorename = iv_datastore_name
          iv_datastoretypeversion = 'R4'
        ).
        MESSAGE 'Data store created successfully.' TYPE 'I'.
      CATCH /aws1/cx_hllvalidationex INTO DATA(lo_validation_ex).
        DATA(lv_error) = |Validation error: { lo_validation_ex->av_err_code }-{ lo_validation_ex->av_err_msg }|.
        MESSAGE lv_error TYPE 'I'.
        RAISE EXCEPTION lo_validation_ex.
      CATCH /aws1/cx_hllinternalserverex INTO DATA(lo_internal_ex).
        lv_error = |Internal server error: { lo_internal_ex->av_err_code }-{ lo_internal_ex->av_err_msg }|.
        MESSAGE lv_error TYPE 'I'.
        RAISE EXCEPTION lo_internal_ex.
      CATCH /aws1/cx_hllthrottlingex INTO DATA(lo_throttling_ex).
        lv_error = |Throttling error: { lo_throttling_ex->av_err_code }-{ lo_throttling_ex->av_err_msg }|.
        MESSAGE lv_error TYPE 'I'.
        RAISE EXCEPTION lo_throttling_ex.
    ENDTRY.
```
+  如需 API 詳細資訊，請參閱《適用於 *AWS SAP ABAP 的 SDK API 參考*》中的 [CreateFHIRDatastore](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/index.html)。

------

**可用性範例**  
找不到所需的內容嗎？ 使用此頁面右側的**提供意見回饋**連結來請求程式碼範例。

## AWS 主控台
<a name="managing-data-stores-create-console"></a>

**注意**  
下列程序會使用 [AWS SigV4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html) 授權建立 HealthLake 資料存放區。HealthLake 主控台不支援在 FHIR 資料存放區上建立 SMART。

**使用 AWS SigV4 授權建立 HealthLake 資料存放區**

1. 登入 HealthLake 主控台上的[建立資料存放](https://console.aws.amazon.com/healthlake/home#/create-datastore)區頁面。

1. 選擇**建立資料存放區**。

1. 在**資料存放區設定**區段中，針對**資料存放區名稱**指定名稱。

1. （選用） 在**資料存放區設定**區段中，針對**預先載入範例資料**，選取核取方塊以預先載入 Synthea 資料。Synthea 資料是開放原始碼範例資料集。如需詳細資訊，請參閱[HealthLake 的 Synthea 預先載入資料類型](reference-healthlake-preloaded-data-types.md)。

1. 在**資料存放區加密**區段中，選擇**使用 AWS 擁有的金鑰 （預設）** 或**選擇不同的 AWS KMS 金鑰 （進階）**。

1. 在**標籤 - *選用***區段中，您可以將標籤新增至資料存放區。若要進一步了解如何標記資料存放區，請參閱 [標記 HealthLake 資料存放區](managing-data-stores-tagging.md)。

1. 選擇**建立資料存放區**。

   資料存放區的狀態可在**資料存放**區頁面上取得。