Skip to content

Commit

Permalink
Merge pull request #1 from koen-mertens/radiology-insights-GA-cb3
Browse files Browse the repository at this point in the history
Radiology insights ga cb3
  • Loading branch information
koen-mertens authored Apr 19, 2024
2 parents 3c98a95 + 8bee798 commit 38a9659
Show file tree
Hide file tree
Showing 35 changed files with 15,169 additions and 3,246 deletions.
150 changes: 138 additions & 12 deletions sdk/healthinsights/azure-healthinsights-radiologyinsights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### Prequisites

- Python 3.8 or later is required to use this package.
- [Python 3.8+][python] is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing Cognitive Services Health Insights instance.

Expand Down Expand Up @@ -51,7 +51,7 @@ az cognitiveservices account keys list --resource-group <your-resource-group-nam
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:

<!-- SNIPPET:sample_critical_result_inference_async.create_radiology_insights_client-->
```python
```Python
import os
from azure.core.credentials import AzureKeyCredential
from azure.healthinsights.radiologyinsights import RadiologyInsightsClient
Expand All @@ -76,31 +76,154 @@ Sample code snippets are provided to illustrate using long-running operations [b

## Key concepts

Once you've initialized a 'RadiologyInsightsClient', you can use it to analyse document text by displaying inferences found within the text.
* Age Mismatch
* Laterality Discrepancy
* Sex Mismatch
* Complete Order Discrepancy
* Limited Order Discrepancy
* Finding
* Critical Result
* Follow-up Recommendation
* Communication
* Radiology Procedure
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.

## Examples

### Create a RadiologyInsights request and get the result using an asynchronous client

For each inference samples are available that show how to retrieve the information either in a synchronous (block until operation is complete, slower) or in an asynchronous way (non-blocking, faster).
For an example how to create a client, a request and get the result see the example in the [sample folder][sample_folder].

* [Age Mismatch](#get-age-mismatch-inference-information)
* [Complete Order Discrepancy](#get-complete-order-discrepancy-inference-information)
* [Critical Result](#get-critical-result-inference-information)
* [Finding](#get-finding-information)
* [Follow-up Communication](#get-follow-up-communication-information)
* [Follow-up Recommendation](#get-follow-up-recommendation-information)
* [Laterality Descripancy](#get-laterality-discrepancy-information)
* [Limited Order Descripancy](#get-limited-order-discrepancy-information)
* [Radiology Procedure](#get-radiology-procedure-information)
* [Sex Mismatch](#get-sex-mismatch-information)

### Running the samples

1. Open a terminal window and `cd` to the directory that the samples are saved in.
2. Set the environment variables specified in the sample file you wish to run.

### Get Age Mismatch Inference information

<!-- SNIPPET:sample_age_mismatch_inference_async.display_age_mismatch-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.AGE_MISMATCH:
print(f"Age Mismatch Inference found")
```
<!-- SNIPPET:sample_age_mismatch_inference_async.display_age_mismatch-->

### Get Complete Order Discrepancy Inference information

<!-- SNIPPET:sample_complete_order_discrespancy_inference_async.display_complete_order_discrepancy-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.COMPLETE_ORDER_DISCREPANCY:
print(f"Complete Order Discrepancy Inference found")
```
<!-- SNIPPET:sample_complete_order_discrespancy_inference_async.display_complete_order_discrepancy-->

### Get Critical Result Inference information

<!-- SNIPPET:sample_critical_result_inference_async.display_critical_results-->
```python
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if (
ri_inference.kind
== models.RadiologyInsightsInferenceType.CRITICAL_RESULT
):
if ri_inference.kind == models.RadiologyInsightsInferenceType.CRITICAL_RESULT:
critical_result = ri_inference.result
print(
f"Critical Result Inference found: {critical_result.description}"
)
print(
f"Critical Result Inference found: {critical_result.description}")
```
<!-- SNIPPET:sample_critical_result_inference_async.display_critical_results-->

### Get Finding Inference information

<!-- SNIPPET:sample_finding_inference_async.display_finding-->
```Python
for patient_result in radiology_insights_result.patient_results:
counter = 0
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FINDING:
counter += 1
print(f"Finding Inference found")
```
<!-- SNIPPET:sample_finding_inference_async.display_finding-->

### Get Follow-up Communication information

<!-- SNIPPET:sample_followup_communication_inference_async.display_followup_communication-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FOLLOWUP_COMMUNICATION:
print(f"Follow-up Communication Inference found")
```
<!-- SNIPPET:sample_followup_communication_inference_async.display_followup_communication-->

### Get Follow-up Recommendation information

<!-- SNIPPET:sample_followup_recommendation_inference_async.display_followup_recommendation-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FOLLOWUP_RECOMMENDATION:
print(f"Follow-up Recommendation Inference found")
```
<!-- SNIPPET:sample_followup_recommendation_inference_async.display_followup_recommendation-->

### Get Laterality Discrepancy information

<!-- SNIPPET:sample_laterality_discrepancy_inference_async.display_laterality_discrepancy-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.LATERALITY_DISCREPANCY:
print(f"Laterality Discrepancy Inference found")
```
<!-- SNIPPET:sample_laterality_discrepancy_inference_async.display_laterality_discrepancy-->

### Get Limited Order Discrepancy information

<!-- SNIPPET:sample_limited_order_discrepancy_inference_async.display_limited_order_discrepancy-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.LIMITED_ORDER_DISCREPANCY:
print(f"Limited Order Discrepancy Inference found")
```
<!-- SNIPPET:sample_limited_order_discrepancy_inference_async.display_limited_order_discrepancy-->

### Get Radiology Procedure information

<!-- SNIPPET:sample_radiology_procedure_inference_async.display_radiology_procedure-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.RADIOLOGY_PROCEDURE:
print(f"Radiology Procedure Inference found")
```
<!-- SNIPPET:sample_radiology_procedure_inference_async.display_radiology_procedure-->

### Get Sex Mismatch information

<!-- SNIPPET:sample_sex_mismatch_inference_async.display_sex_mismatch-->
```Python
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.SEX_MISMATCH:
print(f"Sex Mismatch Inference found")
```
<!-- SNIPPET:sample_sex_mismatch_inference_async.display_sex_mismatch-->

For detailed conceptual information of this and other inferences please read more [here][inferences].

## Troubleshooting
Expand Down Expand Up @@ -140,6 +263,8 @@ see the Code of Conduct FAQ or contact <opencode@microsoft.com> with any
additional questions or comments.

<!-- LINKS -->
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_portal]: https://portal.azure.com
[health_insights]: https://learn.microsoft.com/azure/azure-health-insights/overview
[radiology_insights_docs]: https://learn.microsoft.com/azure/azure-health-insights/radiology-insights/
[azure_sub]: https://azure.microsoft.com/free/
Expand All @@ -148,4 +273,5 @@ additional questions or comments.
[azure_cli]: https://learn.microsoft.com/cli/azure/
[inferences]: https://learn.microsoft.com/azure/azure-health-insights/radiology-insights/inferences
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[python]: https://www.python.org/downloads/
[sample_folder]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/healthinsights/azure-healthinsights-radiologyinsights/samples
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class RadiologyInsightsClient(
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
https://westus2.api.cognitive.microsoft.com). Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
"2023-09-01-preview". Note that overriding this default value may result in unsupported
behavior.
:keyword api_version: The API version to use for this operation. Default value is "2024-04-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ class RadiologyInsightsClientConfiguration: # pylint: disable=too-many-instance
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
https://westus2.api.cognitive.microsoft.com). Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
"2023-09-01-preview". Note that overriding this default value may result in unsupported
behavior.
:keyword api_version: The API version to use for this operation. Default value is "2024-04-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
api_version: str = kwargs.pop("api_version", "2023-09-01-preview")
api_version: str = kwargs.pop("api_version", "2024-04-01")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down
Loading

0 comments on commit 38a9659

Please sign in to comment.