This quickstart will walk you through creating a simple custom operation on top of the FHIR Service using Azure Functions. We'll cover everything from deploying infrastructure, debugging locally, and deploying to Azure.
This sample does not address authorization for simplicity - the endpoint is open to anyone with the address. Please only use test or sample data for this quickstart.
- An Azure account with an active subscription.
- You need access to create resource groups, resources, and role assignments in Azure
- .NET 6.0
- Azure Command-Line Interface (CLI)
- Azure Developer CLI
- Visual Studio or Visual Studio Code
- For Visual Studio, you will need the Azure Functions Tools. To add Azure Function Tools, include the Azure development workload in your Visual Studio installation.
- For Visual Studio Code, you will need to install the Azure Function Core Tools.
- In a terminal or command window, run
dotnet --version
to check that the .NET SDK is version 6.0 or later. - Run
az --version
andazd version
to check that you have the appropriate Azure command-line tools installed. - Login to the Azure CLI
This quickstart will create the below resources. These will be used both for local development and the Azure deployment.
- Azure Health Data Services workspace
- FHIR Service
- Function App (and associated storage account)
- APIM - Azure API Management (for Function App and Fhir Service)
- Log Analytics Workspace (for FHIR Service, Function App and APIM logs)
- Application Insights (for monitoring your custom operation)
-
Create a new directory on your local machine and open that directory in a terminal or command prompt.
-
Setup your local Quickstart files .
azd init --template Azure-Samples/azure-health-data-services-toolkit-fhir-function-quickstart
Note: lower-case name is needed to be compatible with all the resource types
-
If you want to use an existing FHIR Service, you need to open
infra/main.parameters.json
in a code editor and change the following settings:existingResourceGroupName
: The name of an existing resource group if you want to deploy your Function App there.existingAzureHealthDataServicesWorkspaceName
: The name of your existing Azure Health Data Services workspace.existingFhirServiceName
: The name of your existing FHIR Service.
-
By default, APIM is enabled for use. if you do not want to use APIM then pass
useAPIM
value as false Or Openinfra/main.parameters.json
in a code editor and set the value of the parameter nameduseAPIM
to false. -
Next, you need to provision your Azure resources to run the sample with azd. If you are creating a new FHIR Service, this deploy may take 20 minutes.
azd provision
-
To deploy your code (this can be done after local testing), run the deploy command.
azd deploy
Note: For more information for developing on the Azure Health Data Services Toolkit, check out the concepts document.
- Open this folder in Visual Studio Code (
samples/Quickstart
). - You may be asked to install recommended extensions for the repository. Click "Yes" to install the needed tools
- Relaunch Visual Studio Code if this is your first time working with the Azure Function Tools.
- Start the Azurite emulator by clicking
Azurite Blob Service
in the bottom blue bar or selectingAzurite: Start
from the command palate. - Start the Quickstart function app by going to "Run and Debug" and selecting the play button (or hit F5 on your keyboard).
- You can now test your code locally! Set a breakpoint and go to
http://localhost:7071/Patient
in your browser or API testing tool.
- Open the
Quickstart.sln
project inside of Visual Studio. - Debug the custom operation inside of Visual Studio.
- You can now test your code locally! Set a breakpoint and go to
http://localhost:7256/Patient
in your browser or API testing tool.
- Once you are ready to deploy to Azure, we can use azd. Run
azd deploy
from your terminal or command prompt. - The command will output ae endpoint for your function app. Copy this.
- Test the endpoint by going to
<Endpoint>/Patient
in your browser or API testing tool. - For APIM endpoint, get APIM Gateway URL from section Get the deployment details and test endpoint in API testing tool.
To get the deployed APIM Gateway URL variable named APIM_GatewayUrl
Run the below command:
azd get-values
If you don't want to use the APIM and are planning to call the Azure function instead, please follow the below steps to get the function url and key.
-
Run the below command to get the deployed Azure function URL variable named
Azure_FunctionURL
.azd get-values
-
Run the below command to get the default key from the deployed Azure function.
az functionapp keys list --name --resource-group
As output, it will return the default key and master key.
Please click on link to read more about the function key.
Program.cs
outlines how we can use Azure Function for Simple custom operation using various types of services like authenticator, headers and filters.- UseCustomHeaders() Used for custom headers Setup, using this service we can add custom header, here we have added custom header with name
X-MS-AZUREFHIR-AUDIT-USER-TOKEN-TEST
. - UseAzureFunctionPipeline() setup pipeline for Azure function.
- AddInputFilter(typeof(QuickstartFilter)) Input filter added with name
QuickStart
which in turn used to modify the patient data using JsonTransform. - Add binding to pass the call to the FHIR service.
- UseAuthenticator() Configures the binding to use an Azure.Identity DefaultAzureCredential.
- UseCustomHeaders() Used for custom headers Setup, using this service we can add custom header, here we have added custom header with name
- Please refer
QuickstartFilter.cs
file for input filter modifications in the Patient Data.- Added language to resource as ‘en’ (English)
- If there is no
Patient.meta.security
label, added HTEST
- Custom operation QuickstartSample end point methods listed below.
- GET: used to get the patient details using patient id.
- POST: creates new patient record with updated filter data which is given above,to verify the new created record use GET method and pass created id.
- PUT: it updates the patient data, need to pass patient id,to verify the updated record use GET method and pass updated id.
- DELETE: used to delete the patient record from FHIR server by passing patient id, to verify the deleted record use GET method and pass deleted id.
- APIM supports the complete API lifecycle, this template is prepared to use APIM for Fhir Service and Function App endpoints.
- in given APIM all the operations related to Patient are routed to QuickStart function app and for Fhir Service endpoints we have four methods like GET, POST, PUT, DELETE.
Please follow the below instructions if you want to perform operations using the Azure function instead of APIM.
For POST,
url : <QuickStartFunctionURL>/Patient?Code=defaultkey
For GET/PUT/DELETE,
url : <QuickStartFunctionURL>/Patient/{id}?Code=defaultkey
-
Please copy the quickstartfunction URL from the above command and replace it with
QuickStartFunctionURL
. -
Copy the default key value from the above command and replace it with 'defaultkey'. Remove the
?Code='defaultkey'
from the URL if AuthorizationLevel is Anonymous as it does not require any authorization.