@medplum/mock 0.9.14 → 0.9.17

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.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createReference, Operator, evalFhirPath, MedplumClient, badRequest, allOk, notFound, getStatus, parseSearchDefinition } from '@medplum/core';
1
+ import { createReference, getReferenceString, Operator, evalFhirPath, MedplumClient, isOk, badRequest, allOk, notFound, getStatus, parseSearchDefinition } from '@medplum/core';
2
2
 
3
3
  const ExampleAccessPolicy = {
4
4
  resourceType: 'AccessPolicy',
@@ -298,6 +298,10 @@ const HomerDiagnosticReport = {
298
298
  const HomerObservation1 = {
299
299
  resourceType: 'Observation',
300
300
  id: '1',
301
+ subject: {
302
+ reference: 'Patient/123',
303
+ display: 'Homer Simpson',
304
+ },
301
305
  code: {
302
306
  text: 'Test 1',
303
307
  },
@@ -306,6 +310,10 @@ const HomerObservation1 = {
306
310
  const HomerObservation2 = {
307
311
  resourceType: 'Observation',
308
312
  id: '2',
313
+ subject: {
314
+ reference: 'Patient/123',
315
+ display: 'Homer Simpson',
316
+ },
309
317
  code: {
310
318
  text: 'Test 2',
311
319
  },
@@ -324,6 +332,10 @@ const HomerObservation2 = {
324
332
  const HomerObservation3 = {
325
333
  resourceType: 'Observation',
326
334
  id: '3',
335
+ subject: {
336
+ reference: 'Patient/123',
337
+ display: 'Homer Simpson',
338
+ },
327
339
  code: {
328
340
  text: 'Test 3',
329
341
  },
@@ -342,6 +354,10 @@ const HomerObservation3 = {
342
354
  const HomerObservation4 = {
343
355
  resourceType: 'Observation',
344
356
  id: '4',
357
+ subject: {
358
+ reference: 'Patient/123',
359
+ display: 'Homer Simpson',
360
+ },
345
361
  code: {
346
362
  text: 'Test 4',
347
363
  },
@@ -371,6 +387,10 @@ const HomerObservation4 = {
371
387
  const HomerObservation5 = {
372
388
  resourceType: 'Observation',
373
389
  id: '5',
390
+ subject: {
391
+ reference: 'Patient/123',
392
+ display: 'Homer Simpson',
393
+ },
374
394
  code: {
375
395
  text: 'Test 5',
376
396
  },
@@ -384,6 +404,10 @@ const HomerObservation5 = {
384
404
  const HomerObservation6 = {
385
405
  resourceType: 'Observation',
386
406
  id: '6',
407
+ subject: {
408
+ reference: 'Patient/123',
409
+ display: 'Homer Simpson',
410
+ },
387
411
  code: {
388
412
  text: 'Test 6',
389
413
  },
@@ -506,6 +530,176 @@ const ExampleAuditEvent = {
506
530
  };
507
531
 
508
532
  var StructureDefinitionList = [
533
+ {
534
+ resourceType: "StructureDefinition",
535
+ id: "Address",
536
+ name: "Address",
537
+ description: "Base StructureDefinition for Address Type: An address expressed using postal conventions (as opposed to GPS or other location definition formats). This data type may be used to convey addresses for use in delivering mail as well as for visiting locations which might not be valid for mail delivery. There are a variety of postal address formats defined around the world.",
538
+ type: "Address",
539
+ snapshot: {
540
+ element: [
541
+ {
542
+ id: "Address",
543
+ path: "Address",
544
+ definition: "An address expressed using postal conventions (as opposed to GPS or other location definition formats). This data type may be used to convey addresses for use in delivering mail as well as for visiting locations which might not be valid for mail delivery. There are a variety of postal address formats defined around the world.",
545
+ min: 0,
546
+ max: "*"
547
+ },
548
+ {
549
+ id: "Address.id",
550
+ path: "Address.id",
551
+ definition: "Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.",
552
+ min: 0,
553
+ max: "1",
554
+ type: [
555
+ {
556
+ code: "http://hl7.org/fhirpath/System.String"
557
+ }
558
+ ]
559
+ },
560
+ {
561
+ id: "Address.extension",
562
+ path: "Address.extension",
563
+ definition: "May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.",
564
+ min: 0,
565
+ max: "*",
566
+ type: [
567
+ {
568
+ code: "Extension"
569
+ }
570
+ ]
571
+ },
572
+ {
573
+ id: "Address.use",
574
+ path: "Address.use",
575
+ definition: "The purpose of this address.",
576
+ min: 0,
577
+ max: "1",
578
+ type: [
579
+ {
580
+ code: "code"
581
+ }
582
+ ],
583
+ binding: {
584
+ description: "The use of an address.",
585
+ valueSet: "http://hl7.org/fhir/ValueSet/address-use|4.0.1"
586
+ }
587
+ },
588
+ {
589
+ id: "Address.type",
590
+ path: "Address.type",
591
+ definition: "Distinguishes between physical addresses (those you can visit) and mailing addresses (e.g. PO Boxes and care-of addresses). Most addresses are both.",
592
+ min: 0,
593
+ max: "1",
594
+ type: [
595
+ {
596
+ code: "code"
597
+ }
598
+ ],
599
+ binding: {
600
+ description: "The type of an address (physical / postal).",
601
+ valueSet: "http://hl7.org/fhir/ValueSet/address-type|4.0.1"
602
+ }
603
+ },
604
+ {
605
+ id: "Address.text",
606
+ path: "Address.text",
607
+ definition: "Specifies the entire address as it should be displayed e.g. on a postal label. This may be provided instead of or as well as the specific parts.",
608
+ min: 0,
609
+ max: "1",
610
+ type: [
611
+ {
612
+ code: "string"
613
+ }
614
+ ]
615
+ },
616
+ {
617
+ id: "Address.line",
618
+ path: "Address.line",
619
+ definition: "This component contains the house number, apartment number, street name, street direction, P.O. Box number, delivery hints, and similar address information.",
620
+ min: 0,
621
+ max: "*",
622
+ type: [
623
+ {
624
+ code: "string"
625
+ }
626
+ ]
627
+ },
628
+ {
629
+ id: "Address.city",
630
+ path: "Address.city",
631
+ definition: "The name of the city, town, suburb, village or other community or delivery center.",
632
+ min: 0,
633
+ max: "1",
634
+ type: [
635
+ {
636
+ code: "string"
637
+ }
638
+ ]
639
+ },
640
+ {
641
+ id: "Address.district",
642
+ path: "Address.district",
643
+ definition: "The name of the administrative area (county).",
644
+ min: 0,
645
+ max: "1",
646
+ type: [
647
+ {
648
+ code: "string"
649
+ }
650
+ ]
651
+ },
652
+ {
653
+ id: "Address.state",
654
+ path: "Address.state",
655
+ definition: "Sub-unit of a country with limited sovereignty in a federally organized country. A code may be used if codes are in common use (e.g. US 2 letter state codes).",
656
+ min: 0,
657
+ max: "1",
658
+ type: [
659
+ {
660
+ code: "string"
661
+ }
662
+ ]
663
+ },
664
+ {
665
+ id: "Address.postalCode",
666
+ path: "Address.postalCode",
667
+ definition: "A postal code designating a region defined by the postal service.",
668
+ min: 0,
669
+ max: "1",
670
+ type: [
671
+ {
672
+ code: "string"
673
+ }
674
+ ]
675
+ },
676
+ {
677
+ id: "Address.country",
678
+ path: "Address.country",
679
+ definition: "Country - a nation as commonly understood or generally accepted.",
680
+ min: 0,
681
+ max: "1",
682
+ type: [
683
+ {
684
+ code: "string"
685
+ }
686
+ ]
687
+ },
688
+ {
689
+ id: "Address.period",
690
+ path: "Address.period",
691
+ definition: "Time period when address was/is in use.",
692
+ min: 0,
693
+ max: "1",
694
+ type: [
695
+ {
696
+ code: "Period"
697
+ }
698
+ ]
699
+ }
700
+ ]
701
+ }
702
+ },
509
703
  {
510
704
  resourceType: "StructureDefinition",
511
705
  id: "DiagnosticReport",
@@ -6424,7 +6618,7 @@ const PatientSearchParameters = [
6424
6618
  base: ['Patient', 'Practitioner'],
6425
6619
  code: 'address-city',
6426
6620
  name: 'address-city',
6427
- type: 'token',
6621
+ type: 'string',
6428
6622
  expression: 'Patient.address.city | Practitioner.address.city',
6429
6623
  },
6430
6624
  {
@@ -6461,6 +6655,14 @@ const PatientSearchParameters = [
6461
6655
  type: 'quantity',
6462
6656
  expression: '(Observation.value as Quantity) | (Observation.value as SampledData)',
6463
6657
  },
6658
+ {
6659
+ resourceType: 'SearchParameter',
6660
+ id: 'Observation-value-string',
6661
+ code: 'value-string',
6662
+ base: ['Observation'],
6663
+ type: 'string',
6664
+ expression: '(Observation.value as string) | (Observation.value as CodeableConcept).text',
6665
+ },
6464
6666
  {
6465
6667
  resourceType: 'SearchParameter',
6466
6668
  id: 'Encounter-length',
@@ -6490,6 +6692,121 @@ const exampleValueSet = {
6490
6692
  },
6491
6693
  };
6492
6694
 
6695
+ const ExampleWorkflowQuestionnaire1 = {
6696
+ resourceType: 'Questionnaire',
6697
+ id: 'workflow-questionnaire-1',
6698
+ name: 'Patient Registration',
6699
+ title: 'Patient Registration',
6700
+ subjectType: ['Patient'],
6701
+ item: [
6702
+ {
6703
+ linkId: '1',
6704
+ text: 'First question',
6705
+ type: 'string',
6706
+ },
6707
+ ],
6708
+ };
6709
+ const ExampleWorkflowQuestionnaire2 = {
6710
+ resourceType: 'Questionnaire',
6711
+ id: 'workflow-questionnaire-2',
6712
+ name: 'Surgery History',
6713
+ title: 'Surgery History',
6714
+ subjectType: ['Patient'],
6715
+ item: [
6716
+ {
6717
+ linkId: '1',
6718
+ text: 'First question',
6719
+ type: 'string',
6720
+ },
6721
+ ],
6722
+ };
6723
+ const ExampleWorkflowQuestionnaire3 = {
6724
+ resourceType: 'Questionnaire',
6725
+ id: 'workflow-questionnaire-3',
6726
+ name: 'Family Health History',
6727
+ title: 'Family Health History',
6728
+ subjectType: ['Patient'],
6729
+ item: [
6730
+ {
6731
+ linkId: '1',
6732
+ text: 'First question',
6733
+ type: 'string',
6734
+ },
6735
+ ],
6736
+ };
6737
+ const ExampleWorkflowPlanDefinition = {
6738
+ resourceType: 'PlanDefinition',
6739
+ id: 'workflow-plan-definition-1',
6740
+ title: 'Example Plan Definition',
6741
+ action: [
6742
+ {
6743
+ title: ExampleWorkflowQuestionnaire1.title,
6744
+ definitionCanonical: getReferenceString(ExampleWorkflowQuestionnaire1),
6745
+ },
6746
+ {
6747
+ title: ExampleWorkflowQuestionnaire2.title,
6748
+ definitionCanonical: getReferenceString(ExampleWorkflowQuestionnaire2),
6749
+ },
6750
+ {
6751
+ title: ExampleWorkflowQuestionnaire3.title,
6752
+ definitionCanonical: getReferenceString(ExampleWorkflowQuestionnaire3),
6753
+ },
6754
+ ],
6755
+ };
6756
+ const ExampleWorkflowQuestionnaireResponse1 = {
6757
+ resourceType: 'QuestionnaireResponse',
6758
+ id: 'workflow-questionnaire-response-1',
6759
+ questionnaire: getReferenceString(ExampleWorkflowQuestionnaire1),
6760
+ subject: createReference(HomerSimpson),
6761
+ source: createReference(HomerSimpson),
6762
+ };
6763
+ // Based on: http://build.fhir.org/ig/HL7/sdc/Task-example.json.html
6764
+ const ExampleWorkflowTask1 = {
6765
+ resourceType: 'Task',
6766
+ id: 'workflow-task-1',
6767
+ status: 'completed',
6768
+ meta: { author: createReference(HomerSimpson) },
6769
+ requester: createReference(DrAliceSmith),
6770
+ input: [{ valueReference: createReference(ExampleWorkflowQuestionnaire1) }],
6771
+ output: [{ valueReference: createReference(ExampleWorkflowQuestionnaireResponse1) }],
6772
+ };
6773
+ const ExampleWorkflowTask2 = {
6774
+ resourceType: 'Task',
6775
+ id: 'workflow-task-2',
6776
+ status: 'requested',
6777
+ meta: { author: createReference(DrAliceSmith) },
6778
+ requester: createReference(DrAliceSmith),
6779
+ input: [{ valueReference: createReference(ExampleWorkflowQuestionnaire2) }],
6780
+ };
6781
+ const ExampleWorkflowTask3 = {
6782
+ resourceType: 'Task',
6783
+ id: 'workflow-task-3',
6784
+ status: 'requested',
6785
+ meta: { author: createReference(DrAliceSmith) },
6786
+ requester: createReference(DrAliceSmith),
6787
+ input: [{ valueReference: createReference(ExampleWorkflowQuestionnaire3) }],
6788
+ };
6789
+ const ExampleWorkflowRequestGroup = {
6790
+ resourceType: 'RequestGroup',
6791
+ id: 'workflow-request-group-1',
6792
+ instantiatesCanonical: [getReferenceString(ExampleWorkflowPlanDefinition)],
6793
+ status: 'active',
6794
+ action: [
6795
+ {
6796
+ title: ExampleWorkflowQuestionnaire1.title,
6797
+ resource: createReference(ExampleWorkflowTask1),
6798
+ },
6799
+ {
6800
+ title: ExampleWorkflowQuestionnaire2.title,
6801
+ resource: createReference(ExampleWorkflowTask2),
6802
+ },
6803
+ {
6804
+ title: ExampleWorkflowQuestionnaire3.title,
6805
+ resource: createReference(ExampleWorkflowTask3),
6806
+ },
6807
+ ],
6808
+ };
6809
+
6493
6810
  /******************************************************************************
6494
6811
  Copyright (c) Microsoft Corporation.
6495
6812
 
@@ -6527,7 +6844,7 @@ class MemoryRepository {
6527
6844
  __classPrivateFieldSet(this, _MemoryRepository_history, {}, "f");
6528
6845
  }
6529
6846
  createResource(resource) {
6530
- var _a;
6847
+ var _a, _b;
6531
6848
  const result = resource;
6532
6849
  if (!result.id) {
6533
6850
  result.id = this.generateId();
@@ -6538,6 +6855,9 @@ class MemoryRepository {
6538
6855
  if (!((_a = result.meta) === null || _a === void 0 ? void 0 : _a.versionId)) {
6539
6856
  result.meta.versionId = this.generateId();
6540
6857
  }
6858
+ if (!((_b = result.meta) === null || _b === void 0 ? void 0 : _b.lastUpdated)) {
6859
+ result.meta.lastUpdated = new Date().toISOString();
6860
+ }
6541
6861
  const { resourceType, id } = resource;
6542
6862
  if (!(resourceType in __classPrivateFieldGet(this, _MemoryRepository_resources, "f"))) {
6543
6863
  __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType] = {};
@@ -6589,7 +6909,15 @@ class MemoryRepository {
6589
6909
  }
6590
6910
  }
6591
6911
  generateId() {
6592
- return Date.now().toString(36);
6912
+ // Cross platform random UUID generator
6913
+ // Note that this is not intended for production use, but rather for testing
6914
+ // This should be replaced when crypto.randomUUID is fully supported
6915
+ // https://stackoverflow.com/revisions/2117523/28
6916
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
6917
+ const r = (Math.random() * 16) | 0;
6918
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
6919
+ return v.toString(16);
6920
+ });
6593
6921
  }
6594
6922
  }
6595
6923
  _MemoryRepository_resources = new WeakMap(), _MemoryRepository_history = new WeakMap();
@@ -6645,7 +6973,7 @@ class MockClient extends MedplumClient {
6645
6973
  console.log(` ${JSON.stringify(tableLayouts, null, 2)},`);
6646
6974
  console.log(` ${JSON.stringify(fonts, null, 2)});`);
6647
6975
  }
6648
- return Promise.resolve(new Blob());
6976
+ return Promise.resolve({});
6649
6977
  },
6650
6978
  fetch: (url, options) => {
6651
6979
  const method = options.method || 'GET';
@@ -6660,6 +6988,9 @@ class MockClient extends MedplumClient {
6660
6988
  if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
6661
6989
  console.log('MockClient', JSON.stringify(response, null, 2));
6662
6990
  }
6991
+ if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !isOk(response)) {
6992
+ return Promise.reject(response);
6993
+ }
6663
6994
  return Promise.resolve({
6664
6995
  blob: () => Promise.resolve(response),
6665
6996
  json: () => Promise.resolve(response),
@@ -6883,6 +7214,15 @@ mockRepo.createResource(BartSimpson);
6883
7214
  mockRepo.createResource(DrAliceSmithPreviousVersion);
6884
7215
  mockRepo.createResource(DrAliceSmith);
6885
7216
  mockRepo.createResource(DrAliceSmithSchedule);
7217
+ mockRepo.createResource(ExampleWorkflowQuestionnaire1);
7218
+ mockRepo.createResource(ExampleWorkflowQuestionnaire2);
7219
+ mockRepo.createResource(ExampleWorkflowQuestionnaire3);
7220
+ mockRepo.createResource(ExampleWorkflowPlanDefinition);
7221
+ mockRepo.createResource(ExampleWorkflowQuestionnaireResponse1);
7222
+ mockRepo.createResource(ExampleWorkflowTask1);
7223
+ mockRepo.createResource(ExampleWorkflowTask2);
7224
+ mockRepo.createResource(ExampleWorkflowTask3);
7225
+ mockRepo.createResource(ExampleWorkflowRequestGroup);
6886
7226
  DrAliceSmithSlots.forEach((slot) => mockRepo.createResource(slot));
6887
7227
  function mockFhirHandler(method, url, options) {
6888
7228
  const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
@@ -6982,5 +7322,5 @@ function mockFhirBatchHandler(_method, _path, options) {
6982
7322
  };
6983
7323
  }
6984
7324
 
6985
- export { BartSimpson, DifferentOrganization, DrAliceSmith, DrAliceSmithPreviousVersion, DrAliceSmithSchedule, DrAliceSmithSlots, ExampleAccessPolicy, ExampleAuditEvent, ExampleBot, ExampleClient, ExampleQuestionnaire, ExampleQuestionnaireResponse, ExampleStatusValueSet, ExampleSubscription, ExampleUserConfiguration, GraphQLSchemaResponse, HomerCommunication, HomerDiagnosticReport, HomerEncounter, HomerMedia, HomerObservation1, HomerObservation2, HomerObservation3, HomerObservation4, HomerObservation5, HomerObservation6, HomerServiceRequest, HomerSimpson, HomerSimpsonPreviousVersion, HomerSimpsonSpecimen, MockClient, PatientSearchParameters, TestOrganization, exampleValueSet };
7325
+ export { BartSimpson, DifferentOrganization, DrAliceSmith, DrAliceSmithPreviousVersion, DrAliceSmithSchedule, DrAliceSmithSlots, ExampleAccessPolicy, ExampleAuditEvent, ExampleBot, ExampleClient, ExampleQuestionnaire, ExampleQuestionnaireResponse, ExampleStatusValueSet, ExampleSubscription, ExampleUserConfiguration, ExampleWorkflowPlanDefinition, ExampleWorkflowQuestionnaire1, ExampleWorkflowQuestionnaire2, ExampleWorkflowQuestionnaire3, ExampleWorkflowQuestionnaireResponse1, ExampleWorkflowRequestGroup, ExampleWorkflowTask1, ExampleWorkflowTask2, ExampleWorkflowTask3, GraphQLSchemaResponse, HomerCommunication, HomerDiagnosticReport, HomerEncounter, HomerMedia, HomerObservation1, HomerObservation2, HomerObservation3, HomerObservation4, HomerObservation5, HomerObservation6, HomerServiceRequest, HomerSimpson, HomerSimpsonPreviousVersion, HomerSimpsonSpecimen, MockClient, PatientSearchParameters, TestOrganization, exampleValueSet };
6986
7326
  //# sourceMappingURL=index.js.map