@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.
@@ -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
  *
package/dist/cjs/index.js CHANGED
@@ -305,7 +305,7 @@
305
305
  * @return Human friendly display string.
306
306
  */
307
307
  function getDisplayString(resource) {
308
- var _a, _b;
308
+ var _a;
309
309
  if (isProfileResource(resource)) {
310
310
  const profileName = getProfileResourceDisplayString(resource);
311
311
  if (profileName) {
@@ -320,7 +320,7 @@
320
320
  }
321
321
  if (resource.resourceType === 'Observation') {
322
322
  if ('code' in resource && ((_a = resource.code) === null || _a === void 0 ? void 0 : _a.text)) {
323
- return (_b = resource.code) === null || _b === void 0 ? void 0 : _b.text;
323
+ return resource.code.text;
324
324
  }
325
325
  }
326
326
  if (resource.resourceType === 'User') {
@@ -363,22 +363,23 @@
363
363
  * @returns The image URL for the resource or undefined.
364
364
  */
365
365
  function getImageSrc(resource) {
366
- if (isProfileResource(resource)) {
367
- const photos = resource.photo;
368
- if (photos) {
369
- for (const photo of photos) {
370
- const url = getPhotoImageSrc(photo);
371
- if (url) {
372
- return url;
373
- }
366
+ if (!('photo' in resource)) {
367
+ return undefined;
368
+ }
369
+ const photo = resource.photo;
370
+ if (!photo) {
371
+ return undefined;
372
+ }
373
+ if (Array.isArray(photo)) {
374
+ for (const p of photo) {
375
+ const url = getPhotoImageSrc(p);
376
+ if (url) {
377
+ return url;
374
378
  }
375
379
  }
376
380
  }
377
- if (resource.resourceType === 'Bot' && resource.photo) {
378
- const url = getPhotoImageSrc(resource.photo);
379
- if (url) {
380
- return url;
381
- }
381
+ else {
382
+ return getPhotoImageSrc(photo);
382
383
  }
383
384
  return undefined;
384
385
  }
@@ -6264,7 +6265,7 @@
6264
6265
  // PKCE auth based on:
6265
6266
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6266
6267
  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;
6267
- const MEDPLUM_VERSION = "0.10.2-f713edf5";
6268
+ const MEDPLUM_VERSION = "1.0.0-a614a88a";
6268
6269
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6269
6270
  const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
6270
6271
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
@@ -6711,7 +6712,9 @@
6711
6712
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6712
6713
  *
6713
6714
  * @category Search
6715
+ * @param resourceType The FHIR resource type.
6714
6716
  * @param query The search query as either a string or a structured search object.
6717
+ * @param options Optional fetch options.
6715
6718
  * @returns Promise to the search result bundle.
6716
6719
  */
6717
6720
  search(resourceType, query, options = {}) {
@@ -6734,7 +6737,9 @@
6734
6737
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6735
6738
  *
6736
6739
  * @category Search
6740
+ * @param resourceType The FHIR resource type.
6737
6741
  * @param query The search query as either a string or a structured search object.
6742
+ * @param options Optional fetch options.
6738
6743
  * @returns Promise to the search result bundle.
6739
6744
  */
6740
6745
  searchOne(resourceType, query, options = {}) {
@@ -6767,7 +6772,9 @@
6767
6772
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6768
6773
  *
6769
6774
  * @category Search
6775
+ * @param resourceType The FHIR resource type.
6770
6776
  * @param query The search query as either a string or a structured search object.
6777
+ * @param options Optional fetch options.
6771
6778
  * @returns Promise to the search result bundle.
6772
6779
  */
6773
6780
  searchResources(resourceType, query, options = {}) {
@@ -6788,6 +6795,7 @@
6788
6795
  * @category Search
6789
6796
  * @param system The ValueSet system url.
6790
6797
  * @param filter The search string.
6798
+ * @param options Optional fetch options.
6791
6799
  * @returns Promise to expanded ValueSet.
6792
6800
  */
6793
6801
  searchValueSet(system, filter, options = {}) {
@@ -6841,6 +6849,7 @@
6841
6849
  * @category Read
6842
6850
  * @param resourceType The FHIR resource type.
6843
6851
  * @param id The resource ID.
6852
+ * @param options Optional fetch options.
6844
6853
  * @returns The resource if available; undefined otherwise.
6845
6854
  */
6846
6855
  readResource(resourceType, id, options = {}) {
@@ -6863,6 +6872,7 @@
6863
6872
  *
6864
6873
  * @category Read
6865
6874
  * @param reference The FHIR reference object.
6875
+ * @param options Optional fetch options.
6866
6876
  * @returns The resource if available; undefined otherwise.
6867
6877
  */
6868
6878
  readReference(reference, options = {}) {
@@ -6881,7 +6891,6 @@
6881
6891
  * If the schema is not cached, returns undefined.
6882
6892
  * It is assumed that a client will call requestSchema before using this method.
6883
6893
  * @category Schema
6884
- * @param resourceType The FHIR resource type.
6885
6894
  * @returns The schema if immediately available, undefined otherwise.
6886
6895
  * @deprecated Use globalSchema instead.
6887
6896
  */
@@ -6956,6 +6965,7 @@
6956
6965
  * @category Read
6957
6966
  * @param resourceType The FHIR resource type.
6958
6967
  * @param id The resource ID.
6968
+ * @param options Optional fetch options.
6959
6969
  * @returns Promise to the resource history.
6960
6970
  */
6961
6971
  readHistory(resourceType, id, options = {}) {
@@ -6976,6 +6986,8 @@
6976
6986
  * @category Read
6977
6987
  * @param resourceType The FHIR resource type.
6978
6988
  * @param id The resource ID.
6989
+ * @param vid The version ID.
6990
+ * @param options Optional fetch options.
6979
6991
  * @returns The resource if available; undefined otherwise.
6980
6992
  */
6981
6993
  readVersion(resourceType, id, vid, options = {}) {
@@ -6985,6 +6997,7 @@
6985
6997
  *
6986
6998
  * @category Read
6987
6999
  * @param id The Patient Id
7000
+ * @param options Optional fetch options.
6988
7001
  * @returns A Bundle of all Resources related to the Patient
6989
7002
  */
6990
7003
  readPatientEverything(id, options = {}) {
@@ -7091,12 +7104,44 @@
7091
7104
  * @param contentType Content type for the binary.
7092
7105
  * @returns The result of the create operation.
7093
7106
  */
7094
- createBinary(data, filename, contentType) {
7107
+ createBinary(data, filename, contentType, onProgress) {
7095
7108
  const url = this.fhirUrl('Binary');
7096
7109
  if (filename) {
7097
7110
  url.searchParams.set('_filename', filename);
7098
7111
  }
7099
- return this.post(url, data, contentType);
7112
+ if (onProgress) {
7113
+ return this.uploadwithProgress(url, data, contentType, onProgress);
7114
+ }
7115
+ else {
7116
+ return this.post(url, data, contentType);
7117
+ }
7118
+ }
7119
+ uploadwithProgress(url, data, contentType, onProgress) {
7120
+ return new Promise((resolve, reject) => {
7121
+ const xhr = new XMLHttpRequest();
7122
+ xhr.responseType = 'json';
7123
+ xhr.onabort = () => reject(new Error('Request aborted'));
7124
+ xhr.onerror = () => reject(new Error('Request error'));
7125
+ if (onProgress) {
7126
+ xhr.upload.onprogress = (e) => onProgress(e);
7127
+ xhr.upload.onload = (e) => onProgress(e);
7128
+ }
7129
+ xhr.onload = () => {
7130
+ if (xhr.status >= 200 && xhr.status < 300) {
7131
+ resolve(xhr.response);
7132
+ }
7133
+ else {
7134
+ reject(new Error(xhr.statusText));
7135
+ }
7136
+ };
7137
+ xhr.open('POST', url);
7138
+ xhr.withCredentials = true;
7139
+ xhr.setRequestHeader('Authorization', 'Bearer ' + __classPrivateFieldGet(this, _MedplumClient_accessToken, "f"));
7140
+ xhr.setRequestHeader('Cache-Control', 'no-cache, no-store, max-age=0');
7141
+ xhr.setRequestHeader('Content-Type', contentType);
7142
+ xhr.setRequestHeader('X-Medplum', 'extended');
7143
+ xhr.send(data);
7144
+ });
7100
7145
  }
7101
7146
  /**
7102
7147
  * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
@@ -7252,6 +7297,26 @@
7252
7297
  this.invalidateSearches(resourceType);
7253
7298
  return this.delete(this.fhirUrl(resourceType, id));
7254
7299
  }
7300
+ /**
7301
+ * Executes the validate operation with the provided resource.
7302
+ *
7303
+ * Example:
7304
+ *
7305
+ * ```typescript
7306
+ * const result = await medplum.validateResource({
7307
+ * resourceType: 'Patient',
7308
+ * name: [{ given: ['Alice'], family: 'Smith' }],
7309
+ * });
7310
+ * ```
7311
+ *
7312
+ * See the FHIR "$validate" operation for full details: https://www.hl7.org/fhir/resource-operation-validate.html
7313
+ *
7314
+ * @param resource The FHIR resource.
7315
+ * @returns The validate operation outcome.
7316
+ */
7317
+ validateResource(resource) {
7318
+ return this.post(this.fhirUrl(resource.resourceType, '$validate'), resource);
7319
+ }
7255
7320
  /**
7256
7321
  * Executes a batch or transaction of FHIR operations.
7257
7322
  *
@@ -10944,11 +11009,8 @@
10944
11009
  // We need to maintain this behavior for backwards compatibility
10945
11010
  match = references.some((reference) => reference === null || reference === void 0 ? void 0 : reference.endsWith('/' + filterValue));
10946
11011
  }
10947
- if (match && !negated) {
10948
- return true;
10949
- }
10950
- if (match && negated) {
10951
- return false;
11012
+ if (match) {
11013
+ return !negated;
10952
11014
  }
10953
11015
  }
10954
11016
  // If "not equals" and no matches, then return true
@@ -10977,11 +11039,8 @@
10977
11039
  for (const resourceValue of resourceValues) {
10978
11040
  for (const filterValue of filterValues) {
10979
11041
  const match = matchesStringValue(resourceValue, filter.operator, filterValue);
10980
- if (match && !negated) {
10981
- return true;
10982
- }
10983
- if (match && negated) {
10984
- return false;
11042
+ if (match) {
11043
+ return !negated;
10985
11044
  }
10986
11045
  }
10987
11046
  }
@@ -11008,11 +11067,8 @@
11008
11067
  for (const resourceValue of resourceValues) {
11009
11068
  for (const filterValue of filterValues) {
11010
11069
  const match = matchesDateValue(resourceValue, filter.operator, filterValue);
11011
- if (match && !negated) {
11012
- return true;
11013
- }
11014
- if (match && negated) {
11015
- return false;
11070
+ if (match) {
11071
+ return !negated;
11016
11072
  }
11017
11073
  }
11018
11074
  }
@@ -11376,7 +11432,5 @@
11376
11432
  exports.tooManyRequests = tooManyRequests;
11377
11433
  exports.unauthorized = unauthorized;
11378
11434
 
11379
- Object.defineProperty(exports, '__esModule', { value: true });
11380
-
11381
11435
  }));
11382
11436
  //# sourceMappingURL=index.js.map