

# 使用 AWS CLI 的 HealthLake 示例
<a name="cli_healthlake_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 HealthLake 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `create-fhir-datastore`
<a name="healthlake_CreateFHIRDatastore_cli_topic"></a>

以下代码示例演示了如何使用 `create-fhir-datastore`。

**AWS CLI**  
**示例 1：创建已启用 SigV4 的 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` 示例演示如何在 AWS HealthLake 中已启用 FHIR 的数据存储中创建新的 SMART。  

```
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 Developer Guide》**中的 [Creating and monitoring a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/working-with-FHIR-healthlake.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [CreateFHIRDatastore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/create-fhir-datastore.html)。

### `delete-fhir-datastore`
<a name="healthlake_DeleteFHIRDatastore_cli_topic"></a>

以下代码示例演示了如何使用 `delete-fhir-datastore`。

**AWS CLI**  
**删除 FHIR 数据存储**  
以下 `delete-fhir-datastore` 示例演示如何在 AWS HealthLake 中删除数据存储及其所有内容。  

```
aws healthlake delete-fhir-datastore \
    --datastore-id (Data store ID)
```
输出：  

```
{
    "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": "DELETING",
    "DatastoreId": "(Data store ID)"
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的“Creating and monitoring a FHIR data store”<https://docs.aws.amazon.com/healthlake/latest/devguide/working-with-FHIR-healthlake.html>。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DeleteFHIRDatastore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/delete-fhir-datastore.html)。

### `describe-fhir-datastore`
<a name="healthlake_DescribeFHIRDatastore_cli_topic"></a>

以下代码示例演示了如何使用 `describe-fhir-datastore`。

**AWS CLI**  
**描述 FHIR 数据存储**  
以下 `describe-fhir-datastore` 示例演示如何在 AWS HealthLake 中查找数据存储的属性。  

```
aws healthlake describe-fhir-datastore \
    --datastore-id "1f2f459836ac6c513ce899f9e4f66a59"
```
输出：  

```
{
    "DatastoreProperties": {
        "PreloadDataConfig": {
            "PreloadDataType": "SYNTHEA"
        },
        "SseConfiguration": {
            "KmsEncryptionConfig": {
                "CmkType": "CUSTOMER_MANAGED_KMS_KEY",
                "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
            }
        },
        "DatastoreName": "Demo",
        "DatastoreArn": "arn:aws:healthlake:us-east-1:<AWS Account ID>:datastore/<Data store ID>",
        "DatastoreEndpoint": "https://healthlake.us-east-1.amazonaws.com/datastore/<Data store ID>/r4/",
        "DatastoreStatus": "ACTIVE",
        "DatastoreTypeVersion": "R4",
        "CreatedAt": 1603761064.881,
        "DatastoreId": "<Data store ID>",
        "IdentityProviderConfiguration": {
            "AuthorizationStrategy": "AWS_AUTH",
            "FineGrainedAuthorizationEnabled": false
        }
    }
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Creating and monitoring a FHIR data stores](https://docs.aws.amazon.com/healthlake/latest/devguide/working-with-FHIR-healthlake.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DescribeFHIRDatastore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/describe-fhir-datastore.html)。

### `describe-fhir-export-job`
<a name="healthlake_DescribeFHIRExportJob_cli_topic"></a>

以下代码示例演示了如何使用 `describe-fhir-export-job`。

**AWS CLI**  
**描述 FHIR 导出作业**  
以下 `describe-fhir-export-job` 示例演示如何在 AWS HealthLake 中查找 FHIR 导出作业的属性。  

```
aws healthlake describe-fhir-export-job \
    --datastore-id (Data store ID) \
    --job-id 9b9a51943afaedd0a8c0c26c49135a31
```
输出：  

```
{
    "ExportJobProperties": {
        "DataAccessRoleArn": "arn:aws:iam::(AWS Account ID):role/(Role Name)",
        "JobStatus": "IN_PROGRESS",
        "JobId": "9009813e9d69ba7cf79bcb3468780f16",
        "SubmitTime": "2024-11-20T11:31:46.672000-05:00",
        "EndTime": "2024-11-20T11:34:01.636000-05:00",
        "OutputDataConfig": {
            "S3Configuration": {
            "S3Uri": "s3://(Bucket Name)/(Prefix Name)/",
            "KmsKeyId": "arn:aws:kms:us-east-1:012345678910:key/d330e7fc-b56c-4216-a250-f4c43ef46e83"
        }

        },
        "DatastoreId": "(Data store ID)"
    }
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Exporting files from a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/export-datastore.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DescribeFHIRExportJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/describe-fhir-export-job.html)。

### `describe-fhir-import-job`
<a name="healthlake_DescribeFHIRImportJob_cli_topic"></a>

以下代码示例演示了如何使用 `describe-fhir-import-job`。

**AWS CLI**  
**描述 FHIR 导入作业**  
以下 `describe-fhir-import-job` 示例演示如何使用 AWS HealthLake 了解 FHIR 导入作业的属性。  

```
aws healthlake describe-fhir-import-job \
    --datastore-id (Data store ID) \
    --job-id c145fbb27b192af392f8ce6e7838e34f
```
输出：  

```
{
    "ImportJobProperties": {
    "InputDataConfig": {
        "S3Uri": "s3://(Bucket Name)/(Prefix Name)/"
        { "arrayitem2": 2 }
    },
    "DataAccessRoleArn": "arn:aws:iam::(AWS Account ID):role/(Role Name)",
    "JobStatus": "COMPLETED",
    "JobId": "c145fbb27b192af392f8ce6e7838e34f",
    "SubmitTime": 1606272542.161,
    "EndTime": 1606272609.497,
    "DatastoreId": "(Data store ID)"
    }
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Importing files to a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/import-datastore.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》中的 **[DescribeFHIRImportJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/describe-fhir-import-job.html)。

### `list-fhir-datastores`
<a name="healthlake_ListFHIRDatastores_cli_topic"></a>

以下代码示例演示了如何使用 `list-fhir-datastores`。

**AWS CLI**  
**列出 FHIR 数据存储**  
以下 `list-fhir-datastores` 示例演示如何在 AWS HealthLake 中使用该命令以及用户如何基于数据存储状态筛选结果。  

```
aws healthlake list-fhir-datastores \
    --filter DatastoreStatus=ACTIVE
```
输出：  

```
{
    "DatastorePropertiesList": [
    {
        "PreloadDataConfig": {
            "PreloadDataType": "SYNTHEA"
        },
        "SseConfiguration": {
            "KmsEncryptionConfig": {
                "CmkType": "CUSTOMER_MANAGED_KMS_KEY",
                "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
            }
        },
        "DatastoreName": "Demo",
        "DatastoreArn": "arn:aws:healthlake:us-east-1:<AWS Account ID>:datastore/<Data store ID>",
        "DatastoreEndpoint": "https://healthlake.us-east-1.amazonaws.com/datastore/<Data store ID>/r4/",
        "DatastoreStatus": "ACTIVE",
        "DatastoreTypeVersion": "R4",
        "CreatedAt": 1603761064.881,
        "DatastoreId": "<Data store ID>",
        "IdentityProviderConfiguration": {
            "AuthorizationStrategy": "AWS_AUTH",
            "FineGrainedAuthorizationEnabled": false
        }
    }
    ]
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Creating and monitoring a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/working-with-FHIR-healthlake.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [ListFHIRDatastores](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/list-fhir-datastores.html)。

### `list-fhir-export-jobs`
<a name="healthlake_ListFHIRExportJobs_cli_topic"></a>

以下代码示例演示了如何使用 `list-fhir-export-jobs`。

**AWS CLI**  
**列出所有 FHIR 导出作业**  
以下 `list-fhir-export-jobs` 示例演示了如何使用该命令查看与账户关联的导出作业列表。  

```
aws healthlake list-fhir-export-jobs \
    --datastore-id (Data store ID) \
    --submitted-before (DATE like 2024-10-13T19:00:00Z)\
    --submitted-after (DATE like 2020-10-13T19:00:00Z )\
    --job-name "FHIR-EXPORT" \
    --job-status SUBMITTED  \
    --max-results (Integer between 1 and 500)
```
输出：  

```
{
    "ExportJobPropertiesList": [
        {
            "ExportJobProperties": {
                "OutputDataConfig": {
                    "S3Uri": "s3://(Bucket Name)/(Prefix Name)/",
                    "S3Configuration": {
                        "S3Uri": "s3://(Bucket Name)/(Prefix Name)/",
                        "KmsKeyId": "(KmsKey Id)"
                    }
                },
                "DataAccessRoleArn": "arn:aws:iam::(AWS Account ID):role/(Role Name)",
                "JobStatus": "COMPLETED",
                "JobId": "c145fbb27b192af392f8ce6e7838e34f",
                "JobName": "FHIR-EXPORT",
                "SubmitTime": "2024-11-20T11:31:46.672000-05:00",
                "EndTime": "2024-11-20T11:34:01.636000-05:00",
                "DatastoreId": "(Data store ID)"
            }
        }
    ]
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》中的 [Exporting files from a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/export-datastore.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [ListFHIRExportJobs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/list-fhir-export-jobs.html)。

### `list-fhir-import-jobs`
<a name="healthlake_ListFHIRImportJobs_cli_topic"></a>

以下代码示例演示了如何使用 `list-fhir-import-jobs`。

**AWS CLI**  
**列出所有 FHIR 导入作业**  
以下 `list-fhir-import-jobs` 示例演示了如何使用该命令查看与账户关联的所有导入作业的列表。  

```
aws healthlake list-fhir-import-jobs \
    --datastore-id (Data store ID) \
    --submitted-before (DATE like 2024-10-13T19:00:00Z) \
    --submitted-after (DATE like 2020-10-13T19:00:00Z ) \
    --job-name "FHIR-IMPORT" \
    --job-status SUBMITTED  \
    -max-results (Integer between 1 and 500)
```
输出：  

```
{
    "ImportJobPropertiesList": [
        {
            "JobId": "c0fddbf76f238297632d4aebdbfc9ddf",
            "JobStatus": "COMPLETED",
            "SubmitTime": "2024-11-20T10:08:46.813000-05:00",
            "EndTime": "2024-11-20T10:10:09.093000-05:00",
            "DatastoreId": "(Data store ID)",
            "InputDataConfig": {
                "S3Uri": "s3://(Bucket Name)/(Prefix Name)/"
            },
            "JobOutputDataConfig": {
                "S3Configuration": {
                    "S3Uri": "s3://(Bucket Name)/import/6407b9ae4c2def3cb6f1a46a0c599ec0-FHIR_IMPORT-c0fddbf76f238297632d4aebdbfc9ddf/",
                    "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/b7f645cb-e564-4981-8672-9e012d1ff1a0"
                }
            },
            "JobProgressReport": {
                "TotalNumberOfScannedFiles": 1,
                "TotalSizeOfScannedFilesInMB": 0.001798,
                "TotalNumberOfImportedFiles": 1,
                "TotalNumberOfResourcesScanned": 1,
                "TotalNumberOfResourcesImported": 1,
                "TotalNumberOfResourcesWithCustomerError": 0,
                "TotalNumberOfFilesReadWithCustomerError": 0,
                "Throughput": 0.0
            },
            "DataAccessRoleArn": "arn:aws:iam::(AWS Account ID):role/(Role Name)"
        }
    ]
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》中的 [Importing files to FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/import-examples.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [ListFHIRImportJobs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/list-fhir-import-jobs.html)。

### `list-tags-for-resource`
<a name="healthlake_ListTagsForResource_cli_topic"></a>

以下代码示例演示了如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出数据存储的标签**  
以下 `list-tags-for-resource` 示例列出与指定数据存储关联的标签。  

```
aws healthlake list-tags-for-resource \
    --resource-arn "arn:aws:healthlake:us-east-1:123456789012:datastore/fhir/0725c83f4307f263e16fd56b6d8ebdbe"
```
输出：  

```
{
    "tags": {
        "key": "value",
        "key1": "value1"
    }
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》中的 [Tagging resources in AWS HealthLake](https://docs.aws.amazon.com/healthlake/latest/devguide/tagging.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/list-tags-for-resource.html)。

### `start-fhir-export-job`
<a name="healthlake_StartFHIRExportJob_cli_topic"></a>

以下代码示例演示了如何使用 `start-fhir-export-job`。

**AWS CLI**  
**启动 FHIR 导出作业**  
以下 `start-fhir-export-job` 示例演示如何使用 AWS HealthLake 启动 FHIR 导出作业。  

```
aws healthlake start-fhir-export-job \
    --output-data-config '{"S3Configuration": {"S3Uri":"s3://(Bucket Name)/(Prefix Name)/","KmsKeyId":"arn:aws:kms:us-east-1:012345678910:key/d330e7fc-b56c-4216-a250-f4c43ef46e83"}}' \
    --datastore-id (Data store ID) \
    --data-access-role-arn arn:aws:iam::(AWS Account ID):role/(Role Name)
```
输出：  

```
{
    "DatastoreId": "(Data store ID)",
    "JobStatus": "SUBMITTED",
    "JobId": "9b9a51943afaedd0a8c0c26c49135a31"
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Exporting files from a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/export-datastore.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [StartFHIRExportJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/start-fhir-export-job.html)。

### `start-fhir-import-job`
<a name="healthlake_StartFHIRImportJob_cli_topic"></a>

以下代码示例演示了如何使用 `start-fhir-import-job`。

**AWS CLI**  
**启动 FHIR 导入作业**  
以下 `start-fhir-import-job` 示例演示如何使用 AWS HealthLake 启动 FHIR 导入作业。  

```
aws healthlake start-fhir-import-job \
    --input-data-config S3Uri="s3://(Bucket Name)/(Prefix Name)/" \
    --job-output-data-config '{"S3Configuration": {"S3Uri":"s3://(Bucket Name)/(Prefix Name)/","KmsKeyId":"arn:aws:kms:us-east-1:012345678910:key/d330e7fc-b56c-4216-a250-f4c43ef46e83"}}' \
    --datastore-id (Data store ID) \
    --data-access-role-arn "arn:aws:iam::(AWS Account ID):role/(Role Name)"
```
输出：  

```
{
    "DatastoreId": "(Data store ID)",
    "JobStatus": "SUBMITTED",
    "JobId": "c145fbb27b192af392f8ce6e7838e34f"
}
```
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Importing files to a FHIR data store](https://docs.aws.amazon.com/healthlake/latest/devguide/import-datastore.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [StartFHIRImportJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/start-fhir-import-job.html)。

### `tag-resource`
<a name="healthlake_TagResource_cli_topic"></a>

以下代码示例演示了如何使用 `tag-resource`。

**AWS CLI**  
**向数据存储中添加标签**  
以下 `tag-resource` 示例演示如何向数据存储中添加标签。  

```
aws healthlake tag-resource \
    --resource-arn "arn:aws:healthlake:us-east-1:123456789012:datastore/fhir/0725c83f4307f263e16fd56b6d8ebdbe" \
    --tags '[{"Key": "key1", "Value": "value1"}]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Adding a tag to a data store](https://docs.aws.amazon.com/healthlake/latest/devguide/add-a-tag.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/tag-resource.html)。

### `untag-resource`
<a name="healthlake_UntagResource_cli_topic"></a>

以下代码示例演示了如何使用 `untag-resource`。

**AWS CLI**  
**从数据存储中移除标签**  
以下 `untag-resource` 示例演示如何从数据存储中移除标签。  

```
aws healthlake untag-resource \
    --resource-arn "arn:aws:healthlake:us-east-1:123456789012:datastore/fhir/b91723d65c6fdeb1d26543a49d2ed1fa" \
    --tag-keys '["key1"]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS HealthLake Developer Guide》**中的 [Removing tags from a data store](https://docs.aws.amazon.com/healthlake/latest/devguide/remove-tags.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/healthlake/untag-resource.html)。