|
| 1 | +# Azure Cognitive Services Health Insights Radiology Insights client library for Python |
| 2 | +[Health Insights][health_insights] is an Azure Applied AI Service built with the Azure Cognitive Services Framework, that leverages multiple Cognitive Services, Healthcare API services and other Azure resources. |
| 3 | + |
| 4 | +[Radiology Insights][radiology_insights_docs] is a model that aims to provide quality checks as feedback on errors and inconsistencies (mismatches) and ensures critical findings are identified and communicated using the full context of the report. Follow-up recommendations and clinical findings with measurements (sizes) documented by the radiologist are also identified. |
| 5 | + |
| 6 | +## Getting started |
| 7 | + |
| 8 | +### Prequisites |
| 9 | + |
| 10 | +- Python 3.8 or later is required to use this package. |
| 11 | +- You need an [Azure subscription][azure_sub] to use this package. |
| 12 | +- An existing Cognitive Services Health Insights instance. |
| 13 | + |
| 14 | +For more information about creating the resource or how to get the location and sku information see [here][cognitive_resource_cli]. |
| 15 | + |
| 16 | +### Installing the module |
| 17 | + |
| 18 | +```bash |
| 19 | +python -m pip install azure-healthinsights-radiologyinsights |
| 20 | +``` |
| 21 | +This table shows the relationship between SDK versions and supported API versions of the service: |
| 22 | + |
| 23 | +| SDK version | Supported API version of service | |
| 24 | +|-------------|----------------------------------| |
| 25 | +| 1.0.0b1 | 2023-09-01-preview | |
| 26 | + |
| 27 | + |
| 28 | +### Authenticate the client |
| 29 | + |
| 30 | +#### Get the endpoint |
| 31 | + |
| 32 | +You can find the endpoint for your Health Insights service resource using the [Azure Portal][azure_portal] or [Azure CLI][azure_cli] |
| 33 | + |
| 34 | + |
| 35 | +```bash |
| 36 | +# Get the endpoint for the Health Insights service resource |
| 37 | +az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint" |
| 38 | +``` |
| 39 | + |
| 40 | +#### Get the API Key |
| 41 | + |
| 42 | +You can get the **API Key** from the Health Insights service resource in the Azure Portal. |
| 43 | +Alternatively, you can use **Azure CLI** snippet below to get the API key of your resource. |
| 44 | + |
| 45 | +```PowerShell |
| 46 | +az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name> |
| 47 | +``` |
| 48 | + |
| 49 | +#### Create a RadiologyInsightsClient with an API Key Credential |
| 50 | + |
| 51 | +Once you have the value for the API key, you can pass it as a string into an instance of **AzureKeyCredential**. Use the key as the credential parameter to authenticate the client: |
| 52 | + |
| 53 | +<!-- SNIPPET:sample_critical_result_inference_async.create_radiology_insights_client--> |
| 54 | +```python |
| 55 | +import os |
| 56 | +from azure.core.credentials import AzureKeyCredential |
| 57 | +from azure.healthinsights.radiologyinsights import RadiologyInsightsClient |
| 58 | + |
| 59 | +KEY = os.environ["AZURE_HEALTH_INSIGHTS_API_KEY"] |
| 60 | +ENDPOINT = os.environ["AZURE_HEALTH_INSIGHTS_ENDPOINT"] |
| 61 | + |
| 62 | +radiology_insights_client = RadiologyInsightsClient(endpoint=ENDPOINT, credential=AzureKeyCredential(KEY)) |
| 63 | +``` |
| 64 | +<!-- SNIPPET:sample_critical_result_inference_async.create_radiology_insights_client--> |
| 65 | + |
| 66 | +### Long-Running Operations |
| 67 | + |
| 68 | +Long-running operations are operations which consist of an initial request sent to the service to start an operation, |
| 69 | +followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has |
| 70 | +succeeded, to get the result. |
| 71 | + |
| 72 | +Methods that support healthcare analysis, custom text analysis, or multiple analyses are modeled as long-running operations. |
| 73 | +The client exposes a `begin_<method-name>` method that returns a poller object. Callers should wait |
| 74 | +for the operation to complete by calling `result()` on the poller object returned from the `begin_<method-name>` method. |
| 75 | +Sample code snippets are provided to illustrate using long-running operations [below](#examples "Examples"). |
| 76 | + |
| 77 | +## Key concepts |
| 78 | + |
| 79 | +Radiology Insights currently supports one document from one patient. Please take a look [here][inferences] for more detailed information about the inferences this service produces. |
| 80 | + |
| 81 | +## Examples |
| 82 | + |
| 83 | +### Create a RadiologyInsights request and get the result using an asynchronous client |
| 84 | + |
| 85 | +For an example how to create a client, a request and get the result see the example in the sample folder. |
| 86 | + |
| 87 | +### Get Critical Result Inference information |
| 88 | + |
| 89 | +<!-- SNIPPET:sample_critical_result_inference_async.display_critical_results--> |
| 90 | +```python |
| 91 | +for patient_result in radiology_insights_result.patient_results: |
| 92 | + for ri_inference in patient_result.inferences: |
| 93 | + if ( |
| 94 | + ri_inference.kind |
| 95 | + == models.RadiologyInsightsInferenceType.CRITICAL_RESULT |
| 96 | + ): |
| 97 | + critical_result = ri_inference.result |
| 98 | + print( |
| 99 | + f"Critical Result Inference found: {critical_result.description}" |
| 100 | + ) |
| 101 | +``` |
| 102 | +<!-- SNIPPET:sample_critical_result_inference_async.display_critical_results--> |
| 103 | + |
| 104 | +For detailed conceptual information of this and other inferences please read more [here][inferences]. |
| 105 | + |
| 106 | +## Troubleshooting |
| 107 | + |
| 108 | +### General |
| 109 | + |
| 110 | +Health Insights Radiology Insights client library will raise exceptions defined in [Azure Core][azure_core]. |
| 111 | + |
| 112 | +### Logging |
| 113 | + |
| 114 | +This library uses the standard [logging](https://docs.python.org/3/library/logging.html) library for logging. |
| 115 | + |
| 116 | +Basic information about HTTP sessions (URLs, headers, etc.) is logged at `INFO` level. |
| 117 | + |
| 118 | +Detailed `DEBUG` level logging, including request/response bodies and **unredacted** |
| 119 | +headers, can be enabled on the client or per-operation with the `logging_enable` keyword argument. |
| 120 | + |
| 121 | +See full SDK logging documentation with examples [here](https://learn.microsoft.com/azure/developer/python/sdk/azure-sdk-logging). |
| 122 | + |
| 123 | +## Next steps |
| 124 | + |
| 125 | +## Contributing |
| 126 | + |
| 127 | +This project welcomes contributions and suggestions. Most contributions require |
| 128 | +you to agree to a Contributor License Agreement (CLA) declaring that you have |
| 129 | +the right to, and actually do, grant us the rights to use your contribution. |
| 130 | +For details, visit https://cla.microsoft.com. |
| 131 | + |
| 132 | +When you submit a pull request, a CLA-bot will automatically determine whether |
| 133 | +you need to provide a CLA and decorate the PR appropriately (e.g., label, |
| 134 | +comment). Simply follow the instructions provided by the bot. You will only |
| 135 | +need to do this once across all repos using our CLA. |
| 136 | + |
| 137 | +This project has adopted the |
| 138 | +[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information, |
| 139 | +see the Code of Conduct FAQ or contact <[email protected]> with any |
| 140 | +additional questions or comments. |
| 141 | + |
| 142 | +<!-- LINKS --> |
| 143 | +[health_insights]: https://learn.microsoft.com/azure/azure-health-insights/overview |
| 144 | +[radiology_insights_docs]: https://learn.microsoft.com/azure/azure-health-insights/radiology-insights/ |
| 145 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 146 | +[cognitive_resource_cli]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli |
| 147 | +[azure_portal]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesHealthInsights |
| 148 | +[azure_cli]: https://learn.microsoft.com/cli/azure/ |
| 149 | +[inferences]: https://learn.microsoft.com/azure/azure-health-insights/radiology-insights/inferences |
| 150 | +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ |
0 commit comments