phenoml 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of phenoml might be problematic. Click here for more details.
- phenoml/__init__.py +30 -0
- phenoml/agent/__init__.py +58 -0
- phenoml/agent/client.py +820 -0
- phenoml/agent/errors/__init__.py +11 -0
- phenoml/agent/errors/bad_request_error.py +10 -0
- phenoml/agent/errors/forbidden_error.py +10 -0
- phenoml/agent/errors/internal_server_error.py +10 -0
- phenoml/agent/errors/not_found_error.py +10 -0
- phenoml/agent/errors/unauthorized_error.py +10 -0
- phenoml/agent/prompts/__init__.py +7 -0
- phenoml/agent/prompts/client.py +707 -0
- phenoml/agent/prompts/raw_client.py +1345 -0
- phenoml/agent/prompts/types/__init__.py +8 -0
- phenoml/agent/prompts/types/prompts_delete_response.py +20 -0
- phenoml/agent/prompts/types/prompts_list_response.py +22 -0
- phenoml/agent/raw_client.py +1501 -0
- phenoml/agent/types/__init__.py +45 -0
- phenoml/agent/types/agent_chat_response.py +33 -0
- phenoml/agent/types/agent_create_request_provider.py +13 -0
- phenoml/agent/types/agent_create_request_provider_item.py +7 -0
- phenoml/agent/types/agent_delete_response.py +20 -0
- phenoml/agent/types/agent_fhir_config.py +31 -0
- phenoml/agent/types/agent_list_response.py +22 -0
- phenoml/agent/types/agent_prompts_response.py +22 -0
- phenoml/agent/types/agent_response.py +22 -0
- phenoml/agent/types/agent_template.py +56 -0
- phenoml/agent/types/agent_template_provider.py +13 -0
- phenoml/agent/types/agent_template_provider_item.py +5 -0
- phenoml/agent/types/agent_update_request_provider.py +13 -0
- phenoml/agent/types/agent_update_request_provider_item.py +7 -0
- phenoml/agent/types/chat_fhir_client_config.py +31 -0
- phenoml/agent/types/json_patch.py +7 -0
- phenoml/agent/types/json_patch_operation.py +36 -0
- phenoml/agent/types/json_patch_operation_op.py +5 -0
- phenoml/agent/types/prompt_template.py +52 -0
- phenoml/agent/types/success_response.py +20 -0
- phenoml/authtoken/__init__.py +17 -0
- phenoml/authtoken/auth/__init__.py +7 -0
- phenoml/authtoken/auth/client.py +129 -0
- phenoml/authtoken/auth/raw_client.py +173 -0
- phenoml/authtoken/auth/types/__init__.py +7 -0
- phenoml/authtoken/auth/types/auth_generate_token_response.py +22 -0
- phenoml/authtoken/client.py +39 -0
- phenoml/authtoken/errors/__init__.py +8 -0
- phenoml/authtoken/errors/bad_request_error.py +10 -0
- phenoml/authtoken/errors/unauthorized_error.py +10 -0
- phenoml/authtoken/raw_client.py +13 -0
- phenoml/authtoken/types/__init__.py +8 -0
- phenoml/authtoken/types/bad_request_error_body.py +21 -0
- phenoml/authtoken/types/unauthorized_error_body.py +21 -0
- phenoml/client.py +168 -0
- phenoml/cohort/__init__.py +8 -0
- phenoml/cohort/client.py +113 -0
- phenoml/cohort/errors/__init__.py +9 -0
- phenoml/cohort/errors/bad_request_error.py +10 -0
- phenoml/cohort/errors/internal_server_error.py +10 -0
- phenoml/cohort/errors/unauthorized_error.py +10 -0
- phenoml/cohort/raw_client.py +185 -0
- phenoml/cohort/types/__init__.py +8 -0
- phenoml/cohort/types/cohort_response.py +33 -0
- phenoml/cohort/types/search_concept.py +37 -0
- phenoml/construe/__init__.py +45 -0
- phenoml/construe/client.py +399 -0
- phenoml/construe/errors/__init__.py +11 -0
- phenoml/construe/errors/bad_request_error.py +10 -0
- phenoml/construe/errors/conflict_error.py +10 -0
- phenoml/construe/errors/failed_dependency_error.py +10 -0
- phenoml/construe/errors/internal_server_error.py +10 -0
- phenoml/construe/errors/unauthorized_error.py +10 -0
- phenoml/construe/raw_client.py +706 -0
- phenoml/construe/types/__init__.py +41 -0
- phenoml/construe/types/bad_request_error_body.py +27 -0
- phenoml/construe/types/construe_cohort_request_config.py +37 -0
- phenoml/construe/types/construe_cohort_response.py +33 -0
- phenoml/construe/types/construe_cohort_response_queries_item.py +49 -0
- phenoml/construe/types/construe_cohort_response_queries_item_code_extract_results_item.py +31 -0
- phenoml/construe/types/construe_cohort_response_queries_item_code_extract_results_item_codes_item.py +32 -0
- phenoml/construe/types/construe_upload_code_system_response.py +19 -0
- phenoml/construe/types/extract_codes_result.py +22 -0
- phenoml/construe/types/extract_request_config.py +23 -0
- phenoml/construe/types/extract_request_config_chunking_method.py +5 -0
- phenoml/construe/types/extract_request_system.py +37 -0
- phenoml/construe/types/extracted_code_result.py +41 -0
- phenoml/construe/types/internal_server_error_body.py +27 -0
- phenoml/construe/types/unauthorized_error_body.py +27 -0
- phenoml/construe/types/upload_request_format.py +5 -0
- phenoml/core/__init__.py +52 -0
- phenoml/core/api_error.py +23 -0
- phenoml/core/client_wrapper.py +85 -0
- phenoml/core/datetime_utils.py +28 -0
- phenoml/core/file.py +67 -0
- phenoml/core/force_multipart.py +16 -0
- phenoml/core/http_client.py +543 -0
- phenoml/core/http_response.py +55 -0
- phenoml/core/jsonable_encoder.py +100 -0
- phenoml/core/pydantic_utilities.py +255 -0
- phenoml/core/query_encoder.py +58 -0
- phenoml/core/remove_none_from_dict.py +11 -0
- phenoml/core/request_options.py +35 -0
- phenoml/core/serialization.py +276 -0
- phenoml/environment.py +7 -0
- phenoml/lang2fhir/__init__.py +27 -0
- phenoml/lang2fhir/client.py +430 -0
- phenoml/lang2fhir/errors/__init__.py +11 -0
- phenoml/lang2fhir/errors/bad_request_error.py +10 -0
- phenoml/lang2fhir/errors/failed_dependency_error.py +10 -0
- phenoml/lang2fhir/errors/forbidden_error.py +10 -0
- phenoml/lang2fhir/errors/internal_server_error.py +10 -0
- phenoml/lang2fhir/errors/unauthorized_error.py +10 -0
- phenoml/lang2fhir/raw_client.py +788 -0
- phenoml/lang2fhir/types/__init__.py +19 -0
- phenoml/lang2fhir/types/create_request_resource.py +25 -0
- phenoml/lang2fhir/types/document_request_file_type.py +7 -0
- phenoml/lang2fhir/types/document_request_resource.py +5 -0
- phenoml/lang2fhir/types/fhir_resource.py +5 -0
- phenoml/lang2fhir/types/lang2fhir_upload_profile_response.py +23 -0
- phenoml/lang2fhir/types/search_response.py +33 -0
- phenoml/py.typed +0 -0
- phenoml/tools/__init__.py +33 -0
- phenoml/tools/client.py +392 -0
- phenoml/tools/errors/__init__.py +11 -0
- phenoml/tools/errors/bad_request_error.py +10 -0
- phenoml/tools/errors/failed_dependency_error.py +10 -0
- phenoml/tools/errors/forbidden_error.py +10 -0
- phenoml/tools/errors/internal_server_error.py +10 -0
- phenoml/tools/errors/unauthorized_error.py +10 -0
- phenoml/tools/raw_client.py +745 -0
- phenoml/tools/types/__init__.py +25 -0
- phenoml/tools/types/cohort_request_provider.py +5 -0
- phenoml/tools/types/cohort_response.py +49 -0
- phenoml/tools/types/fhir_client_config.py +31 -0
- phenoml/tools/types/lang2fhir_and_create_request_provider.py +7 -0
- phenoml/tools/types/lang2fhir_and_create_request_resource.py +25 -0
- phenoml/tools/types/lang2fhir_and_create_response.py +33 -0
- phenoml/tools/types/lang2fhir_and_search_request_provider.py +7 -0
- phenoml/tools/types/lang2fhir_and_search_response.py +40 -0
- phenoml/tools/types/search_concept.py +41 -0
- phenoml/version.py +3 -0
- phenoml/wrapper_client.py +123 -0
- phenoml-0.0.1.dist-info/LICENSE +21 -0
- phenoml-0.0.1.dist-info/METADATA +192 -0
- phenoml-0.0.1.dist-info/RECORD +143 -0
- phenoml-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from json.decoder import JSONDecodeError
|
|
5
|
+
|
|
6
|
+
from ..core.api_error import ApiError
|
|
7
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
8
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
9
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
10
|
+
from ..core.request_options import RequestOptions
|
|
11
|
+
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
12
|
+
from .errors.bad_request_error import BadRequestError
|
|
13
|
+
from .errors.failed_dependency_error import FailedDependencyError
|
|
14
|
+
from .errors.forbidden_error import ForbiddenError
|
|
15
|
+
from .errors.internal_server_error import InternalServerError
|
|
16
|
+
from .errors.unauthorized_error import UnauthorizedError
|
|
17
|
+
from .types.cohort_request_provider import CohortRequestProvider
|
|
18
|
+
from .types.cohort_response import CohortResponse
|
|
19
|
+
from .types.fhir_client_config import FhirClientConfig
|
|
20
|
+
from .types.lang2fhir_and_create_request_provider import Lang2FhirAndCreateRequestProvider
|
|
21
|
+
from .types.lang2fhir_and_create_request_resource import Lang2FhirAndCreateRequestResource
|
|
22
|
+
from .types.lang2fhir_and_create_response import Lang2FhirAndCreateResponse
|
|
23
|
+
from .types.lang2fhir_and_search_request_provider import Lang2FhirAndSearchRequestProvider
|
|
24
|
+
from .types.lang2fhir_and_search_response import Lang2FhirAndSearchResponse
|
|
25
|
+
|
|
26
|
+
# this is used as the default value for optional parameters
|
|
27
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class RawToolsClient:
|
|
31
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
32
|
+
self._client_wrapper = client_wrapper
|
|
33
|
+
|
|
34
|
+
def create_fhir_resource(
|
|
35
|
+
self,
|
|
36
|
+
*,
|
|
37
|
+
resource: Lang2FhirAndCreateRequestResource,
|
|
38
|
+
text: str,
|
|
39
|
+
provider: typing.Optional[Lang2FhirAndCreateRequestProvider] = OMIT,
|
|
40
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
41
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
42
|
+
) -> HttpResponse[Lang2FhirAndCreateResponse]:
|
|
43
|
+
"""
|
|
44
|
+
Converts natural language to FHIR resource and optionally stores it in a FHIR server
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
resource : Lang2FhirAndCreateRequestResource
|
|
49
|
+
Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile.
|
|
50
|
+
|
|
51
|
+
text : str
|
|
52
|
+
Natural language text to convert to FHIR resource
|
|
53
|
+
|
|
54
|
+
provider : typing.Optional[Lang2FhirAndCreateRequestProvider]
|
|
55
|
+
FHIR provider to use for storing the resource
|
|
56
|
+
|
|
57
|
+
meta : typing.Optional[FhirClientConfig]
|
|
58
|
+
|
|
59
|
+
request_options : typing.Optional[RequestOptions]
|
|
60
|
+
Request-specific configuration.
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
HttpResponse[Lang2FhirAndCreateResponse]
|
|
65
|
+
Successfully created FHIR resource
|
|
66
|
+
"""
|
|
67
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
68
|
+
"tools/lang2fhir-and-create",
|
|
69
|
+
method="POST",
|
|
70
|
+
json={
|
|
71
|
+
"resource": resource,
|
|
72
|
+
"text": text,
|
|
73
|
+
"provider": provider,
|
|
74
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
75
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
headers={
|
|
79
|
+
"content-type": "application/json",
|
|
80
|
+
},
|
|
81
|
+
request_options=request_options,
|
|
82
|
+
omit=OMIT,
|
|
83
|
+
)
|
|
84
|
+
try:
|
|
85
|
+
if 200 <= _response.status_code < 300:
|
|
86
|
+
_data = typing.cast(
|
|
87
|
+
Lang2FhirAndCreateResponse,
|
|
88
|
+
parse_obj_as(
|
|
89
|
+
type_=Lang2FhirAndCreateResponse, # type: ignore
|
|
90
|
+
object_=_response.json(),
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
return HttpResponse(response=_response, data=_data)
|
|
94
|
+
if _response.status_code == 400:
|
|
95
|
+
raise BadRequestError(
|
|
96
|
+
headers=dict(_response.headers),
|
|
97
|
+
body=typing.cast(
|
|
98
|
+
typing.Optional[typing.Any],
|
|
99
|
+
parse_obj_as(
|
|
100
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
101
|
+
object_=_response.json(),
|
|
102
|
+
),
|
|
103
|
+
),
|
|
104
|
+
)
|
|
105
|
+
if _response.status_code == 401:
|
|
106
|
+
raise UnauthorizedError(
|
|
107
|
+
headers=dict(_response.headers),
|
|
108
|
+
body=typing.cast(
|
|
109
|
+
typing.Optional[typing.Any],
|
|
110
|
+
parse_obj_as(
|
|
111
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
112
|
+
object_=_response.json(),
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
if _response.status_code == 403:
|
|
117
|
+
raise ForbiddenError(
|
|
118
|
+
headers=dict(_response.headers),
|
|
119
|
+
body=typing.cast(
|
|
120
|
+
typing.Optional[typing.Any],
|
|
121
|
+
parse_obj_as(
|
|
122
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
123
|
+
object_=_response.json(),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
if _response.status_code == 424:
|
|
128
|
+
raise FailedDependencyError(
|
|
129
|
+
headers=dict(_response.headers),
|
|
130
|
+
body=typing.cast(
|
|
131
|
+
typing.Optional[typing.Any],
|
|
132
|
+
parse_obj_as(
|
|
133
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
134
|
+
object_=_response.json(),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
if _response.status_code == 500:
|
|
139
|
+
raise InternalServerError(
|
|
140
|
+
headers=dict(_response.headers),
|
|
141
|
+
body=typing.cast(
|
|
142
|
+
typing.Optional[typing.Any],
|
|
143
|
+
parse_obj_as(
|
|
144
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
145
|
+
object_=_response.json(),
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
_response_json = _response.json()
|
|
150
|
+
except JSONDecodeError:
|
|
151
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
152
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
153
|
+
|
|
154
|
+
def search_fhir_resources(
|
|
155
|
+
self,
|
|
156
|
+
*,
|
|
157
|
+
text: str,
|
|
158
|
+
patient_id: typing.Optional[str] = OMIT,
|
|
159
|
+
practitioner_id: typing.Optional[str] = OMIT,
|
|
160
|
+
count: typing.Optional[int] = OMIT,
|
|
161
|
+
provider: typing.Optional[Lang2FhirAndSearchRequestProvider] = OMIT,
|
|
162
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
163
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
164
|
+
) -> HttpResponse[Lang2FhirAndSearchResponse]:
|
|
165
|
+
"""
|
|
166
|
+
Converts natural language to FHIR search parameters and executes search in FHIR server
|
|
167
|
+
|
|
168
|
+
Parameters
|
|
169
|
+
----------
|
|
170
|
+
text : str
|
|
171
|
+
Natural language text to convert to FHIR search parameters
|
|
172
|
+
|
|
173
|
+
patient_id : typing.Optional[str]
|
|
174
|
+
Patient ID to filter results
|
|
175
|
+
|
|
176
|
+
practitioner_id : typing.Optional[str]
|
|
177
|
+
Practitioner ID to filter results
|
|
178
|
+
|
|
179
|
+
count : typing.Optional[int]
|
|
180
|
+
Maximum number of results to return
|
|
181
|
+
|
|
182
|
+
provider : typing.Optional[Lang2FhirAndSearchRequestProvider]
|
|
183
|
+
FHIR provider to use for searching
|
|
184
|
+
|
|
185
|
+
meta : typing.Optional[FhirClientConfig]
|
|
186
|
+
|
|
187
|
+
request_options : typing.Optional[RequestOptions]
|
|
188
|
+
Request-specific configuration.
|
|
189
|
+
|
|
190
|
+
Returns
|
|
191
|
+
-------
|
|
192
|
+
HttpResponse[Lang2FhirAndSearchResponse]
|
|
193
|
+
Successfully generated search and retrieved results
|
|
194
|
+
"""
|
|
195
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
196
|
+
"tools/lang2fhir-and-search",
|
|
197
|
+
method="POST",
|
|
198
|
+
json={
|
|
199
|
+
"text": text,
|
|
200
|
+
"patient_id": patient_id,
|
|
201
|
+
"practitioner_id": practitioner_id,
|
|
202
|
+
"count": count,
|
|
203
|
+
"provider": provider,
|
|
204
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
205
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
206
|
+
),
|
|
207
|
+
},
|
|
208
|
+
headers={
|
|
209
|
+
"content-type": "application/json",
|
|
210
|
+
},
|
|
211
|
+
request_options=request_options,
|
|
212
|
+
omit=OMIT,
|
|
213
|
+
)
|
|
214
|
+
try:
|
|
215
|
+
if 200 <= _response.status_code < 300:
|
|
216
|
+
_data = typing.cast(
|
|
217
|
+
Lang2FhirAndSearchResponse,
|
|
218
|
+
parse_obj_as(
|
|
219
|
+
type_=Lang2FhirAndSearchResponse, # type: ignore
|
|
220
|
+
object_=_response.json(),
|
|
221
|
+
),
|
|
222
|
+
)
|
|
223
|
+
return HttpResponse(response=_response, data=_data)
|
|
224
|
+
if _response.status_code == 400:
|
|
225
|
+
raise BadRequestError(
|
|
226
|
+
headers=dict(_response.headers),
|
|
227
|
+
body=typing.cast(
|
|
228
|
+
typing.Optional[typing.Any],
|
|
229
|
+
parse_obj_as(
|
|
230
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
231
|
+
object_=_response.json(),
|
|
232
|
+
),
|
|
233
|
+
),
|
|
234
|
+
)
|
|
235
|
+
if _response.status_code == 401:
|
|
236
|
+
raise UnauthorizedError(
|
|
237
|
+
headers=dict(_response.headers),
|
|
238
|
+
body=typing.cast(
|
|
239
|
+
typing.Optional[typing.Any],
|
|
240
|
+
parse_obj_as(
|
|
241
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
242
|
+
object_=_response.json(),
|
|
243
|
+
),
|
|
244
|
+
),
|
|
245
|
+
)
|
|
246
|
+
if _response.status_code == 403:
|
|
247
|
+
raise ForbiddenError(
|
|
248
|
+
headers=dict(_response.headers),
|
|
249
|
+
body=typing.cast(
|
|
250
|
+
typing.Optional[typing.Any],
|
|
251
|
+
parse_obj_as(
|
|
252
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
253
|
+
object_=_response.json(),
|
|
254
|
+
),
|
|
255
|
+
),
|
|
256
|
+
)
|
|
257
|
+
if _response.status_code == 424:
|
|
258
|
+
raise FailedDependencyError(
|
|
259
|
+
headers=dict(_response.headers),
|
|
260
|
+
body=typing.cast(
|
|
261
|
+
typing.Optional[typing.Any],
|
|
262
|
+
parse_obj_as(
|
|
263
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
264
|
+
object_=_response.json(),
|
|
265
|
+
),
|
|
266
|
+
),
|
|
267
|
+
)
|
|
268
|
+
if _response.status_code == 500:
|
|
269
|
+
raise InternalServerError(
|
|
270
|
+
headers=dict(_response.headers),
|
|
271
|
+
body=typing.cast(
|
|
272
|
+
typing.Optional[typing.Any],
|
|
273
|
+
parse_obj_as(
|
|
274
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
275
|
+
object_=_response.json(),
|
|
276
|
+
),
|
|
277
|
+
),
|
|
278
|
+
)
|
|
279
|
+
_response_json = _response.json()
|
|
280
|
+
except JSONDecodeError:
|
|
281
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
282
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
283
|
+
|
|
284
|
+
def analyze_cohort(
|
|
285
|
+
self,
|
|
286
|
+
*,
|
|
287
|
+
text: str,
|
|
288
|
+
provider: CohortRequestProvider,
|
|
289
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
290
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
291
|
+
) -> HttpResponse[CohortResponse]:
|
|
292
|
+
"""
|
|
293
|
+
Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria
|
|
294
|
+
|
|
295
|
+
Parameters
|
|
296
|
+
----------
|
|
297
|
+
text : str
|
|
298
|
+
Natural language text describing the patient cohort criteria
|
|
299
|
+
|
|
300
|
+
provider : CohortRequestProvider
|
|
301
|
+
FHIR provider to use for searching
|
|
302
|
+
|
|
303
|
+
meta : typing.Optional[FhirClientConfig]
|
|
304
|
+
|
|
305
|
+
request_options : typing.Optional[RequestOptions]
|
|
306
|
+
Request-specific configuration.
|
|
307
|
+
|
|
308
|
+
Returns
|
|
309
|
+
-------
|
|
310
|
+
HttpResponse[CohortResponse]
|
|
311
|
+
Successfully analyzed cohort and retrieved patient list
|
|
312
|
+
"""
|
|
313
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
314
|
+
"tools/cohort",
|
|
315
|
+
method="POST",
|
|
316
|
+
json={
|
|
317
|
+
"text": text,
|
|
318
|
+
"provider": provider,
|
|
319
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
320
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
321
|
+
),
|
|
322
|
+
},
|
|
323
|
+
headers={
|
|
324
|
+
"content-type": "application/json",
|
|
325
|
+
},
|
|
326
|
+
request_options=request_options,
|
|
327
|
+
omit=OMIT,
|
|
328
|
+
)
|
|
329
|
+
try:
|
|
330
|
+
if 200 <= _response.status_code < 300:
|
|
331
|
+
_data = typing.cast(
|
|
332
|
+
CohortResponse,
|
|
333
|
+
parse_obj_as(
|
|
334
|
+
type_=CohortResponse, # type: ignore
|
|
335
|
+
object_=_response.json(),
|
|
336
|
+
),
|
|
337
|
+
)
|
|
338
|
+
return HttpResponse(response=_response, data=_data)
|
|
339
|
+
if _response.status_code == 400:
|
|
340
|
+
raise BadRequestError(
|
|
341
|
+
headers=dict(_response.headers),
|
|
342
|
+
body=typing.cast(
|
|
343
|
+
typing.Optional[typing.Any],
|
|
344
|
+
parse_obj_as(
|
|
345
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
346
|
+
object_=_response.json(),
|
|
347
|
+
),
|
|
348
|
+
),
|
|
349
|
+
)
|
|
350
|
+
if _response.status_code == 401:
|
|
351
|
+
raise UnauthorizedError(
|
|
352
|
+
headers=dict(_response.headers),
|
|
353
|
+
body=typing.cast(
|
|
354
|
+
typing.Optional[typing.Any],
|
|
355
|
+
parse_obj_as(
|
|
356
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
357
|
+
object_=_response.json(),
|
|
358
|
+
),
|
|
359
|
+
),
|
|
360
|
+
)
|
|
361
|
+
if _response.status_code == 403:
|
|
362
|
+
raise ForbiddenError(
|
|
363
|
+
headers=dict(_response.headers),
|
|
364
|
+
body=typing.cast(
|
|
365
|
+
typing.Optional[typing.Any],
|
|
366
|
+
parse_obj_as(
|
|
367
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
368
|
+
object_=_response.json(),
|
|
369
|
+
),
|
|
370
|
+
),
|
|
371
|
+
)
|
|
372
|
+
if _response.status_code == 500:
|
|
373
|
+
raise InternalServerError(
|
|
374
|
+
headers=dict(_response.headers),
|
|
375
|
+
body=typing.cast(
|
|
376
|
+
typing.Optional[typing.Any],
|
|
377
|
+
parse_obj_as(
|
|
378
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
379
|
+
object_=_response.json(),
|
|
380
|
+
),
|
|
381
|
+
),
|
|
382
|
+
)
|
|
383
|
+
_response_json = _response.json()
|
|
384
|
+
except JSONDecodeError:
|
|
385
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
386
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
class AsyncRawToolsClient:
|
|
390
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
391
|
+
self._client_wrapper = client_wrapper
|
|
392
|
+
|
|
393
|
+
async def create_fhir_resource(
|
|
394
|
+
self,
|
|
395
|
+
*,
|
|
396
|
+
resource: Lang2FhirAndCreateRequestResource,
|
|
397
|
+
text: str,
|
|
398
|
+
provider: typing.Optional[Lang2FhirAndCreateRequestProvider] = OMIT,
|
|
399
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
400
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
401
|
+
) -> AsyncHttpResponse[Lang2FhirAndCreateResponse]:
|
|
402
|
+
"""
|
|
403
|
+
Converts natural language to FHIR resource and optionally stores it in a FHIR server
|
|
404
|
+
|
|
405
|
+
Parameters
|
|
406
|
+
----------
|
|
407
|
+
resource : Lang2FhirAndCreateRequestResource
|
|
408
|
+
Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile.
|
|
409
|
+
|
|
410
|
+
text : str
|
|
411
|
+
Natural language text to convert to FHIR resource
|
|
412
|
+
|
|
413
|
+
provider : typing.Optional[Lang2FhirAndCreateRequestProvider]
|
|
414
|
+
FHIR provider to use for storing the resource
|
|
415
|
+
|
|
416
|
+
meta : typing.Optional[FhirClientConfig]
|
|
417
|
+
|
|
418
|
+
request_options : typing.Optional[RequestOptions]
|
|
419
|
+
Request-specific configuration.
|
|
420
|
+
|
|
421
|
+
Returns
|
|
422
|
+
-------
|
|
423
|
+
AsyncHttpResponse[Lang2FhirAndCreateResponse]
|
|
424
|
+
Successfully created FHIR resource
|
|
425
|
+
"""
|
|
426
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
427
|
+
"tools/lang2fhir-and-create",
|
|
428
|
+
method="POST",
|
|
429
|
+
json={
|
|
430
|
+
"resource": resource,
|
|
431
|
+
"text": text,
|
|
432
|
+
"provider": provider,
|
|
433
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
434
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
435
|
+
),
|
|
436
|
+
},
|
|
437
|
+
headers={
|
|
438
|
+
"content-type": "application/json",
|
|
439
|
+
},
|
|
440
|
+
request_options=request_options,
|
|
441
|
+
omit=OMIT,
|
|
442
|
+
)
|
|
443
|
+
try:
|
|
444
|
+
if 200 <= _response.status_code < 300:
|
|
445
|
+
_data = typing.cast(
|
|
446
|
+
Lang2FhirAndCreateResponse,
|
|
447
|
+
parse_obj_as(
|
|
448
|
+
type_=Lang2FhirAndCreateResponse, # type: ignore
|
|
449
|
+
object_=_response.json(),
|
|
450
|
+
),
|
|
451
|
+
)
|
|
452
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
453
|
+
if _response.status_code == 400:
|
|
454
|
+
raise BadRequestError(
|
|
455
|
+
headers=dict(_response.headers),
|
|
456
|
+
body=typing.cast(
|
|
457
|
+
typing.Optional[typing.Any],
|
|
458
|
+
parse_obj_as(
|
|
459
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
460
|
+
object_=_response.json(),
|
|
461
|
+
),
|
|
462
|
+
),
|
|
463
|
+
)
|
|
464
|
+
if _response.status_code == 401:
|
|
465
|
+
raise UnauthorizedError(
|
|
466
|
+
headers=dict(_response.headers),
|
|
467
|
+
body=typing.cast(
|
|
468
|
+
typing.Optional[typing.Any],
|
|
469
|
+
parse_obj_as(
|
|
470
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
471
|
+
object_=_response.json(),
|
|
472
|
+
),
|
|
473
|
+
),
|
|
474
|
+
)
|
|
475
|
+
if _response.status_code == 403:
|
|
476
|
+
raise ForbiddenError(
|
|
477
|
+
headers=dict(_response.headers),
|
|
478
|
+
body=typing.cast(
|
|
479
|
+
typing.Optional[typing.Any],
|
|
480
|
+
parse_obj_as(
|
|
481
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
482
|
+
object_=_response.json(),
|
|
483
|
+
),
|
|
484
|
+
),
|
|
485
|
+
)
|
|
486
|
+
if _response.status_code == 424:
|
|
487
|
+
raise FailedDependencyError(
|
|
488
|
+
headers=dict(_response.headers),
|
|
489
|
+
body=typing.cast(
|
|
490
|
+
typing.Optional[typing.Any],
|
|
491
|
+
parse_obj_as(
|
|
492
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
493
|
+
object_=_response.json(),
|
|
494
|
+
),
|
|
495
|
+
),
|
|
496
|
+
)
|
|
497
|
+
if _response.status_code == 500:
|
|
498
|
+
raise InternalServerError(
|
|
499
|
+
headers=dict(_response.headers),
|
|
500
|
+
body=typing.cast(
|
|
501
|
+
typing.Optional[typing.Any],
|
|
502
|
+
parse_obj_as(
|
|
503
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
504
|
+
object_=_response.json(),
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
)
|
|
508
|
+
_response_json = _response.json()
|
|
509
|
+
except JSONDecodeError:
|
|
510
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
511
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
512
|
+
|
|
513
|
+
async def search_fhir_resources(
|
|
514
|
+
self,
|
|
515
|
+
*,
|
|
516
|
+
text: str,
|
|
517
|
+
patient_id: typing.Optional[str] = OMIT,
|
|
518
|
+
practitioner_id: typing.Optional[str] = OMIT,
|
|
519
|
+
count: typing.Optional[int] = OMIT,
|
|
520
|
+
provider: typing.Optional[Lang2FhirAndSearchRequestProvider] = OMIT,
|
|
521
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
522
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
523
|
+
) -> AsyncHttpResponse[Lang2FhirAndSearchResponse]:
|
|
524
|
+
"""
|
|
525
|
+
Converts natural language to FHIR search parameters and executes search in FHIR server
|
|
526
|
+
|
|
527
|
+
Parameters
|
|
528
|
+
----------
|
|
529
|
+
text : str
|
|
530
|
+
Natural language text to convert to FHIR search parameters
|
|
531
|
+
|
|
532
|
+
patient_id : typing.Optional[str]
|
|
533
|
+
Patient ID to filter results
|
|
534
|
+
|
|
535
|
+
practitioner_id : typing.Optional[str]
|
|
536
|
+
Practitioner ID to filter results
|
|
537
|
+
|
|
538
|
+
count : typing.Optional[int]
|
|
539
|
+
Maximum number of results to return
|
|
540
|
+
|
|
541
|
+
provider : typing.Optional[Lang2FhirAndSearchRequestProvider]
|
|
542
|
+
FHIR provider to use for searching
|
|
543
|
+
|
|
544
|
+
meta : typing.Optional[FhirClientConfig]
|
|
545
|
+
|
|
546
|
+
request_options : typing.Optional[RequestOptions]
|
|
547
|
+
Request-specific configuration.
|
|
548
|
+
|
|
549
|
+
Returns
|
|
550
|
+
-------
|
|
551
|
+
AsyncHttpResponse[Lang2FhirAndSearchResponse]
|
|
552
|
+
Successfully generated search and retrieved results
|
|
553
|
+
"""
|
|
554
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
555
|
+
"tools/lang2fhir-and-search",
|
|
556
|
+
method="POST",
|
|
557
|
+
json={
|
|
558
|
+
"text": text,
|
|
559
|
+
"patient_id": patient_id,
|
|
560
|
+
"practitioner_id": practitioner_id,
|
|
561
|
+
"count": count,
|
|
562
|
+
"provider": provider,
|
|
563
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
564
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
565
|
+
),
|
|
566
|
+
},
|
|
567
|
+
headers={
|
|
568
|
+
"content-type": "application/json",
|
|
569
|
+
},
|
|
570
|
+
request_options=request_options,
|
|
571
|
+
omit=OMIT,
|
|
572
|
+
)
|
|
573
|
+
try:
|
|
574
|
+
if 200 <= _response.status_code < 300:
|
|
575
|
+
_data = typing.cast(
|
|
576
|
+
Lang2FhirAndSearchResponse,
|
|
577
|
+
parse_obj_as(
|
|
578
|
+
type_=Lang2FhirAndSearchResponse, # type: ignore
|
|
579
|
+
object_=_response.json(),
|
|
580
|
+
),
|
|
581
|
+
)
|
|
582
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
583
|
+
if _response.status_code == 400:
|
|
584
|
+
raise BadRequestError(
|
|
585
|
+
headers=dict(_response.headers),
|
|
586
|
+
body=typing.cast(
|
|
587
|
+
typing.Optional[typing.Any],
|
|
588
|
+
parse_obj_as(
|
|
589
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
590
|
+
object_=_response.json(),
|
|
591
|
+
),
|
|
592
|
+
),
|
|
593
|
+
)
|
|
594
|
+
if _response.status_code == 401:
|
|
595
|
+
raise UnauthorizedError(
|
|
596
|
+
headers=dict(_response.headers),
|
|
597
|
+
body=typing.cast(
|
|
598
|
+
typing.Optional[typing.Any],
|
|
599
|
+
parse_obj_as(
|
|
600
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
601
|
+
object_=_response.json(),
|
|
602
|
+
),
|
|
603
|
+
),
|
|
604
|
+
)
|
|
605
|
+
if _response.status_code == 403:
|
|
606
|
+
raise ForbiddenError(
|
|
607
|
+
headers=dict(_response.headers),
|
|
608
|
+
body=typing.cast(
|
|
609
|
+
typing.Optional[typing.Any],
|
|
610
|
+
parse_obj_as(
|
|
611
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
612
|
+
object_=_response.json(),
|
|
613
|
+
),
|
|
614
|
+
),
|
|
615
|
+
)
|
|
616
|
+
if _response.status_code == 424:
|
|
617
|
+
raise FailedDependencyError(
|
|
618
|
+
headers=dict(_response.headers),
|
|
619
|
+
body=typing.cast(
|
|
620
|
+
typing.Optional[typing.Any],
|
|
621
|
+
parse_obj_as(
|
|
622
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
623
|
+
object_=_response.json(),
|
|
624
|
+
),
|
|
625
|
+
),
|
|
626
|
+
)
|
|
627
|
+
if _response.status_code == 500:
|
|
628
|
+
raise InternalServerError(
|
|
629
|
+
headers=dict(_response.headers),
|
|
630
|
+
body=typing.cast(
|
|
631
|
+
typing.Optional[typing.Any],
|
|
632
|
+
parse_obj_as(
|
|
633
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
634
|
+
object_=_response.json(),
|
|
635
|
+
),
|
|
636
|
+
),
|
|
637
|
+
)
|
|
638
|
+
_response_json = _response.json()
|
|
639
|
+
except JSONDecodeError:
|
|
640
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
641
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
642
|
+
|
|
643
|
+
async def analyze_cohort(
|
|
644
|
+
self,
|
|
645
|
+
*,
|
|
646
|
+
text: str,
|
|
647
|
+
provider: CohortRequestProvider,
|
|
648
|
+
meta: typing.Optional[FhirClientConfig] = OMIT,
|
|
649
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
650
|
+
) -> AsyncHttpResponse[CohortResponse]:
|
|
651
|
+
"""
|
|
652
|
+
Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria
|
|
653
|
+
|
|
654
|
+
Parameters
|
|
655
|
+
----------
|
|
656
|
+
text : str
|
|
657
|
+
Natural language text describing the patient cohort criteria
|
|
658
|
+
|
|
659
|
+
provider : CohortRequestProvider
|
|
660
|
+
FHIR provider to use for searching
|
|
661
|
+
|
|
662
|
+
meta : typing.Optional[FhirClientConfig]
|
|
663
|
+
|
|
664
|
+
request_options : typing.Optional[RequestOptions]
|
|
665
|
+
Request-specific configuration.
|
|
666
|
+
|
|
667
|
+
Returns
|
|
668
|
+
-------
|
|
669
|
+
AsyncHttpResponse[CohortResponse]
|
|
670
|
+
Successfully analyzed cohort and retrieved patient list
|
|
671
|
+
"""
|
|
672
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
673
|
+
"tools/cohort",
|
|
674
|
+
method="POST",
|
|
675
|
+
json={
|
|
676
|
+
"text": text,
|
|
677
|
+
"provider": provider,
|
|
678
|
+
"meta": convert_and_respect_annotation_metadata(
|
|
679
|
+
object_=meta, annotation=FhirClientConfig, direction="write"
|
|
680
|
+
),
|
|
681
|
+
},
|
|
682
|
+
headers={
|
|
683
|
+
"content-type": "application/json",
|
|
684
|
+
},
|
|
685
|
+
request_options=request_options,
|
|
686
|
+
omit=OMIT,
|
|
687
|
+
)
|
|
688
|
+
try:
|
|
689
|
+
if 200 <= _response.status_code < 300:
|
|
690
|
+
_data = typing.cast(
|
|
691
|
+
CohortResponse,
|
|
692
|
+
parse_obj_as(
|
|
693
|
+
type_=CohortResponse, # type: ignore
|
|
694
|
+
object_=_response.json(),
|
|
695
|
+
),
|
|
696
|
+
)
|
|
697
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
698
|
+
if _response.status_code == 400:
|
|
699
|
+
raise BadRequestError(
|
|
700
|
+
headers=dict(_response.headers),
|
|
701
|
+
body=typing.cast(
|
|
702
|
+
typing.Optional[typing.Any],
|
|
703
|
+
parse_obj_as(
|
|
704
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
705
|
+
object_=_response.json(),
|
|
706
|
+
),
|
|
707
|
+
),
|
|
708
|
+
)
|
|
709
|
+
if _response.status_code == 401:
|
|
710
|
+
raise UnauthorizedError(
|
|
711
|
+
headers=dict(_response.headers),
|
|
712
|
+
body=typing.cast(
|
|
713
|
+
typing.Optional[typing.Any],
|
|
714
|
+
parse_obj_as(
|
|
715
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
716
|
+
object_=_response.json(),
|
|
717
|
+
),
|
|
718
|
+
),
|
|
719
|
+
)
|
|
720
|
+
if _response.status_code == 403:
|
|
721
|
+
raise ForbiddenError(
|
|
722
|
+
headers=dict(_response.headers),
|
|
723
|
+
body=typing.cast(
|
|
724
|
+
typing.Optional[typing.Any],
|
|
725
|
+
parse_obj_as(
|
|
726
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
727
|
+
object_=_response.json(),
|
|
728
|
+
),
|
|
729
|
+
),
|
|
730
|
+
)
|
|
731
|
+
if _response.status_code == 500:
|
|
732
|
+
raise InternalServerError(
|
|
733
|
+
headers=dict(_response.headers),
|
|
734
|
+
body=typing.cast(
|
|
735
|
+
typing.Optional[typing.Any],
|
|
736
|
+
parse_obj_as(
|
|
737
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
738
|
+
object_=_response.json(),
|
|
739
|
+
),
|
|
740
|
+
),
|
|
741
|
+
)
|
|
742
|
+
_response_json = _response.json()
|
|
743
|
+
except JSONDecodeError:
|
|
744
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
745
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|