共用方式為


使用 Azure Bicep 部署 Azure Health Data Services

在本文中,您將瞭解如何使用 Azure Bicep 建立 Azure Health Data Services,包括工作區、FHIR 服務、DICOM 服務和 MedTech 服務。 您可以在 Azure Health Data Services 範例檢視及下載本文中使用的 Bicep 腳本。

什麼是 Azure Bicep

Bicep 是以 Azure Resource Manager (ARM) 範本為基礎所建置。 Bicep 立即支援所有預覽和正式運作的 Azure 服務版本,包括 Azure Health Data Services。 在開發期間,您可以使用 命令來產生 JSON ARM 範本檔案 az bicep build 。 相反地,您可以使用 命令將 JSON 檔案分解為 Bicep az bicep decompile 。 在部署期間,Bicep CLI 會將 Bicep 檔案轉換成 ARM 範本 JSON。

您可以繼續使用 JSON ARM 範本,或使用 Bicep 來開發 ARM 範本。 如需 Bicep 的詳細資訊,請參閱 什麼是 Bicep

注意

文章中的範本和腳本會在公開預覽期間在Visual StudioCode中測試。 某些變更可能需要調整程序代碼,才能在您的環境中執行。

定義參數和變數

使用 Bicep 參數和變數,而不是硬式編碼名稱和其他值,可讓您偵錯及重複使用 Bicep 範本。

我們會先使用工作區、FHIR 服務、DICOM 服務、MedTech 服務的關鍵詞 參數 來定義參數。 此外,我們會定義 Azure 訂用帳戶和Microsoft Entra 租用戶的參數。 它們會與 「--parameters」 選項一起使用在 CLI 命令行中。

接著,我們會使用 關鍵詞 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'

建立工作區範本

若要定義資源,請使用 關鍵詞 資源。 針對工作區資源,必要的屬性包括工作區名稱和位置。 在範本中,會使用資源群組的位置,但您可以為位置指定不同的值。 針對資源名稱,您可以參考定義的參數或變數。

如需資源和模組的詳細資訊,請參閱 Bicep 中的資源宣告。

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

若要使用或參考現有的工作區而不建立工作區,請使用現有的 關鍵詞。 指定工作區資源名稱,以及 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
    }
    }
}

同樣地,您可以使用或參考現有的 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: {}
}

同樣地,您可以使用或參考現有的 DICOM 服務,並使用現有的 關鍵詞

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

建立 MedTech 服務範本

針對 MedTech 服務資源,必要的屬性包括 MedTech 服務名稱、位置、受控識別,以及工作區的相依性。 針對 MedTech 服務本身,必要的屬性包括 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'
                                      }
                                      ]
                                }
                    }
                  ]
            }
          }
      }
    }

同樣地,您可以使用 或參考現有的 MedTech 服務,並使用現有的 關鍵詞

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

MedTech 服務需要子資源、目的地,且目前僅支援 FHIR 服務目的地。 針對 MedTech 服務目的地資源,必要的屬性包括名稱、位置和 MedTech 服務的相依性。 針對 FHIR 服務目的地,必要的屬性包括解析類型,其會採用建立查閱、FHIR 服務資源識別碼,以及 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 健康資料服務

您可以使用 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 範本進行偵錯,並根據回應對問題進行疑難解答。 此外,您可以在偵錯時檢閱資源群組中特定資源的活動記錄。

此外,您可以使用 輸出 值進行偵錯,或作為部署回應的一部分。 例如,您可以定義兩個輸出值,以顯示回應中 FHIR 服務的授權單位和物件值。 如需詳細資訊,請參閱 Bicep 中的輸出

output stringOutput1 string = authority
output stringOutput2 string = audience

下一步

在本文中,您已瞭解如何使用 Bicep 建立 Azure Health Data Services,包括工作區、FHIR 服務、DICOM 服務和 MedTech 服務。 您也瞭解如何建立和偵錯 Bicep 範本。 如需 Azure 健康資料服務的詳細資訊,請參閱

FHIR® 是 HL7 的註冊商標,在 HL7 的許可下使用。