@medplum/mock 0.4.0

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.
@@ -0,0 +1,1108 @@
1
+ import { allOk, badRequest, notFound, getStatus, MedplumClient } from '@medplum/core';
2
+
3
+ const TestOrganization = {
4
+ resourceType: 'Organization',
5
+ id: '123',
6
+ meta: {
7
+ versionId: '1',
8
+ },
9
+ name: 'Test Organization',
10
+ };
11
+ const DifferentOrganization = {
12
+ resourceType: 'Organization',
13
+ id: '456',
14
+ meta: {
15
+ versionId: '1',
16
+ },
17
+ name: 'Different',
18
+ };
19
+ const OrganizationSearchBundle = {
20
+ resourceType: 'Bundle',
21
+ type: 'searchset',
22
+ entry: [
23
+ {
24
+ resource: DifferentOrganization,
25
+ },
26
+ ],
27
+ };
28
+ const DrAliceSmith = {
29
+ resourceType: 'Practitioner',
30
+ id: '123',
31
+ meta: {
32
+ versionId: '2',
33
+ lastUpdated: '2021-01-02T12:00:00Z',
34
+ author: {
35
+ reference: 'Practitioner/123',
36
+ },
37
+ },
38
+ name: [
39
+ {
40
+ given: ['Alice'],
41
+ family: 'Smith',
42
+ },
43
+ ],
44
+ };
45
+ const DrAliceSmithHistoryBundle = {
46
+ resourceType: 'Bundle',
47
+ type: 'history',
48
+ entry: [
49
+ {
50
+ resource: DrAliceSmith,
51
+ },
52
+ {
53
+ resource: {
54
+ resourceType: 'Practitioner',
55
+ id: '123',
56
+ meta: {
57
+ versionId: '1',
58
+ lastUpdated: '2021-01-01T12:00:00Z',
59
+ author: {
60
+ reference: 'Practitioner/123',
61
+ },
62
+ },
63
+ name: [{ given: ['Medplum'], family: 'Admin' }],
64
+ },
65
+ },
66
+ ],
67
+ };
68
+
69
+ const ExampleBot = {
70
+ resourceType: 'Bot',
71
+ id: '123',
72
+ name: 'Test Bot',
73
+ code: 'console.log("hello world");',
74
+ };
75
+
76
+ const ExampleQuestionnaire = {
77
+ resourceType: 'Questionnaire',
78
+ id: '123',
79
+ name: 'Vitals',
80
+ title: 'Vitals',
81
+ item: [
82
+ {
83
+ linkId: '1',
84
+ text: 'First question',
85
+ type: 'string',
86
+ },
87
+ ],
88
+ };
89
+ const ExampleQuestionnaireBundle = {
90
+ resourceType: 'Bundle',
91
+ type: 'searchset',
92
+ entry: [
93
+ {
94
+ resource: ExampleQuestionnaire,
95
+ },
96
+ ],
97
+ };
98
+ const ExampleQuestionnaireResponse = {
99
+ resourceType: 'QuestionnaireResponse',
100
+ id: '123',
101
+ questionnaire: 'Questionnaire/123',
102
+ subject: {
103
+ reference: 'Patient/123',
104
+ },
105
+ source: {
106
+ reference: 'Practitioner/123',
107
+ },
108
+ };
109
+
110
+ const HomerSimpson = {
111
+ resourceType: 'Patient',
112
+ id: '123',
113
+ meta: {
114
+ versionId: '2',
115
+ lastUpdated: '2020-01-02T00:00:00.000Z',
116
+ author: {
117
+ reference: 'Practitioner/123',
118
+ },
119
+ },
120
+ identifier: [
121
+ { system: 'abc', value: '123' },
122
+ { system: 'def', value: '456' },
123
+ ],
124
+ name: [
125
+ {
126
+ given: ['Homer'],
127
+ family: 'Simpson',
128
+ },
129
+ ],
130
+ photo: [
131
+ {
132
+ contentType: 'image/jpeg',
133
+ url: 'https://example.com/picture.jpg',
134
+ },
135
+ ],
136
+ };
137
+ const HomerSimpsonHistory = {
138
+ resourceType: 'Bundle',
139
+ type: 'history',
140
+ entry: [
141
+ {
142
+ resource: HomerSimpson,
143
+ },
144
+ {
145
+ resource: {
146
+ resourceType: 'Patient',
147
+ id: '123',
148
+ meta: {
149
+ versionId: '1',
150
+ lastUpdated: '2020-01-01T00:00:00.000Z',
151
+ author: {
152
+ reference: 'Practitioner/123',
153
+ },
154
+ },
155
+ name: [
156
+ {
157
+ given: ['Homer'],
158
+ family: 'Simpson',
159
+ },
160
+ ],
161
+ photo: [
162
+ {
163
+ contentType: 'image/jpeg',
164
+ url: 'https://example.com/picture.jpg',
165
+ },
166
+ ],
167
+ },
168
+ },
169
+ ],
170
+ };
171
+ const HomerEncounter = {
172
+ resourceType: 'Encounter',
173
+ id: '123',
174
+ meta: {
175
+ versionId: '456',
176
+ },
177
+ };
178
+ const HomerEncounterHistory = {
179
+ resourceType: 'Bundle',
180
+ type: 'history',
181
+ entry: [
182
+ {
183
+ resource: HomerEncounter,
184
+ },
185
+ ],
186
+ };
187
+ const HomerCommunications = {
188
+ resourceType: 'Bundle',
189
+ entry: [
190
+ {
191
+ resource: {
192
+ resourceType: 'Communication',
193
+ id: '123',
194
+ meta: {
195
+ lastUpdated: '2020-01-01T12:00:00Z',
196
+ author: {
197
+ reference: 'Practitioner/123',
198
+ },
199
+ },
200
+ payload: [
201
+ {
202
+ contentString: 'Hello world',
203
+ },
204
+ ],
205
+ },
206
+ },
207
+ ],
208
+ };
209
+ const HomerMedia = {
210
+ resourceType: 'Bundle',
211
+ entry: [
212
+ {
213
+ resource: {
214
+ resourceType: 'Media',
215
+ id: '123',
216
+ meta: {
217
+ lastUpdated: '2020-01-01T12:00:00Z',
218
+ author: {
219
+ reference: 'Practitioner/123',
220
+ },
221
+ },
222
+ content: {
223
+ contentType: 'text/plain',
224
+ url: 'https://example.com/test.txt',
225
+ },
226
+ },
227
+ },
228
+ ],
229
+ };
230
+ const HomerDiagnosticReport = {
231
+ resourceType: 'DiagnosticReport',
232
+ id: '123',
233
+ subject: {
234
+ reference: 'Patient/123',
235
+ display: 'Homer Simpson',
236
+ },
237
+ resultsInterpreter: [
238
+ {
239
+ reference: 'Practitioner/123',
240
+ display: 'Dr. Alice Smith',
241
+ },
242
+ ],
243
+ result: [
244
+ { reference: 'Observation/1' },
245
+ { reference: 'Observation/2' },
246
+ { reference: 'Observation/3' },
247
+ { reference: 'Observation/4' },
248
+ { reference: 'Observation/5' },
249
+ { reference: 'Observation/6' },
250
+ ],
251
+ };
252
+ const HomerDiagnosticReportBundle = {
253
+ resourceType: 'Bundle',
254
+ type: 'searchset',
255
+ entry: [
256
+ {
257
+ resource: HomerDiagnosticReport,
258
+ },
259
+ ],
260
+ };
261
+ const HomerObservation1 = {
262
+ resourceType: 'Observation',
263
+ id: '1',
264
+ valueString: 'test',
265
+ };
266
+ const HomerObservation2 = {
267
+ resourceType: 'Observation',
268
+ id: '2',
269
+ valueQuantity: {
270
+ value: 20,
271
+ unit: 'x',
272
+ },
273
+ referenceRange: [
274
+ {
275
+ low: {
276
+ value: 10,
277
+ },
278
+ },
279
+ ],
280
+ };
281
+ const HomerObservation3 = {
282
+ resourceType: 'Observation',
283
+ id: '3',
284
+ valueQuantity: {
285
+ value: 30,
286
+ unit: 'x',
287
+ },
288
+ referenceRange: [
289
+ {
290
+ high: {
291
+ value: 50,
292
+ },
293
+ },
294
+ ],
295
+ };
296
+ const HomerObservation4 = {
297
+ resourceType: 'Observation',
298
+ id: '4',
299
+ valueQuantity: {
300
+ value: 50,
301
+ unit: 'x',
302
+ },
303
+ referenceRange: [
304
+ {
305
+ low: {
306
+ value: 10,
307
+ },
308
+ high: {
309
+ value: 50,
310
+ },
311
+ },
312
+ ],
313
+ interpretation: [
314
+ {
315
+ text: 'HIGH',
316
+ },
317
+ ],
318
+ };
319
+ const HomerObservation5 = {
320
+ resourceType: 'Observation',
321
+ id: '5',
322
+ valueQuantity: {
323
+ value: 100,
324
+ unit: 'x',
325
+ },
326
+ referenceRange: [{}],
327
+ interpretation: [{}],
328
+ };
329
+ const HomerObservation6 = {
330
+ resourceType: 'Observation',
331
+ component: [
332
+ {
333
+ valueQuantity: {
334
+ value: 110,
335
+ unit: 'mmHg',
336
+ system: 'http://unitsofmeasure.org',
337
+ },
338
+ },
339
+ {
340
+ valueQuantity: {
341
+ value: 75,
342
+ unit: 'mmHg',
343
+ system: 'http://unitsofmeasure.org',
344
+ },
345
+ },
346
+ ],
347
+ };
348
+ const HomerObservationSearchBundle = {
349
+ resourceType: 'Bundle',
350
+ total: 1,
351
+ entry: [
352
+ {
353
+ resource: HomerObservation3,
354
+ },
355
+ ],
356
+ };
357
+ const HomerServiceRequest = {
358
+ resourceType: 'ServiceRequest',
359
+ id: '123',
360
+ meta: {
361
+ versionId: '1',
362
+ lastUpdated: '2020-01-01T12:00:00Z',
363
+ author: {
364
+ reference: 'Practitioner/123',
365
+ },
366
+ },
367
+ code: {
368
+ coding: [
369
+ {
370
+ system: 'http://snomed.info/sct',
371
+ code: 'SERVICE_REQUEST_CODE',
372
+ },
373
+ ],
374
+ },
375
+ subject: {
376
+ reference: 'Patient/123',
377
+ display: 'Homer Simpson',
378
+ },
379
+ };
380
+ const HomerServiceRequestHistoryBundle = {
381
+ resourceType: 'Bundle',
382
+ type: 'history',
383
+ entry: [
384
+ {
385
+ resource: HomerServiceRequest,
386
+ },
387
+ ],
388
+ };
389
+ const HomerServiceRequestSearchBundle = {
390
+ resourceType: 'Bundle',
391
+ type: 'searchset',
392
+ entry: [
393
+ {
394
+ resource: HomerServiceRequest,
395
+ },
396
+ ],
397
+ };
398
+ const BartSimpson = {
399
+ resourceType: 'Patient',
400
+ id: '555',
401
+ meta: {
402
+ versionId: '1',
403
+ lastUpdated: '2020-01-01T12:00:00Z',
404
+ author: {
405
+ reference: 'Practitioner/123',
406
+ },
407
+ },
408
+ name: [
409
+ {
410
+ given: ['Bart'],
411
+ family: 'Simpson',
412
+ },
413
+ ],
414
+ photo: [
415
+ {
416
+ contentType: 'image/jpeg',
417
+ url: 'https://example.com/picture.jpg',
418
+ },
419
+ ],
420
+ };
421
+ const SimpsonSearchBundle = {
422
+ resourceType: 'Bundle',
423
+ type: 'searchset',
424
+ total: 2,
425
+ entry: [
426
+ {
427
+ resource: HomerSimpson,
428
+ },
429
+ {
430
+ resource: BartSimpson,
431
+ },
432
+ ],
433
+ };
434
+
435
+ const ExampleSubscription = {
436
+ resourceType: 'Subscription',
437
+ id: '123',
438
+ meta: {
439
+ versionId: '456',
440
+ },
441
+ };
442
+ const ExampleSubscriptionHistory = {
443
+ resourceType: 'Bundle',
444
+ type: 'history',
445
+ entry: [
446
+ {
447
+ resource: ExampleSubscription,
448
+ },
449
+ ],
450
+ };
451
+ const ExampleAuditEvent = {
452
+ resourceType: 'AuditEvent',
453
+ id: '123',
454
+ meta: {
455
+ lastUpdated: new Date().toISOString(),
456
+ versionId: '456',
457
+ author: {
458
+ reference: 'Practitioner/123',
459
+ },
460
+ },
461
+ };
462
+ const ExampleAuditEventBundle = {
463
+ resourceType: 'Bundle',
464
+ entry: [
465
+ {
466
+ resource: ExampleAuditEvent,
467
+ },
468
+ ],
469
+ };
470
+
471
+ const EmptySearchBundle = {
472
+ resourceType: 'Bundle',
473
+ type: 'searchset',
474
+ total: 0,
475
+ entry: [],
476
+ };
477
+ const ObservationStructureDefinition = {
478
+ resourceType: 'StructureDefinition',
479
+ name: 'Observation',
480
+ snapshot: {
481
+ element: [
482
+ {
483
+ path: 'Observation.id',
484
+ type: [
485
+ {
486
+ code: 'code',
487
+ },
488
+ ],
489
+ },
490
+ {
491
+ path: 'Observation.value[x]',
492
+ min: 0,
493
+ max: '1',
494
+ type: [
495
+ {
496
+ code: 'Quantity',
497
+ },
498
+ {
499
+ code: 'CodeableConcept',
500
+ },
501
+ {
502
+ code: 'string',
503
+ },
504
+ {
505
+ code: 'boolean',
506
+ },
507
+ {
508
+ code: 'integer',
509
+ },
510
+ {
511
+ code: 'Range',
512
+ },
513
+ {
514
+ code: 'Ratio',
515
+ },
516
+ {
517
+ code: 'SampledData',
518
+ },
519
+ {
520
+ code: 'time',
521
+ },
522
+ {
523
+ code: 'dateTime',
524
+ },
525
+ {
526
+ code: 'Period',
527
+ },
528
+ ],
529
+ },
530
+ ],
531
+ },
532
+ };
533
+ const PatientStructureDefinition = {
534
+ resourceType: 'StructureDefinition',
535
+ id: '123',
536
+ name: 'Patient',
537
+ snapshot: {
538
+ element: [
539
+ {
540
+ id: 'Patient.name',
541
+ path: 'Patient.name',
542
+ type: [
543
+ {
544
+ code: 'HumanName',
545
+ },
546
+ ],
547
+ max: '*',
548
+ },
549
+ ],
550
+ },
551
+ };
552
+ const PatientSearchParameters = [
553
+ {
554
+ resourceType: 'SearchParameter',
555
+ id: 'Patient-name',
556
+ base: ['Patient'],
557
+ code: 'name',
558
+ name: 'name',
559
+ type: 'string',
560
+ expression: 'Patient.name',
561
+ },
562
+ {
563
+ resourceType: 'SearchParameter',
564
+ id: 'Patient-birthdate',
565
+ base: ['Patient'],
566
+ code: 'birthdate',
567
+ name: 'birthdate',
568
+ type: 'date',
569
+ expression: 'Patient.birthdate',
570
+ },
571
+ {
572
+ resourceType: 'SearchParameter',
573
+ id: 'Patient-organization',
574
+ base: ['Patient'],
575
+ code: 'organization',
576
+ name: 'organization',
577
+ type: 'reference',
578
+ expression: 'Patient.organization',
579
+ target: ['Organization'],
580
+ },
581
+ ];
582
+ const PractitionerStructureDefinition = {
583
+ resourceType: 'StructureDefinition',
584
+ name: 'Practitioner',
585
+ snapshot: {
586
+ element: [
587
+ {
588
+ path: 'Practitioner.id',
589
+ type: [
590
+ {
591
+ code: 'code',
592
+ },
593
+ ],
594
+ },
595
+ {
596
+ path: 'Practitioner.name',
597
+ type: [
598
+ {
599
+ code: 'HumanName',
600
+ },
601
+ ],
602
+ max: '*',
603
+ },
604
+ {
605
+ path: 'Practitioner.gender',
606
+ type: [
607
+ {
608
+ code: 'code',
609
+ },
610
+ ],
611
+ },
612
+ ],
613
+ },
614
+ };
615
+ const QuestionnaireStructureDefinition = {
616
+ resourceType: 'StructureDefinition',
617
+ name: 'Questionnaire',
618
+ snapshot: {
619
+ element: [
620
+ {
621
+ id: 'Questionnaire.item',
622
+ path: 'Questionnaire.item',
623
+ type: [
624
+ {
625
+ code: 'BackboneElement',
626
+ },
627
+ ],
628
+ },
629
+ {
630
+ id: 'Questionnaire.item.answerOption',
631
+ path: 'Questionnaire.item.answerOption',
632
+ type: [
633
+ {
634
+ code: 'BackboneElement',
635
+ },
636
+ ],
637
+ },
638
+ {
639
+ id: 'Questionnaire.item.answerOption.value[x]',
640
+ path: 'Questionnaire.item.answerOption.value[x]',
641
+ min: 1,
642
+ max: '1',
643
+ type: [
644
+ {
645
+ code: 'integer',
646
+ },
647
+ {
648
+ code: 'date',
649
+ },
650
+ {
651
+ code: 'time',
652
+ },
653
+ {
654
+ code: 'string',
655
+ },
656
+ {
657
+ code: 'Coding',
658
+ },
659
+ {
660
+ code: 'Reference',
661
+ targetProfile: ['http://hl7.org/fhir/StructureDefinition/Resource'],
662
+ },
663
+ ],
664
+ },
665
+ ],
666
+ },
667
+ };
668
+ const ServiceRequestServiceDefinition = {
669
+ resourceType: 'StructureDefinition',
670
+ name: 'ServiceRequest',
671
+ snapshot: {
672
+ element: [
673
+ {
674
+ path: 'ServiceRequest.id',
675
+ type: [
676
+ {
677
+ code: 'code',
678
+ },
679
+ ],
680
+ },
681
+ {
682
+ path: 'ServiceRequest.code',
683
+ type: [
684
+ {
685
+ code: 'CodeableConcept',
686
+ },
687
+ ],
688
+ },
689
+ ],
690
+ },
691
+ };
692
+ const GraphQLSchemaResponse = {
693
+ data: {
694
+ StructureDefinitionList: [
695
+ ObservationStructureDefinition,
696
+ PatientStructureDefinition,
697
+ PractitionerStructureDefinition,
698
+ QuestionnaireStructureDefinition,
699
+ ServiceRequestServiceDefinition,
700
+ ],
701
+ SearchParameterList: [...PatientSearchParameters],
702
+ },
703
+ };
704
+
705
+ const exampleValueSet = {
706
+ resourceType: 'ValueSet',
707
+ expansion: {
708
+ contains: [
709
+ {
710
+ system: 'x',
711
+ code: 'test-code',
712
+ display: 'Test Display',
713
+ },
714
+ ],
715
+ },
716
+ };
717
+
718
+ const ExampleAccessPolicy = {
719
+ resourceType: 'AccessPolicy',
720
+ id: '123',
721
+ name: 'Example Access Policy',
722
+ };
723
+ const ExampleAccessPolicySearchBundle = {
724
+ resourceType: 'Bundle',
725
+ type: 'searchset',
726
+ entry: [
727
+ {
728
+ resource: ExampleAccessPolicy,
729
+ },
730
+ ],
731
+ };
732
+
733
+ const newComment = {
734
+ resourceType: 'Communication',
735
+ id: 'new-comment',
736
+ payload: [
737
+ {
738
+ contentString: 'Test comment',
739
+ },
740
+ ],
741
+ };
742
+ const newMedia = {
743
+ resourceType: 'Media',
744
+ id: 'new-media',
745
+ content: {
746
+ contentType: 'text/plain',
747
+ url: 'https://example.com/test2.txt',
748
+ },
749
+ };
750
+ const routes = {
751
+ 'admin/projects/123': {
752
+ GET: {
753
+ project: { id: '123', name: 'Project 123' },
754
+ members: [{ profile: 'Practitioner/123', name: 'Alice Smith' }],
755
+ },
756
+ },
757
+ 'admin/super/structuredefinitions': {
758
+ POST: {
759
+ ok: true,
760
+ },
761
+ },
762
+ 'admin/super/valuesets': {
763
+ POST: {
764
+ ok: true,
765
+ },
766
+ },
767
+ 'admin/super/reindex': {
768
+ POST: {
769
+ ok: true,
770
+ },
771
+ },
772
+ 'auth/changepassword': {
773
+ POST: (body) => {
774
+ const { oldPassword } = JSON.parse(body);
775
+ if (oldPassword === 'orange') {
776
+ return allOk;
777
+ }
778
+ else {
779
+ return {
780
+ resourceType: 'OperationOutcome',
781
+ issue: [
782
+ {
783
+ expression: ['oldPassword'],
784
+ details: {
785
+ text: 'Incorrect password',
786
+ },
787
+ },
788
+ ],
789
+ };
790
+ }
791
+ },
792
+ },
793
+ 'auth/login': {
794
+ POST: {
795
+ profile: { reference: 'Practitioner/123' },
796
+ },
797
+ },
798
+ 'auth/setpassword': {
799
+ POST: (body) => {
800
+ const { password } = JSON.parse(body);
801
+ if (password === 'orange') {
802
+ return allOk;
803
+ }
804
+ else {
805
+ return {
806
+ resourceType: 'OperationOutcome',
807
+ issue: [
808
+ {
809
+ expression: ['password'],
810
+ details: {
811
+ text: 'Invalid password',
812
+ },
813
+ },
814
+ ],
815
+ };
816
+ }
817
+ },
818
+ },
819
+ 'auth/register': {
820
+ POST: (body) => {
821
+ const { email, password } = JSON.parse(body);
822
+ if (email === 'george@example.com' && password === 'password') {
823
+ return allOk;
824
+ }
825
+ else {
826
+ return {
827
+ resourceType: 'OperationOutcome',
828
+ issue: [
829
+ {
830
+ details: {
831
+ text: 'Invalid',
832
+ },
833
+ },
834
+ ],
835
+ };
836
+ }
837
+ },
838
+ },
839
+ 'auth/resetpassword': {
840
+ POST: (body) => {
841
+ const { email } = JSON.parse(body);
842
+ if (email === 'admin@example.com') {
843
+ return allOk;
844
+ }
845
+ else {
846
+ return {
847
+ resourceType: 'OperationOutcome',
848
+ issue: [
849
+ {
850
+ expression: ['email'],
851
+ details: {
852
+ text: 'Email not found',
853
+ },
854
+ },
855
+ ],
856
+ };
857
+ }
858
+ },
859
+ },
860
+ 'fhir/R4/AccessPolicy?name=Example%20Access%20Policy': {
861
+ GET: ExampleAccessPolicySearchBundle,
862
+ },
863
+ 'fhir/R4/AccessPolicy/123': {
864
+ GET: ExampleAccessPolicy,
865
+ },
866
+ 'fhir/R4/AuditEvent?entity=Subscription/123&_count=20&_sort=-_lastUpdated': {
867
+ GET: ExampleAuditEventBundle,
868
+ },
869
+ 'fhir/R4/Binary?_filename=hello.exe': {
870
+ POST: badRequest('Invalid file type'),
871
+ },
872
+ 'fhir/R4/Bot/123': {
873
+ GET: ExampleBot,
874
+ },
875
+ 'fhir/R4/Communication': {
876
+ POST: newComment,
877
+ },
878
+ 'fhir/R4/Communication?based-on=ServiceRequest/123': {
879
+ GET: HomerCommunications,
880
+ },
881
+ 'fhir/R4/Communication?encounter=Encounter/123': {
882
+ GET: HomerCommunications,
883
+ },
884
+ 'fhir/R4/Communication?subject=Patient/123': {
885
+ GET: HomerCommunications,
886
+ },
887
+ 'fhir/R4/Device?subject=Patient/123': {
888
+ GET: EmptySearchBundle,
889
+ },
890
+ 'fhir/R4/DeviceRequest?patient=Patient/123': {
891
+ GET: EmptySearchBundle,
892
+ },
893
+ 'fhir/R4/DiagnosticReport/123': {
894
+ GET: HomerDiagnosticReport,
895
+ },
896
+ 'fhir/R4/DiagnosticReport/123/_history': {
897
+ GET: HomerDiagnosticReportBundle,
898
+ },
899
+ 'fhir/R4/DiagnosticReport?based-on=ServiceRequest/123': {
900
+ GET: HomerDiagnosticReportBundle,
901
+ },
902
+ 'fhir/R4/DiagnosticReport?subject=Patient/123': {
903
+ GET: HomerDiagnosticReportBundle,
904
+ },
905
+ 'fhir/R4/Encounter/123': {
906
+ GET: HomerEncounter,
907
+ },
908
+ 'fhir/R4/Encounter/123/_history': {
909
+ GET: HomerEncounterHistory,
910
+ },
911
+ 'fhir/R4/Media': {
912
+ POST: newMedia,
913
+ },
914
+ 'fhir/R4/Media?based-on=ServiceRequest/123': {
915
+ GET: HomerMedia,
916
+ },
917
+ 'fhir/R4/Media?encounter=Encounter/123': {
918
+ GET: HomerMedia,
919
+ },
920
+ 'fhir/R4/Media?subject=Patient/123': {
921
+ GET: HomerMedia,
922
+ },
923
+ 'fhir/R4/Observation?_fields=value[x]': {
924
+ GET: HomerObservationSearchBundle,
925
+ },
926
+ 'fhir/R4/Observation/1': {
927
+ GET: HomerObservation1,
928
+ },
929
+ 'fhir/R4/Observation/2': {
930
+ GET: HomerObservation2,
931
+ },
932
+ 'fhir/R4/Observation/3': {
933
+ GET: HomerObservation3,
934
+ },
935
+ 'fhir/R4/Observation/4': {
936
+ GET: HomerObservation4,
937
+ },
938
+ 'fhir/R4/Observation/5': {
939
+ GET: HomerObservation5,
940
+ },
941
+ 'fhir/R4/Observation/6': {
942
+ GET: HomerObservation6,
943
+ },
944
+ 'fhir/R4/Organization?name=Different': {
945
+ GET: OrganizationSearchBundle,
946
+ },
947
+ 'fhir/R4/Organization/123': {
948
+ GET: TestOrganization,
949
+ },
950
+ 'fhir/R4/Organization/456': {
951
+ GET: DifferentOrganization,
952
+ },
953
+ 'fhir/R4/Patient?name=Simpson': {
954
+ GET: SimpsonSearchBundle,
955
+ },
956
+ 'fhir/R4/Patient?_fields=id,_lastUpdated,name&name=Simpson': {
957
+ GET: SimpsonSearchBundle,
958
+ },
959
+ 'fhir/R4/Patient?_count=20&_fields=id,_lastUpdated,name,birthDate,gender&_sort=-_lastUpdated': {
960
+ GET: SimpsonSearchBundle,
961
+ },
962
+ 'fhir/R4/Patient?_fields=id,_lastUpdated,name&_lastUpdated=ge2021-12-01T00%3A00%3A00.000Z': {
963
+ GET: SimpsonSearchBundle,
964
+ },
965
+ 'fhir/R4/Patient?name=Bob': {
966
+ GET: EmptySearchBundle,
967
+ },
968
+ 'fhir/R4/Patient/123': {
969
+ GET: HomerSimpson,
970
+ },
971
+ 'fhir/R4/Patient/123/_history': {
972
+ GET: HomerSimpsonHistory,
973
+ },
974
+ 'fhir/R4/Practitioner': {
975
+ POST: HomerSimpson,
976
+ },
977
+ 'fhir/R4/Practitioner/123': {
978
+ GET: DrAliceSmith,
979
+ },
980
+ 'fhir/R4/Practitioner/123/_history': {
981
+ GET: DrAliceSmithHistoryBundle,
982
+ },
983
+ 'fhir/R4/Practitioner/123/_history/1': {
984
+ GET: DrAliceSmith,
985
+ },
986
+ 'fhir/R4/Practitioner/not-found/_history': {
987
+ GET: notFound,
988
+ },
989
+ 'fhir/R4/Questionnaire?subject-type=Patient': {
990
+ GET: ExampleQuestionnaireBundle,
991
+ },
992
+ 'fhir/R4/Questionnaire/not-found': {
993
+ GET: notFound,
994
+ },
995
+ 'fhir/R4/Questionnaire/123': {
996
+ GET: ExampleQuestionnaire,
997
+ },
998
+ 'fhir/R4/QuestionnaireResponse': {
999
+ POST: ExampleQuestionnaireResponse,
1000
+ },
1001
+ 'fhir/R4/QuestionnaireResponse/123': {
1002
+ GET: ExampleQuestionnaireResponse,
1003
+ },
1004
+ 'fhir/R4/ServiceRequest/123': {
1005
+ GET: HomerServiceRequest,
1006
+ },
1007
+ 'fhir/R4/ServiceRequest/123/_history': {
1008
+ GET: HomerServiceRequestHistoryBundle,
1009
+ },
1010
+ 'fhir/R4/ServiceRequest?subject=Patient/123': {
1011
+ GET: HomerServiceRequestSearchBundle,
1012
+ },
1013
+ 'fhir/R4/Subscription/123': {
1014
+ GET: ExampleSubscription,
1015
+ },
1016
+ 'fhir/R4/Subscription/123/_history': {
1017
+ GET: ExampleSubscriptionHistory,
1018
+ },
1019
+ 'fhir/R4/ValueSet/%24expand?url=https%3A%2F%2Fexample.com%2Ftest&filter=xyz': {
1020
+ GET: exampleValueSet,
1021
+ },
1022
+ 'fhir/R4/%24graphql': {
1023
+ POST: GraphQLSchemaResponse,
1024
+ },
1025
+ 'fhir/R4': {
1026
+ POST: (body) => {
1027
+ var _a;
1028
+ const request = JSON.parse(body);
1029
+ return {
1030
+ resourceType: 'Bundle',
1031
+ type: 'batch-response',
1032
+ entry: (_a = request.entry) === null || _a === void 0 ? void 0 : _a.map((e) => {
1033
+ var _a, _b, _c;
1034
+ const url = 'fhir/R4/' + ((_a = e === null || e === void 0 ? void 0 : e.request) === null || _a === void 0 ? void 0 : _a.url);
1035
+ const method = (_b = e === null || e === void 0 ? void 0 : e.request) === null || _b === void 0 ? void 0 : _b.method;
1036
+ const resource = (_c = routes[url]) === null || _c === void 0 ? void 0 : _c[method];
1037
+ if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
1038
+ return { resource, response: { status: getStatus(resource).toString() } };
1039
+ }
1040
+ else if (resource) {
1041
+ return { resource, response: { status: '200' } };
1042
+ }
1043
+ else {
1044
+ return { resource: notFound, response: { status: '404' } };
1045
+ }
1046
+ }),
1047
+ };
1048
+ },
1049
+ },
1050
+ };
1051
+ class MockClient extends MedplumClient {
1052
+ constructor(clientOptions) {
1053
+ super({
1054
+ baseUrl: 'https://example.com/',
1055
+ clientId: 'my-client-id',
1056
+ fetch: (url, options) => {
1057
+ var _a;
1058
+ const method = options.method;
1059
+ const path = url.replace('https://example.com/', '');
1060
+ if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
1061
+ console.log('MockClient', method, path);
1062
+ }
1063
+ let result = (_a = routes[path]) === null || _a === void 0 ? void 0 : _a[method];
1064
+ if (typeof result === 'function') {
1065
+ result = result(options.body);
1066
+ }
1067
+ if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !result) {
1068
+ console.log('MockClient: not found', method, path);
1069
+ }
1070
+ const response = Object.assign({ request: {
1071
+ url,
1072
+ options,
1073
+ } }, result);
1074
+ if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
1075
+ console.log('MockClient', JSON.stringify(response, null, 2));
1076
+ }
1077
+ return Promise.resolve({
1078
+ json: () => Promise.resolve(response),
1079
+ });
1080
+ },
1081
+ });
1082
+ }
1083
+ clear() {
1084
+ super.clear();
1085
+ this.activeLoginOverride = undefined;
1086
+ }
1087
+ getProfile() {
1088
+ return {
1089
+ resourceType: 'Practitioner',
1090
+ id: '123',
1091
+ meta: {
1092
+ versionId: '456',
1093
+ },
1094
+ };
1095
+ }
1096
+ setActiveLoginOverride(activeLoginOverride) {
1097
+ this.activeLoginOverride = activeLoginOverride;
1098
+ }
1099
+ getActiveLogin() {
1100
+ if (this.activeLoginOverride !== undefined) {
1101
+ return this.activeLoginOverride;
1102
+ }
1103
+ return super.getActiveLogin();
1104
+ }
1105
+ }
1106
+
1107
+ export { BartSimpson, DifferentOrganization, DrAliceSmith, DrAliceSmithHistoryBundle, EmptySearchBundle, ExampleAuditEvent, ExampleAuditEventBundle, ExampleBot, ExampleQuestionnaire, ExampleQuestionnaireBundle, ExampleQuestionnaireResponse, ExampleSubscription, ExampleSubscriptionHistory, GraphQLSchemaResponse, HomerCommunications, HomerDiagnosticReport, HomerDiagnosticReportBundle, HomerEncounter, HomerEncounterHistory, HomerMedia, HomerObservation1, HomerObservation2, HomerObservation3, HomerObservation4, HomerObservation5, HomerObservation6, HomerObservationSearchBundle, HomerServiceRequest, HomerServiceRequestHistoryBundle, HomerServiceRequestSearchBundle, HomerSimpson, HomerSimpsonHistory, MockClient, ObservationStructureDefinition, OrganizationSearchBundle, PatientSearchParameters, PatientStructureDefinition, PractitionerStructureDefinition, QuestionnaireStructureDefinition, ServiceRequestServiceDefinition, SimpsonSearchBundle, TestOrganization, exampleValueSet };
1108
+ //# sourceMappingURL=index.js.map