Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate FHIR Integration Tasks from PowerShell
Are you in search of a quick and easy way to access FHIR data from PowerShell? This article demonstrates how to utilize the FHIR Cmdlets for tasks like connecting to FHIR data, automating operations, downloading data, and more.
The CData Cmdlets for FHIR are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to FHIR.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to FHIR, but also an SQL interface; this tutorial shows how to use both to retrieve FHIR data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for FHIR. To access FHIR data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for FHIR.
Once you have acquired the necessary connection properties, accessing FHIR data in PowerShell can be enabled in three steps.
Set URL to the Service Base URL of the FHIR server. This is the address where the resources are defined in the FHIR server you would like to connect to. Set ConnectionType to a supported connection type. Set ContentType to the format of your documents. Set AuthScheme based on the authentication requirements for your FHIR server.
Generic, Azure-based, AWS-based, and Google-based FHIR server implementations are supported.
Sample Service Base URLs
- Generic: http://my_fhir_server/r4b/
- Azure: https://MY_AZURE_FHIR.azurehealthcareapis.com/
- AWS: https://healthlake.REGION.amazonaws.com/datastore/DATASTORE_ID/r4/
- Google: https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/
Generic FHIR Instances
The product supports connections to custom instances of FHIR. Authentication to custom FHIR servers is handled via OAuth (read more about OAuth in the Help documentation. Before you can connect to custom FHIR instances, you must set ConnectionType to Generic.
PowerShell
-
Install the module:
Install-Module FHIRCmdlets
-
Connect:
$fhir = Connect-FHIR -URL "$URL" -ConnectionType "$ConnectionType" -ContentType "$ContentType" -AuthScheme "$AuthScheme"
-
Search for and retrieve data:
$[address-city] = "New York" $patient = Select-FHIR -Connection $fhir -Table "Patient" -Where "[address-city] = `'$[address-city]`'" $patient
You can also use the Invoke-FHIR cmdlet to execute SQL commands:
$patient = Invoke-FHIR -Connection $fhir -Query 'SELECT * FROM Patient WHERE [address-city] = @[address-city]' -Params @{'@[address-city]'='New York'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for FHIR\lib\System.Data.CData.FHIR.dll")
-
Connect to FHIR:
$conn= New-Object System.Data.CData.FHIR.FHIRConnection("URL=http://test.fhir.org/r4b/;ConnectionType=Generic;ContentType=JSON;AuthScheme=None;") $conn.Open()
-
Instantiate the FHIRDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, [name-use] from Patient" $da= New-Object System.Data.CData.FHIR.FHIRDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.[name-use] }