Skip to content

Commit 756a893

Browse files
[textanalytics] support for healthcare action + FHIR (Azure#24298)
* add impl for healthcare action + fhir and tests * update changelog * updates for validate + tests
1 parent cb41ede commit 756a893

15 files changed

+6077
-23
lines changed

sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
## 5.2.0b4 (Unreleased)
44

5+
This version of the client library defaults to the latest supported API version, which currently is `2022-04-01-preview`.
6+
57
### Features Added
68

9+
- Added support for Healthcare Entities Analysis through the `begin_analyze_actions` API with the `AnalyzeHealthcareEntitiesAction` type.
10+
- Added keyword argument `fhir_version` to `begin_analyze_healthcare_entities` and `AnalyzeHealthcareEntitiesAction`. Use the keyword to indicate the version for the `fhir_bundle` contained on the `AnalyzeHealthcareEntitiesResult`.
11+
- Added property `fhir_bundle` to `AnalyzeHealthcareEntitiesResult`.
12+
- Added keyword argument `display_name` to `begin_analyze_healthcare_entities`.
13+
714
### Breaking Changes
815

916
### Bugs Fixed

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
MultiCategoryClassifyAction,
6060
MultiCategoryClassifyResult,
6161
ClassificationCategory,
62+
AnalyzeHealthcareEntitiesAction,
6263
)
6364

6465
from ._lro import AnalyzeHealthcareEntitiesLROPoller, AnalyzeActionsLROPoller
@@ -120,6 +121,7 @@
120121
"MultiCategoryClassifyAction",
121122
"MultiCategoryClassifyResult",
122123
"ClassificationCategory",
124+
"AnalyzeHealthcareEntitiesAction",
123125
]
124126

