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

使用 Azure Bicep 部署 Azure Health Data Services

本文介绍如何使用 Azure Bicep 创建 Azure Health Data Services,包括工作区、FHIR 服务、DICOM 服务和医疗技术服务。 可以在 Azure Health Data Services 示例中查看和下载本文中使用的 Bicep 脚本。

什么是 Azure Bicep

Bicep 是基于 Azure 资源管理器 (ARM) 模板而构建的。 Bicep 直接支持 Azure 服务(包括 Azure Health Data Services)的所有预览版和正式版 (GA)。 在开发过程中,可以使用 az bicep build 命令生成 JSON ARM 模板文件。 相反,可以使用 az bicep decompile 命令将 JSON 文件反向编译为 Bicep。 在部署期间,Bicep CLI 将 Bicep 文件转换为 ARM 模板 JSON。

可以继续使用 JSON ARM 模板,或者使用 Bicep 来开发 ARM 模板。 有关 Bicep 的详细信息,请参阅什么是 Bicep

注意

本文中的模板和脚本在公共预览期间在 Visual Studio Code 中进行了测试。 可能需要进行一些更改才能使代码适合在你的环境中运行。

定义参数和变量

使用 Bicep 参数和变量(而不是将名称和其他值进行硬编码),可以调试和重复使用 Bicep 模板。

我们首先使用关键字 param 定义工作区、FHIR 服务、DICOM 服务、医疗技术服务务的参数。 此外,我们还定义 Azure 订阅和 Microsoft Entra 租户的参数。 它们在 CLI 命令行中与“--parameters”选项配合使用。

然后,我们使用关键字 var 定义资源的变量。 此外,我们还为 FHIR 服务的机构和受众等属性定义变量。 它们在 Bicep 模板内部指定和使用,并且可以与参数、Bicep 函数和其他变量组合使用。 与参数不同,它们不会在 CLI 命令行中使用。

请务必注意,需要一个 Bicep 函数和环境才能指定登录 URL https://login.microsoftonline.com。 有关 Bicep 函数的详细信息,请参阅 Bicep 的部署函数

//Define parameters
param workspaceName string
param fhirName string
param dicomName string
param medtechName string
param tenantId string
param location string

//Define variables
var fhirservicename = '${workspaceName}/${fhirName}'
var dicomservicename = '${workspaceName}/${dicomName}'
var medtechservicename = '${workspaceName}/${medtechName}'
var medtechdestinationname = '${medtechservicename}/output1'
var loginURL = environment().authentication.loginEndpoint
var authority = '${loginURL}${tenantId}'
var audience = 'https://${workspaceName}-${fhirName}.fhir.azurehealthcareapis.com'

创建工作区模板

若要定义资源,请使用关键字 resource。 对于工作区资源,所需的属性包括工作区名称和位置。 在模板中,使用了资源组的位置,但可以为该位置指定一个不同的值。 对于资源名称,可以引用已定义的参数或变量。

有关资源和模块的详细信息,请参阅 Bicep 中的资源声明

//Create a workspace
resource exampleWorkspace 'Microsoft.HealthcareApis/workspaces@2021-06-01-preview' = {
  name: workspaceName
  location: resourceGroup().location
}

若要使用或引用现有工作区而不创建工作区,请使用关键字 existing。 指定工作区资源名称,并为 name 属性指定现有工作区实例名称。 请注意,模板中使用了现有工作区资源的另一个名称,但这不是必需的。

//Use an existing workspace
resource exampleExistingWorkspace 'Microsoft.HealthcareApis/workspaces@2021-06-01-preview' existing = {
   name: workspaceName
}

现在已准备就绪,可以使用 az deployment group create 命令部署工作区资源了。 还可以将它与它的其他资源一起部署,如本文后面进一步所述。

创建 FHIR 服务模板

对于 FHIR 服务资源,所需的属性包括服务实例名称、位置、种类和托管标识。 此外,它还对工作区资源有依赖关系。 对于 FHIR 服务本身,所需的属性包括机构和受众,这些属性在 properties 元素中指定。

resource exampleFHIR 'Microsoft.HealthcareApis/workspaces/fhirservices@2021-11-01' = {
  name: fhirservicename
  location: resourceGroup().location
  kind: 'fhir-R4'
  identity: {
    type: 'SystemAssigned'
  }
  dependsOn: [
    exampleWorkspace  
    //exampleExistingWorkspace
  ]
  properties: {
    accessPolicies: []
    authenticationConfiguration: {
      authority: authority
      audience: audience
      smartProxyEnabled: false
    }
    }
}

同样,可以通过关键字 existing 使用或引用现有 FHIR 服务

//Use an existing FHIR service
resource exampleExistingFHIR 'Microsoft.HealthcareApis/workspaces/fhirservices@2021-11-01' existing = {
    name: fhirservicename
}

创建 DICOM 服务模板

对于 DICOM 服务资源,所需的属性包括服务实例名称和位置,以及对工作区资源类型的依赖关系。

//Create DICOM service
resource exampleDICOM 'Microsoft.HealthcareApis/workspaces/dicomservices@2021-11-01' = {
  name: dicomservicename
  location: resourceGroup().location
  dependsOn: [
    exampleWorkspace
  ]
  properties: {}
}

同样,可以通过关键字 existing 使用或引用现有 DICOM 服务

//Use an existing DICOM service
 resource exampleExistingDICOM 'Microsoft.HealthcareApis/workspaces/dicomservices@2021-11-01' existing = {
   name: dicomservicename
}

