@medplum/core 0.10.2 → 1.0.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.
@@ -26,7 +26,7 @@ export declare function resolveId(reference: Reference | undefined): string | un
26
26
  * @param resource The FHIR resource.
27
27
  * @returns True if the resource is a "ProfileResource".
28
28
  */
29
- export declare function isProfileResource(resource: Resource): boolean;
29
+ export declare function isProfileResource(resource: Resource): resource is ProfileResource;
30
30
  /**
31
31
  * Returns a display string for the resource.
32
32
  * @param resource The input resource.
@@ -142,6 +142,7 @@ export interface LoginRequest {
142
142
  readonly remember?: boolean;
143
143
  readonly projectId?: string;
144
144
  readonly clientId?: string;
145
+ readonly resourceType?: string;
145
146
  readonly scope?: string;
146
147
  readonly nonce?: string;
147
148
  readonly codeChallenge?: string;
@@ -174,6 +175,7 @@ export interface GoogleLoginRequest {
174
175
  readonly googleCredential: string;
175
176
  readonly projectId?: string;
176
177
  readonly clientId?: string;
178
+ readonly resourceType?: string;
177
179
  readonly scope?: string;
178
180
  readonly nonce?: string;
179
181
  readonly codeChallenge?: string;
@@ -544,7 +546,9 @@ export declare class MedplumClient extends EventTarget {
544
546
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
545
547
  *
546
548
  * @category Search
549
+ * @param resourceType The FHIR resource type.
547
550
  * @param query The search query as either a string or a structured search object.
551
+ * @param options Optional fetch options.
548
552
  * @returns Promise to the search result bundle.
549
553
  */
550
554
  search<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
