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,788 @@
|
|
|
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 .errors.bad_request_error import BadRequestError
|
|
12
|
+
from .errors.failed_dependency_error import FailedDependencyError
|
|
13
|
+
from .errors.forbidden_error import ForbiddenError
|
|
14
|
+
from .errors.internal_server_error import InternalServerError
|
|
15
|
+
from .errors.unauthorized_error import UnauthorizedError
|
|
16
|
+
from .types.create_request_resource import CreateRequestResource
|
|
17
|
+
from .types.document_request_file_type import DocumentRequestFileType
|
|
18
|
+
from .types.document_request_resource import DocumentRequestResource
|
|
19
|
+
from .types.fhir_resource import FhirResource
|
|
20
|
+
from .types.lang2fhir_upload_profile_response import Lang2FhirUploadProfileResponse
|
|
21
|
+
from .types.search_response import SearchResponse
|
|
22
|
+
|
|
23
|
+
# this is used as the default value for optional parameters
|
|
24
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RawLang2FhirClient:
|
|
28
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
29
|
+
self._client_wrapper = client_wrapper
|
|
30
|
+
|
|
31
|
+
def create(
|
|
32
|
+
self,
|
|
33
|
+
*,
|
|
34
|
+
version: str,
|
|
35
|
+
resource: CreateRequestResource,
|
|
36
|
+
text: str,
|
|
37
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
38
|
+
) -> HttpResponse[FhirResource]:
|
|
39
|
+
"""
|
|
40
|
+
Converts natural language text into a structured FHIR resource
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
version : str
|
|
45
|
+
FHIR version to use
|
|
46
|
+
|
|
47
|
+
resource : CreateRequestResource
|
|
48
|
+
Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile. Recommended to use the supported US Core Profiles for validated results but you can also use any custom profile you've uploaded (if you're a develop or launch customer)
|
|
49
|
+
|
|
50
|
+
text : str
|
|
51
|
+
Natural language text to convert
|
|
52
|
+
|
|
53
|
+
request_options : typing.Optional[RequestOptions]
|
|
54
|
+
Request-specific configuration.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
HttpResponse[FhirResource]
|
|
59
|
+
Successfully created FHIR resource
|
|
60
|
+
"""
|
|
61
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
62
|
+
"lang2fhir/create",
|
|
63
|
+
method="POST",
|
|
64
|
+
json={
|
|
65
|
+
"version": version,
|
|
66
|
+
"resource": resource,
|
|
67
|
+
"text": text,
|
|
68
|
+
},
|
|
69
|
+
headers={
|
|
70
|
+
"content-type": "application/json",
|
|
71
|
+
},
|
|
72
|
+
request_options=request_options,
|
|
73
|
+
omit=OMIT,
|
|
74
|
+
)
|
|
75
|
+
try:
|
|
76
|
+
if 200 <= _response.status_code < 300:
|
|
77
|
+
_data = typing.cast(
|
|
78
|
+
FhirResource,
|
|
79
|
+
parse_obj_as(
|
|
80
|
+
type_=FhirResource, # type: ignore
|
|
81
|
+
object_=_response.json(),
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
return HttpResponse(response=_response, data=_data)
|
|
85
|
+
if _response.status_code == 400:
|
|
86
|
+
raise BadRequestError(
|
|
87
|
+
headers=dict(_response.headers),
|
|
88
|
+
body=typing.cast(
|
|
89
|
+
typing.Optional[typing.Any],
|
|
90
|
+
parse_obj_as(
|
|
91
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
92
|
+
object_=_response.json(),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
if _response.status_code == 401:
|
|
97
|
+
raise UnauthorizedError(
|
|
98
|
+
headers=dict(_response.headers),
|
|
99
|
+
body=typing.cast(
|
|
100
|
+
typing.Optional[typing.Any],
|
|
101
|
+
parse_obj_as(
|
|
102
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
103
|
+
object_=_response.json(),
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
if _response.status_code == 500:
|
|
108
|
+
raise InternalServerError(
|
|
109
|
+
headers=dict(_response.headers),
|
|
110
|
+
body=typing.cast(
|
|
111
|
+
typing.Optional[typing.Any],
|
|
112
|
+
parse_obj_as(
|
|
113
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
114
|
+
object_=_response.json(),
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
_response_json = _response.json()
|
|
119
|
+
except JSONDecodeError:
|
|
120
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
121
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
122
|
+
|
|
123
|
+
def search(
|
|
124
|
+
self, *, text: str, request_options: typing.Optional[RequestOptions] = None
|
|
125
|
+
) -> HttpResponse[SearchResponse]:
|
|
126
|
+
"""
|
|
127
|
+
Converts natural language text into FHIR search parameters
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
text : str
|
|
132
|
+
Natural language text to convert into FHIR search parameters
|
|
133
|
+
|
|
134
|
+
request_options : typing.Optional[RequestOptions]
|
|
135
|
+
Request-specific configuration.
|
|
136
|
+
|
|
137
|
+
Returns
|
|
138
|
+
-------
|
|
139
|
+
HttpResponse[SearchResponse]
|
|
140
|
+
Successfully generated FHIR search parameters
|
|
141
|
+
"""
|
|
142
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
143
|
+
"lang2fhir/search",
|
|
144
|
+
method="POST",
|
|
145
|
+
json={
|
|
146
|
+
"text": text,
|
|
147
|
+
},
|
|
148
|
+
headers={
|
|
149
|
+
"content-type": "application/json",
|
|
150
|
+
},
|
|
151
|
+
request_options=request_options,
|
|
152
|
+
omit=OMIT,
|
|
153
|
+
)
|
|
154
|
+
try:
|
|
155
|
+
if 200 <= _response.status_code < 300:
|
|
156
|
+
_data = typing.cast(
|
|
157
|
+
SearchResponse,
|
|
158
|
+
parse_obj_as(
|
|
159
|
+
type_=SearchResponse, # type: ignore
|
|
160
|
+
object_=_response.json(),
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
return HttpResponse(response=_response, data=_data)
|
|
164
|
+
if _response.status_code == 400:
|
|
165
|
+
raise BadRequestError(
|
|
166
|
+
headers=dict(_response.headers),
|
|
167
|
+
body=typing.cast(
|
|
168
|
+
typing.Optional[typing.Any],
|
|
169
|
+
parse_obj_as(
|
|
170
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
171
|
+
object_=_response.json(),
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
if _response.status_code == 401:
|
|
176
|
+
raise UnauthorizedError(
|
|
177
|
+
headers=dict(_response.headers),
|
|
178
|
+
body=typing.cast(
|
|
179
|
+
typing.Optional[typing.Any],
|
|
180
|
+
parse_obj_as(
|
|
181
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
182
|
+
object_=_response.json(),
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
if _response.status_code == 424:
|
|
187
|
+
raise FailedDependencyError(
|
|
188
|
+
headers=dict(_response.headers),
|
|
189
|
+
body=typing.cast(
|
|
190
|
+
typing.Optional[typing.Any],
|
|
191
|
+
parse_obj_as(
|
|
192
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
193
|
+
object_=_response.json(),
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
if _response.status_code == 500:
|
|
198
|
+
raise InternalServerError(
|
|
199
|
+
headers=dict(_response.headers),
|
|
200
|
+
body=typing.cast(
|
|
201
|
+
typing.Optional[typing.Any],
|
|
202
|
+
parse_obj_as(
|
|
203
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
204
|
+
object_=_response.json(),
|
|
205
|
+
),
|
|
206
|
+
),
|
|
207
|
+
)
|
|
208
|
+
_response_json = _response.json()
|
|
209
|
+
except JSONDecodeError:
|
|
210
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
211
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
212
|
+
|
|
213
|
+
def upload_profile(
|
|
214
|
+
self, *, version: str, resource: str, profile: str, request_options: typing.Optional[RequestOptions] = None
|
|
215
|
+
) -> HttpResponse[Lang2FhirUploadProfileResponse]:
|
|
216
|
+
"""
|
|
217
|
+
Upload a custom FHIR StructureDefinition profile for use with the lang2fhir service
|
|
218
|
+
|
|
219
|
+
Parameters
|
|
220
|
+
----------
|
|
221
|
+
version : str
|
|
222
|
+
FHIR version that this profile implements
|
|
223
|
+
|
|
224
|
+
resource : str
|
|
225
|
+
Name for the custom resource profile (will be converted to lowercase)
|
|
226
|
+
|
|
227
|
+
profile : str
|
|
228
|
+
Base64 encoded JSON string of the FHIR StructureDefinition profile
|
|
229
|
+
|
|
230
|
+
request_options : typing.Optional[RequestOptions]
|
|
231
|
+
Request-specific configuration.
|
|
232
|
+
|
|
233
|
+
Returns
|
|
234
|
+
-------
|
|
235
|
+
HttpResponse[Lang2FhirUploadProfileResponse]
|
|
236
|
+
Profile successfully uploaded
|
|
237
|
+
"""
|
|
238
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
239
|
+
"lang2fhir/profile/upload",
|
|
240
|
+
method="POST",
|
|
241
|
+
json={
|
|
242
|
+
"version": version,
|
|
243
|
+
"resource": resource,
|
|
244
|
+
"profile": profile,
|
|
245
|
+
},
|
|
246
|
+
headers={
|
|
247
|
+
"content-type": "application/json",
|
|
248
|
+
},
|
|
249
|
+
request_options=request_options,
|
|
250
|
+
omit=OMIT,
|
|
251
|
+
)
|
|
252
|
+
try:
|
|
253
|
+
if 200 <= _response.status_code < 300:
|
|
254
|
+
_data = typing.cast(
|
|
255
|
+
Lang2FhirUploadProfileResponse,
|
|
256
|
+
parse_obj_as(
|
|
257
|
+
type_=Lang2FhirUploadProfileResponse, # type: ignore
|
|
258
|
+
object_=_response.json(),
|
|
259
|
+
),
|
|
260
|
+
)
|
|
261
|
+
return HttpResponse(response=_response, data=_data)
|
|
262
|
+
if _response.status_code == 400:
|
|
263
|
+
raise BadRequestError(
|
|
264
|
+
headers=dict(_response.headers),
|
|
265
|
+
body=typing.cast(
|
|
266
|
+
typing.Optional[typing.Any],
|
|
267
|
+
parse_obj_as(
|
|
268
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
269
|
+
object_=_response.json(),
|
|
270
|
+
),
|
|
271
|
+
),
|
|
272
|
+
)
|
|
273
|
+
if _response.status_code == 401:
|
|
274
|
+
raise UnauthorizedError(
|
|
275
|
+
headers=dict(_response.headers),
|
|
276
|
+
body=typing.cast(
|
|
277
|
+
typing.Optional[typing.Any],
|
|
278
|
+
parse_obj_as(
|
|
279
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
280
|
+
object_=_response.json(),
|
|
281
|
+
),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
if _response.status_code == 403:
|
|
285
|
+
raise ForbiddenError(
|
|
286
|
+
headers=dict(_response.headers),
|
|
287
|
+
body=typing.cast(
|
|
288
|
+
typing.Optional[typing.Any],
|
|
289
|
+
parse_obj_as(
|
|
290
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
291
|
+
object_=_response.json(),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
if _response.status_code == 500:
|
|
296
|
+
raise InternalServerError(
|
|
297
|
+
headers=dict(_response.headers),
|
|
298
|
+
body=typing.cast(
|
|
299
|
+
typing.Optional[typing.Any],
|
|
300
|
+
parse_obj_as(
|
|
301
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
302
|
+
object_=_response.json(),
|
|
303
|
+
),
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
_response_json = _response.json()
|
|
307
|
+
except JSONDecodeError:
|
|
308
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
309
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
310
|
+
|
|
311
|
+
def document(
|
|
312
|
+
self,
|
|
313
|
+
*,
|
|
314
|
+
version: str,
|
|
315
|
+
resource: DocumentRequestResource,
|
|
316
|
+
content: str,
|
|
317
|
+
file_type: DocumentRequestFileType,
|
|
318
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
319
|
+
) -> HttpResponse[FhirResource]:
|
|
320
|
+
"""
|
|
321
|
+
Extracts text from a document (PDF or image) and converts it into a structured FHIR resource
|
|
322
|
+
|
|
323
|
+
Parameters
|
|
324
|
+
----------
|
|
325
|
+
version : str
|
|
326
|
+
FHIR version to use
|
|
327
|
+
|
|
328
|
+
resource : DocumentRequestResource
|
|
329
|
+
Type of FHIR resource to create (questionnaire and US Core questionnaireresponse profiles currently supported)
|
|
330
|
+
|
|
331
|
+
content : str
|
|
332
|
+
Base64 encoded file content
|
|
333
|
+
|
|
334
|
+
file_type : DocumentRequestFileType
|
|
335
|
+
MIME type of the file
|
|
336
|
+
|
|
337
|
+
request_options : typing.Optional[RequestOptions]
|
|
338
|
+
Request-specific configuration.
|
|
339
|
+
|
|
340
|
+
Returns
|
|
341
|
+
-------
|
|
342
|
+
HttpResponse[FhirResource]
|
|
343
|
+
Successfully created FHIR resource from document
|
|
344
|
+
"""
|
|
345
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
346
|
+
"lang2fhir/document",
|
|
347
|
+
method="POST",
|
|
348
|
+
json={
|
|
349
|
+
"version": version,
|
|
350
|
+
"resource": resource,
|
|
351
|
+
"content": content,
|
|
352
|
+
"fileType": file_type,
|
|
353
|
+
},
|
|
354
|
+
headers={
|
|
355
|
+
"content-type": "application/json",
|
|
356
|
+
},
|
|
357
|
+
request_options=request_options,
|
|
358
|
+
omit=OMIT,
|
|
359
|
+
)
|
|
360
|
+
try:
|
|
361
|
+
if 200 <= _response.status_code < 300:
|
|
362
|
+
_data = typing.cast(
|
|
363
|
+
FhirResource,
|
|
364
|
+
parse_obj_as(
|
|
365
|
+
type_=FhirResource, # type: ignore
|
|
366
|
+
object_=_response.json(),
|
|
367
|
+
),
|
|
368
|
+
)
|
|
369
|
+
return HttpResponse(response=_response, data=_data)
|
|
370
|
+
if _response.status_code == 400:
|
|
371
|
+
raise BadRequestError(
|
|
372
|
+
headers=dict(_response.headers),
|
|
373
|
+
body=typing.cast(
|
|
374
|
+
typing.Optional[typing.Any],
|
|
375
|
+
parse_obj_as(
|
|
376
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
377
|
+
object_=_response.json(),
|
|
378
|
+
),
|
|
379
|
+
),
|
|
380
|
+
)
|
|
381
|
+
if _response.status_code == 401:
|
|
382
|
+
raise UnauthorizedError(
|
|
383
|
+
headers=dict(_response.headers),
|
|
384
|
+
body=typing.cast(
|
|
385
|
+
typing.Optional[typing.Any],
|
|
386
|
+
parse_obj_as(
|
|
387
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
388
|
+
object_=_response.json(),
|
|
389
|
+
),
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
if _response.status_code == 500:
|
|
393
|
+
raise InternalServerError(
|
|
394
|
+
headers=dict(_response.headers),
|
|
395
|
+
body=typing.cast(
|
|
396
|
+
typing.Optional[typing.Any],
|
|
397
|
+
parse_obj_as(
|
|
398
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
399
|
+
object_=_response.json(),
|
|
400
|
+
),
|
|
401
|
+
),
|
|
402
|
+
)
|
|
403
|
+
_response_json = _response.json()
|
|
404
|
+
except JSONDecodeError:
|
|
405
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
406
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
class AsyncRawLang2FhirClient:
|
|
410
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
411
|
+
self._client_wrapper = client_wrapper
|
|
412
|
+
|
|
413
|
+
async def create(
|
|
414
|
+
self,
|
|
415
|
+
*,
|
|
416
|
+
version: str,
|
|
417
|
+
resource: CreateRequestResource,
|
|
418
|
+
text: str,
|
|
419
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
420
|
+
) -> AsyncHttpResponse[FhirResource]:
|
|
421
|
+
"""
|
|
422
|
+
Converts natural language text into a structured FHIR resource
|
|
423
|
+
|
|
424
|
+
Parameters
|
|
425
|
+
----------
|
|
426
|
+
version : str
|
|
427
|
+
FHIR version to use
|
|
428
|
+
|
|
429
|
+
resource : CreateRequestResource
|
|
430
|
+
Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile. Recommended to use the supported US Core Profiles for validated results but you can also use any custom profile you've uploaded (if you're a develop or launch customer)
|
|
431
|
+
|
|
432
|
+
text : str
|
|
433
|
+
Natural language text to convert
|
|
434
|
+
|
|
435
|
+
request_options : typing.Optional[RequestOptions]
|
|
436
|
+
Request-specific configuration.
|
|
437
|
+
|
|
438
|
+
Returns
|
|
439
|
+
-------
|
|
440
|
+
AsyncHttpResponse[FhirResource]
|
|
441
|
+
Successfully created FHIR resource
|
|
442
|
+
"""
|
|
443
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
444
|
+
"lang2fhir/create",
|
|
445
|
+
method="POST",
|
|
446
|
+
json={
|
|
447
|
+
"version": version,
|
|
448
|
+
"resource": resource,
|
|
449
|
+
"text": text,
|
|
450
|
+
},
|
|
451
|
+
headers={
|
|
452
|
+
"content-type": "application/json",
|
|
453
|
+
},
|
|
454
|
+
request_options=request_options,
|
|
455
|
+
omit=OMIT,
|
|
456
|
+
)
|
|
457
|
+
try:
|
|
458
|
+
if 200 <= _response.status_code < 300:
|
|
459
|
+
_data = typing.cast(
|
|
460
|
+
FhirResource,
|
|
461
|
+
parse_obj_as(
|
|
462
|
+
type_=FhirResource, # type: ignore
|
|
463
|
+
object_=_response.json(),
|
|
464
|
+
),
|
|
465
|
+
)
|
|
466
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
467
|
+
if _response.status_code == 400:
|
|
468
|
+
raise BadRequestError(
|
|
469
|
+
headers=dict(_response.headers),
|
|
470
|
+
body=typing.cast(
|
|
471
|
+
typing.Optional[typing.Any],
|
|
472
|
+
parse_obj_as(
|
|
473
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
474
|
+
object_=_response.json(),
|
|
475
|
+
),
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
if _response.status_code == 401:
|
|
479
|
+
raise UnauthorizedError(
|
|
480
|
+
headers=dict(_response.headers),
|
|
481
|
+
body=typing.cast(
|
|
482
|
+
typing.Optional[typing.Any],
|
|
483
|
+
parse_obj_as(
|
|
484
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
485
|
+
object_=_response.json(),
|
|
486
|
+
),
|
|
487
|
+
),
|
|
488
|
+
)
|
|
489
|
+
if _response.status_code == 500:
|
|
490
|
+
raise InternalServerError(
|
|
491
|
+
headers=dict(_response.headers),
|
|
492
|
+
body=typing.cast(
|
|
493
|
+
typing.Optional[typing.Any],
|
|
494
|
+
parse_obj_as(
|
|
495
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
496
|
+
object_=_response.json(),
|
|
497
|
+
),
|
|
498
|
+
),
|
|
499
|
+
)
|
|
500
|
+
_response_json = _response.json()
|
|
501
|
+
except JSONDecodeError:
|
|
502
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
503
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
504
|
+
|
|
505
|
+
async def search(
|
|
506
|
+
self, *, text: str, request_options: typing.Optional[RequestOptions] = None
|
|
507
|
+
) -> AsyncHttpResponse[SearchResponse]:
|
|
508
|
+
"""
|
|
509
|
+
Converts natural language text into FHIR search parameters
|
|
510
|
+
|
|
511
|
+
Parameters
|
|
512
|
+
----------
|
|
513
|
+
text : str
|
|
514
|
+
Natural language text to convert into FHIR search parameters
|
|
515
|
+
|
|
516
|
+
request_options : typing.Optional[RequestOptions]
|
|
517
|
+
Request-specific configuration.
|
|
518
|
+
|
|
519
|
+
Returns
|
|
520
|
+
-------
|
|
521
|
+
AsyncHttpResponse[SearchResponse]
|
|
522
|
+
Successfully generated FHIR search parameters
|
|
523
|
+
"""
|
|
524
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
525
|
+
"lang2fhir/search",
|
|
526
|
+
method="POST",
|
|
527
|
+
json={
|
|
528
|
+
"text": text,
|
|
529
|
+
},
|
|
530
|
+
headers={
|
|
531
|
+
"content-type": "application/json",
|
|
532
|
+
},
|
|
533
|
+
request_options=request_options,
|
|
534
|
+
omit=OMIT,
|
|
535
|
+
)
|
|
536
|
+
try:
|
|
537
|
+
if 200 <= _response.status_code < 300:
|
|
538
|
+
_data = typing.cast(
|
|
539
|
+
SearchResponse,
|
|
540
|
+
parse_obj_as(
|
|
541
|
+
type_=SearchResponse, # type: ignore
|
|
542
|
+
object_=_response.json(),
|
|
543
|
+
),
|
|
544
|
+
)
|
|
545
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
546
|
+
if _response.status_code == 400:
|
|
547
|
+
raise BadRequestError(
|
|
548
|
+
headers=dict(_response.headers),
|
|
549
|
+
body=typing.cast(
|
|
550
|
+
typing.Optional[typing.Any],
|
|
551
|
+
parse_obj_as(
|
|
552
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
553
|
+
object_=_response.json(),
|
|
554
|
+
),
|
|
555
|
+
),
|
|
556
|
+
)
|
|
557
|
+
if _response.status_code == 401:
|
|
558
|
+
raise UnauthorizedError(
|
|
559
|
+
headers=dict(_response.headers),
|
|
560
|
+
body=typing.cast(
|
|
561
|
+
typing.Optional[typing.Any],
|
|
562
|
+
parse_obj_as(
|
|
563
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
564
|
+
object_=_response.json(),
|
|
565
|
+
),
|
|
566
|
+
),
|
|
567
|
+
)
|
|
568
|
+
if _response.status_code == 424:
|
|
569
|
+
raise FailedDependencyError(
|
|
570
|
+
headers=dict(_response.headers),
|
|
571
|
+
body=typing.cast(
|
|
572
|
+
typing.Optional[typing.Any],
|
|
573
|
+
parse_obj_as(
|
|
574
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
575
|
+
object_=_response.json(),
|
|
576
|
+
),
|
|
577
|
+
),
|
|
578
|
+
)
|
|
579
|
+
if _response.status_code == 500:
|
|
580
|
+
raise InternalServerError(
|
|
581
|
+
headers=dict(_response.headers),
|
|
582
|
+
body=typing.cast(
|
|
583
|
+
typing.Optional[typing.Any],
|
|
584
|
+
parse_obj_as(
|
|
585
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
586
|
+
object_=_response.json(),
|
|
587
|
+
),
|
|
588
|
+
),
|
|
589
|
+
)
|
|
590
|
+
_response_json = _response.json()
|
|
591
|
+
except JSONDecodeError:
|
|
592
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
593
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
594
|
+
|
|
595
|
+
async def upload_profile(
|
|
596
|
+
self, *, version: str, resource: str, profile: str, request_options: typing.Optional[RequestOptions] = None
|
|
597
|
+
) -> AsyncHttpResponse[Lang2FhirUploadProfileResponse]:
|
|
598
|
+
"""
|
|
599
|
+
Upload a custom FHIR StructureDefinition profile for use with the lang2fhir service
|
|
600
|
+
|
|
601
|
+
Parameters
|
|
602
|
+
----------
|
|
603
|
+
version : str
|
|
604
|
+
FHIR version that this profile implements
|
|
605
|
+
|
|
606
|
+
resource : str
|
|
607
|
+
Name for the custom resource profile (will be converted to lowercase)
|
|
608
|
+
|
|
609
|
+
profile : str
|
|
610
|
+
Base64 encoded JSON string of the FHIR StructureDefinition profile
|
|
611
|
+
|
|
612
|
+
request_options : typing.Optional[RequestOptions]
|
|
613
|
+
Request-specific configuration.
|
|
614
|
+
|
|
615
|
+
Returns
|
|
616
|
+
-------
|
|
617
|
+
AsyncHttpResponse[Lang2FhirUploadProfileResponse]
|
|
618
|
+
Profile successfully uploaded
|
|
619
|
+
"""
|
|
620
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
621
|
+
"lang2fhir/profile/upload",
|
|
622
|
+
method="POST",
|
|
623
|
+
json={
|
|
624
|
+
"version": version,
|
|
625
|
+
"resource": resource,
|
|
626
|
+
"profile": profile,
|
|
627
|
+
},
|
|
628
|
+
headers={
|
|
629
|
+
"content-type": "application/json",
|
|
630
|
+
},
|
|
631
|
+
request_options=request_options,
|
|
632
|
+
omit=OMIT,
|
|
633
|
+
)
|
|
634
|
+
try:
|
|
635
|
+
if 200 <= _response.status_code < 300:
|
|
636
|
+
_data = typing.cast(
|
|
637
|
+
Lang2FhirUploadProfileResponse,
|
|
638
|
+
parse_obj_as(
|
|
639
|
+
type_=Lang2FhirUploadProfileResponse, # type: ignore
|
|
640
|
+
object_=_response.json(),
|
|
641
|
+
),
|
|
642
|
+
)
|
|
643
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
644
|
+
if _response.status_code == 400:
|
|
645
|
+
raise BadRequestError(
|
|
646
|
+
headers=dict(_response.headers),
|
|
647
|
+
body=typing.cast(
|
|
648
|
+
typing.Optional[typing.Any],
|
|
649
|
+
parse_obj_as(
|
|
650
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
651
|
+
object_=_response.json(),
|
|
652
|
+
),
|
|
653
|
+
),
|
|
654
|
+
)
|
|
655
|
+
if _response.status_code == 401:
|
|
656
|
+
raise UnauthorizedError(
|
|
657
|
+
headers=dict(_response.headers),
|
|
658
|
+
body=typing.cast(
|
|
659
|
+
typing.Optional[typing.Any],
|
|
660
|
+
parse_obj_as(
|
|
661
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
662
|
+
object_=_response.json(),
|
|
663
|
+
),
|
|
664
|
+
),
|
|
665
|
+
)
|
|
666
|
+
if _response.status_code == 403:
|
|
667
|
+
raise ForbiddenError(
|
|
668
|
+
headers=dict(_response.headers),
|
|
669
|
+
body=typing.cast(
|
|
670
|
+
typing.Optional[typing.Any],
|
|
671
|
+
parse_obj_as(
|
|
672
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
673
|
+
object_=_response.json(),
|
|
674
|
+
),
|
|
675
|
+
),
|
|
676
|
+
)
|
|
677
|
+
if _response.status_code == 500:
|
|
678
|
+
raise InternalServerError(
|
|
679
|
+
headers=dict(_response.headers),
|
|
680
|
+
body=typing.cast(
|
|
681
|
+
typing.Optional[typing.Any],
|
|
682
|
+
parse_obj_as(
|
|
683
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
684
|
+
object_=_response.json(),
|
|
685
|
+
),
|
|
686
|
+
),
|
|
687
|
+
)
|
|
688
|
+
_response_json = _response.json()
|
|
689
|
+
except JSONDecodeError:
|
|
690
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
691
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
692
|
+
|
|
693
|
+
async def document(
|
|
694
|
+
self,
|
|
695
|
+
*,
|
|
696
|
+
version: str,
|
|
697
|
+
resource: DocumentRequestResource,
|
|
698
|
+
content: str,
|
|
699
|
+
file_type: DocumentRequestFileType,
|
|
700
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
701
|
+
) -> AsyncHttpResponse[FhirResource]:
|
|
702
|
+
"""
|
|
703
|
+
Extracts text from a document (PDF or image) and converts it into a structured FHIR resource
|
|
704
|
+
|
|
705
|
+
Parameters
|
|
706
|
+
----------
|
|
707
|
+
version : str
|
|
708
|
+
FHIR version to use
|
|
709
|
+
|
|
710
|
+
resource : DocumentRequestResource
|
|
711
|
+
Type of FHIR resource to create (questionnaire and US Core questionnaireresponse profiles currently supported)
|
|
712
|
+
|
|
713
|
+
content : str
|
|
714
|
+
Base64 encoded file content
|
|
715
|
+
|
|
716
|
+
file_type : DocumentRequestFileType
|
|
717
|
+
MIME type of the file
|
|
718
|
+
|
|
719
|
+
request_options : typing.Optional[RequestOptions]
|
|
720
|
+
Request-specific configuration.
|
|
721
|
+
|
|
722
|
+
Returns
|
|
723
|
+
-------
|
|
724
|
+
AsyncHttpResponse[FhirResource]
|
|
725
|
+
Successfully created FHIR resource from document
|
|
726
|
+
"""
|
|
727
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
728
|
+
"lang2fhir/document",
|
|
729
|
+
method="POST",
|
|
730
|
+
json={
|
|
731
|
+
"version": version,
|
|
732
|
+
"resource": resource,
|
|
733
|
+
"content": content,
|
|
734
|
+
"fileType": file_type,
|
|
735
|
+
},
|
|
736
|
+
headers={
|
|
737
|
+
"content-type": "application/json",
|
|
738
|
+
},
|
|
739
|
+
request_options=request_options,
|
|
740
|
+
omit=OMIT,
|
|
741
|
+
)
|
|
742
|
+
try:
|
|
743
|
+
if 200 <= _response.status_code < 300:
|
|
744
|
+
_data = typing.cast(
|
|
745
|
+
FhirResource,
|
|
746
|
+
parse_obj_as(
|
|
747
|
+
type_=FhirResource, # type: ignore
|
|
748
|
+
object_=_response.json(),
|
|
749
|
+
),
|
|
750
|
+
)
|
|
751
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
752
|
+
if _response.status_code == 400:
|
|
753
|
+
raise BadRequestError(
|
|
754
|
+
headers=dict(_response.headers),
|
|
755
|
+
body=typing.cast(
|
|
756
|
+
typing.Optional[typing.Any],
|
|
757
|
+
parse_obj_as(
|
|
758
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
759
|
+
object_=_response.json(),
|
|
760
|
+
),
|
|
761
|
+
),
|
|
762
|
+
)
|
|
763
|
+
if _response.status_code == 401:
|
|
764
|
+
raise UnauthorizedError(
|
|
765
|
+
headers=dict(_response.headers),
|
|
766
|
+
body=typing.cast(
|
|
767
|
+
typing.Optional[typing.Any],
|
|
768
|
+
parse_obj_as(
|
|
769
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
770
|
+
object_=_response.json(),
|
|
771
|
+
),
|
|
772
|
+
),
|
|
773
|
+
)
|
|
774
|
+
if _response.status_code == 500:
|
|
775
|
+
raise InternalServerError(
|
|
776
|
+
headers=dict(_response.headers),
|
|
777
|
+
body=typing.cast(
|
|
778
|
+
typing.Optional[typing.Any],
|
|
779
|
+
parse_obj_as(
|
|
780
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
781
|
+
object_=_response.json(),
|
|
782
|
+
),
|
|
783
|
+
),
|
|
784
|
+
)
|
|
785
|
+
_response_json = _response.json()
|
|
786
|
+
except JSONDecodeError:
|
|
787
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
788
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|