Skip to content

Commit 8383c97

Browse files
Update quickstart-python.md - sdk changed, breaking code resolved
sdk changed, breaking changes resolved
1 parent f63a8c9 commit 8383c97

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

articles/healthcare-apis/deidentification/quickstart-python.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,46 +76,65 @@ python -m pip install azure-health-deidentification
7676
```
7777

7878
## Test the service
79-
In terminal, [log in to Microsoft azure.](/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.
79+
In terminal, [log in to Microsoft Azure.](/cli/azure/authenticate-azure-cli)
80+
The code below references the [python SDK for text.](https://github.com/Azure/azure-sdk-for-python/blob/azure-health-deidentification_1.0.0/sdk/healthdataaiservices/azure-health-deidentification/samples/deidentify_text_redact.py)
81+
82+
To use it, create a python file called "deidentify_text_redact.py" and paste the following code in. Run "python deidentify_text_redact.py".
83+
84+
Be sure to replace AZURE_HEALTH_DEIDENTIFICATION_ENDPOINT with the URL you noted when creating a resource.
8285
You can also change the operation type between REDACT, TAG, or SURROGATE.
8386

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)
87+
```python
88+
89+
"""
90+
FILE: deidentify_text_redact.py
91+
92+
DESCRIPTION:
93+
This sample demonstrates the most simple de-identification scenario, calling the service to redact
94+
PHI values in a string.
95+
96+
USAGE:
97+
python deidentify_text_redact.py
98+
99+
Set the environment variables with your own values before running the sample:
100+
1) AZURE_HEALTH_DEIDENTIFICATION_ENDPOINT - the service URL endpoint for a de-identification service.
101+
"""
102+
103+
104+
from azure.health.deidentification import DeidentificationClient
105+
from azure.health.deidentification.models import (
106+
DeidentificationContent,
107+
DeidentificationOperationType,
108+
DeidentificationResult,
109+
)
110+
from azure.identity import DefaultAzureCredential
111+
112+
113+
def deidentify_text_redact():
114+
endpoint = AZURE_HEALTH_DEIDENTIFICATION_ENDPOINT
115+
credential = DefaultAzureCredential()
116+
client = DeidentificationClient(endpoint, credential)
117+
118+
# [START redact]
119+
body = DeidentificationContent(
120+
input_text="It's great to work at Contoso.", operation_type=DeidentificationOperationType.SURROGATE
121+
)
122+
result: DeidentificationResult = client.deidentify_text(body)
123+
print(f'\nOriginal Text: "{body.input_text}"')
124+
print(f'Redacted Text: "{result.output_text}"') # Redacted output: "It's great to work at [organization]."
125+
# [END redact]
126+
127+
128+
if __name__ == "__main__":
129+
deidentify_text_redact()
111130

112131
```
113132

114133
## Example input & output
115134

116135
| Input | Output |
117136
|----------------|---------|
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 |
137+
| Kimberly Brown is a 34 y.o. female presenting with bilateral eye discomfort. Last seen by her PCP 2/6/2025 Dr. Orlo at Overlake Clinics Downtown Bellevue PCP. | Britt Macdonough is a 34 y.o. female presenting with bilateral eye discomfort. Last seen by her PCP 1/18/2025 Dr. Defiore at Cardston Hospital PCP. |
119138

120139
## Clean up resources
121140

0 commit comments

Comments
 (0)