phenoml 0.0.2__py3-none-any.whl → 0.0.5__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.

Files changed (68) hide show
  1. phenoml/agent/__init__.py +6 -8
  2. phenoml/agent/client.py +45 -75
  3. phenoml/agent/raw_client.py +37 -77
  4. phenoml/agent/types/__init__.py +6 -8
  5. phenoml/agent/types/agent_create_request.py +53 -0
  6. phenoml/agent/types/agent_create_request_provider.py +5 -0
  7. phenoml/agent/types/agent_template.py +3 -6
  8. phenoml/agent/types/agent_template_provider.py +5 -0
  9. phenoml/client.py +6 -0
  10. phenoml/core/client_wrapper.py +2 -2
  11. phenoml/fhir/__init__.py +36 -0
  12. phenoml/fhir/client.py +970 -0
  13. phenoml/fhir/errors/__init__.py +10 -0
  14. phenoml/fhir/errors/bad_request_error.py +10 -0
  15. phenoml/fhir/errors/internal_server_error.py +10 -0
  16. phenoml/fhir/errors/not_found_error.py +10 -0
  17. phenoml/fhir/errors/unauthorized_error.py +10 -0
  18. phenoml/fhir/raw_client.py +1385 -0
  19. phenoml/fhir/types/__init__.py +29 -0
  20. phenoml/{agent/types/chat_fhir_client_config.py → fhir/types/error_response.py} +11 -6
  21. phenoml/fhir/types/fhir_bundle.py +43 -0
  22. phenoml/fhir/types/fhir_bundle_entry_item.py +34 -0
  23. phenoml/{agent/types/agent_fhir_config.py → fhir/types/fhir_bundle_entry_item_request.py} +5 -11
  24. phenoml/fhir/types/fhir_bundle_entry_item_request_method.py +5 -0
  25. phenoml/fhir/types/fhir_bundle_entry_item_response.py +24 -0
  26. phenoml/fhir/types/fhir_patch_request_body_item.py +36 -0
  27. phenoml/fhir/types/fhir_patch_request_body_item_op.py +7 -0
  28. phenoml/fhir/types/fhir_resource.py +40 -0
  29. phenoml/fhir/types/fhir_resource_meta.py +28 -0
  30. phenoml/fhir/types/fhir_search_response.py +8 -0
  31. phenoml/fhir_provider/__init__.py +43 -0
  32. phenoml/fhir_provider/client.py +731 -0
  33. phenoml/fhir_provider/errors/__init__.py +11 -0
  34. phenoml/fhir_provider/errors/bad_request_error.py +10 -0
  35. phenoml/fhir_provider/errors/forbidden_error.py +10 -0
  36. phenoml/fhir_provider/errors/internal_server_error.py +10 -0
  37. phenoml/fhir_provider/errors/not_found_error.py +10 -0
  38. phenoml/fhir_provider/errors/unauthorized_error.py +10 -0
  39. phenoml/fhir_provider/raw_client.py +1445 -0
  40. phenoml/fhir_provider/types/__init__.py +35 -0
  41. phenoml/fhir_provider/types/auth_method.py +7 -0
  42. phenoml/fhir_provider/types/fhir_provider_auth_config.py +53 -0
  43. phenoml/fhir_provider/types/fhir_provider_delete_response.py +20 -0
  44. phenoml/fhir_provider/types/fhir_provider_list_response.py +22 -0
  45. phenoml/fhir_provider/types/fhir_provider_remove_auth_config_response.py +22 -0
  46. phenoml/fhir_provider/types/fhir_provider_response.py +22 -0
  47. phenoml/fhir_provider/types/fhir_provider_set_active_auth_config_response.py +22 -0
  48. phenoml/fhir_provider/types/fhir_provider_template.py +66 -0
  49. phenoml/fhir_provider/types/fhir_query_response.py +27 -0
  50. phenoml/fhir_provider/types/fhir_query_response_data.py +5 -0
  51. phenoml/fhir_provider/types/json_web_key.py +51 -0
  52. phenoml/fhir_provider/types/provider.py +8 -0
  53. phenoml/fhir_provider/types/service_account_key.py +35 -0
  54. phenoml/fhir_provider/types/smart_configuration.py +46 -0
  55. phenoml/tools/__init__.py +0 -8
  56. phenoml/tools/client.py +24 -60
  57. phenoml/tools/raw_client.py +18 -67
  58. phenoml/tools/types/__init__.py +0 -8
  59. phenoml-0.0.5.dist-info/LICENSE +21 -0
  60. {phenoml-0.0.2.dist-info → phenoml-0.0.5.dist-info}/METADATA +1 -1
  61. {phenoml-0.0.2.dist-info → phenoml-0.0.5.dist-info}/RECORD +62 -22
  62. phenoml/agent/types/agent_provider.py +0 -7
  63. phenoml/agent/types/provider_type.py +0 -5
  64. phenoml/tools/types/cohort_request_provider.py +0 -5
  65. phenoml/tools/types/fhir_client_config.py +0 -31
  66. phenoml/tools/types/lang2fhir_and_create_request_provider.py +0 -7
  67. phenoml/tools/types/lang2fhir_and_search_request_provider.py +0 -7
  68. {phenoml-0.0.2.dist-info → phenoml-0.0.5.dist-info}/WHEEL +0 -0
