phenoml 0.0.15__py3-none-any.whl → 0.0.17__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.
- phenoml/core/client_wrapper.py +2 -2
- phenoml/lang2fhir/__init__.py +10 -0
- phenoml/lang2fhir/client.py +111 -6
- phenoml/lang2fhir/raw_client.py +189 -0
- phenoml/lang2fhir/types/__init__.py +10 -0
- phenoml/lang2fhir/types/create_multi_response.py +39 -0
- phenoml/lang2fhir/types/create_multi_response_bundle.py +28 -0
- phenoml/lang2fhir/types/create_multi_response_bundle_entry_item.py +24 -0
- phenoml/lang2fhir/types/create_multi_response_bundle_entry_item_request.py +20 -0
- phenoml/lang2fhir/types/create_multi_response_resources_item.py +38 -0
- phenoml/summary/__init__.py +2 -0
- phenoml/summary/client.py +16 -4
- phenoml/summary/raw_client.py +16 -4
- phenoml/summary/types/__init__.py +2 -0
- phenoml/summary/types/create_summary_request_mode.py +1 -1
- phenoml/summary/types/error_response.py +23 -0
- phenoml/tools/__init__.py +6 -0
- phenoml/tools/client.py +145 -0
- phenoml/tools/raw_client.py +261 -0
- phenoml/tools/types/__init__.py +6 -0
- phenoml/tools/types/lang2fhir_and_create_multi_response.py +41 -0
- phenoml/tools/types/lang2fhir_and_create_multi_response_resource_info_item.py +38 -0
- phenoml/tools/types/lang2fhir_and_create_multi_response_response_bundle.py +27 -0
- {phenoml-0.0.15.dist-info → phenoml-0.0.17.dist-info}/METADATA +1 -1
- {phenoml-0.0.15.dist-info → phenoml-0.0.17.dist-info}/RECORD +27 -18
- {phenoml-0.0.15.dist-info → phenoml-0.0.17.dist-info}/LICENSE +0 -0
- {phenoml-0.0.15.dist-info → phenoml-0.0.17.dist-info}/WHEEL +0 -0
phenoml/summary/raw_client.py
CHANGED
|
@@ -497,19 +497,25 @@ class RawSummaryClient:
|
|
|
497
497
|
request_options: typing.Optional[RequestOptions] = None,
|
|
498
498
|
) -> HttpResponse[CreateSummaryResponse]:
|
|
499
499
|
"""
|
|
500
|
-
Creates a summary from FHIR resources using one of
|
|
500
|
+
Creates a summary from FHIR resources using one of three modes:
|
|
501
501
|
- **narrative**: Uses a template to substitute FHIR data into placeholders (requires template_id)
|
|
502
502
|
- **flatten**: Flattens FHIR resources into a searchable format for RAG/search (no template needed)
|
|
503
|
+
- **ips**: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
|
|
503
504
|
|
|
504
505
|
Parameters
|
|
505
506
|
----------
|
|
506
507
|
fhir_resources : CreateSummaryRequestFhirResources
|
|
507
|
-
FHIR resources (single resource or Bundle)
|
|
508
|
+
FHIR resources (single resource or Bundle).
|
|
509
|
+
For IPS mode, must be a Bundle containing exactly one Patient resource with at least one
|
|
510
|
+
identifier (id, fullUrl, or identifier field). Returns an error if no Patient is found,
|
|
511
|
+
if multiple Patients are present, or if the Patient has no identifiers. Resources are
|
|
512
|
+
automatically filtered to only include those referencing the patient.
|
|
508
513
|
|
|
509
514
|
mode : typing.Optional[CreateSummaryRequestMode]
|
|
510
515
|
Summary generation mode:
|
|
511
516
|
- narrative: Substitute FHIR data into a template (requires template_id)
|
|
512
517
|
- flatten: Flatten FHIR resources for RAG/search (no template needed)
|
|
518
|
+
- ips: Generate International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG
|
|
513
519
|
|
|
514
520
|
template_id : typing.Optional[str]
|
|
515
521
|
ID of the template to use (required for narrative mode)
|
|
@@ -1078,19 +1084,25 @@ class AsyncRawSummaryClient:
|
|
|
1078
1084
|
request_options: typing.Optional[RequestOptions] = None,
|
|
1079
1085
|
) -> AsyncHttpResponse[CreateSummaryResponse]:
|
|
1080
1086
|
"""
|
|
1081
|
-
Creates a summary from FHIR resources using one of
|
|
1087
|
+
Creates a summary from FHIR resources using one of three modes:
|
|
1082
1088
|
- **narrative**: Uses a template to substitute FHIR data into placeholders (requires template_id)
|
|
1083
1089
|
- **flatten**: Flattens FHIR resources into a searchable format for RAG/search (no template needed)
|
|
1090
|
+
- **ips**: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
|
|
1084
1091
|
|
|
1085
1092
|
Parameters
|
|
1086
1093
|
----------
|
|
1087
1094
|
fhir_resources : CreateSummaryRequestFhirResources
|
|
1088
|
-
FHIR resources (single resource or Bundle)
|
|
1095
|
+
FHIR resources (single resource or Bundle).
|
|
1096
|
+
For IPS mode, must be a Bundle containing exactly one Patient resource with at least one
|
|
1097
|
+
identifier (id, fullUrl, or identifier field). Returns an error if no Patient is found,
|
|
1098
|
+
if multiple Patients are present, or if the Patient has no identifiers. Resources are
|
|
1099
|
+
automatically filtered to only include those referencing the patient.
|
|
1089
1100
|
|
|
1090
1101
|
mode : typing.Optional[CreateSummaryRequestMode]
|
|
1091
1102
|
Summary generation mode:
|
|
1092
1103
|
- narrative: Substitute FHIR data into a template (requires template_id)
|
|
1093
1104
|
- flatten: Flatten FHIR resources for RAG/search (no template needed)
|
|
1105
|
+
- ips: Generate International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG
|
|
1094
1106
|
|
|
1095
1107
|
template_id : typing.Optional[str]
|
|
1096
1108
|
ID of the template to use (required for narrative mode)
|
|
@@ -6,6 +6,7 @@ from .create_summary_request_fhir_resources import CreateSummaryRequestFhirResou
|
|
|
6
6
|
from .create_summary_request_mode import CreateSummaryRequestMode
|
|
7
7
|
from .create_summary_response import CreateSummaryResponse
|
|
8
8
|
from .create_summary_template_response import CreateSummaryTemplateResponse
|
|
9
|
+
from .error_response import ErrorResponse
|
|
9
10
|
from .fhir_bundle import FhirBundle
|
|
10
11
|
from .fhir_bundle_entry_item import FhirBundleEntryItem
|
|
11
12
|
from .fhir_resource import FhirResource
|
|
@@ -20,6 +21,7 @@ __all__ = [
|
|
|
20
21
|
"CreateSummaryRequestMode",
|
|
21
22
|
"CreateSummaryResponse",
|
|
22
23
|
"CreateSummaryTemplateResponse",
|
|
24
|
+
"ErrorResponse",
|
|
23
25
|
"FhirBundle",
|
|
24
26
|
"FhirBundleEntryItem",
|
|
25
27
|
"FhirResource",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ErrorResponse(UniversalBaseModel):
|
|
10
|
+
success: typing.Optional[bool] = None
|
|
11
|
+
error: typing.Optional[str] = pydantic.Field(default=None)
|
|
12
|
+
"""
|
|
13
|
+
Error message describing what went wrong
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
if IS_PYDANTIC_V2:
|
|
17
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class Config:
|
|
21
|
+
frozen = True
|
|
22
|
+
smart_union = True
|
|
23
|
+
extra = pydantic.Extra.allow
|
phenoml/tools/__init__.py
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
from .types import (
|
|
6
6
|
CohortResponse,
|
|
7
|
+
Lang2FhirAndCreateMultiResponse,
|
|
8
|
+
Lang2FhirAndCreateMultiResponseResourceInfoItem,
|
|
9
|
+
Lang2FhirAndCreateMultiResponseResponseBundle,
|
|
7
10
|
Lang2FhirAndCreateRequestResource,
|
|
8
11
|
Lang2FhirAndCreateResponse,
|
|
9
12
|
Lang2FhirAndSearchResponse,
|
|
@@ -23,6 +26,9 @@ __all__ = [
|
|
|
23
26
|
"FailedDependencyError",
|
|
24
27
|
"ForbiddenError",
|
|
25
28
|
"InternalServerError",
|
|
29
|
+
"Lang2FhirAndCreateMultiResponse",
|
|
30
|
+
"Lang2FhirAndCreateMultiResponseResourceInfoItem",
|
|
31
|
+
"Lang2FhirAndCreateMultiResponseResponseBundle",
|
|
26
32
|
"Lang2FhirAndCreateRequestResource",
|
|
27
33
|
"Lang2FhirAndCreateResponse",
|
|
28
34
|
"Lang2FhirAndSearchResponse",
|
phenoml/tools/client.py
CHANGED
|
@@ -7,6 +7,7 @@ from ..core.request_options import RequestOptions
|
|
|
7
7
|
from .mcp_server.client import AsyncMcpServerClient, McpServerClient
|
|
8
8
|
from .raw_client import AsyncRawToolsClient, RawToolsClient
|
|
9
9
|
from .types.cohort_response import CohortResponse
|
|
10
|
+
from .types.lang2fhir_and_create_multi_response import Lang2FhirAndCreateMultiResponse
|
|
10
11
|
from .types.lang2fhir_and_create_request_resource import Lang2FhirAndCreateRequestResource
|
|
11
12
|
from .types.lang2fhir_and_create_response import Lang2FhirAndCreateResponse
|
|
12
13
|
from .types.lang2fhir_and_search_response import Lang2FhirAndSearchResponse
|
|
@@ -95,6 +96,74 @@ class ToolsClient:
|
|
|
95
96
|
)
|
|
96
97
|
return _response.data
|
|
97
98
|
|
|
99
|
+
def create_fhir_resources_multi(
|
|
100
|
+
self,
|
|
101
|
+
*,
|
|
102
|
+
text: str,
|
|
103
|
+
provider: str,
|
|
104
|
+
phenoml_on_behalf_of: typing.Optional[str] = None,
|
|
105
|
+
phenoml_fhir_provider: typing.Optional[str] = None,
|
|
106
|
+
version: typing.Optional[str] = OMIT,
|
|
107
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
108
|
+
) -> Lang2FhirAndCreateMultiResponse:
|
|
109
|
+
"""
|
|
110
|
+
Extracts multiple FHIR resources from natural language text and stores them in a FHIR server.
|
|
111
|
+
Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types.
|
|
112
|
+
Resources are linked with proper references and submitted as a transaction bundle.
|
|
113
|
+
For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically
|
|
114
|
+
resolve them via PUT requests after the initial bundle creation.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
text : str
|
|
119
|
+
Natural language text containing multiple clinical concepts to extract
|
|
120
|
+
|
|
121
|
+
provider : str
|
|
122
|
+
FHIR provider ID or name
|
|
123
|
+
|
|
124
|
+
phenoml_on_behalf_of : typing.Optional[str]
|
|
125
|
+
Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
|
|
126
|
+
Must be in the format: Patient/{uuid} or Practitioner/{uuid}
|
|
127
|
+
|
|
128
|
+
phenoml_fhir_provider : typing.Optional[str]
|
|
129
|
+
Optional header for FHIR provider authentication. Contains credentials in the format {fhir_provider_id}:{oauth2_token}.
|
|
130
|
+
Multiple FHIR provider integrations can be provided as comma-separated values.
|
|
131
|
+
|
|
132
|
+
version : typing.Optional[str]
|
|
133
|
+
FHIR version to use
|
|
134
|
+
|
|
135
|
+
request_options : typing.Optional[RequestOptions]
|
|
136
|
+
Request-specific configuration.
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
Lang2FhirAndCreateMultiResponse
|
|
141
|
+
Successfully created FHIR resources
|
|
142
|
+
|
|
143
|
+
Examples
|
|
144
|
+
--------
|
|
145
|
+
from phenoml import phenoml
|
|
146
|
+
|
|
147
|
+
client = phenoml(
|
|
148
|
+
token="YOUR_TOKEN",
|
|
149
|
+
)
|
|
150
|
+
client.tools.create_fhir_resources_multi(
|
|
151
|
+
phenoml_on_behalf_of="Patient/550e8400-e29b-41d4-a716-446655440000",
|
|
152
|
+
phenoml_fhir_provider="550e8400-e29b-41d4-a716-446655440000:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c...",
|
|
153
|
+
text="John Smith, 45-year-old male, diagnosed with Type 2 Diabetes. Prescribed Metformin 500mg twice daily.",
|
|
154
|
+
provider="medplum",
|
|
155
|
+
)
|
|
156
|
+
"""
|
|
157
|
+
_response = self._raw_client.create_fhir_resources_multi(
|
|
158
|
+
text=text,
|
|
159
|
+
provider=provider,
|
|
160
|
+
phenoml_on_behalf_of=phenoml_on_behalf_of,
|
|
161
|
+
phenoml_fhir_provider=phenoml_fhir_provider,
|
|
162
|
+
version=version,
|
|
163
|
+
request_options=request_options,
|
|
164
|
+
)
|
|
165
|
+
return _response.data
|
|
166
|
+
|
|
98
167
|
def search_fhir_resources(
|
|
99
168
|
self,
|
|
100
169
|
*,
|
|
@@ -316,6 +385,82 @@ class AsyncToolsClient:
|
|
|
316
385
|
)
|
|
317
386
|
return _response.data
|
|
318
387
|
|
|
388
|
+
async def create_fhir_resources_multi(
|
|
389
|
+
self,
|
|
390
|
+
*,
|
|
391
|
+
text: str,
|
|
392
|
+
provider: str,
|
|
393
|
+
phenoml_on_behalf_of: typing.Optional[str] = None,
|
|
394
|
+
phenoml_fhir_provider: typing.Optional[str] = None,
|
|
395
|
+
version: typing.Optional[str] = OMIT,
|
|
396
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
397
|
+
) -> Lang2FhirAndCreateMultiResponse:
|
|
398
|
+
"""
|
|
399
|
+
Extracts multiple FHIR resources from natural language text and stores them in a FHIR server.
|
|
400
|
+
Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types.
|
|
401
|
+
Resources are linked with proper references and submitted as a transaction bundle.
|
|
402
|
+
For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically
|
|
403
|
+
resolve them via PUT requests after the initial bundle creation.
|
|
404
|
+
|
|
405
|
+
Parameters
|
|
406
|
+
----------
|
|
407
|
+
text : str
|
|
408
|
+
Natural language text containing multiple clinical concepts to extract
|
|
409
|
+
|
|
410
|
+
provider : str
|
|
411
|
+
FHIR provider ID or name
|
|
412
|
+
|
|
413
|
+
phenoml_on_behalf_of : typing.Optional[str]
|
|
414
|
+
Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
|
|
415
|
+
Must be in the format: Patient/{uuid} or Practitioner/{uuid}
|
|
416
|
+
|
|
417
|
+
phenoml_fhir_provider : typing.Optional[str]
|
|
418
|
+
Optional header for FHIR provider authentication. Contains credentials in the format {fhir_provider_id}:{oauth2_token}.
|
|
419
|
+
Multiple FHIR provider integrations can be provided as comma-separated values.
|
|
420
|
+
|
|
421
|
+
version : typing.Optional[str]
|
|
422
|
+
FHIR version to use
|
|
423
|
+
|
|
424
|
+
request_options : typing.Optional[RequestOptions]
|
|
425
|
+
Request-specific configuration.
|
|
426
|
+
|
|
427
|
+
Returns
|
|
428
|
+
-------
|
|
429
|
+
Lang2FhirAndCreateMultiResponse
|
|
430
|
+
Successfully created FHIR resources
|
|
431
|
+
|
|
432
|
+
Examples
|
|
433
|
+
--------
|
|
434
|
+
import asyncio
|
|
435
|
+
|
|
436
|
+
from phenoml import Asyncphenoml
|
|
437
|
+
|
|
438
|
+
client = Asyncphenoml(
|
|
439
|
+
token="YOUR_TOKEN",
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
async def main() -> None:
|
|
444
|
+
await client.tools.create_fhir_resources_multi(
|
|
445
|
+
phenoml_on_behalf_of="Patient/550e8400-e29b-41d4-a716-446655440000",
|
|
446
|
+
phenoml_fhir_provider="550e8400-e29b-41d4-a716-446655440000:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c...",
|
|
447
|
+
text="John Smith, 45-year-old male, diagnosed with Type 2 Diabetes. Prescribed Metformin 500mg twice daily.",
|
|
448
|
+
provider="medplum",
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
asyncio.run(main())
|
|
453
|
+
"""
|
|
454
|
+
_response = await self._raw_client.create_fhir_resources_multi(
|
|
455
|
+
text=text,
|
|
456
|
+
provider=provider,
|
|
457
|
+
phenoml_on_behalf_of=phenoml_on_behalf_of,
|
|
458
|
+
phenoml_fhir_provider=phenoml_fhir_provider,
|
|
459
|
+
version=version,
|
|
460
|
+
request_options=request_options,
|
|
461
|
+
)
|
|
462
|
+
return _response.data
|
|
463
|
+
|
|
319
464
|
async def search_fhir_resources(
|
|
320
465
|
self,
|
|
321
466
|
*,
|
phenoml/tools/raw_client.py
CHANGED
|
@@ -14,6 +14,7 @@ from .errors.forbidden_error import ForbiddenError
|
|
|
14
14
|
from .errors.internal_server_error import InternalServerError
|
|
15
15
|
from .errors.unauthorized_error import UnauthorizedError
|
|
16
16
|
from .types.cohort_response import CohortResponse
|
|
17
|
+
from .types.lang2fhir_and_create_multi_response import Lang2FhirAndCreateMultiResponse
|
|
17
18
|
from .types.lang2fhir_and_create_request_resource import Lang2FhirAndCreateRequestResource
|
|
18
19
|
from .types.lang2fhir_and_create_response import Lang2FhirAndCreateResponse
|
|
19
20
|
from .types.lang2fhir_and_search_response import Lang2FhirAndSearchResponse
|
|
@@ -152,6 +153,136 @@ class RawToolsClient:
|
|
|
152
153
|
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
153
154
|
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
154
155
|
|
|
156
|
+
def create_fhir_resources_multi(
|
|
157
|
+
self,
|
|
158
|
+
*,
|
|
159
|
+
text: str,
|
|
160
|
+
provider: str,
|
|
161
|
+
phenoml_on_behalf_of: typing.Optional[str] = None,
|
|
162
|
+
phenoml_fhir_provider: typing.Optional[str] = None,
|
|
163
|
+
version: typing.Optional[str] = OMIT,
|
|
164
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
165
|
+
) -> HttpResponse[Lang2FhirAndCreateMultiResponse]:
|
|
166
|
+
"""
|
|
167
|
+
Extracts multiple FHIR resources from natural language text and stores them in a FHIR server.
|
|
168
|
+
Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types.
|
|
169
|
+
Resources are linked with proper references and submitted as a transaction bundle.
|
|
170
|
+
For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically
|
|
171
|
+
resolve them via PUT requests after the initial bundle creation.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
text : str
|
|
176
|
+
Natural language text containing multiple clinical concepts to extract
|
|
177
|
+
|
|
178
|
+
provider : str
|
|
179
|
+
FHIR provider ID or name
|
|
180
|
+
|
|
181
|
+
phenoml_on_behalf_of : typing.Optional[str]
|
|
182
|
+
Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
|
|
183
|
+
Must be in the format: Patient/{uuid} or Practitioner/{uuid}
|
|
184
|
+
|
|
185
|
+
phenoml_fhir_provider : typing.Optional[str]
|
|
186
|
+
Optional header for FHIR provider authentication. Contains credentials in the format {fhir_provider_id}:{oauth2_token}.
|
|
187
|
+
Multiple FHIR provider integrations can be provided as comma-separated values.
|
|
188
|
+
|
|
189
|
+
version : typing.Optional[str]
|
|
190
|
+
FHIR version to use
|
|
191
|
+
|
|
192
|
+
request_options : typing.Optional[RequestOptions]
|
|
193
|
+
Request-specific configuration.
|
|
194
|
+
|
|
195
|
+
Returns
|
|
196
|
+
-------
|
|
197
|
+
HttpResponse[Lang2FhirAndCreateMultiResponse]
|
|
198
|
+
Successfully created FHIR resources
|
|
199
|
+
"""
|
|
200
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
201
|
+
"tools/lang2fhir-and-create-multi",
|
|
202
|
+
method="POST",
|
|
203
|
+
json={
|
|
204
|
+
"text": text,
|
|
205
|
+
"version": version,
|
|
206
|
+
"provider": provider,
|
|
207
|
+
},
|
|
208
|
+
headers={
|
|
209
|
+
"content-type": "application/json",
|
|
210
|
+
"X-Phenoml-On-Behalf-Of": str(phenoml_on_behalf_of) if phenoml_on_behalf_of is not None else None,
|
|
211
|
+
"X-Phenoml-Fhir-Provider": str(phenoml_fhir_provider) if phenoml_fhir_provider is not None else None,
|
|
212
|
+
},
|
|
213
|
+
request_options=request_options,
|
|
214
|
+
omit=OMIT,
|
|
215
|
+
)
|
|
216
|
+
try:
|
|
217
|
+
if 200 <= _response.status_code < 300:
|
|
218
|
+
_data = typing.cast(
|
|
219
|
+
Lang2FhirAndCreateMultiResponse,
|
|
220
|
+
parse_obj_as(
|
|
221
|
+
type_=Lang2FhirAndCreateMultiResponse, # type: ignore
|
|
222
|
+
object_=_response.json(),
|
|
223
|
+
),
|
|
224
|
+
)
|
|
225
|
+
return HttpResponse(response=_response, data=_data)
|
|
226
|
+
if _response.status_code == 400:
|
|
227
|
+
raise BadRequestError(
|
|
228
|
+
headers=dict(_response.headers),
|
|
229
|
+
body=typing.cast(
|
|
230
|
+
typing.Optional[typing.Any],
|
|
231
|
+
parse_obj_as(
|
|
232
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
233
|
+
object_=_response.json(),
|
|
234
|
+
),
|
|
235
|
+
),
|
|
236
|
+
)
|
|
237
|
+
if _response.status_code == 401:
|
|
238
|
+
raise UnauthorizedError(
|
|
239
|
+
headers=dict(_response.headers),
|
|
240
|
+
body=typing.cast(
|
|
241
|
+
typing.Optional[typing.Any],
|
|
242
|
+
parse_obj_as(
|
|
243
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
244
|
+
object_=_response.json(),
|
|
245
|
+
),
|
|
246
|
+
),
|
|
247
|
+
)
|
|
248
|
+
if _response.status_code == 403:
|
|
249
|
+
raise ForbiddenError(
|
|
250
|
+
headers=dict(_response.headers),
|
|
251
|
+
body=typing.cast(
|
|
252
|
+
typing.Optional[typing.Any],
|
|
253
|
+
parse_obj_as(
|
|
254
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
255
|
+
object_=_response.json(),
|
|
256
|
+
),
|
|
257
|
+
),
|
|
258
|
+
)
|
|
259
|
+
if _response.status_code == 424:
|
|
260
|
+
raise FailedDependencyError(
|
|
261
|
+
headers=dict(_response.headers),
|
|
262
|
+
body=typing.cast(
|
|
263
|
+
typing.Optional[typing.Any],
|
|
264
|
+
parse_obj_as(
|
|
265
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
266
|
+
object_=_response.json(),
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
if _response.status_code == 500:
|
|
271
|
+
raise InternalServerError(
|
|
272
|
+
headers=dict(_response.headers),
|
|
273
|
+
body=typing.cast(
|
|
274
|
+
typing.Optional[typing.Any],
|
|
275
|
+
parse_obj_as(
|
|
276
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
277
|
+
object_=_response.json(),
|
|
278
|
+
),
|
|
279
|
+
),
|
|
280
|
+
)
|
|
281
|
+
_response_json = _response.json()
|
|
282
|
+
except JSONDecodeError:
|
|
283
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
284
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
285
|
+
|
|
155
286
|
def search_fhir_resources(
|
|
156
287
|
self,
|
|
157
288
|
*,
|
|
@@ -529,6 +660,136 @@ class AsyncRawToolsClient:
|
|
|
529
660
|
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
530
661
|
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
531
662
|
|
|
663
|
+
async def create_fhir_resources_multi(
|
|
664
|
+
self,
|
|
665
|
+
*,
|
|
666
|
+
text: str,
|
|
667
|
+
provider: str,
|
|
668
|
+
phenoml_on_behalf_of: typing.Optional[str] = None,
|
|
669
|
+
phenoml_fhir_provider: typing.Optional[str] = None,
|
|
670
|
+
version: typing.Optional[str] = OMIT,
|
|
671
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
672
|
+
) -> AsyncHttpResponse[Lang2FhirAndCreateMultiResponse]:
|
|
673
|
+
"""
|
|
674
|
+
Extracts multiple FHIR resources from natural language text and stores them in a FHIR server.
|
|
675
|
+
Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types.
|
|
676
|
+
Resources are linked with proper references and submitted as a transaction bundle.
|
|
677
|
+
For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically
|
|
678
|
+
resolve them via PUT requests after the initial bundle creation.
|
|
679
|
+
|
|
680
|
+
Parameters
|
|
681
|
+
----------
|
|
682
|
+
text : str
|
|
683
|
+
Natural language text containing multiple clinical concepts to extract
|
|
684
|
+
|
|
685
|
+
provider : str
|
|
686
|
+
FHIR provider ID or name
|
|
687
|
+
|
|
688
|
+
phenoml_on_behalf_of : typing.Optional[str]
|
|
689
|
+
Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
|
|
690
|
+
Must be in the format: Patient/{uuid} or Practitioner/{uuid}
|
|
691
|
+
|
|
692
|
+
phenoml_fhir_provider : typing.Optional[str]
|
|
693
|
+
Optional header for FHIR provider authentication. Contains credentials in the format {fhir_provider_id}:{oauth2_token}.
|
|
694
|
+
Multiple FHIR provider integrations can be provided as comma-separated values.
|
|
695
|
+
|
|
696
|
+
version : typing.Optional[str]
|
|
697
|
+
FHIR version to use
|
|
698
|
+
|
|
699
|
+
request_options : typing.Optional[RequestOptions]
|
|
700
|
+
Request-specific configuration.
|
|
701
|
+
|
|
702
|
+
Returns
|
|
703
|
+
-------
|
|
704
|
+
AsyncHttpResponse[Lang2FhirAndCreateMultiResponse]
|
|
705
|
+
Successfully created FHIR resources
|
|
706
|
+
"""
|
|
707
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
708
|
+
"tools/lang2fhir-and-create-multi",
|
|
709
|
+
method="POST",
|
|
710
|
+
json={
|
|
711
|
+
"text": text,
|
|
712
|
+
"version": version,
|
|
713
|
+
"provider": provider,
|
|
714
|
+
},
|
|
715
|
+
headers={
|
|
716
|
+
"content-type": "application/json",
|
|
717
|
+
"X-Phenoml-On-Behalf-Of": str(phenoml_on_behalf_of) if phenoml_on_behalf_of is not None else None,
|
|
718
|
+
"X-Phenoml-Fhir-Provider": str(phenoml_fhir_provider) if phenoml_fhir_provider is not None else None,
|
|
719
|
+
},
|
|
720
|
+
request_options=request_options,
|
|
721
|
+
omit=OMIT,
|
|
722
|
+
)
|
|
723
|
+
try:
|
|
724
|
+
if 200 <= _response.status_code < 300:
|
|
725
|
+
_data = typing.cast(
|
|
726
|
+
Lang2FhirAndCreateMultiResponse,
|
|
727
|
+
parse_obj_as(
|
|
728
|
+
type_=Lang2FhirAndCreateMultiResponse, # type: ignore
|
|
729
|
+
object_=_response.json(),
|
|
730
|
+
),
|
|
731
|
+
)
|
|
732
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
733
|
+
if _response.status_code == 400:
|
|
734
|
+
raise BadRequestError(
|
|
735
|
+
headers=dict(_response.headers),
|
|
736
|
+
body=typing.cast(
|
|
737
|
+
typing.Optional[typing.Any],
|
|
738
|
+
parse_obj_as(
|
|
739
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
740
|
+
object_=_response.json(),
|
|
741
|
+
),
|
|
742
|
+
),
|
|
743
|
+
)
|
|
744
|
+
if _response.status_code == 401:
|
|
745
|
+
raise UnauthorizedError(
|
|
746
|
+
headers=dict(_response.headers),
|
|
747
|
+
body=typing.cast(
|
|
748
|
+
typing.Optional[typing.Any],
|
|
749
|
+
parse_obj_as(
|
|
750
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
751
|
+
object_=_response.json(),
|
|
752
|
+
),
|
|
753
|
+
),
|
|
754
|
+
)
|
|
755
|
+
if _response.status_code == 403:
|
|
756
|
+
raise ForbiddenError(
|
|
757
|
+
headers=dict(_response.headers),
|
|
758
|
+
body=typing.cast(
|
|
759
|
+
typing.Optional[typing.Any],
|
|
760
|
+
parse_obj_as(
|
|
761
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
762
|
+
object_=_response.json(),
|
|
763
|
+
),
|
|
764
|
+
),
|
|
765
|
+
)
|
|
766
|
+
if _response.status_code == 424:
|
|
767
|
+
raise FailedDependencyError(
|
|
768
|
+
headers=dict(_response.headers),
|
|
769
|
+
body=typing.cast(
|
|
770
|
+
typing.Optional[typing.Any],
|
|
771
|
+
parse_obj_as(
|
|
772
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
773
|
+
object_=_response.json(),
|
|
774
|
+
),
|
|
775
|
+
),
|
|
776
|
+
)
|
|
777
|
+
if _response.status_code == 500:
|
|
778
|
+
raise InternalServerError(
|
|
779
|
+
headers=dict(_response.headers),
|
|
780
|
+
body=typing.cast(
|
|
781
|
+
typing.Optional[typing.Any],
|
|
782
|
+
parse_obj_as(
|
|
783
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
784
|
+
object_=_response.json(),
|
|
785
|
+
),
|
|
786
|
+
),
|
|
787
|
+
)
|
|
788
|
+
_response_json = _response.json()
|
|
789
|
+
except JSONDecodeError:
|
|
790
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
791
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
792
|
+
|
|
532
793
|
async def search_fhir_resources(
|
|
533
794
|
self,
|
|
534
795
|
*,
|
phenoml/tools/types/__init__.py
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
# isort: skip_file
|
|
4
4
|
|
|
5
5
|
from .cohort_response import CohortResponse
|
|
6
|
+
from .lang2fhir_and_create_multi_response import Lang2FhirAndCreateMultiResponse
|
|
7
|
+
from .lang2fhir_and_create_multi_response_resource_info_item import Lang2FhirAndCreateMultiResponseResourceInfoItem
|
|
8
|
+
from .lang2fhir_and_create_multi_response_response_bundle import Lang2FhirAndCreateMultiResponseResponseBundle
|
|
6
9
|
from .lang2fhir_and_create_request_resource import Lang2FhirAndCreateRequestResource
|
|
7
10
|
from .lang2fhir_and_create_response import Lang2FhirAndCreateResponse
|
|
8
11
|
from .lang2fhir_and_search_response import Lang2FhirAndSearchResponse
|
|
@@ -15,6 +18,9 @@ from .search_concept import SearchConcept
|
|
|
15
18
|
|
|
16
19
|
__all__ = [
|
|
17
20
|
"CohortResponse",
|
|
21
|
+
"Lang2FhirAndCreateMultiResponse",
|
|
22
|
+
"Lang2FhirAndCreateMultiResponseResourceInfoItem",
|
|
23
|
+
"Lang2FhirAndCreateMultiResponseResponseBundle",
|
|
18
24
|
"Lang2FhirAndCreateRequestResource",
|
|
19
25
|
"Lang2FhirAndCreateResponse",
|
|
20
26
|
"Lang2FhirAndSearchResponse",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
from .lang2fhir_and_create_multi_response_resource_info_item import Lang2FhirAndCreateMultiResponseResourceInfoItem
|
|
8
|
+
from .lang2fhir_and_create_multi_response_response_bundle import Lang2FhirAndCreateMultiResponseResponseBundle
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Lang2FhirAndCreateMultiResponse(UniversalBaseModel):
|
|
12
|
+
success: typing.Optional[bool] = pydantic.Field(default=None)
|
|
13
|
+
"""
|
|
14
|
+
Whether the resources were created successfully
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
message: typing.Optional[str] = pydantic.Field(default=None)
|
|
18
|
+
"""
|
|
19
|
+
Status message
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
response_bundle: typing.Optional[Lang2FhirAndCreateMultiResponseResponseBundle] = pydantic.Field(default=None)
|
|
23
|
+
"""
|
|
24
|
+
FHIR transaction-response Bundle from the server with resolved resource IDs
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
resource_info: typing.Optional[typing.List[Lang2FhirAndCreateMultiResponseResourceInfoItem]] = pydantic.Field(
|
|
28
|
+
default=None
|
|
29
|
+
)
|
|
30
|
+
"""
|
|
31
|
+
Metadata about created resources (temp IDs, types, descriptions)
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
if IS_PYDANTIC_V2:
|
|
35
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
36
|
+
else:
|
|
37
|
+
|
|
38
|
+
class Config:
|
|
39
|
+
frozen = True
|
|
40
|
+
smart_union = True
|
|
41
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
import typing_extensions
|
|
7
|
+
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
8
|
+
from ...core.serialization import FieldMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Lang2FhirAndCreateMultiResponseResourceInfoItem(UniversalBaseModel):
|
|
12
|
+
temp_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="tempId")] = pydantic.Field(
|
|
13
|
+
default=None
|
|
14
|
+
)
|
|
15
|
+
"""
|
|
16
|
+
Original temporary UUID
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
resource_type: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="resourceType")] = (
|
|
20
|
+
pydantic.Field(default=None)
|
|
21
|
+
)
|
|
22
|
+
"""
|
|
23
|
+
FHIR resource type
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
description: typing.Optional[str] = pydantic.Field(default=None)
|
|
27
|
+
"""
|
|
28
|
+
Text excerpt this resource was extracted from
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
if IS_PYDANTIC_V2:
|
|
32
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
33
|
+
else:
|
|
34
|
+
|
|
35
|
+
class Config:
|
|
36
|
+
frozen = True
|
|
37
|
+
smart_union = True
|
|
38
|
+
extra = pydantic.Extra.allow
|