你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Visual Studio Code 中使用 REST 客户端扩展访问 Azure Health Data Services

本文介绍如何在 Visual Studio Code 中使用 REST 客户端扩展访问 Azure Health Data Services。

安装 REST 客户端扩展

选择 Visual Studio Code 左侧面板中的“扩展”图标,然后搜索“REST 客户端”。 找到 REST 客户端扩展并安装。

REST 客户端 VSCode 扩展

创建 .http 文件并定义变量

在 Visual Studio Code 中创建新文件。 在文件中输入 GET 请求命令行,并将其另存为 test.http。 文件后缀 .http 自动激活 REST 客户端环境。 选择 Send Request 以获取元数据。

发送请求

获取客户端应用程序值

重要

在调用 FHIR® 服务器 REST API(而不是获取元数据)之前,必须完成应用程序注册。 记下 Azure 租户 ID客户端 ID、客户端密码和服务 URL。

虽然可以直接在对 REST API 的调用中使用客户端 ID 等值,但最好为这些值定义一些变量,并改用变量。

test.http 文件中,包括从注册应用程序获取的以下信息。

### REST Client
@fhirurl =https://xxx.azurehealthcareapis.com
@clientid =xxx....
@clientsecret =xxx....
@tenantid =xxx....

获取 Microsoft Entra 访问令牌

test.http 文件中包括以下信息后,点击 Send Request。 你将看到包含访问令牌的 HTTP 响应。

@name 开头的行包含一个变量,用于捕获包含访问令牌的 HTTP 响应。 @token 变量用于存储访问令牌。

注意

client_credentialsgrant_type 用于获取访问令牌。

### Get access token 
# @name getAADToken 
POST https://login.microsoftonline.com/{{tenantid}}/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&resource={{fhirurl}}
&client_id={{clientid}}
&client_secret={{clientsecret}}
&scope={{fhirurl}}/.default

### Extract access token from getAADToken request
@token = {{getAADToken.response.body.access_token}}

获取访问令牌

注意

当 FHIR 服务受众参数未映射到 FHIR 服务终结点 URL 时,资源参数值应映射到 FHIR 服务的“身份验证”窗格上的受众值。

获取 FHIR 患者数据

现在,可以使用 GET 请求获取患者或特定患者的列表。 带有 Authorization 的行是 GET 请求的标头信息。 还可以发送 PUTPOST 请求来创建和更新 FHIR 资源。

### GET Patient 
GET {{fhirurl}}/Patient/<patientid>
Authorization: Bearer {{token}}

获取患者

运行 PowerShell 或 CLI

可以在 Visual Studio Code 中运行 PowerShell 或 CLI 脚本。 按 CTRL~ 键,然后选择 PowerShell 或 Bash。 在集成终端可以找到更多详细信息。

Visual Studio Code 中的 PowerShell

运行 PowerShell

Visual Studio Code 中的 CLI

正在运行的 CLI

故障排除

如果无法获取元数据(不需要基于 HL7 规范的访问令牌),请检查 FHIR 服务器是否正常运行。

如果无法获取访问令牌,请确保客户端应用程序已正确注册,并且正在使用应用程序注册步骤中的正确值。

如果无法从 FHIR 服务器获取数据,请确保已向客户端应用程序(或服务主体)授予对 FHIR 服务器的“FHIR 数据参与者”等访问权限。

后续步骤

本文介绍如何在 Visual Studio Code 中使用 REST 客户端扩展访问 Azure Health Data Services 数据。

若要了解如何根据 Azure Health Data Services 中的配置文件验证 FHIR 资源,请参阅

注意

FHIR® 是 HL7 的注册商标,经 HL7 许可使用。