hubble-sdk-python 0.0.3__tar.gz → 0.2.0__tar.gz

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 (64) hide show
  1. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/CHANGELOG.md +26 -0
  2. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/PKG-INFO +34 -4
  3. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/README.md +33 -3
  4. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/__init__.py +12 -0
  5. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/attach_client_authorization.py +19 -16
  6. hubble_sdk_python-0.2.0/hubble_sdk/_generated/api/default/export_patient_fhir.py +262 -0
  7. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/export_patient_pdf.py +64 -14
  8. hubble_sdk_python-0.2.0/hubble_sdk/_generated/api/default/get_patient_pdf_export.py +261 -0
  9. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/list_consents.py +46 -0
  10. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/client.py +9 -11
  11. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/__init__.py +20 -8
  12. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent.py +1 -26
  13. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_link_request.py +14 -1
  14. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_list.py +16 -1
  15. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_source.py +11 -1
  16. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_source_status.py +3 -2
  17. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_source_type.py +2 -2
  18. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_status.py +2 -2
  19. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/device_authorization_request.py +23 -1
  20. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_fhir_prefer.py +8 -0
  21. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_fhir_response_202.py +105 -0
  22. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_fhir_response_202_status.py +9 -0
  23. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_pdf_prefer.py +8 -0
  24. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_pdf_response_202.py +105 -0
  25. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/export_patient_pdf_response_202_status.py +9 -0
  26. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/get_patient_pdf_export_download.py +8 -0
  27. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/get_patient_pdf_export_response_200.py +114 -0
  28. hubble_sdk_python-0.2.0/hubble_sdk/_generated/models/get_patient_pdf_export_response_200_status.py +8 -0
  29. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/o_auth_error_error.py +2 -2
  30. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/operation_outcome.py +3 -1
  31. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/patient_address.py +9 -0
  32. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/token_request.py +1 -1
  33. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/token_request_grant_type.py +2 -3
  34. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_hubble.py +99 -11
  35. hubble_sdk_python-0.2.0/hubble_sdk/_webhooks.py +200 -0
  36. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/pydoc-markdown.yml +6 -4
  37. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/pyproject.toml +1 -1
  38. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/tests/test_hubble.py +145 -4
  39. hubble_sdk_python-0.2.0/tests/test_webhooks.py +181 -0
  40. hubble_sdk_python-0.0.3/hubble_sdk/_generated/models/attach_client_authorization_response_201.py +0 -100
  41. hubble_sdk_python-0.0.3/hubble_sdk/_generated/models/attach_client_authorization_response_201_status.py +0 -8
  42. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/.gitignore +0 -0
  43. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/LICENSE +0 -0
  44. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/config.yaml +0 -0
  45. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/__init__.py +0 -0
  46. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/__init__.py +0 -0
  47. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/__init__.py +0 -0
  48. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/create_consent_link.py +0 -0
  49. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/exchange_token.py +0 -0
  50. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/get_consent.py +0 -0
  51. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/read_fhir.py +0 -0
  52. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/api/default/revoke_consent.py +0 -0
  53. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/errors.py +0 -0
  54. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/api_error.py +0 -0
  55. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/attach_client_authorization_body.py +0 -0
  56. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/consent_error.py +0 -0
  57. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/device_authorization_response.py +0 -0
  58. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/fhir_resource.py +0 -0
  59. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/o_auth_error.py +0 -0
  60. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/operation_outcome_issue_item.py +0 -0
  61. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/patient_demographics.py +0 -0
  62. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/provider_seed.py +0 -0
  63. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/models/token_response.py +0 -0
  64. {hubble_sdk_python-0.0.3 → hubble_sdk_python-0.2.0}/hubble_sdk/_generated/types.py +0 -0
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.0](https://github.com/hubble-dot-ai/hubble-sdks/compare/hubble-sdk-python-v0.1.0...hubble-sdk-python-v0.2.0) (2026-09-30)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * the `authorization_code` value is removed from the token `grant_type` enum (it was never available), and `ConsentList.next_cursor` / `ConsentSource.id` are now required response fields.
9
+
10
+ ### Features
11
+
12
+ * add revoked consent source status ([#51](https://github.com/hubble-dot-ai/hubble-sdks/issues/51)) ([b2dc24d](https://github.com/hubble-dot-ai/hubble-sdks/commit/b2dc24d3359ce1ea245bd881303ada2c425e3132))
13
+ * async record exports, consent pagination, and per-source ids ([#47](https://github.com/hubble-dot-ai/hubble-sdks/issues/47)) ([ddf8e5b](https://github.com/hubble-dot-ai/hubble-sdks/commit/ddf8e5b02436d6ae69d0ca20e723752ee21349a9))
14
+ * verify and parse webhook events ([#50](https://github.com/hubble-dot-ai/hubble-sdks/issues/50)) ([e71b0bc](https://github.com/hubble-dot-ai/hubble-sdks/commit/e71b0bc80b38fbd070a4b6fd5ddfcbada1e8e311))
15
+
16
+ ## [0.1.0](https://github.com/hubble-dot-ai/hubble-sdks/compare/hubble-sdk-python-v0.0.3...hubble-sdk-python-v0.1.0) (2026-09-02)
17
+
18
+
19
+ ### ⚠ BREAKING CHANGES
20
+
21
+ * `Consent.granted_at` is removed. Callers reading it must derive authorization time another way (e.g. status transitions).
22
+
23
+ ### Features
24
+
25
+ * add attach_authorization for BYO HIPAA authorization ([#41](https://github.com/hubble-dot-ai/hubble-sdks/issues/41)) ([66baf11](https://github.com/hubble-dot-ai/hubble-sdks/commit/66baf1192291b31cb03e325be44f1e6c5e4371f3))
26
+ * drop granted_at from Consent ([#44](https://github.com/hubble-dot-ai/hubble-sdks/issues/44)) ([cb61be8](https://github.com/hubble-dot-ai/hubble-sdks/commit/cb61be8dc6e8c4784e30332cb4e31317f773ec3b))
27
+ * support represented organizations in SDK links ([#45](https://github.com/hubble-dot-ai/hubble-sdks/issues/45)) ([430a1d0](https://github.com/hubble-dot-ai/hubble-sdks/commit/430a1d022f75ea645d27b0b7ebf87b910f1c51a9))
28
+
3
29
  ## [0.0.3](https://github.com/hubble-dot-ai/hubble-sdks/compare/hubble-sdk-python-v0.0.2...hubble-sdk-python-v0.0.3) (2026-08-23)
4
30
 
5
31
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hubble-sdk-python
3
- Version: 0.0.3
3
+ Version: 0.2.0
4
4
  Summary: Python client for the Hubble Patient Access API.
5
5
  Project-URL: Homepage, https://github.com/hubble-dot-ai/hubble-sdks
6
6
  Project-URL: Repository, https://github.com/hubble-dot-ai/hubble-sdks
@@ -45,8 +45,9 @@ from hubble_sdk import Hubble
45
45
  hub = Hubble(client_id="hbl_client_prod_...", client_secret="hbl_prod_...")
46
46
 
47
47
  # 1. Create a patient link and send the patient to it. Optionally prefill with
48
- # patient={"first_name": ...} demographics and providers=[{"name": ...}].
49
- link = hub.create_link(patient_ref="abc123")
48
+ # patient={"first_name": ...} demographics, providers=[{"name": ...}], and
49
+ # the optional organization your verified Hubble organization represents.
50
+ link = hub.create_link(patient_ref="abc123", on_behalf_of_organization_name="Acme Health")
50
51
  print(link.verification_uri_complete)
51
52
 
52
53
  # 2. Wait for the patient to authorize (polls the token endpoint for you).
@@ -63,6 +64,35 @@ for consent in hub.list_consents(status="active"):
63
64
  hub.revoke_consent(session.consent_id)
64
65
  ```
65
66
 
67
+ ## Receiving webhooks
68
+
69
+ Verify each delivery against your endpoint's signing secret (from the portal's
70
+ Webhooks page) and get the event back. Pass the **raw** body: a body that was
71
+ parsed and re-serialized will not verify.
72
+
73
+ ```python
74
+ from hubble_sdk import WebhookSignatureError, construct_webhook_event
75
+
76
+ # e.g. Flask
77
+ @app.post("/hubble/webhooks")
78
+ def hubble_webhook():
79
+ try:
80
+ event = construct_webhook_event(
81
+ request.get_data(), request.headers.get("Hubble-Signature"), WEBHOOK_SECRET
82
+ )
83
+ except WebhookSignatureError:
84
+ return "bad signature", 400
85
+ if event.type == "consent.source.available":
86
+ print(event.consent_id, event.source.id)
87
+ # newer event types may arrive; ignore what you don't handle
88
+ return "", 204
89
+ ```
90
+
91
+ In FastAPI, read the body with `await request.body()`. Deliveries are
92
+ at-least-once, so dedupe on `event.id`. Pass `secret` as a list to accept the old
93
+ and new secret during a rotation, and `tolerance` to change the default 5-minute
94
+ replay window.
95
+
66
96
  ## What the client handles for you
67
97
 
68
98
  - **Auth per plane** — HTTP Basic (your app credentials) for consent management
@@ -81,7 +111,7 @@ hub.revoke_consent(session.consent_id)
81
111
 
82
112
  ## Layout
83
113
 
84
- `Hubble` / `PatientSession` are hand-written. The low-level client generated
114
+ `Hubble` / `PatientSession` and the webhook helpers are hand-written. The low-level client generated
85
115
  from the OpenAPI contract with
86
116
  [openapi-python-client](https://github.com/openapi-generators/openapi-python-client)
87
117
  lives under `hubble_sdk._generated` (regenerated on every spec change;
@@ -13,8 +13,9 @@ from hubble_sdk import Hubble
13
13
  hub = Hubble(client_id="hbl_client_prod_...", client_secret="hbl_prod_...")
14
14
 
15
15
  # 1. Create a patient link and send the patient to it. Optionally prefill with
16
- # patient={"first_name": ...} demographics and providers=[{"name": ...}].
17
- link = hub.create_link(patient_ref="abc123")
16
+ # patient={"first_name": ...} demographics, providers=[{"name": ...}], and
17
+ # the optional organization your verified Hubble organization represents.
18
+ link = hub.create_link(patient_ref="abc123", on_behalf_of_organization_name="Acme Health")
18
19
  print(link.verification_uri_complete)
19
20
 
20
21
  # 2. Wait for the patient to authorize (polls the token endpoint for you).
@@ -31,6 +32,35 @@ for consent in hub.list_consents(status="active"):
31
32
  hub.revoke_consent(session.consent_id)
32
33
  ```
33
34
 
35
+ ## Receiving webhooks
36
+
37
+ Verify each delivery against your endpoint's signing secret (from the portal's
38
+ Webhooks page) and get the event back. Pass the **raw** body: a body that was
39
+ parsed and re-serialized will not verify.
40
+
41
+ ```python
42
+ from hubble_sdk import WebhookSignatureError, construct_webhook_event
43
+
44
+ # e.g. Flask
45
+ @app.post("/hubble/webhooks")
46
+ def hubble_webhook():
47
+ try:
48
+ event = construct_webhook_event(
49
+ request.get_data(), request.headers.get("Hubble-Signature"), WEBHOOK_SECRET
50
+ )
51
+ except WebhookSignatureError:
52
+ return "bad signature", 400
53
+ if event.type == "consent.source.available":
54
+ print(event.consent_id, event.source.id)
55
+ # newer event types may arrive; ignore what you don't handle
56
+ return "", 204
57
+ ```
58
+
59
+ In FastAPI, read the body with `await request.body()`. Deliveries are
60
+ at-least-once, so dedupe on `event.id`. Pass `secret` as a list to accept the old
61
+ and new secret during a rotation, and `tolerance` to change the default 5-minute
62
+ replay window.
63
+
34
64
  ## What the client handles for you
35
65
 
36
66
  - **Auth per plane** — HTTP Basic (your app credentials) for consent management
@@ -49,7 +79,7 @@ hub.revoke_consent(session.consent_id)
49
79
 
50
80
  ## Layout
51
81
 
52
- `Hubble` / `PatientSession` are hand-written. The low-level client generated
82
+ `Hubble` / `PatientSession` and the webhook helpers are hand-written. The low-level client generated
53
83
  from the OpenAPI contract with
54
84
  [openapi-python-client](https://github.com/openapi-generators/openapi-python-client)
55
85
  lives under `hubble_sdk._generated` (regenerated on every spec change;
@@ -28,6 +28,13 @@ from ._hubble import (
28
28
  PdfExport,
29
29
  TokenSet,
30
30
  )
31
+ from ._webhooks import (
32
+ WEBHOOK_SIGNATURE_HEADER,
33
+ WebhookEvent,
34
+ WebhookEventSource,
35
+ WebhookSignatureError,
36
+ construct_webhook_event,
37
+ )
31
38
 
32
39
  __all__ = [
33
40
  "Hubble",
@@ -36,6 +43,11 @@ __all__ = [
36
43
  "ConsentTimeout",
37
44
  "TokenSet",
38
45
  "PdfExport",
46
+ "construct_webhook_event",
47
+ "WebhookEvent",
48
+ "WebhookEventSource",
49
+ "WebhookSignatureError",
50
+ "WEBHOOK_SIGNATURE_HEADER",
39
51
  "Consent",
40
52
  "ConsentStatus",
41
53
  "DeviceAuthorizationResponse",
@@ -8,9 +8,7 @@ from ... import errors
8
8
  from ...client import AuthenticatedClient, Client
9
9
  from ...models.api_error import ApiError
10
10
  from ...models.attach_client_authorization_body import AttachClientAuthorizationBody
11
- from ...models.attach_client_authorization_response_201 import (
12
- AttachClientAuthorizationResponse201,
13
- )
11
+ from ...models.consent import Consent
14
12
  from ...types import Response
15
13
 
16
14
 
@@ -38,11 +36,11 @@ def _get_kwargs(
38
36
 
39
37
  def _parse_response(
40
38
  *, client: AuthenticatedClient | Client, response: httpx.Response
41
- ) -> ApiError | AttachClientAuthorizationResponse201 | None:
42
- if response.status_code == 201:
43
- response_201 = AttachClientAuthorizationResponse201.from_dict(response.json())
39
+ ) -> ApiError | Consent | None:
40
+ if response.status_code == 200:
41
+ response_200 = Consent.from_dict(response.json())
44
42
 
45
- return response_201
43
+ return response_200
46
44
 
47
45
  if response.status_code == 400:
48
46
  response_400 = ApiError.from_dict(response.json())
@@ -64,6 +62,11 @@ def _parse_response(
64
62
 
65
63
  return response_404
66
64
 
65
+ if response.status_code == 409:
66
+ response_409 = ApiError.from_dict(response.json())
67
+
68
+ return response_409
69
+
67
70
  if response.status_code == 413:
68
71
  response_413 = ApiError.from_dict(response.json())
69
72
 
@@ -77,7 +80,7 @@ def _parse_response(
77
80
 
78
81
  def _build_response(
79
82
  *, client: AuthenticatedClient | Client, response: httpx.Response
80
- ) -> Response[ApiError | AttachClientAuthorizationResponse201]:
83
+ ) -> Response[ApiError | Consent]:
81
84
  return Response(
82
85
  status_code=HTTPStatus(response.status_code),
83
86
  content=response.content,
@@ -91,7 +94,7 @@ def sync_detailed(
91
94
  *,
92
95
  client: AuthenticatedClient,
93
96
  body: AttachClientAuthorizationBody,
94
- ) -> Response[ApiError | AttachClientAuthorizationResponse201]:
97
+ ) -> Response[ApiError | Consent]:
95
98
  """Attach a customer-supplied HIPAA authorization
96
99
 
97
100
  Upload an already-signed HIPAA authorization for a consent and grant delegated retrieval from the
@@ -107,7 +110,7 @@ def sync_detailed(
107
110
  httpx.TimeoutException: If the request takes longer than Client.timeout.
108
111
 
109
112
  Returns:
110
- Response[ApiError | AttachClientAuthorizationResponse201]
113
+ Response[ApiError | Consent]
111
114
  """
112
115
 
113
116
  kwargs = _get_kwargs(
@@ -127,7 +130,7 @@ def sync(
127
130
  *,
128
131
  client: AuthenticatedClient,
129
132
  body: AttachClientAuthorizationBody,
130
- ) -> ApiError | AttachClientAuthorizationResponse201 | None:
133
+ ) -> ApiError | Consent | None:
131
134
  """Attach a customer-supplied HIPAA authorization
132
135
 
133
136
  Upload an already-signed HIPAA authorization for a consent and grant delegated retrieval from the
@@ -143,7 +146,7 @@ def sync(
143
146
  httpx.TimeoutException: If the request takes longer than Client.timeout.
144
147
 
145
148
  Returns:
146
- ApiError | AttachClientAuthorizationResponse201
149
+ ApiError | Consent
147
150
  """
148
151
 
149
152
  return sync_detailed(
@@ -158,7 +161,7 @@ async def asyncio_detailed(
158
161
  *,
159
162
  client: AuthenticatedClient,
160
163
  body: AttachClientAuthorizationBody,
161
- ) -> Response[ApiError | AttachClientAuthorizationResponse201]:
164
+ ) -> Response[ApiError | Consent]:
162
165
  """Attach a customer-supplied HIPAA authorization
163
166
 
164
167
  Upload an already-signed HIPAA authorization for a consent and grant delegated retrieval from the
@@ -174,7 +177,7 @@ async def asyncio_detailed(
174
177
  httpx.TimeoutException: If the request takes longer than Client.timeout.
175
178
 
176
179
  Returns:
177
- Response[ApiError | AttachClientAuthorizationResponse201]
180
+ Response[ApiError | Consent]
178
181
  """
179
182
 
180
183
  kwargs = _get_kwargs(
@@ -192,7 +195,7 @@ async def asyncio(
192
195
  *,
193
196
  client: AuthenticatedClient,
194
197
  body: AttachClientAuthorizationBody,
195
- ) -> ApiError | AttachClientAuthorizationResponse201 | None:
198
+ ) -> ApiError | Consent | None:
196
199
  """Attach a customer-supplied HIPAA authorization
197
200
 
198
201
  Upload an already-signed HIPAA authorization for a consent and grant delegated retrieval from the
@@ -208,7 +211,7 @@ async def asyncio(
208
211
  httpx.TimeoutException: If the request takes longer than Client.timeout.
209
212
 
210
213
  Returns:
211
- ApiError | AttachClientAuthorizationResponse201
214
+ ApiError | Consent
212
215
  """
213
216
 
214
217
  return (
@@ -0,0 +1,262 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.export_patient_fhir_prefer import ExportPatientFhirPrefer
9
+ from ...models.export_patient_fhir_response_202 import ExportPatientFhirResponse202
10
+ from ...models.fhir_resource import FhirResource
11
+ from ...models.operation_outcome import OperationOutcome
12
+ from ...types import UNSET, Response, Unset
13
+
14
+
15
+ def _get_kwargs(
16
+ *,
17
+ field_count: int | Unset = UNSET,
18
+ field_offset: int | Unset = UNSET,
19
+ prefer: ExportPatientFhirPrefer | Unset = UNSET,
20
+ ) -> dict[str, Any]:
21
+ headers: dict[str, Any] = {}
22
+ if not isinstance(prefer, Unset):
23
+ headers["Prefer"] = str(prefer)
24
+
25
+ params: dict[str, Any] = {}
26
+
27
+ params["_count"] = field_count
28
+
29
+ params["_offset"] = field_offset
30
+
31
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
32
+
33
+ _kwargs: dict[str, Any] = {
34
+ "method": "get",
35
+ "url": "/api/v1/fhir/Patient/$everything",
36
+ "params": params,
37
+ }
38
+
39
+ _kwargs["headers"] = headers
40
+ return _kwargs
41
+
42
+
43
+ def _parse_response(
44
+ *, client: AuthenticatedClient | Client, response: httpx.Response
45
+ ) -> ExportPatientFhirResponse202 | FhirResource | OperationOutcome | None:
46
+ if response.status_code == 200:
47
+ response_200 = FhirResource.from_dict(response.json())
48
+
49
+ return response_200
50
+
51
+ if response.status_code == 202:
52
+ response_202 = ExportPatientFhirResponse202.from_dict(response.json())
53
+
54
+ return response_202
55
+
56
+ if response.status_code == 400:
57
+ response_400 = OperationOutcome.from_dict(response.json())
58
+
59
+ return response_400
60
+
61
+ if response.status_code == 401:
62
+ response_401 = OperationOutcome.from_dict(response.json())
63
+
64
+ return response_401
65
+
66
+ if response.status_code == 403:
67
+ response_403 = OperationOutcome.from_dict(response.json())
68
+
69
+ return response_403
70
+
71
+ if response.status_code == 404:
72
+ response_404 = OperationOutcome.from_dict(response.json())
73
+
74
+ return response_404
75
+
76
+ if response.status_code == 429:
77
+ response_429 = OperationOutcome.from_dict(response.json())
78
+
79
+ return response_429
80
+
81
+ if response.status_code == 503:
82
+ response_503 = OperationOutcome.from_dict(response.json())
83
+
84
+ return response_503
85
+
86
+ if client.raise_on_unexpected_status:
87
+ raise errors.UnexpectedStatus(response.status_code, response.content)
88
+ else:
89
+ return None
90
+
91
+
92
+ def _build_response(
93
+ *, client: AuthenticatedClient | Client, response: httpx.Response
94
+ ) -> Response[ExportPatientFhirResponse202 | FhirResource | OperationOutcome]:
95
+ return Response(
96
+ status_code=HTTPStatus(response.status_code),
97
+ content=response.content,
98
+ headers=response.headers,
99
+ parsed=_parse_response(client=client, response=response),
100
+ )
101
+
102
+
103
+ def sync_detailed(
104
+ *,
105
+ client: AuthenticatedClient,
106
+ field_count: int | Unset = UNSET,
107
+ field_offset: int | Unset = UNSET,
108
+ prefer: ExportPatientFhirPrefer | Unset = UNSET,
109
+ ) -> Response[ExportPatientFhirResponse202 | FhirResource | OperationOutcome]:
110
+ """Read or asynchronously export the patient's FHIR record
111
+
112
+ Without Prefer, returns the existing paginated FHIR searchset. Send Prefer: respond-async without
113
+ query parameters to prepare health-records.json in the background. The file is a FHIR collection
114
+ Bundle containing the captured provider sources, including each source's Patient and warnings for
115
+ incomplete sources. It has no paging links, search metadata or total field, and is not a Bulk Data
116
+ $export/NDJSON response. Poll Content-Location with the same consent token no sooner than Retry-
117
+ After for a 303 download redirect. An organization can hold 20 exports in flight at once; a repeat
118
+ request for one already running reuses it. Payer records are not included.
119
+
120
+ Args:
121
+ field_count (int | Unset):
122
+ field_offset (int | Unset):
123
+ prefer (ExportPatientFhirPrefer | Unset):
124
+
125
+ Raises:
126
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
127
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
128
+
129
+ Returns:
130
+ Response[ExportPatientFhirResponse202 | FhirResource | OperationOutcome]
131
+ """
132
+
133
+ kwargs = _get_kwargs(
134
+ field_count=field_count,
135
+ field_offset=field_offset,
136
+ prefer=prefer,
137
+ )
138
+
139
+ response = client.get_httpx_client().request(
140
+ **kwargs,
141
+ )
142
+
143
+ return _build_response(client=client, response=response)
144
+
145
+
146
+ def sync(
147
+ *,
148
+ client: AuthenticatedClient,
149
+ field_count: int | Unset = UNSET,
150
+ field_offset: int | Unset = UNSET,
151
+ prefer: ExportPatientFhirPrefer | Unset = UNSET,
152
+ ) -> ExportPatientFhirResponse202 | FhirResource | OperationOutcome | None:
153
+ """Read or asynchronously export the patient's FHIR record
154
+
155
+ Without Prefer, returns the existing paginated FHIR searchset. Send Prefer: respond-async without
156
+ query parameters to prepare health-records.json in the background. The file is a FHIR collection
157
+ Bundle containing the captured provider sources, including each source's Patient and warnings for
158
+ incomplete sources. It has no paging links, search metadata or total field, and is not a Bulk Data
159
+ $export/NDJSON response. Poll Content-Location with the same consent token no sooner than Retry-
160
+ After for a 303 download redirect. An organization can hold 20 exports in flight at once; a repeat
161
+ request for one already running reuses it. Payer records are not included.
162
+
163
+ Args:
164
+ field_count (int | Unset):
165
+ field_offset (int | Unset):
166
+ prefer (ExportPatientFhirPrefer | Unset):
167
+
168
+ Raises:
169
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
170
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
171
+
172
+ Returns:
173
+ ExportPatientFhirResponse202 | FhirResource | OperationOutcome
174
+ """
175
+
176
+ return sync_detailed(
177
+ client=client,
178
+ field_count=field_count,
179
+ field_offset=field_offset,
180
+ prefer=prefer,
181
+ ).parsed
182
+
183
+
184
+ async def asyncio_detailed(
185
+ *,
186
+ client: AuthenticatedClient,
187
+ field_count: int | Unset = UNSET,
188
+ field_offset: int | Unset = UNSET,
189
+ prefer: ExportPatientFhirPrefer | Unset = UNSET,
190
+ ) -> Response[ExportPatientFhirResponse202 | FhirResource | OperationOutcome]:
191
+ """Read or asynchronously export the patient's FHIR record
192
+
193
+ Without Prefer, returns the existing paginated FHIR searchset. Send Prefer: respond-async without
194
+ query parameters to prepare health-records.json in the background. The file is a FHIR collection
195
+ Bundle containing the captured provider sources, including each source's Patient and warnings for
196
+ incomplete sources. It has no paging links, search metadata or total field, and is not a Bulk Data
197
+ $export/NDJSON response. Poll Content-Location with the same consent token no sooner than Retry-
198
+ After for a 303 download redirect. An organization can hold 20 exports in flight at once; a repeat
199
+ request for one already running reuses it. Payer records are not included.
200
+
201
+ Args:
202
+ field_count (int | Unset):
203
+ field_offset (int | Unset):
204
+ prefer (ExportPatientFhirPrefer | Unset):
205
+
206
+ Raises:
207
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
208
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
209
+
210
+ Returns:
211
+ Response[ExportPatientFhirResponse202 | FhirResource | OperationOutcome]
212
+ """
213
+
214
+ kwargs = _get_kwargs(
215
+ field_count=field_count,
216
+ field_offset=field_offset,
217
+ prefer=prefer,
218
+ )
219
+
220
+ response = await client.get_async_httpx_client().request(**kwargs)
221
+
222
+ return _build_response(client=client, response=response)
223
+
224
+
225
+ async def asyncio(
226
+ *,
227
+ client: AuthenticatedClient,
228
+ field_count: int | Unset = UNSET,
229
+ field_offset: int | Unset = UNSET,
230
+ prefer: ExportPatientFhirPrefer | Unset = UNSET,
231
+ ) -> ExportPatientFhirResponse202 | FhirResource | OperationOutcome | None:
232
+ """Read or asynchronously export the patient's FHIR record
233
+
234
+ Without Prefer, returns the existing paginated FHIR searchset. Send Prefer: respond-async without
235
+ query parameters to prepare health-records.json in the background. The file is a FHIR collection
236
+ Bundle containing the captured provider sources, including each source's Patient and warnings for
237
+ incomplete sources. It has no paging links, search metadata or total field, and is not a Bulk Data
238
+ $export/NDJSON response. Poll Content-Location with the same consent token no sooner than Retry-
239
+ After for a 303 download redirect. An organization can hold 20 exports in flight at once; a repeat
240
+ request for one already running reuses it. Payer records are not included.
241
+
242
+ Args:
243
+ field_count (int | Unset):
244
+ field_offset (int | Unset):
245
+ prefer (ExportPatientFhirPrefer | Unset):
246
+
247
+ Raises:
248
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
249
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
250
+
251
+ Returns:
252
+ ExportPatientFhirResponse202 | FhirResource | OperationOutcome
253
+ """
254
+
255
+ return (
256
+ await asyncio_detailed(
257
+ client=client,
258
+ field_count=field_count,
259
+ field_offset=field_offset,
260
+ prefer=prefer,
261
+ )
262
+ ).parsed