phenoml/fhir/client.py ADDED
@@ -0,0 +1,970 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6
+ from ..core.request_options import RequestOptions
7
+ from .raw_client import AsyncRawFhirClient, RawFhirClient
8
+ from .types.fhir_bundle import FhirBundle
9
+ from .types.fhir_bundle_entry_item import FhirBundleEntryItem
10
+ from .types.fhir_patch_request_body_item import FhirPatchRequestBodyItem
11
+ from .types.fhir_resource import FhirResource
12
+ from .types.fhir_resource_meta import FhirResourceMeta
13
+ from .types.fhir_search_response import FhirSearchResponse
14
+
15
+ # this is used as the default value for optional parameters
16
+ OMIT = typing.cast(typing.Any, ...)
17
+
18
+
19
+ class FhirClient:
20
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
21
+ self._raw_client = RawFhirClient(client_wrapper=client_wrapper)
22
+
23
+ @property
24
+ def with_raw_response(self) -> RawFhirClient:
25
+ """
26
+ Retrieves a raw implementation of this client that returns raw responses.
27
+
28
+ Returns
29
+ -------
30
+ RawFhirClient
31
+ """
32
+ return self._raw_client
33
+
34
+ def search(
35
+ self,
36
+ fhir_provider_id: str,
37
+ fhir_path: str,
38
+ *,
39
+ query_parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
40
+ phenoml_on_behalf_of: typing.Optional[str] = None,
41
+ request_options: typing.Optional[RequestOptions] = None,
42
+ ) -> FhirSearchResponse:
43
+ """
44
+ Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters.
45
+
46
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
47
+
48
+ Parameters
49
+ ----------
50
+ fhir_provider_id : str
51
+ The ID of the FHIR provider to use. Can be either:
52
+ - A UUID representing the provider ID
53
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
54
+
55
+ fhir_path : str
56
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
57
+ Examples:
58
+ - "Patient" (for resource type operations)
59
+ - "Patient/123" (for specific resource operations)
60
+ - "Patient/123/_history" (for history operations)
61
+
62
+ query_parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
63
+ FHIR-compliant query parameters for search operations. Supports standard FHIR search parameters including:
64
+ - Resource-specific search parameters (e.g., name for Patient, status for Observation)
65
+ - Common search parameters (_id, _lastUpdated, _tag, _profile, _security, _text, _content, _filter)
66
+ - Result parameters (_count, _offset, _sort, _include, _revinclude, _summary, _elements)
67
+ - Search prefixes for dates, numbers, quantities (eq, ne, gt, ge, lt, le, sa, eb, ap)
68
+
69
+ phenoml_on_behalf_of : typing.Optional[str]
70
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
71
+
72
+ request_options : typing.Optional[RequestOptions]
73
+ Request-specific configuration.
74
+
75
+ Returns
76
+ -------
77
+ FhirSearchResponse
78
+ Successfully retrieved FHIR resource(s)
79
+
80
+ Examples
81
+ --------
82
+ from phenoml import phenoml
83
+
84
+ client = phenoml(
85
+ token="YOUR_TOKEN",
86
+ )
87
+ client.fhir.search(
88
+ fhir_provider_id="fhir_provider_id",
89
+ fhir_path="fhir_path",
90
+ phenoml_on_behalf_of="user@example.com",
91
+ )
92
+ """
93
+ _response = self._raw_client.search(
94
+ fhir_provider_id,
95
+ fhir_path,
96
+ query_parameters=query_parameters,
97
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
98
+ request_options=request_options,
99
+ )
100
+ return _response.data
101
+
102
+ def create(
103
+ self,
104
+ fhir_provider_id: str,
105
+ fhir_path: str,
106
+ *,
107
+ resource_type: str,
108
+ phenoml_on_behalf_of: typing.Optional[str] = None,
109
+ id: typing.Optional[str] = OMIT,
110
+ meta: typing.Optional[FhirResourceMeta] = OMIT,
111
+ request_options: typing.Optional[RequestOptions] = None,
112
+ ) -> FhirResource:
113
+ """
114
+ Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format.
115
+
116
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
117
+
118
+ Parameters
119
+ ----------
120
+ fhir_provider_id : str
121
+ The ID of the FHIR provider to use. Can be either:
122
+ - A UUID representing the provider ID
123
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
124
+
125
+ fhir_path : str
126
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
127
+ Examples:
128
+ - "Patient" (for resource type operations)
129
+ - "Patient/123" (for specific resource operations)
130
+ - "Patient/123/_history" (for history operations)
131
+
132
+ resource_type : str
133
+ The type of FHIR resource (e.g., Patient, Observation, etc.)
134
+
135
+ phenoml_on_behalf_of : typing.Optional[str]
136
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
137
+
138
+ id : typing.Optional[str]
139
+ Logical ID of the resource
140
+
141
+ meta : typing.Optional[FhirResourceMeta]
142
+ Metadata about the resource
143
+
144
+ request_options : typing.Optional[RequestOptions]
145
+ Request-specific configuration.
146
+
147
+ Returns
148
+ -------
149
+ FhirResource
150
+ Resource created successfully
151
+
152
+ Examples
153
+ --------
154
+ from phenoml import phenoml
155
+
156
+ client = phenoml(
157
+ token="YOUR_TOKEN",
158
+ )
159
+ client.fhir.create(
160
+ fhir_provider_id="fhir_provider_id",
161
+ fhir_path="fhir_path",
162
+ phenoml_on_behalf_of="user@example.com",
163
+ resource_type="Patient",
164
+ )
165
+ """
166
+ _response = self._raw_client.create(
167
+ fhir_provider_id,
168
+ fhir_path,
169
+ resource_type=resource_type,
170
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
171
+ id=id,
172
+ meta=meta,
173
+ request_options=request_options,
174
+ )
175
+ return _response.data
176
+
177
+ def upsert(
178
+ self,
179
+ fhir_provider_id: str,
180
+ fhir_path: str,
181
+ *,
182
+ resource_type: str,
183
+ phenoml_on_behalf_of: typing.Optional[str] = None,
184
+ id: typing.Optional[str] = OMIT,
185
+ meta: typing.Optional[FhirResourceMeta] = OMIT,
186
+ request_options: typing.Optional[RequestOptions] = None,
187
+ ) -> FhirResource:
188
+ """
189
+ Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created.
190
+
191
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
192
+
193
+ Parameters
194
+ ----------
195
+ fhir_provider_id : str
196
+ The ID of the FHIR provider to use. Can be either:
197
+ - A UUID representing the provider ID
198
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
199
+
200
+ fhir_path : str
201
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
202
+ Examples:
203
+ - "Patient" (for resource type operations)
204
+ - "Patient/123" (for specific resource operations)
205
+ - "Patient/123/_history" (for history operations)
206
+
207
+ resource_type : str
208
+ The type of FHIR resource (e.g., Patient, Observation, etc.)
209
+
210
+ phenoml_on_behalf_of : typing.Optional[str]
211
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
212
+
213
+ id : typing.Optional[str]
214
+ Logical ID of the resource
215
+
216
+ meta : typing.Optional[FhirResourceMeta]
217
+ Metadata about the resource
218
+
219
+ request_options : typing.Optional[RequestOptions]
220
+ Request-specific configuration.
221
+
222
+ Returns
223
+ -------
224
+ FhirResource
225
+ Resource upserted successfully
226
+
227
+ Examples
228
+ --------
229
+ from phenoml import phenoml
230
+
231
+ client = phenoml(
232
+ token="YOUR_TOKEN",
233
+ )
234
+ client.fhir.upsert(
235
+ fhir_provider_id="fhir_provider_id",
236
+ fhir_path="fhir_path",
237
+ phenoml_on_behalf_of="user@example.com",
238
+ resource_type="Patient",
239
+ id="123",
240
+ )
241
+ """
242
+ _response = self._raw_client.upsert(
243
+ fhir_provider_id,
244
+ fhir_path,
245
+ resource_type=resource_type,
246
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
247
+ id=id,
248
+ meta=meta,
249
+ request_options=request_options,
250
+ )
251
+ return _response.data
252
+
253
+ def delete(
254
+ self,
255
+ fhir_provider_id: str,
256
+ fhir_path: str,
257
+ *,
258
+ phenoml_on_behalf_of: typing.Optional[str] = None,
259
+ request_options: typing.Optional[RequestOptions] = None,
260
+ ) -> typing.Dict[str, typing.Optional[typing.Any]]:
261
+ """
262
+ Deletes a FHIR resource from the specified provider.
263
+
264
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
265
+
266
+ Parameters
267
+ ----------
268
+ fhir_provider_id : str
269
+ The ID of the FHIR provider to use. Can be either:
270
+ - A UUID representing the provider ID
271
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
272
+
273
+ fhir_path : str
274
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
275
+ Examples:
276
+ - "Patient" (for resource type operations)
277
+ - "Patient/123" (for specific resource operations)
278
+ - "Patient/123/_history" (for history operations)
279
+
280
+ phenoml_on_behalf_of : typing.Optional[str]
281
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
282
+
283
+ request_options : typing.Optional[RequestOptions]
284
+ Request-specific configuration.
285
+
286
+ Returns
287
+ -------
288
+ typing.Dict[str, typing.Optional[typing.Any]]
289
+ Resource deleted successfully
290
+
291
+ Examples
292
+ --------
293
+ from phenoml import phenoml
294
+
295
+ client = phenoml(
296
+ token="YOUR_TOKEN",
297
+ )
298
+ client.fhir.delete(
299
+ fhir_provider_id="fhir_provider_id",
300
+ fhir_path="fhir_path",
301
+ phenoml_on_behalf_of="user@example.com",
302
+ )
303
+ """
304
+ _response = self._raw_client.delete(
305
+ fhir_provider_id, fhir_path, phenoml_on_behalf_of=phenoml_on_behalf_of, request_options=request_options
306
+ )
307
+ return _response.data
308
+
309
+ def patch(
310
+ self,
311
+ fhir_provider_id: str,
312
+ fhir_path: str,
313
+ *,
314
+ request: typing.Sequence[FhirPatchRequestBodyItem],
315
+ phenoml_on_behalf_of: typing.Optional[str] = None,
316
+ request_options: typing.Optional[RequestOptions] = None,
317
+ ) -> FhirResource:
318
+ """
319
+ Partially updates a FHIR resource on the specified provider using JSON Patch operations as defined in RFC 6902.
320
+
321
+ The request body should contain an array of JSON Patch operations. Each operation specifies:
322
+ - `op`: The operation type (add, remove, replace, move, copy, test)
323
+ - `path`: JSON Pointer to the target location in the resource
324
+ - `value`: The value to use (required for add, replace, and test operations)
325
+
326
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
327
+
328
+ Parameters
329
+ ----------
330
+ fhir_provider_id : str
331
+ The ID of the FHIR provider to use. Can be either:
332
+ - A UUID representing the provider ID
333
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
334
+
335
+ fhir_path : str
336
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
337
+ Examples:
338
+ - "Patient" (for resource type operations)
339
+ - "Patient/123" (for specific resource operations)
340
+ - "Patient/123/_history" (for history operations)
341
+
342
+ request : typing.Sequence[FhirPatchRequestBodyItem]
343
+
344
+ phenoml_on_behalf_of : typing.Optional[str]
345
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
346
+
347
+ request_options : typing.Optional[RequestOptions]
348
+ Request-specific configuration.
349
+
350
+ Returns
351
+ -------
352
+ FhirResource
353
+ Resource patched successfully
354
+
355
+ Examples
356
+ --------
357
+ from phenoml import phenoml
358
+ from phenoml.fhir import FhirPatchRequestBodyItem
359
+
360
+ client = phenoml(
361
+ token="YOUR_TOKEN",
362
+ )
363
+ client.fhir.patch(
364
+ fhir_provider_id="fhir_provider_id",
365
+ fhir_path="fhir_path",
366
+ phenoml_on_behalf_of="user@example.com",
367
+ request=[
368
+ FhirPatchRequestBodyItem(
369
+ op="replace",
370
+ path="/name/0/family",
371
+ value="NewFamilyName",
372
+ )
373
+ ],
374
+ )
375
+ """
376
+ _response = self._raw_client.patch(
377
+ fhir_provider_id,
378
+ fhir_path,
379
+ request=request,
380
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
381
+ request_options=request_options,
382
+ )
383
+ return _response.data
384
+
385
+ def execute_bundle(
386
+ self,
387
+ fhir_provider_id: str,
388
+ *,
389
+ entry: typing.Sequence[FhirBundleEntryItem],
390
+ phenoml_on_behalf_of: typing.Optional[str] = None,
391
+ total: typing.Optional[int] = OMIT,
392
+ request_options: typing.Optional[RequestOptions] = None,
393
+ ) -> FhirBundle:
394
+ """
395
+ Executes a FHIR Bundle transaction or batch operation on the specified provider. This allows multiple FHIR resources to be processed in a single request.
396
+
397
+ The request body should contain a valid FHIR Bundle resource with transaction or batch type.
398
+
399
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
400
+
401
+ Parameters
402
+ ----------
403
+ fhir_provider_id : str
404
+ The ID of the FHIR provider to use. Can be either:
405
+ - A UUID representing the provider ID
406
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
407
+
408
+ entry : typing.Sequence[FhirBundleEntryItem]
409
+ Array of bundle entries containing resources or operation results
410
+
411
+ phenoml_on_behalf_of : typing.Optional[str]
412
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
413
+
414
+ total : typing.Optional[int]
415
+ Total number of resources that match the search criteria.
416
+ Optional field as not all FHIR servers include it (e.g., Medplum).
417
+
418
+ request_options : typing.Optional[RequestOptions]
419
+ Request-specific configuration.
420
+
421
+ Returns
422
+ -------
423
+ FhirBundle
424
+ Bundle executed successfully
425
+
426
+ Examples
427
+ --------
428
+ from phenoml import phenoml
429
+ from phenoml.fhir import FhirBundleEntryItem, FhirBundleEntryItemRequest
430
+
431
+ client = phenoml(
432
+ token="YOUR_TOKEN",
433
+ )
434
+ client.fhir.execute_bundle(
435
+ fhir_provider_id="fhir_provider_id",
436
+ phenoml_on_behalf_of="user@example.com",
437
+ entry=[
438
+ FhirBundleEntryItem(
439
+ resource={
440
+ "resourceType": "Patient",
441
+ "name": [{"family": "Doe", "given": ["John"]}],
442
+ },
443
+ request=FhirBundleEntryItemRequest(
444
+ method="POST",
445
+ url="Patient",
446
+ ),
447
+ ),
448
+ FhirBundleEntryItem(
449
+ resource={
450
+ "resourceType": "Observation",
451
+ "status": "final",
452
+ "subject": {"reference": "Patient/123"},
453
+ },
454
+ request=FhirBundleEntryItemRequest(
455
+ method="POST",
456
+ url="Observation",
457
+ ),
458
+ ),
459
+ ],
460
+ )
461
+ """
462
+ _response = self._raw_client.execute_bundle(
463
+ fhir_provider_id,
464
+ entry=entry,
465
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
466
+ total=total,
467
+ request_options=request_options,
468
+ )
469
+ return _response.data
470
+
471
+
472
+ class AsyncFhirClient:
473
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
474
+ self._raw_client = AsyncRawFhirClient(client_wrapper=client_wrapper)
475
+
476
+ @property
477
+ def with_raw_response(self) -> AsyncRawFhirClient:
478
+ """
479
+ Retrieves a raw implementation of this client that returns raw responses.
480
+
481
+ Returns
482
+ -------
483
+ AsyncRawFhirClient
484
+ """
485
+ return self._raw_client
486
+
487
+ async def search(
488
+ self,
489
+ fhir_provider_id: str,
490
+ fhir_path: str,
491
+ *,
492
+ query_parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
493
+ phenoml_on_behalf_of: typing.Optional[str] = None,
494
+ request_options: typing.Optional[RequestOptions] = None,
495
+ ) -> FhirSearchResponse:
496
+ """
497
+ Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters.
498
+
499
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
500
+
501
+ Parameters
502
+ ----------
503
+ fhir_provider_id : str
504
+ The ID of the FHIR provider to use. Can be either:
505
+ - A UUID representing the provider ID
506
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
507
+
508
+ fhir_path : str
509
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
510
+ Examples:
511
+ - "Patient" (for resource type operations)
512
+ - "Patient/123" (for specific resource operations)
513
+ - "Patient/123/_history" (for history operations)
514
+
515
+ query_parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
516
+ FHIR-compliant query parameters for search operations. Supports standard FHIR search parameters including:
517
+ - Resource-specific search parameters (e.g., name for Patient, status for Observation)
518
+ - Common search parameters (_id, _lastUpdated, _tag, _profile, _security, _text, _content, _filter)
519
+ - Result parameters (_count, _offset, _sort, _include, _revinclude, _summary, _elements)
520
+ - Search prefixes for dates, numbers, quantities (eq, ne, gt, ge, lt, le, sa, eb, ap)
521
+
522
+ phenoml_on_behalf_of : typing.Optional[str]
523
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
524
+
525
+ request_options : typing.Optional[RequestOptions]
526
+ Request-specific configuration.
527
+
528
+ Returns
529
+ -------
530
+ FhirSearchResponse
531
+ Successfully retrieved FHIR resource(s)
532
+
533
+ Examples
534
+ --------
535
+ import asyncio
536
+
537
+ from phenoml import Asyncphenoml
538
+
539
+ client = Asyncphenoml(
540
+ token="YOUR_TOKEN",
541
+ )
542
+
543
+
544
+ async def main() -> None:
545
+ await client.fhir.search(
546
+ fhir_provider_id="fhir_provider_id",
547
+ fhir_path="fhir_path",
548
+ phenoml_on_behalf_of="user@example.com",
549
+ )
550
+
551
+
552
+ asyncio.run(main())
553
+ """
554
+ _response = await self._raw_client.search(
555
+ fhir_provider_id,
556
+ fhir_path,
557
+ query_parameters=query_parameters,
558
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
559
+ request_options=request_options,
560
+ )
561
+ return _response.data
562
+
563
+ async def create(
564
+ self,
565
+ fhir_provider_id: str,
566
+ fhir_path: str,
567
+ *,
568
+ resource_type: str,
569
+ phenoml_on_behalf_of: typing.Optional[str] = None,
570
+ id: typing.Optional[str] = OMIT,
571
+ meta: typing.Optional[FhirResourceMeta] = OMIT,
572
+ request_options: typing.Optional[RequestOptions] = None,
573
+ ) -> FhirResource:
574
+ """
575
+ Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format.
576
+
577
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
578
+
579
+ Parameters
580
+ ----------
581
+ fhir_provider_id : str
582
+ The ID of the FHIR provider to use. Can be either:
583
+ - A UUID representing the provider ID
584
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
585
+
586
+ fhir_path : str
587
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
588
+ Examples:
589
+ - "Patient" (for resource type operations)
590
+ - "Patient/123" (for specific resource operations)
591
+ - "Patient/123/_history" (for history operations)
592
+
593
+ resource_type : str
594
+ The type of FHIR resource (e.g., Patient, Observation, etc.)
595
+
596
+ phenoml_on_behalf_of : typing.Optional[str]
597
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
598
+
599
+ id : typing.Optional[str]
600
+ Logical ID of the resource
601
+
602
+ meta : typing.Optional[FhirResourceMeta]
603
+ Metadata about the resource
604
+
605
+ request_options : typing.Optional[RequestOptions]
606
+ Request-specific configuration.
607
+
608
+ Returns
609
+ -------
610
+ FhirResource
611
+ Resource created successfully
612
+
613
+ Examples
614
+ --------
615
+ import asyncio
616
+
617
+ from phenoml import Asyncphenoml
618
+
619
+ client = Asyncphenoml(
620
+ token="YOUR_TOKEN",
621
+ )
622
+
623
+
624
+ async def main() -> None:
625
+ await client.fhir.create(
626
+ fhir_provider_id="fhir_provider_id",
627
+ fhir_path="fhir_path",
628
+ phenoml_on_behalf_of="user@example.com",
629
+ resource_type="Patient",
630
+ )
631
+
632
+
633
+ asyncio.run(main())
634
+ """
635
+ _response = await self._raw_client.create(
636
+ fhir_provider_id,
637
+ fhir_path,
638
+ resource_type=resource_type,
639
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
640
+ id=id,
641
+ meta=meta,
642
+ request_options=request_options,
643
+ )
644
+ return _response.data
645
+
646
+ async def upsert(
647
+ self,
648
+ fhir_provider_id: str,
649
+ fhir_path: str,
650
+ *,
651
+ resource_type: str,
652
+ phenoml_on_behalf_of: typing.Optional[str] = None,
653
+ id: typing.Optional[str] = OMIT,
654
+ meta: typing.Optional[FhirResourceMeta] = OMIT,
655
+ request_options: typing.Optional[RequestOptions] = None,
656
+ ) -> FhirResource:
657
+ """
658
+ Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created.
659
+
660
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
661
+
662
+ Parameters
663
+ ----------
664
+ fhir_provider_id : str
665
+ The ID of the FHIR provider to use. Can be either:
666
+ - A UUID representing the provider ID
667
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
668
+
669
+ fhir_path : str
670
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
671
+ Examples:
672
+ - "Patient" (for resource type operations)
673
+ - "Patient/123" (for specific resource operations)
674
+ - "Patient/123/_history" (for history operations)
675
+
676
+ resource_type : str
677
+ The type of FHIR resource (e.g., Patient, Observation, etc.)
678
+
679
+ phenoml_on_behalf_of : typing.Optional[str]
680
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
681
+
682
+ id : typing.Optional[str]
683
+ Logical ID of the resource
684
+
685
+ meta : typing.Optional[FhirResourceMeta]
686
+ Metadata about the resource
687
+
688
+ request_options : typing.Optional[RequestOptions]
689
+ Request-specific configuration.
690
+
691
+ Returns
692
+ -------
693
+ FhirResource
694
+ Resource upserted successfully
695
+
696
+ Examples
697
+ --------
698
+ import asyncio
699
+
700
+ from phenoml import Asyncphenoml
701
+
702
+ client = Asyncphenoml(
703
+ token="YOUR_TOKEN",
704
+ )
705
+
706
+
707
+ async def main() -> None:
708
+ await client.fhir.upsert(
709
+ fhir_provider_id="fhir_provider_id",
710
+ fhir_path="fhir_path",
711
+ phenoml_on_behalf_of="user@example.com",
712
+ resource_type="Patient",
713
+ id="123",
714
+ )
715
+
716
+
717
+ asyncio.run(main())
718
+ """
719
+ _response = await self._raw_client.upsert(
720
+ fhir_provider_id,
721
+ fhir_path,
722
+ resource_type=resource_type,
723
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
724
+ id=id,
725
+ meta=meta,
726
+ request_options=request_options,
727
+ )
728
+ return _response.data
729
+
730
+ async def delete(
731
+ self,
732
+ fhir_provider_id: str,
733
+ fhir_path: str,
734
+ *,
735
+ phenoml_on_behalf_of: typing.Optional[str] = None,
736
+ request_options: typing.Optional[RequestOptions] = None,
737
+ ) -> typing.Dict[str, typing.Optional[typing.Any]]:
738
+ """
739
+ Deletes a FHIR resource from the specified provider.
740
+
741
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
742
+
743
+ Parameters
744
+ ----------
745
+ fhir_provider_id : str
746
+ The ID of the FHIR provider to use. Can be either:
747
+ - A UUID representing the provider ID
748
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
749
+
750
+ fhir_path : str
751
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
752
+ Examples:
753
+ - "Patient" (for resource type operations)
754
+ - "Patient/123" (for specific resource operations)
755
+ - "Patient/123/_history" (for history operations)
756
+
757
+ phenoml_on_behalf_of : typing.Optional[str]
758
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
759
+
760
+ request_options : typing.Optional[RequestOptions]
761
+ Request-specific configuration.
762
+
763
+ Returns
764
+ -------
765
+ typing.Dict[str, typing.Optional[typing.Any]]
766
+ Resource deleted successfully
767
+
768
+ Examples
769
+ --------
770
+ import asyncio
771
+
772
+ from phenoml import Asyncphenoml
773
+
774
+ client = Asyncphenoml(
775
+ token="YOUR_TOKEN",
776
+ )
777
+
778
+
779
+ async def main() -> None:
780
+ await client.fhir.delete(
781
+ fhir_provider_id="fhir_provider_id",
782
+ fhir_path="fhir_path",
783
+ phenoml_on_behalf_of="user@example.com",
784
+ )
785
+
786
+
787
+ asyncio.run(main())
788
+ """
789
+ _response = await self._raw_client.delete(
790
+ fhir_provider_id, fhir_path, phenoml_on_behalf_of=phenoml_on_behalf_of, request_options=request_options
791
+ )
792
+ return _response.data
793
+
794
+ async def patch(
795
+ self,
796
+ fhir_provider_id: str,
797
+ fhir_path: str,
798
+ *,
799
+ request: typing.Sequence[FhirPatchRequestBodyItem],
800
+ phenoml_on_behalf_of: typing.Optional[str] = None,
801
+ request_options: typing.Optional[RequestOptions] = None,
802
+ ) -> FhirResource:
803
+ """
804
+ Partially updates a FHIR resource on the specified provider using JSON Patch operations as defined in RFC 6902.
805
+
806
+ The request body should contain an array of JSON Patch operations. Each operation specifies:
807
+ - `op`: The operation type (add, remove, replace, move, copy, test)
808
+ - `path`: JSON Pointer to the target location in the resource
809
+ - `value`: The value to use (required for add, replace, and test operations)
810
+
811
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
812
+
813
+ Parameters
814
+ ----------
815
+ fhir_provider_id : str
816
+ The ID of the FHIR provider to use. Can be either:
817
+ - A UUID representing the provider ID
818
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
819
+
820
+ fhir_path : str
821
+ The FHIR resource path to operate on. This follows FHIR RESTful API conventions.
822
+ Examples:
823
+ - "Patient" (for resource type operations)
824
+ - "Patient/123" (for specific resource operations)
825
+ - "Patient/123/_history" (for history operations)
826
+
827
+ request : typing.Sequence[FhirPatchRequestBodyItem]
828
+
829
+ phenoml_on_behalf_of : typing.Optional[str]
830
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
831
+
832
+ request_options : typing.Optional[RequestOptions]
833
+ Request-specific configuration.
834
+
835
+ Returns
836
+ -------
837
+ FhirResource
838
+ Resource patched successfully
839
+
840
+ Examples
841
+ --------
842
+ import asyncio
843
+
844
+ from phenoml import Asyncphenoml
845
+ from phenoml.fhir import FhirPatchRequestBodyItem
846
+
847
+ client = Asyncphenoml(
848
+ token="YOUR_TOKEN",
849
+ )
850
+
851
+
852
+ async def main() -> None:
853
+ await client.fhir.patch(
854
+ fhir_provider_id="fhir_provider_id",
855
+ fhir_path="fhir_path",
856
+ phenoml_on_behalf_of="user@example.com",
857
+ request=[
858
+ FhirPatchRequestBodyItem(
859
+ op="replace",
860
+ path="/name/0/family",
861
+ value="NewFamilyName",
862
+ )
863
+ ],
864
+ )
865
+
866
+
867
+ asyncio.run(main())
868
+ """
869
+ _response = await self._raw_client.patch(
870
+ fhir_provider_id,
871
+ fhir_path,
872
+ request=request,
873
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
874
+ request_options=request_options,
875
+ )
876
+ return _response.data
877
+
878
+ async def execute_bundle(
879
+ self,
880
+ fhir_provider_id: str,
881
+ *,
882
+ entry: typing.Sequence[FhirBundleEntryItem],
883
+ phenoml_on_behalf_of: typing.Optional[str] = None,
884
+ total: typing.Optional[int] = OMIT,
885
+ request_options: typing.Optional[RequestOptions] = None,
886
+ ) -> FhirBundle:
887
+ """
888
+ Executes a FHIR Bundle transaction or batch operation on the specified provider. This allows multiple FHIR resources to be processed in a single request.
889
+
890
+ The request body should contain a valid FHIR Bundle resource with transaction or batch type.
891
+
892
+ The request is proxied to the configured FHIR server with appropriate authentication headers.
893
+
894
+ Parameters
895
+ ----------
896
+ fhir_provider_id : str
897
+ The ID of the FHIR provider to use. Can be either:
898
+ - A UUID representing the provider ID
899
+ - A provider name (legacy support - will just use the most recently updated provider with this name)
900
+
901
+ entry : typing.Sequence[FhirBundleEntryItem]
902
+ Array of bundle entries containing resources or operation results
903
+
904
+ phenoml_on_behalf_of : typing.Optional[str]
905
+ Optional header for on-behalf-of authentication. Used when making requests on behalf of another user or entity.
906
+
907
+ total : typing.Optional[int]
908
+ Total number of resources that match the search criteria.
909
+ Optional field as not all FHIR servers include it (e.g., Medplum).
910
+
911
+ request_options : typing.Optional[RequestOptions]
912
+ Request-specific configuration.
913
+
914
+ Returns
915
+ -------
916
+ FhirBundle
917
+ Bundle executed successfully
918
+
919
+ Examples
920
+ --------
921
+ import asyncio
922
+
923
+ from phenoml import Asyncphenoml
924
+ from phenoml.fhir import FhirBundleEntryItem, FhirBundleEntryItemRequest
925
+
926
+ client = Asyncphenoml(
927
+ token="YOUR_TOKEN",
928
+ )
929
+
930
+
931
+ async def main() -> None:
932
+ await client.fhir.execute_bundle(
933
+ fhir_provider_id="fhir_provider_id",
934
+ phenoml_on_behalf_of="user@example.com",
935
+ entry=[
936
+ FhirBundleEntryItem(
937
+ resource={
938
+ "resourceType": "Patient",
939
+ "name": [{"family": "Doe", "given": ["John"]}],
940
+ },
941
+ request=FhirBundleEntryItemRequest(
942
+ method="POST",
943
+ url="Patient",
944
+ ),
945
+ ),
946
+ FhirBundleEntryItem(
947
+ resource={
948
+ "resourceType": "Observation",
949
+ "status": "final",
950
+ "subject": {"reference": "Patient/123"},
951
+ },
952
+ request=FhirBundleEntryItemRequest(
953
+ method="POST",
954
+ url="Observation",
955
+ ),
956
+ ),
957
+ ],
958
+ )
959
+
960
+
961
+ asyncio.run(main())
962
+ """
963
+ _response = await self._raw_client.execute_bundle(
964
+ fhir_provider_id,
965
+ entry=entry,
966
+ phenoml_on_behalf_of=phenoml_on_behalf_of,
967
+ total=total,
968
+ request_options=request_options,
969
+ )
970
+ return _response.data