@@ -565,7 +569,9 @@ export declare class MedplumClient extends EventTarget {
565
569
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
566
570
  *
567
571
  * @category Search
572
+ * @param resourceType The FHIR resource type.
568
573
  * @param query The search query as either a string or a structured search object.
574
+ * @param options Optional fetch options.
569
575
  * @returns Promise to the search result bundle.
570
576
  */
571
577
  searchOne<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K> | undefined>;
@@ -586,7 +592,9 @@ export declare class MedplumClient extends EventTarget {
586
592
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
587
593
  *
588
594
  * @category Search
595
+ * @param resourceType The FHIR resource type.
589
596
  * @param query The search query as either a string or a structured search object.
597
+ * @param options Optional fetch options.
590
598
  * @returns Promise to the search result bundle.
591
599
  */
592
600
  searchResources<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K>[]>;
@@ -597,6 +605,7 @@ export declare class MedplumClient extends EventTarget {
597
605
  * @category Search
598
606
  * @param system The ValueSet system url.
599
607
  * @param filter The search string.
608
+ * @param options Optional fetch options.
600
609
  * @returns Promise to expanded ValueSet.
601
610
  */
602
611
  searchValueSet(system: string, filter: string, options?: RequestInit): ReadablePromise<ValueSet>;
@@ -631,6 +640,7 @@ export declare class MedplumClient extends EventTarget {
631
640
  * @category Read
632
641
  * @param resourceType The FHIR resource type.
633
642
  * @param id The resource ID.
643
+ * @param options Optional fetch options.
634
644
  * @returns The resource if available; undefined otherwise.
635
645
  */
636
646
  readResource<K extends ResourceType>(resourceType: K, id: string, options?: RequestInit): ReadablePromise<ExtractResource<K>>;
@@ -651,6 +661,7 @@ export declare class MedplumClient extends EventTarget {
651
661
  *
652
662
  * @category Read
653
663
  * @param reference The FHIR reference object.
664
+ * @param options Optional fetch options.
654
665
  * @returns The resource if available; undefined otherwise.
655
666
  */
656
667
  readReference<T extends Resource>(reference: Reference<T>, options?: RequestInit): ReadablePromise<T>;
@@ -659,7 +670,6 @@ export declare class MedplumClient extends EventTarget {
659
670
  * If the schema is not cached, returns undefined.
660
671
  * It is assumed that a client will call requestSchema before using this method.
661
672
  * @category Schema
662
- * @param resourceType The FHIR resource type.
663
673
  * @returns The schema if immediately available, undefined otherwise.
664
674
  * @deprecated Use globalSchema instead.
665
675
  */
@@ -689,6 +699,7 @@ export declare class MedplumClient extends EventTarget {
689
699
  * @category Read
690
700
  * @param resourceType The FHIR resource type.
691
701
  * @param id The resource ID.
702
+ * @param options Optional fetch options.
692
703
  * @returns Promise to the resource history.
693
704
  */
694
705
  readHistory<K extends ResourceType>(resourceType: K, id: string, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
@@ -707,6 +718,8 @@ export declare class MedplumClient extends EventTarget {
707
718
  * @category Read
708
719
  * @param resourceType The FHIR resource type.
709
720
  * @param id The resource ID.
721
+ * @param vid The version ID.
722
+ * @param options Optional fetch options.
710
723
  * @returns The resource if available; undefined otherwise.
711
724
  */
712
725
  readVersion<K extends ResourceType>(resourceType: K, id: string, vid: string, options?: RequestInit): ReadablePromise<ExtractResource<K>>;
@@ -714,6 +727,7 @@ export declare class MedplumClient extends EventTarget {
714
727
  *
715
728
  * @category Read
716
729
  * @param id The Patient Id
730
+ * @param options Optional fetch options.
717
731
  * @returns A Bundle of all Resources related to the Patient
718
732
  */
719
733
  readPatientEverything(id: string, options?: RequestInit): ReadablePromise<Bundle>;
@@ -807,7 +821,8 @@ export declare class MedplumClient extends EventTarget {
807
821
  * @param contentType Content type for the binary.
808
822
  * @returns The result of the create operation.
809
823
  */
810
- createBinary(data: string | File | Blob | Uint8Array, filename: string | undefined, contentType: string): Promise<Binary>;
824
+ createBinary(data: string | File | Blob | Uint8Array, filename: string | undefined, contentType: string, onProgress?: (e: ProgressEvent) => void): Promise<Binary>;
825
+ uploadwithProgress(url: URL, data: string | File | Blob | Uint8Array, contentType: string, onProgress: (e: ProgressEvent) => void): Promise<any>;
811
826
  /**
812
827
  * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
813
828
  *
@@ -912,6 +927,24 @@ export declare class MedplumClient extends EventTarget {
912
927
  * @returns The result of the delete operation.
913
928
  */
914
929
  deleteResource(resourceType: ResourceType, id: string): Promise<any>;
930
+ /**
931
+ * Executes the validate operation with the provided resource.
932
+ *
933
+ * Example:
934
+ *
935
+ * ```typescript
936
+ * const result = await medplum.validateResource({
937
+ * resourceType: 'Patient',
938
+ * name: [{ given: ['Alice'], family: 'Smith' }],
939
+ * });
940
+ * ```
941
+ *
942
+ * See the FHIR "$validate" operation for full details: https://www.hl7.org/fhir/resource-operation-validate.html
943
+ *
944
+ * @param resource The FHIR resource.
945
+ * @returns The validate operation outcome.
946
+ */
947
+ validateResource<T extends Resource>(resource: T): Promise<OperationOutcome>;
915
948
  /**
916
949
  * Executes a batch or transaction of FHIR operations.
917
950
  *
@@ -11,7 +11,7 @@ import { createReference, arrayBufferToBase64 } from './utils.js';
11
11
  // PKCE auth based on:
12
12
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
13
13
  var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
14
- const MEDPLUM_VERSION = "0.10.2-f713edf5";
14
+ const MEDPLUM_VERSION = "1.0.0-a614a88a";
15
15
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
16
16
  const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
17
17
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
@@ -458,7 +458,9 @@ class MedplumClient extends EventTarget {
458
458
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
459
459
  *
460
460
  * @category Search
461
+ * @param resourceType The FHIR resource type.
461
462
  * @param query The search query as either a string or a structured search object.
463
+ * @param options Optional fetch options.
462
464
  * @returns Promise to the search result bundle.
463
465
  */
464
466
  search(resourceType, query, options = {}) {
@@ -481,7 +483,9 @@ class MedplumClient extends EventTarget {
481
483
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
482
484
  *
483
485
  * @category Search
486
+ * @param resourceType The FHIR resource type.
484
487
  * @param query The search query as either a string or a structured search object.
488
+ * @param options Optional fetch options.
485
489
  * @returns Promise to the search result bundle.
486
490
  */
487
491
  searchOne(resourceType, query, options = {}) {
@@ -514,7 +518,9 @@ class MedplumClient extends EventTarget {
514
518
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
515
519
  *
516
520
  * @category Search
521
+ * @param resourceType The FHIR resource type.
517
522
  * @param query The search query as either a string or a structured search object.
523
+ * @param options Optional fetch options.
518
524
  * @returns Promise to the search result bundle.
519
525
  */
520
526
  searchResources(resourceType, query, options = {}) {
@@ -535,6 +541,7 @@ class MedplumClient extends EventTarget {
535
541
  * @category Search
536
542
  * @param system The ValueSet system url.
537
543
  * @param filter The search string.
544
+ * @param options Optional fetch options.
538
545
  * @returns Promise to expanded ValueSet.
539
546
  */
540
547
  searchValueSet(system, filter, options = {}) {
@@ -588,6 +595,7 @@ class MedplumClient extends EventTarget {
588
595
  * @category Read
589
596
  * @param resourceType The FHIR resource type.
590
597
  * @param id The resource ID.
598
+ * @param options Optional fetch options.
591
599
  * @returns The resource if available; undefined otherwise.
592
600
  */
593
601
  readResource(resourceType, id, options = {}) {
@@ -610,6 +618,7 @@ class MedplumClient extends EventTarget {
610
618
  *
611
619
  * @category Read
612
620
  * @param reference The FHIR reference object.
621
+ * @param options Optional fetch options.
613
622
  * @returns The resource if available; undefined otherwise.
614
623
  */
615
624
  readReference(reference, options = {}) {
@@ -628,7 +637,6 @@ class MedplumClient extends EventTarget {
628
637
  * If the schema is not cached, returns undefined.
629
638
  * It is assumed that a client will call requestSchema before using this method.
630
639
  * @category Schema
631
- * @param resourceType The FHIR resource type.
632
640
  * @returns The schema if immediately available, undefined otherwise.
633
641
  * @deprecated Use globalSchema instead.
634
642
  */
@@ -703,6 +711,7 @@ class MedplumClient extends EventTarget {
703
711
  * @category Read
704
712
  * @param resourceType The FHIR resource type.
705
713
  * @param id The resource ID.
714
+ * @param options Optional fetch options.
706
715
  * @returns Promise to the resource history.
707
716
  */
708
717
  readHistory(resourceType, id, options = {}) {
@@ -723,6 +732,8 @@ class MedplumClient extends EventTarget {
723
732
  * @category Read
724
733
  * @param resourceType The FHIR resource type.
725
734
  * @param id The resource ID.
735
+ * @param vid The version ID.
736
+ * @param options Optional fetch options.
726
737
  * @returns The resource if available; undefined otherwise.
727
738
  */
728
739
  readVersion(resourceType, id, vid, options = {}) {
@@ -732,6 +743,7 @@ class MedplumClient extends EventTarget {
732
743
  *
733
744
  * @category Read
734
745
  * @param id The Patient Id
746
+ * @param options Optional fetch options.
735
747
  * @returns A Bundle of all Resources related to the Patient
736
748
  */
737
749
  readPatientEverything(id, options = {}) {
@@ -838,12 +850,44 @@ class MedplumClient extends EventTarget {
838
850
  * @param contentType Content type for the binary.
839
851
  * @returns The result of the create operation.
840
852
  */
841
- createBinary(data, filename, contentType) {
853
+ createBinary(data, filename, contentType, onProgress) {
842
854
  const url = this.fhirUrl('Binary');
843
855
  if (filename) {
844
856
  url.searchParams.set('_filename', filename);
845
857
  }
846
- return this.post(url, data, contentType);
858
+ if (onProgress) {
859
+ return this.uploadwithProgress(url, data, contentType, onProgress);
860
+ }
861
+ else {
862
+ return this.post(url, data, contentType);
863
+ }
864
+ }
865
+ uploadwithProgress(url, data, contentType, onProgress) {
866
+ return new Promise((resolve, reject) => {
867
+ const xhr = new XMLHttpRequest();
868
+ xhr.responseType = 'json';
869
+ xhr.onabort = () => reject(new Error('Request aborted'));
870
+ xhr.onerror = () => reject(new Error('Request error'));
871
+ if (onProgress) {
872
+ xhr.upload.onprogress = (e) => onProgress(e);
873
+ xhr.upload.onload = (e) => onProgress(e);
874
+ }
875
+ xhr.onload = () => {
876
+ if (xhr.status >= 200 && xhr.status < 300) {
877
+ resolve(xhr.response);
878
+ }
879
+ else {
880
+ reject(new Error(xhr.statusText));
881
+ }
882
+ };
883
+ xhr.open('POST', url);
884
+ xhr.withCredentials = true;
885
+ xhr.setRequestHeader('Authorization', 'Bearer ' + __classPrivateFieldGet(this, _MedplumClient_accessToken, "f"));
886
+ xhr.setRequestHeader('Cache-Control', 'no-cache, no-store, max-age=0');
887
+ xhr.setRequestHeader('Content-Type', contentType);
888
+ xhr.setRequestHeader('X-Medplum', 'extended');
889
+ xhr.send(data);
890
+ });
847
891
  }
848
892
  /**
849
893
  * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
@@ -999,6 +1043,26 @@ class MedplumClient extends EventTarget {
999
1043
  this.invalidateSearches(resourceType);
1000
1044
  return this.delete(this.fhirUrl(resourceType, id));
1001
1045
  }
1046
+ /**
1047
+ * Executes the validate operation with the provided resource.
1048
+ *
1049
+ * Example:
1050
+ *
1051
+ * ```typescript
1052
+ * const result = await medplum.validateResource({
1053
+ * resourceType: 'Patient',
1054
+ * name: [{ given: ['Alice'], family: 'Smith' }],
1055
+ * });
1056
+ * ```
1057
+ *
1058
+ * See the FHIR "$validate" operation for full details: https://www.hl7.org/fhir/resource-operation-validate.html
1059
+ *
1060
+ * @param resource The FHIR resource.
1061
+ * @returns The validate operation outcome.
1062
+ */
1063
+ validateResource(resource) {
1064
+ return this.post(this.fhirUrl(resource.resourceType, '$validate'), resource);
1065
+ }
1002
1066
  /**
1003
1067
  * Executes a batch or transaction of FHIR operations.
1004
1068
  *