|
| 1 | +--- |
| 2 | +title: Create an Azure Health Data Services de-identification service by using the synchronous endpoint in Python |
| 3 | +description: Learn how to create an Azure Health Data Services de-identification service by using the synchronous endpoint in Python |
| 4 | +services: azure-resource-manager |
| 5 | +ms.service: azure-health-data-services |
| 6 | +ms.subservice: deidentification-service |
| 7 | +author: kimiamavon |
| 8 | +ms.author: kimiamavon |
| 9 | +ms.topic: quickstart |
| 10 | +ms.date: 04/10/2025 |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Deploy the de-identification service synchronous endpoint in Python |
| 14 | + |
| 15 | +In this quickstart, you deploy an instance of the de-identification service in your Azure subscription using the synchronous endpoint in Python. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- If you don't have an Azure account, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 20 | +- An Azure subscription with write permissions |
| 21 | +- Python 3.8 or later |
| 22 | +- The Azure azure-health-deidentification [Python package](https://learn.microsoft.com/python/api/overview/azure/health-deidentification-readme?view=azure-python-preview) |
| 23 | + |
| 24 | + |
| 25 | +## Create a resource |
| 26 | + |
| 27 | +To deploy an instance of the de-identification service, start at the Azure portal home page. |
| 28 | + |
| 29 | +1. Search for **de-identification** in the top search bar. |
| 30 | +1. Select **De-identification Services** in the search results. |
| 31 | +1. Select the **Create** button. |
| 32 | + |
| 33 | +## Complete the Basics tab |
| 34 | + |
| 35 | +In the **Basics** tab, you provide basic information for your de-identification service. |
| 36 | + |
| 37 | +1. Fill in the **Project Details** section: |
| 38 | + |
| 39 | + | Setting | Action | |
| 40 | + |----------------|----------------------------------------------| |
| 41 | + | Subscription | Select your Azure subscription. | |
| 42 | + | Resource group | Select **Create new** and enter **my-deid**. | |
| 43 | + |
| 44 | +1. Fill in the **Instance details** section: |
| 45 | + |
| 46 | + | Setting | Action | |
| 47 | + |----------------|----------------------------------------------| |
| 48 | + | Name | Name your de-identification service. | |
| 49 | + | Location | Select a supported Azure region. | |
| 50 | + |
| 51 | +Supported regions are located [here.](https://azure.microsoft.com/explore/global-infrastructure/products-by-region/table) |
| 52 | + |
| 53 | +After you complete the configuration, you can deploy the de-identification service. |
| 54 | + |
| 55 | +1. Select **Next: Review + create** to review your choices. |
| 56 | +1. Select Create to start the deployment of your de-identification service. Deployment may take a few minutes. After the deployment is complete, select Go to resource to view your service. |
| 57 | + |
| 58 | +Note your Subscription, Subscription ID, and Service URL. |
| 59 | + |
| 60 | +## Set role-based access control (RBAC) |
| 61 | + |
| 62 | +Now that the resource is deployed, assign yourself as an owner using RBAC. To use the synchronous and asynchronous/Batch API, you need to be a DeID Data Owner. If you only need real-time or batch, you can assign yourself as a DeID Realtime Data User and/or DeID Batch Data Owner, respectively. |
| 63 | + |
| 64 | +1. On the left panel, select **Access control (IAM).** |
| 65 | +1. Click **Add** and **Add role assignment.** |
| 66 | +1. Select **DeID Data Owner** and then select **Members** on the top panel. |
| 67 | +1. Select **+ Select members,** and a panel will appear. Search for your own name and press **Select.** |
| 68 | +1. Back in the **Members** panel, select **Review + assign** at the bottom left. |
| 69 | + |
| 70 | +## Install the package |
| 71 | + |
| 72 | +Install the Azure Health Deidentification client library for Python. More information is available [here.](https://learn.microsoft.com/python/api/overview/azure/health-deidentification-readme?view=azure-python-preview) |
| 73 | + |
| 74 | +```Bash |
| 75 | +python -m pip install azure-health-deidentification |
| 76 | +``` |
| 77 | + |
| 78 | +## Test the service |
| 79 | +In terminal, [log in to Microsoft azure.](https://learn.microsoft.com/cli/azure/authenticate-azure-cli) |
| 80 | +Now, write “python” to open a python shell and paste the following code. |
| 81 | +Be sure to replace your Service URL with the URL you noted when creating a resource. |
| 82 | +You can also change the operation type between REDACT, TAG, or SURROGATE. |
| 83 | + |
| 84 | +```Bash |
| 85 | +from azure.health.deidentification import * |
| 86 | +from azure.health.deidentification.models import * |
| 87 | +from azure.identity import DefaultAzureCredential |
| 88 | + |
| 89 | +SERVICE_URL = "<YOUR SERVICE URL HERE>" ### Replace |
| 90 | +client = DeidentificationClient(SERVICE_URL.replace("https://", ""), DefaultAzureCredential()) |
| 91 | + |
| 92 | +# Input |
| 93 | +text = """ Hannah is a 92-year-old admitted on 9/7/23. First presented symptoms two days earlier on Tuesday, 9/5/23 """ |
| 94 | +operation=OperationType.SURROGATE ### CHANGE OPERATION TYPE AS NEEDED. Options include OperationType.TAG, OperationType.REDACT, and OperationType.SURROGATE |
| 95 | + |
| 96 | +# Processing |
| 97 | +print("############ Input") |
| 98 | +print(text) |
| 99 | +content = DeidentificationContent(input_text=text, operation=operation) |
| 100 | +try: |
| 101 | + response = client.deidentify(content) |
| 102 | +except Exception as e: |
| 103 | + print("Request failed with exception: \n\n", e) |
| 104 | + exit() |
| 105 | +print("\n############ Output") |
| 106 | + |
| 107 | +if operation==OperationType.TAG: |
| 108 | + print(response.tagger_result) |
| 109 | +else: |
| 110 | + print(response.output_text) |
| 111 | + |
| 112 | +``` |
| 113 | +
|
| 114 | +## Example input & output |
| 115 | +
|
| 116 | + | Input | Output | |
| 117 | + |----------------|---------| |
| 118 | + | Hannah is a 92-year-old admitted on 9/7/23. First presented symptoms two days earlier on Tuesday, 9/5/23 | Kim is a 90-year-old admitted on 9/30/23. First presented symptoms two days earlier on Thursday, 9/28/23 | |
| 119 | +
|
| 120 | +## Clean up resources |
| 121 | +
|
| 122 | +If you no longer need them, delete the resource group and de-identification service. To do so, select the resource group and select **Delete**. |
| 123 | +
|
| 124 | +## Next steps |
| 125 | +
|
| 126 | +> [!div class="nextstepaction"] |
| 127 | +> [Tutorial: Configure Azure Storage to de-identify documents](configure-storage.md) |
0 commit comments