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