创建医疗技术服务模板

对于医疗技术服务资源,所需的属性包括医疗技术服务名称、位置、托管标识,以及对工作区的依赖关系。 对于医疗技术服务本身,所需的属性包括 Azure 事件中心命名空间、事件中心、事件中心使用者组和设备映射。 例如,模板中使用了心率设备映射。

//Create IoT connector
resource exampleIoT 'Microsoft.HealthcareApis/workspaces/iotconnectors@2021-11-01' = {
  name: iotconnectorname
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  dependsOn: [
    exampleWorkspace
    //exampleExistingWorkspace
  ]
  properties: {
    ingestionEndpointConfiguration: {
      eventHubName: 'eventhubnamexxx'
      consumerGroup: 'eventhubconsumergroupxxx'
      fullyQualifiedEventHubNamespace: 'eventhubnamespacexxx.servicebus.windows.net'
            }
    deviceMapping: {
    content: {
    templateType: 'CollectionContent'
        template: [
                    {
                      templateType: 'JsonPathContent'
                      template: {
                              typeName: 'heartrate'
                              typeMatchExpression: '$..[?(@heartrate)]'
                              deviceIdExpression: '$.deviceid'
                              timestampExpression: '$.measurementdatetime'
                              values: [
                                {
                                      required: 'true'
                                      valueExpression: '$.heartrate'
                                      valueName: 'Heart rate'
                                      }
                                      ]
                                }
                    }
                  ]
            }
          }
      }
    }

同样,可以通过关键字 existing 使用或引用现有医疗技术服务

//Use an existing IoT 
resource exampleExistingIoT 'Microsoft.HealthcareApis/workspaces/iotconnectors/fhirdestinations@2021-11-01' existing = {
    name: iotconnectorname
}

医疗技术服务需要子资源、目标,并且当前仅支持 FHIR 服务目标。 对于医疗技术服务目标资源,所需的属性包括名称、位置,以及对医疗技术服务的依赖关系。 对于 FHIR 服务目标,所需的属性包括解析类型(其值为 Create 或 Lookup)、FHIR 服务资源 ID 和 FHIR 资源类型。 例如,模板中使用了 FHIR 观测资源的心率映射。

//Create IoT destination
resource exampleIoTDestination 'Microsoft.HealthcareApis/workspaces/iotconnectors/fhirdestinations@2021-11-01'  = {
  name:   iotdestinationname
  location: resourceGroup().location
  dependsOn: [
    exampleIoT
    //exampleExistingIoT
  ]
  properties: {
    resourceIdentityResolutionType: 'Create'
    fhirServiceResourceId: exampleFHIR.id //exampleExistingFHIR.id
    fhirMapping: {
                content: {
                    templateType: 'CollectionFhirTemplate'
                    template: [
                        {
                            templateType: 'CodeValueFhir'
                            template: {
                                codes: [
                                    {
                                        code: '8867-4'
                                        system: 'http://loinc.org'
                                        display: 'Heart rate'
                                    }
                                ]
                                periodInterval: 60
                                typeName: 'heartrate'
                                value: {
                                    defaultPeriod: 5000
                                    unit: 'count/min'
                                    valueName: 'hr'
                                    valueType: 'SampledData'
                                }
                            }
                        }
                    ]
                }
            }
        }
}

部署 Azure Health Data Services

可以使用 az deployment group create 命令部署单个 Bicep 模板或组合模板,类似于使用 JSON 模板部署 Azure 资源的方式。 指定资源组名称,并在命令行中包含参数。 使用“--parameters”选项,以“parameter = value”的形式指定参数和值对,如果定义了多个参数,则用空格分隔参数和值对。

对于 Azure 订阅和租户,可以指定值,或使用 CLI 命令从当前登录会话获取它们。

deploymentname=xxx
resourcegroupname=rg-$deploymentname
location=centralus
workspacename=ws$deploymentname
fhirname=fhir$deploymentname
dicomname=dicom$deploymentname
medtechname=medtech$deploymentname
bicepfilename=ahds.bicep
subscriptionid=$(az account show --query id --output tsv)
tenantid=$(az account show --subscription $subscriptionid --query tenantId --output tsv)

az group create --name $resourcegroupname --location $location
az deployment group create --resource-group $resourcegroupname --template-file $bicepfilename --parameters workspaceName=$workspacename fhirName=$fhirname dicomName=$dicomname medtechName=$medtechname tenantId=$tenantid location=$location

请注意,子资源名称(如 FHIR 服务)包括父资源名称,并且“dependsOn”属性是必需的。 但是,在父资源内创建子资源时,其名称不需要包含父资源名称,并且“dependsOn”属性不是必需的。 有关嵌套资源的详细信息,请参阅在 Bicep 中设置子资源的名称和类型

调试 Bicep 模板

可以在 Visual Studio Code 或其他环境中调试 Bicep 模板,并根据响应排查问题。 此外,还可以在调试时查看资源组中特定资源的活动日志。

此外,还可以使用 output 值进行调试,或将其作为部署响应的一部分使用。 例如,可以定义两个 output 值,以便在响应中显示 FHIR 服务的机构和受众的值。 有关详细信息,请参阅 Bicep 中的输出

output stringOutput1 string = authority
output stringOutput2 string = audience

后续步骤

本文介绍了如何使用 Bicep 创建 Azure Health Data Services,包括工作区、FHIR 服务、DICOM 服务和医疗技术服务。 还介绍了如何创建和调试 Bicep 模板。 有关 Azure Health Data Services 的详细信息,请参阅

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