Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
1572 lines (1257 loc) · 56.8 KB
/
Copy pathclient.py
File metadata and controls
1572 lines (1257 loc) · 56.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
from __future__ import annotations
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.cancel_order_response import CancelOrderResponse
from ..types.create_order_response import CreateOrderResponse
from ..types.get_order_response import GetOrderResponse
from ..types.list_orders_response import ListOrdersResponse
from ..types.preview_order_response import PreviewOrderResponse
from ..types.reject_order_response import RejectOrderResponse
from ..types.sign_and_submit_order_response import SignAndSubmitOrderResponse
from ..types.sign_order_response import SignOrderResponse
from ..types.submit_order_response import SubmitOrderResponse
from .raw_client import AsyncRawOrdersClient, RawOrdersClient
from .types.create_order_request_metadata_value import CreateOrderRequestMetadataValue
from .types.create_order_request_otc_items_item import CreateOrderRequestOtcItemsItem
from .types.create_order_request_patient import CreateOrderRequestPatient
from .types.create_order_request_prescriber import CreateOrderRequestPrescriber
from .types.create_order_request_prescriptions_item import CreateOrderRequestPrescriptionsItem
from .types.list_orders_request_sort import ListOrdersRequestSort
from .types.list_orders_request_status import ListOrdersRequestStatus
from .types.preview_order_request_otc_items_item import PreviewOrderRequestOtcItemsItem
from .types.preview_order_request_patient import PreviewOrderRequestPatient
from .types.preview_order_request_prescriber import PreviewOrderRequestPrescriber
from .types.preview_order_request_prescriptions_item import PreviewOrderRequestPrescriptionsItem
from .types.preview_order_request_shipping import PreviewOrderRequestShipping
from .types.reject_order_request_expected_versions_item import RejectOrderRequestExpectedVersionsItem
from .types.reject_order_request_prescriber import RejectOrderRequestPrescriber
from .types.sign_and_submit_order_request_expected_versions_item import SignAndSubmitOrderRequestExpectedVersionsItem
from .types.sign_and_submit_order_request_prescriber import SignAndSubmitOrderRequestPrescriber
from .types.sign_order_request_expected_versions_item import SignOrderRequestExpectedVersionsItem
from .types.sign_order_request_prescriber import SignOrderRequestPrescriber
from .types.submit_order_request_prescriber import SubmitOrderRequestPrescriber
if typing.TYPE_CHECKING:
from .batches.client import AsyncBatchesClient, BatchesClient
from .events.client import AsyncEventsClient, EventsClient
from .exceptions.client import AsyncExceptionsClient, ExceptionsClient
from .prescriptions.client import AsyncPrescriptionsClient, PrescriptionsClient
from .test_simulation.client import AsyncTestSimulationClient, TestSimulationClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class OrdersClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawOrdersClient(client_wrapper=client_wrapper)
self._client_wrapper = client_wrapper
self._exceptions: typing.Optional[ExceptionsClient] = None
self._events: typing.Optional[EventsClient] = None
self._test_simulation: typing.Optional[TestSimulationClient] = None
self._prescriptions: typing.Optional[PrescriptionsClient] = None
self._batches: typing.Optional[BatchesClient] = None
@property
def with_raw_response(self) -> RawOrdersClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawOrdersClient
"""
return self._raw_client
def list(
self,
*,
query: typing.Optional[str] = None,
external_order_id: typing.Optional[str] = None,
created_after: typing.Optional[str] = None,
created_before: typing.Optional[str] = None,
ending_before: typing.Optional[str] = None,
limit: typing.Optional[int] = None,
order_id: typing.Optional[str] = None,
patient_id: typing.Optional[str] = None,
patient_external_id: typing.Optional[str] = None,
practice_id: typing.Optional[str] = None,
sort: typing.Optional[ListOrdersRequestSort] = None,
starting_after: typing.Optional[str] = None,
status: typing.Optional[ListOrdersRequestStatus] = None,
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ListOrdersResponse:
"""
Parameters
----------
query : typing.Optional[str]
external_order_id : typing.Optional[str]
created_after : typing.Optional[str]
created_before : typing.Optional[str]
ending_before : typing.Optional[str]
limit : typing.Optional[int]
order_id : typing.Optional[str]
patient_id : typing.Optional[str]
patient_external_id : typing.Optional[str]
practice_id : typing.Optional[str]
sort : typing.Optional[ListOrdersRequestSort]
starting_after : typing.Optional[str]
status : typing.Optional[ListOrdersRequestStatus]
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ListOrdersResponse
HTTP 200
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.list(
ending_before="ord_01j2y8m6jcc9tt24af5pw9x1bc",
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
starting_after="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)
"""
_response = self._raw_client.list(
query=query,
external_order_id=external_order_id,
created_after=created_after,
created_before=created_before,
ending_before=ending_before,
limit=limit,
order_id=order_id,
patient_id=patient_id,
patient_external_id=patient_external_id,
practice_id=practice_id,
sort=sort,
starting_after=starting_after,
status=status,
affinity_actor_id=affinity_actor_id,
affinity_actor_type=affinity_actor_type,
request_options=request_options,
)
return _response.data
def create(
self,
*,
idempotency_key: str,
practice_id: str,
prescriptions: typing.Sequence[CreateOrderRequestPrescriptionsItem],
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[CreateOrderRequestPrescriber] = OMIT,
otc_items: typing.Optional[typing.Sequence[CreateOrderRequestOtcItemsItem]] = OMIT,
external_order_id: typing.Optional[str] = OMIT,
metadata: typing.Optional[typing.Dict[str, typing.Optional[CreateOrderRequestMetadataValue]]] = OMIT,
patient_id: typing.Optional[str] = OMIT,
patient: typing.Optional[CreateOrderRequestPatient] = OMIT,
shipping_address_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateOrderResponse:
"""
Creates one unsigned order with 1–20 prescriptions for one patient in one practice. Supply patientId or patient; inline patient creation requires patients:write. Prescriber is optional: select by npi, provider id, or integration-scoped externalId, or leave the draft unassigned until signing. First-use prescriber registration requires team:write. Legacy userId is supported but cannot be combined with prescriber. Idempotency-Key is required.
Parameters
----------
idempotency_key : str
practice_id : str
prescriptions : typing.Sequence[CreateOrderRequestPrescriptionsItem]
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
user_id : typing.Optional[str]
prescriber : typing.Optional[CreateOrderRequestPrescriber]
otc_items : typing.Optional[typing.Sequence[CreateOrderRequestOtcItemsItem]]
external_order_id : typing.Optional[str]
metadata : typing.Optional[typing.Dict[str, typing.Optional[CreateOrderRequestMetadataValue]]]
patient_id : typing.Optional[str]
patient : typing.Optional[CreateOrderRequestPatient]
shipping_address_id : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
from affinity.orders import (
CreateOrderRequestPrescriptionsItem,
CreateOrderRequestPrescriptionsItemDispensing,
)
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.create(
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
prescriptions=[
CreateOrderRequestPrescriptionsItem(
days_supply=1,
dispensing=CreateOrderRequestPrescriptionsItemDispensing(),
directions="directions",
medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
quantity="NaN",
quantity_unit="quantityUnit",
refills=1,
)
],
)
"""
_response = self._raw_client.create(
idempotency_key=idempotency_key,
practice_id=practice_id,
prescriptions=prescriptions,
affinity_actor_id=affinity_actor_id,
affinity_actor_type=affinity_actor_type,
user_id=user_id,
prescriber=prescriber,
otc_items=otc_items,
external_order_id=external_order_id,
metadata=metadata,
patient_id=patient_id,
patient=patient,
shipping_address_id=shipping_address_id,
request_options=request_options,
)
return _response.data
def get(
self,
order_id: str,
*,
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetOrderResponse:
"""
Parameters
----------
order_id : str
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.get(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)
"""
_response = self._raw_client.get(
order_id,
affinity_actor_id=affinity_actor_id,
affinity_actor_type=affinity_actor_type,
request_options=request_options,
)
return _response.data
def cancel(
self,
order_id: str,
*,
idempotency_key: str,
reason: str,
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> CancelOrderResponse:
"""
Requests cancellation. HTTP 200 means the request was handled; check cancellation.status for confirmed, pending, partial, or failed. Only confirmed means the entire order is cancelled. Shipment possession makes a fulfillment cancellation too late.
Parameters
----------
order_id : str
idempotency_key : str
reason : str
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CancelOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.cancel(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
idempotency_key="Idempotency-Key",
reason="reason",
)
"""
_response = self._raw_client.cancel(
order_id,
idempotency_key=idempotency_key,
reason=reason,
affinity_actor_id=affinity_actor_id,
affinity_actor_type=affinity_actor_type,
request_options=request_options,
)
return _response.data
def preview(
self,
*,
practice_id: str,
prescriptions: typing.Sequence[PreviewOrderRequestPrescriptionsItem],
otc_items: typing.Optional[typing.Sequence[PreviewOrderRequestOtcItemsItem]] = OMIT,
patient_id: typing.Optional[str] = OMIT,
patient_external_id: typing.Optional[str] = OMIT,
patient: typing.Optional[PreviewOrderRequestPatient] = OMIT,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[PreviewOrderRequestPrescriber] = OMIT,
shipping_address_id: typing.Optional[str] = OMIT,
external_order_id: typing.Optional[str] = OMIT,
shipping: typing.Optional[PreviewOrderRequestShipping] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> PreviewOrderResponse:
"""
Requires orders:write and catalog:read. Supply exactly one of patientId, patientExternalId, or inline patient details. External-ID lookup additionally requires patients:read; inline details require patients:write. Resolves defaults and explicit edits for 1–20 prescriptions. Reuses stored patient details when identifiers match; otherwise previews inline details without creating a patient. Complete previews contain an orders.create input. Does not create records, reserve prices, sign, charge or transmit. No idempotency key is required. Creation and signing recheck current requirements.
Parameters
----------
practice_id : str
prescriptions : typing.Sequence[PreviewOrderRequestPrescriptionsItem]
otc_items : typing.Optional[typing.Sequence[PreviewOrderRequestOtcItemsItem]]
patient_id : typing.Optional[str]
patient_external_id : typing.Optional[str]
patient : typing.Optional[PreviewOrderRequestPatient]
user_id : typing.Optional[str]
prescriber : typing.Optional[PreviewOrderRequestPrescriber]
shipping_address_id : typing.Optional[str]
external_order_id : typing.Optional[str]
shipping : typing.Optional[PreviewOrderRequestShipping]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
PreviewOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
from affinity.orders import PreviewOrderRequestPrescriptionsItem
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.preview(
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
prescriptions=[
PreviewOrderRequestPrescriptionsItem(
medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
)
],
)
"""
_response = self._raw_client.preview(
practice_id=practice_id,
prescriptions=prescriptions,
otc_items=otc_items,
patient_id=patient_id,
patient_external_id=patient_external_id,
patient=patient,
user_id=user_id,
prescriber=prescriber,
shipping_address_id=shipping_address_id,
external_order_id=external_order_id,
shipping=shipping,
request_options=request_options,
)
return _response.data
def sign(
self,
order_id: str,
*,
idempotency_key: str,
practice_id: str,
signature_attestation: bool,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[SignOrderRequestPrescriber] = OMIT,
expected_revision: typing.Optional[str] = OMIT,
expected_versions: typing.Optional[typing.Sequence[SignOrderRequestExpectedVersionsItem]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SignOrderResponse:
"""
Requires orders:sign, Idempotency-Key, signatureAttestation, and expectedRevision from the reviewed order. Existing integrations may send expectedVersions instead; supply exactly one. A stale revision returns 409 and requires renewed clinician review. Select prescriber by npi, provider id, or integration-scoped externalId, or inherit the draft's prescriber. First-use registration requires team:write. Actor headers are optional audit metadata with prescriber; legacy userId requires matching clinician actor headers. Signing does not submit to a pharmacy.
Parameters
----------
order_id : str
idempotency_key : str
practice_id : str
signature_attestation : bool
user_id : typing.Optional[str]
prescriber : typing.Optional[SignOrderRequestPrescriber]
expected_revision : typing.Optional[str]
Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.
expected_versions : typing.Optional[typing.Sequence[SignOrderRequestExpectedVersionsItem]]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SignOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.sign(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
signature_attestation=True,
)
"""
_response = self._raw_client.sign(
order_id,
idempotency_key=idempotency_key,
practice_id=practice_id,
signature_attestation=signature_attestation,
user_id=user_id,
prescriber=prescriber,
expected_revision=expected_revision,
expected_versions=expected_versions,
request_options=request_options,
)
return _response.data
def sign_and_submit(
self,
order_id: str,
*,
idempotency_key: str,
practice_id: str,
signature_attestation: bool,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[SignAndSubmitOrderRequestPrescriber] = OMIT,
expected_revision: typing.Optional[str] = OMIT,
expected_versions: typing.Optional[typing.Sequence[SignAndSubmitOrderRequestExpectedVersionsItem]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SignAndSubmitOrderResponse:
"""
Requires orders:sign, Idempotency-Key, signatureAttestation, and expectedRevision from the reviewed order. Existing integrations may send expectedVersions instead; supply exactly one. A stale revision returns 409 and requires renewed clinician review. Select prescriber by npi, provider id, or externalId, or inherit the draft's prescriber. First-use registration requires team:write. Actor headers are optional with prescriber; legacy userId requires matching clinician actor headers. Signs the complete order, then attempts each submission. Signing remains committed if submission fails. Replay the same key after an uncertain response; retry reported submission failures through Submit order with a new key. Submitted means queued, not pharmacy acceptance.
Parameters
----------
order_id : str
idempotency_key : str
practice_id : str
signature_attestation : bool
user_id : typing.Optional[str]
prescriber : typing.Optional[SignAndSubmitOrderRequestPrescriber]
expected_revision : typing.Optional[str]
Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.
expected_versions : typing.Optional[typing.Sequence[SignAndSubmitOrderRequestExpectedVersionsItem]]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SignAndSubmitOrderResponse
HTTP 202
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.sign_and_submit(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
signature_attestation=True,
)
"""
_response = self._raw_client.sign_and_submit(
order_id,
idempotency_key=idempotency_key,
practice_id=practice_id,
signature_attestation=signature_attestation,
user_id=user_id,
prescriber=prescriber,
expected_revision=expected_revision,
expected_versions=expected_versions,
request_options=request_options,
)
return _response.data
def submit(
self,
order_id: str,
*,
idempotency_key: str,
practice_id: str,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[SubmitOrderRequestPrescriber] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SubmitOrderResponse:
"""
Requires orders:sign and Idempotency-Key. Queues signed prescriptions after rechecking authorization, signature integrity, billing, and fulfillment eligibility. Track pharmacy acceptance through order reads and webhooks. After a partial failure, retry submission with a new idempotency key; already queued prescriptions are not duplicated.
Parameters
----------
order_id : str
idempotency_key : str
practice_id : str
user_id : typing.Optional[str]
prescriber : typing.Optional[SubmitOrderRequestPrescriber]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SubmitOrderResponse
HTTP 202
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.submit(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)
"""
_response = self._raw_client.submit(
order_id,
idempotency_key=idempotency_key,
practice_id=practice_id,
user_id=user_id,
prescriber=prescriber,
request_options=request_options,
)
return _response.data
def reject(
self,
order_id: str,
*,
idempotency_key: str,
practice_id: str,
reason: str,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[RejectOrderRequestPrescriber] = OMIT,
expected_revision: typing.Optional[str] = OMIT,
expected_versions: typing.Optional[typing.Sequence[RejectOrderRequestExpectedVersionsItem]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> RejectOrderResponse:
"""
Requires orders:sign and Idempotency-Key. Select a prescriber or inherit the draft's prescriber. Legacy userId requires matching clinician actor headers. Supply expectedRevision from the reviewed order, or expectedVersions for existing integrations. Permanently rejects the complete unsigned order after checking its revision.
Parameters
----------
order_id : str
idempotency_key : str
practice_id : str
reason : str
user_id : typing.Optional[str]
prescriber : typing.Optional[RejectOrderRequestPrescriber]
expected_revision : typing.Optional[str]
Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.
expected_versions : typing.Optional[typing.Sequence[RejectOrderRequestExpectedVersionsItem]]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
RejectOrderResponse
HTTP 200
Examples
--------
from affinity import Affinity
client = Affinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
client.orders.reject(
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
reason="reason",
)
"""
_response = self._raw_client.reject(
order_id,
idempotency_key=idempotency_key,
practice_id=practice_id,
reason=reason,
user_id=user_id,
prescriber=prescriber,
expected_revision=expected_revision,
expected_versions=expected_versions,
request_options=request_options,
)
return _response.data
@property
def exceptions(self):
if self._exceptions is None:
from .exceptions.client import ExceptionsClient # noqa: E402
self._exceptions = ExceptionsClient(client_wrapper=self._client_wrapper)
return self._exceptions
@property
def events(self):
if self._events is None:
from .events.client import EventsClient # noqa: E402
self._events = EventsClient(client_wrapper=self._client_wrapper)
return self._events
@property
def test_simulation(self):
if self._test_simulation is None:
from .test_simulation.client import TestSimulationClient # noqa: E402
self._test_simulation = TestSimulationClient(client_wrapper=self._client_wrapper)
return self._test_simulation
@property
def prescriptions(self):
if self._prescriptions is None:
from .prescriptions.client import PrescriptionsClient # noqa: E402
self._prescriptions = PrescriptionsClient(client_wrapper=self._client_wrapper)
return self._prescriptions
@property
def batches(self):
if self._batches is None:
from .batches.client import BatchesClient # noqa: E402
self._batches = BatchesClient(client_wrapper=self._client_wrapper)
return self._batches
class AsyncOrdersClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawOrdersClient(client_wrapper=client_wrapper)
self._client_wrapper = client_wrapper
self._exceptions: typing.Optional[AsyncExceptionsClient] = None
self._events: typing.Optional[AsyncEventsClient] = None
self._test_simulation: typing.Optional[AsyncTestSimulationClient] = None
self._prescriptions: typing.Optional[AsyncPrescriptionsClient] = None
self._batches: typing.Optional[AsyncBatchesClient] = None
@property
def with_raw_response(self) -> AsyncRawOrdersClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawOrdersClient
"""
return self._raw_client
async def list(
self,
*,
query: typing.Optional[str] = None,
external_order_id: typing.Optional[str] = None,
created_after: typing.Optional[str] = None,
created_before: typing.Optional[str] = None,
ending_before: typing.Optional[str] = None,
limit: typing.Optional[int] = None,
order_id: typing.Optional[str] = None,
patient_id: typing.Optional[str] = None,
patient_external_id: typing.Optional[str] = None,
practice_id: typing.Optional[str] = None,
sort: typing.Optional[ListOrdersRequestSort] = None,
starting_after: typing.Optional[str] = None,
status: typing.Optional[ListOrdersRequestStatus] = None,
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ListOrdersResponse:
"""
Parameters
----------
query : typing.Optional[str]
external_order_id : typing.Optional[str]
created_after : typing.Optional[str]
created_before : typing.Optional[str]
ending_before : typing.Optional[str]
limit : typing.Optional[int]
order_id : typing.Optional[str]
patient_id : typing.Optional[str]
patient_external_id : typing.Optional[str]
practice_id : typing.Optional[str]
sort : typing.Optional[ListOrdersRequestSort]
starting_after : typing.Optional[str]
status : typing.Optional[ListOrdersRequestStatus]
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ListOrdersResponse
HTTP 200
Examples
--------
import asyncio
from affinity import AsyncAffinity
client = AsyncAffinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.orders.list(
ending_before="ord_01j2y8m6jcc9tt24af5pw9x1bc",
order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
starting_after="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)
asyncio.run(main())
"""
_response = await self._raw_client.list(
query=query,
external_order_id=external_order_id,
created_after=created_after,
created_before=created_before,
ending_before=ending_before,
limit=limit,
order_id=order_id,
patient_id=patient_id,
patient_external_id=patient_external_id,
practice_id=practice_id,
sort=sort,
starting_after=starting_after,
status=status,
affinity_actor_id=affinity_actor_id,
affinity_actor_type=affinity_actor_type,
request_options=request_options,
)
return _response.data
async def create(
self,
*,
idempotency_key: str,
practice_id: str,
prescriptions: typing.Sequence[CreateOrderRequestPrescriptionsItem],
affinity_actor_id: typing.Optional[str] = None,
affinity_actor_type: typing.Optional[str] = None,
user_id: typing.Optional[str] = OMIT,
prescriber: typing.Optional[CreateOrderRequestPrescriber] = OMIT,
otc_items: typing.Optional[typing.Sequence[CreateOrderRequestOtcItemsItem]] = OMIT,
external_order_id: typing.Optional[str] = OMIT,
metadata: typing.Optional[typing.Dict[str, typing.Optional[CreateOrderRequestMetadataValue]]] = OMIT,
patient_id: typing.Optional[str] = OMIT,
patient: typing.Optional[CreateOrderRequestPatient] = OMIT,
shipping_address_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateOrderResponse:
"""
Creates one unsigned order with 1–20 prescriptions for one patient in one practice. Supply patientId or patient; inline patient creation requires patients:write. Prescriber is optional: select by npi, provider id, or integration-scoped externalId, or leave the draft unassigned until signing. First-use prescriber registration requires team:write. Legacy userId is supported but cannot be combined with prescriber. Idempotency-Key is required.
Parameters
----------
idempotency_key : str
practice_id : str
prescriptions : typing.Sequence[CreateOrderRequestPrescriptionsItem]
affinity_actor_id : typing.Optional[str]
Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
affinity_actor_type : typing.Optional[str]
Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
user_id : typing.Optional[str]
prescriber : typing.Optional[CreateOrderRequestPrescriber]
otc_items : typing.Optional[typing.Sequence[CreateOrderRequestOtcItemsItem]]
external_order_id : typing.Optional[str]
metadata : typing.Optional[typing.Dict[str, typing.Optional[CreateOrderRequestMetadataValue]]]
patient_id : typing.Optional[str]
patient : typing.Optional[CreateOrderRequestPatient]
shipping_address_id : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateOrderResponse
HTTP 200
Examples
--------
import asyncio
from affinity import AsyncAffinity
from affinity.orders import (
CreateOrderRequestPrescriptionsItem,
CreateOrderRequestPrescriptionsItemDispensing,
)
client = AsyncAffinity(
affinity_version="YOUR_AFFINITY_VERSION",
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.orders.create(
idempotency_key="Idempotency-Key",
practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
prescriptions=[
CreateOrderRequestPrescriptionsItem(
days_supply=1,
dispensing=CreateOrderRequestPrescriptionsItemDispensing(),
directions="directions",
medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
quantity="NaN",
quantity_unit="quantityUnit",
refills=1,
)
],
)
asyncio.run(main())
"""
_response = await self._raw_client.create(
idempotency_key=idempotency_key,