125127
__version__ = VERSION

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_models.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,15 @@ class AnalyzeHealthcareEntitiesResult(DictMixin):
491491
field will contain information about the document payload.
492492
:vartype statistics:
493493
~azure.ai.textanalytics.TextDocumentStatistics
494+
:ivar fhir_bundle: If `fhir_version` is passed, this will contain a
495+
FHIR compatible object for consumption in other Healthcare tools. For additional
496+
information see https://www.hl7.org/fhir/overview.html.
497+
:vartype fhir_bundle: dict[str, any]
494498
:ivar bool is_error: Boolean check for error item when iterating over list of
495499
results. Always False for an instance of a AnalyzeHealthcareEntitiesResult.
500+
501+
.. versionadded:: 2022-04-01-preview
502+
The *fhir_bundle* property.
496503
"""
497504

498505
def __init__(self, **kwargs):
@@ -501,6 +508,7 @@ def __init__(self, **kwargs):
501508
self.entity_relations = kwargs.get("entity_relations", None)
502509
self.warnings = kwargs.get("warnings", [])
503510
self.statistics = kwargs.get("statistics", None)
511+
self.fhir_bundle = kwargs.get("fhir_bundle", None)
504512
self.is_error = False
505513

506514
@classmethod
@@ -516,6 +524,8 @@ def _from_generated(cls, healthcare_result):
516524
for r in healthcare_result.relations
517525
]
518526

527+
fhir_bundle = healthcare_result.fhir_bundle if hasattr(healthcare_result, "fhir_bundle") else None
528+
519529
return cls(
520530
id=healthcare_result.id,
521531
entities=entities,
@@ -529,17 +539,19 @@ def _from_generated(cls, healthcare_result):
529539
statistics=TextDocumentStatistics._from_generated( # pylint: disable=protected-access
530540
healthcare_result.statistics
531541
),
542+
fhir_bundle=fhir_bundle,
532543
)
533544

534545
def __repr__(self):
535546
return (
536547
"AnalyzeHealthcareEntitiesResult(id={}, entities={}, entity_relations={}, warnings={}, "
537-
"statistics={}, is_error={})".format(
548+
"statistics={}, fhir_bundle={}, is_error={})".format(
538549
self.id,
539550
repr(self.entities),
540551
repr(self.entity_relations),
541552
repr(self.warnings),
542553
repr(self.statistics),
554+
self.fhir_bundle,
543555
self.is_error,
544556
)[:1024]
545557
)
@@ -2683,3 +2695,74 @@ def _from_generated(cls, result):
26832695
category=result.category,
26842696
confidence_score=result.confidence_score
26852697
)
2698+
2699+
2700+
class AnalyzeHealthcareEntitiesAction(DictMixin):
2701+
"""AnalyzeHealthcareEntitiesAction encapsulates the parameters for starting a long-running
2702+
healthcare entities analysis operation.
2703+
2704+
If you just want to analyze healthcare entities in a list of documents, and not perform multiple
2705+
long running actions on the input of documents, call method `begin_analyze_healthcare_entities` instead
2706+
of interfacing with this model.
2707+
2708+
:keyword str model_version: The model version to use for the analysis.
2709+
:keyword str string_index_type: Specifies the method used to interpret string offsets.
2710+
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
2711+
you can also pass in `Utf16CodeUnit` or TextElement_v8`. For additional information
2712+
see https://aka.ms/text-analytics-offsets
2713+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
2714+
logged on the service side for troubleshooting. By default, Text Analytics logs your
2715+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
2716+
the Text Analytics natural language processing functions. Setting this parameter to true,
2717+
disables input logging and may limit our ability to remediate issues that occur. Please see
2718+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
2719+
additional details, and Microsoft Responsible AI principles at
2720+
https://www.microsoft.com/ai/responsible-ai.
2721+
:keyword str fhir_version: The FHIR Spec version that the result will use to format the fhir_bundle
2722+
on the result object. For additional information see https://www.hl7.org/fhir/overview.html.
2723+
The only acceptable values to pass in are None and "4.0.1". The default value is None.
2724+
:ivar str model_version: The model version to use for the analysis.
2725+
:ivar str string_index_type: Specifies the method used to interpret string offsets.
2726+
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
2727+
you can also pass in `Utf16CodeUnit` or TextElement_v8`. For additional information
2728+
see https://aka.ms/text-analytics-offsets
2729+
:ivar bool disable_service_logs: If set to true, you opt-out of having your text input
2730+
logged on the service side for troubleshooting. By default, Text Analytics logs your
2731+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
2732+
the Text Analytics natural language processing functions. Setting this parameter to true,
2733+
disables input logging and may limit our ability to remediate issues that occur. Please see
2734+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
2735+
additional details, and Microsoft Responsible AI principles at
2736+
https://www.microsoft.com/ai/responsible-ai.
2737+
:ivar str fhir_version: The FHIR Spec version that the result will use to format the fhir_bundle
2738+
on the result object. For additional information see https://www.hl7.org/fhir/overview.html.
2739+
The only acceptable values to pass in are None and "4.0.1". The default value is None.
2740+
"""
2741+
2742+
def __init__(self, **kwargs):
2743+
self.model_version = kwargs.get("model_version", None)
2744+
self.string_index_type = kwargs.get("string_index_type", "UnicodeCodePoint")
2745+
self.disable_service_logs = kwargs.get("disable_service_logs", None)
2746+
self.fhir_version = kwargs.get("fhir_version", None)
2747+
2748+
def __repr__(self):
2749+
return (
2750+
"AnalyzeHealthcareEntitiesAction(model_version={}, string_index_type={}, disable_service_logs={}, "
2751+
"fhir_version={})".format(
2752+
self.model_version,
2753+
self.string_index_type,
2754+
self.disable_service_logs,
2755+
self.fhir_version
2756+
)[:1024]
2757+
)
2758+
2759+
def _to_generated(self, api_version, task_id): # pylint: disable=unused-argument
2760+
return _v2022_04_01_preview_models.HealthcareLROTask(
2761+
task_name=task_id,
2762+
parameters=_v2022_04_01_preview_models.HealthcareTaskParameters(
2763+
model_version=self.model_version,
2764+
string_index_type=string_index_type_compatibility(self.string_index_type),
2765+
logging_opt_out=self.disable_service_logs,
2766+
fhir_version=self.fhir_version
2767+
)
2768+
)

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_request_handlers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ def _determine_action_type(action): # pylint: disable=too-many-return-statement
9797
return _AnalyzeActionsType.SINGLE_CATEGORY_CLASSIFY
9898
if action.__class__.__name__ == "CustomMultiLabelClassificationLROTask":
9999
return _AnalyzeActionsType.MULTI_CATEGORY_CLASSIFY
100+
if action.__class__.__name__ == "HealthcareLROTask":
101+
return _AnalyzeActionsType.ANALYZE_HEALTHCARE_ENTITIES
100102
return _AnalyzeActionsType.EXTRACT_KEY_PHRASES

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
SingleCategoryClassifyResult,
6666
MultiCategoryClassifyAction,
6767
MultiCategoryClassifyResult,
68+
AnalyzeHealthcareEntitiesAction,
6869
_AnalyzeActionsType,
6970
)
7071
from ._check import is_language_api, string_index_type_compatibility
@@ -577,7 +578,7 @@ def _healthcare_result_callback(
577578
@distributed_trace
578579
@validate_multiapi_args(
579580
version_method_added="v3.1",
580-
args_mapping={"2022-04-01-preview": ["display_name"]}
581+
args_mapping={"2022-04-01-preview": ["display_name", "fhir_version"]}
581582
)
582583
def begin_analyze_healthcare_entities(
583584
self,
@@ -610,6 +611,9 @@ def begin_analyze_healthcare_entities(
610611
take precedence over whole batch language. See https://aka.ms/talangs for
611612
supported languages in Text Analytics API.
612613
:keyword str display_name: An optional display name to set for the requested analysis.
614+
:keyword str fhir_version: The FHIR Spec version that the result will use to format the fhir_bundle
615+
on the result object. For additional information see https://www.hl7.org/fhir/overview.html.
616+
The only acceptable values to pass in are None and "4.0.1". The default value is None.
613617
:keyword str string_index_type: Specifies the method used to interpret string offsets.
614618
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
615619
you can also pass in `Utf16CodeUnit` or `TextElement_v8`. For additional information
@@ -639,7 +643,7 @@ def begin_analyze_healthcare_entities(
639643
.. versionadded:: v3.1
640644
The *begin_analyze_healthcare_entities* client method.
641645
.. versionadded:: 2022-04-01-preview
642-
The *display_name* keyword argument.
646+
The *display_name* and *fhir_version* keyword arguments.
643647
644648
.. admonition:: Example:
645649
@@ -659,6 +663,7 @@ def begin_analyze_healthcare_entities(
659663
string_index_type = kwargs.pop("string_index_type", self._string_index_type_default)
660664
disable_service_logs = kwargs.pop("disable_service_logs", None)
661665
display_name = kwargs.pop("display_name", None)
666+
fhir_version = kwargs.pop("fhir_version", None)
662667

663668
if continuation_token:
664669
def get_result_from_cont_token(initial_response, pipeline_response):
@@ -704,7 +709,8 @@ def get_result_from_cont_token(initial_response, pipeline_response):
704709
parameters=models.HealthcareTaskParameters(
705710
model_version=model_version,
706711
logging_opt_out=disable_service_logs,
707-
string_index_type=string_index_type_compatibility(string_index_type)
712+
string_index_type=string_index_type_compatibility(string_index_type),
713+
fhir_version=fhir_version,
708714
)
709715
)
710716
]
@@ -1000,6 +1006,7 @@ def begin_analyze_actions(
10001006
RecognizeCustomEntitiesAction,
10011007
SingleCategoryClassifyAction,
10021008
MultiCategoryClassifyAction,
1009+
AnalyzeHealthcareEntitiesAction,
10031010
]
10041011
],
10051012
**kwargs: Any,
@@ -1016,6 +1023,7 @@ def begin_analyze_actions(
10161023
RecognizeCustomEntitiesResult,
10171024
SingleCategoryClassifyResult,
10181025
MultiCategoryClassifyResult,
1026+
AnalyzeHealthcareEntitiesResult,
10191027
DocumentError,
10201028
]
10211029
]
@@ -1043,7 +1051,8 @@ def begin_analyze_actions(
10431051
:type actions:
10441052
list[RecognizeEntitiesAction or RecognizePiiEntitiesAction or ExtractKeyPhrasesAction or
10451053
RecognizeLinkedEntitiesAction or AnalyzeSentimentAction or ExtractSummaryAction or
1046-
RecognizeCustomEntitiesAction or SingleCategoryClassifyAction or MultiCategoryClassifyAction]
1054+
RecognizeCustomEntitiesAction or SingleCategoryClassifyAction or
1055+
MultiCategoryClassifyAction or AnalyzeHealthcareEntitiesAction]
10471056
:keyword str display_name: An optional display name to set for the requested analysis.
10481057
:keyword str language: The 2 letter ISO 639-1 representation of language for the
10491058
entire batch. For example, use "en" for English; "es" for Spanish etc.
@@ -1072,16 +1081,17 @@ def begin_analyze_actions(
10721081
~azure.ai.textanalytics.AnalyzeActionsLROPoller[~azure.core.paging.ItemPaged[
10731082
list[RecognizeEntitiesResult or RecognizeLinkedEntitiesResult or RecognizePiiEntitiesResult or
10741083
ExtractKeyPhrasesResult or AnalyzeSentimentResult or ExtractSummaryAction or RecognizeCustomEntitiesResult
1075-
or SingleCategoryClassifyResult or MultiCategoryClassifyResult or DocumentError]]]
1084+
or SingleCategoryClassifyResult or MultiCategoryClassifyResult or AnalyzeHealthcareEntitiesResult or
1085+
DocumentError]]]
10761086
:raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError or NotImplementedError:
10771087
10781088
.. versionadded:: v3.1
10791089
The *begin_analyze_actions* client method.
10801090
.. versionadded:: 2022-04-01-preview
10811091
The *ExtractSummaryAction*, *RecognizeCustomEntitiesAction*, *SingleCategoryClassifyAction*,
1082-
and *MultiCategoryClassifyAction* input options and the corresponding *ExtractSummaryResult*,
1083-
*RecognizeCustomEntitiesResult*, *SingleCategoryClassifyResult*, and *MultiCategoryClassifyResult*
1084-
result objects
1092+
*MultiCategoryClassifyAction*, and *AnalyzeHealthcareEntitiesAction* input options and the
1093+
corresponding *ExtractSummaryResult*, *RecognizeCustomEntitiesResult*, *SingleCategoryClassifyResult*,
1094+
*MultiCategoryClassifyResult*, and *AnalyzeHealthcareEntitiesResult* result objects
10851095
10861096
.. admonition:: Example:
10871097

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def check_for_unsupported_actions_types(*args, **kwargs):
2727
"ExtractSummaryAction",
2828
"RecognizeCustomEntitiesAction",
2929
"SingleCategoryClassifyAction",
30-
"MultiCategoryClassifyAction"
30+
"MultiCategoryClassifyAction",
31+
"AnalyzeHealthcareEntitiesAction"
3132
]
3233
}
3334

0 commit comments

Comments
 (0)