@medplum/core 2.0.2 → 2.0.4
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/README.md +7 -3
- package/dist/cjs/client.d.ts +16 -3
- package/dist/cjs/index.cjs +785 -438
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/outcomes.d.ts +1 -0
- package/dist/cjs/{searchparams.d.ts → search/details.d.ts} +0 -0
- package/dist/cjs/{match.d.ts → search/match.d.ts} +0 -0
- package/dist/cjs/search/parse.d.ts +17 -0
- package/dist/cjs/{search.d.ts → search/search.d.ts} +0 -0
- package/dist/cjs/types.d.ts +30 -7
- package/dist/esm/base-schema.json.mjs +7 -0
- package/dist/esm/base-schema.json.mjs.map +1 -1
- package/dist/esm/client.d.ts +16 -3
- package/dist/esm/client.mjs +114 -26
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +6 -5
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/outcomes.d.ts +1 -0
- package/dist/esm/outcomes.mjs +6 -4
- package/dist/esm/outcomes.mjs.map +1 -1
- package/dist/esm/{searchparams.d.ts → search/details.d.ts} +0 -0
- package/dist/esm/{searchparams.mjs → search/details.mjs} +9 -11
- package/dist/esm/search/details.mjs.map +1 -0
- package/dist/esm/{match.d.ts → search/match.d.ts} +0 -0
- package/dist/esm/{match.mjs → search/match.mjs} +7 -7
- package/dist/esm/search/match.mjs.map +1 -0
- package/dist/esm/search/parse.d.ts +17 -0
- package/dist/esm/search/parse.mjs +218 -0
- package/dist/esm/search/parse.mjs.map +1 -0
- package/dist/esm/{search.d.ts → search/search.d.ts} +0 -0
- package/dist/esm/{search.mjs → search/search.mjs} +0 -3
- package/dist/esm/search/search.mjs.map +1 -0
- package/dist/esm/types.d.ts +30 -7
- package/dist/esm/types.mjs +63 -25
- package/dist/esm/types.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/esm/match.mjs.map +0 -1
- package/dist/esm/search.mjs.map +0 -1
- package/dist/esm/searchparams.mjs.map +0 -1
package/dist/cjs/outcomes.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const forbidden: OperationOutcome;
|
|
|
8
8
|
export declare const gone: OperationOutcome;
|
|
9
9
|
export declare const tooManyRequests: OperationOutcome;
|
|
10
10
|
export declare function badRequest(details: string, expression?: string): OperationOutcome;
|
|
11
|
+
export declare function isOperationOutcome(value: unknown): value is OperationOutcome;
|
|
11
12
|
export declare function isOk(outcome: OperationOutcome): boolean;
|
|
12
13
|
export declare function isNotFound(outcome: OperationOutcome): boolean;
|
|
13
14
|
export declare function isGone(outcome: OperationOutcome): boolean;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ResourceType } from '@medplum/fhirtypes';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
import { SearchRequest } from './search';
|
|
5
|
+
/**
|
|
6
|
+
* Parses a search URL into a search request.
|
|
7
|
+
* @param resourceType The FHIR resource type.
|
|
8
|
+
* @param query The collection of query string parameters.
|
|
9
|
+
* @returns A parsed SearchRequest.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseSearchRequest(resourceType: ResourceType, query: Record<string, string[] | string | undefined>): SearchRequest;
|
|
12
|
+
/**
|
|
13
|
+
* Parses a search URL into a search request.
|
|
14
|
+
* @param url The search URL.
|
|
15
|
+
* @returns A parsed SearchRequest.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSearchUrl(url: URL): SearchRequest;
|
|
File without changes
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bundle, ElementDefinition, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
|
|
2
|
-
import { SearchParameterDetails } from './
|
|
2
|
+
import { SearchParameterDetails } from './search/details';
|
|
3
3
|
export interface TypedValue {
|
|
4
4
|
readonly type: string;
|
|
5
5
|
readonly value: any;
|
|
@@ -124,12 +124,6 @@ export interface TypeSchema {
|
|
|
124
124
|
description?: string;
|
|
125
125
|
parentType?: string;
|
|
126
126
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Creates a new empty IndexedStructureDefinition.
|
|
129
|
-
* @returns The empty IndexedStructureDefinition.
|
|
130
|
-
* @deprecated Use globalSchema
|
|
131
|
-
*/
|
|
132
|
-
export declare function createSchema(): IndexedStructureDefinition;
|
|
133
127
|
/**
|
|
134
128
|
* Indexes a bundle of StructureDefinitions for faster lookup.
|
|
135
129
|
* @param bundle A FHIR bundle StructureDefinition resources.
|
|
@@ -162,6 +156,35 @@ export declare function indexSearchParameter(searchParam: SearchParameter): void
|
|
|
162
156
|
*/
|
|
163
157
|
export declare function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string;
|
|
164
158
|
export declare function buildTypeName(components: string[]): string;
|
|
159
|
+
/**
|
|
160
|
+
* Returns true if the type schema is a DomainResource.
|
|
161
|
+
* @param typeSchema The type schema to check.
|
|
162
|
+
* @returns True if the type schema is a DomainResource.
|
|
163
|
+
*/
|
|
164
|
+
export declare function isResourceType(typeSchema: TypeSchema): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Returns an array of all resource types.
|
|
167
|
+
* Note that this is based on globalSchema, and will only return resource types that are currently in memory.
|
|
168
|
+
* @returns An array of all resource types.
|
|
169
|
+
*/
|
|
170
|
+
export declare function getResourceTypes(): string[];
|
|
171
|
+
/**
|
|
172
|
+
* Returns the type schema for the resource type.
|
|
173
|
+
* @param resourceType The resource type.
|
|
174
|
+
* @returns The type schema for the resource type.
|
|
175
|
+
*/
|
|
176
|
+
export declare function getResourceTypeSchema(resourceType: string): TypeSchema;
|
|
177
|
+
/**
|
|
178
|
+
* Returns the search parameters for the resource type indexed by search code.
|
|
179
|
+
* @param resourceType The resource type.
|
|
180
|
+
* @returns The search parameters for the resource type indexed by search code.
|
|
181
|
+
*/
|
|
182
|
+
export declare function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Returns a human friendly display name for a FHIR element definition path.
|
|
185
|
+
* @param path The FHIR element definition path.
|
|
186
|
+
* @returns The best guess of the display name.
|
|
187
|
+
*/
|
|
165
188
|
export declare function getPropertyDisplayName(path: string): string;
|
|
166
189
|
/**
|
|
167
190
|
* Returns an element definition by type and property name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-schema.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-schema.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export interface MedplumClientOptions {
|
|
|
84
84
|
*
|
|
85
85
|
* Default is window.fetch (if available).
|
|
86
86
|
*
|
|
87
|
-
* For
|
|
87
|
+
* For Node.js applications, consider the 'node-fetch' package.
|
|
88
88
|
*/
|
|
89
89
|
fetch?: FetchLike;
|
|
90
90
|
/**
|
|
@@ -105,7 +105,7 @@ export interface MedplumClientOptions {
|
|
|
105
105
|
* </script>
|
|
106
106
|
* ```
|
|
107
107
|
*
|
|
108
|
-
* In
|
|
108
|
+
* In Node.js applications:
|
|
109
109
|
*
|
|
110
110
|
* ```ts
|
|
111
111
|
* import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
|
|
@@ -282,7 +282,7 @@ export interface MailOptions {
|
|
|
282
282
|
/**
|
|
283
283
|
* The MedplumClient class provides a client for the Medplum FHIR server.
|
|
284
284
|
*
|
|
285
|
-
* The client can be used in the browser, in a
|
|
285
|
+
* The client can be used in the browser, in a Node.js application, or in a Medplum Bot.
|
|
286
286
|
*
|
|
287
287
|
* The client provides helpful methods for common operations such as:
|
|
288
288
|
* 1) Authenticating
|
|
@@ -517,8 +517,19 @@ export declare class MedplumClient extends EventTarget {
|
|
|
517
517
|
* @param clientId The external client ID.
|
|
518
518
|
* @param redirectUri The external identity provider redirect URI.
|
|
519
519
|
* @param baseLogin The Medplum login request.
|
|
520
|
+
* @category Authentication
|
|
520
521
|
*/
|
|
521
522
|
signInWithExternalAuth(authorizeUrl: string, clientId: string, redirectUri: string, baseLogin: BaseLoginRequest): Promise<void>;
|
|
523
|
+
/**
|
|
524
|
+
* Builds the external identity provider redirect URI.
|
|
525
|
+
* @param authorizeUrl The external authorization URL.
|
|
526
|
+
* @param clientId The external client ID.
|
|
527
|
+
* @param redirectUri The external identity provider redirect URI.
|
|
528
|
+
* @param loginRequest The Medplum login request.
|
|
529
|
+
* @returns The external identity provider redirect URI.
|
|
530
|
+
* @category Authentication
|
|
531
|
+
*/
|
|
532
|
+
getExternalAuthRedirectUri(authorizeUrl: string, clientId: string, redirectUri: string, loginRequest: BaseLoginRequest): string;
|
|
522
533
|
/**
|
|
523
534
|
* Builds a FHIR URL from a collection of URL path components.
|
|
524
535
|
* For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
|
|
@@ -1182,6 +1193,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
1182
1193
|
/**
|
|
1183
1194
|
* Starts a new PKCE flow.
|
|
1184
1195
|
* These PKCE values are stateful, and must survive redirects and page refreshes.
|
|
1196
|
+
* @category Authentication
|
|
1185
1197
|
*/
|
|
1186
1198
|
startPkce(): Promise<{
|
|
1187
1199
|
codeChallengeMethod: string;
|
|
@@ -1191,6 +1203,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
1191
1203
|
* Processes an OAuth authorization code.
|
|
1192
1204
|
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
|
|
1193
1205
|
* @param code The authorization code received by URL parameter.
|
|
1206
|
+
* @category Authentication
|
|
1194
1207
|
*/
|
|
1195
1208
|
processCode(code: string): Promise<ProfileResource>;
|
|
1196
1209
|
/**
|
package/dist/esm/client.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { LRUCache } from './cache.mjs';
|
|
|
3
3
|
import { getRandomString, encryptSHA256 } from './crypto.mjs';
|
|
4
4
|
import { EventTarget } from './eventtarget.mjs';
|
|
5
5
|
import { parseJWTPayload } from './jwt.mjs';
|
|
6
|
+
import { isOk } from './outcomes.mjs';
|
|
6
7
|
import { ReadablePromise } from './readablepromise.mjs';
|
|
7
8
|
import { ClientStorage } from './storage.mjs';
|
|
8
9
|
import { globalSchema, indexStructureDefinition, indexSearchParameter } from './types.mjs';
|
|
@@ -10,18 +11,19 @@ import { createReference, arrayBufferToBase64 } from './utils.mjs';
|
|
|
10
11
|
|
|
11
12
|
// PKCE auth based on:
|
|
12
13
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
13
|
-
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_fhirBaseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_autoBatchTime, _MedplumClient_autoBatchQueue, _MedplumClient_clientId, _MedplumClient_clientSecret, _MedplumClient_autoBatchTimerId, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_executeAutoBatch, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
|
|
14
|
-
const MEDPLUM_VERSION = "2.0.
|
|
14
|
+
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_fhirBaseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_autoBatchTime, _MedplumClient_autoBatchQueue, _MedplumClient_clientId, _MedplumClient_clientSecret, _MedplumClient_autoBatchTimerId, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_cacheResource, _MedplumClient_deleteCacheEntry, _MedplumClient_request, _MedplumClient_fetchWithRetry, _MedplumClient_executeAutoBatch, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
|
|
15
|
+
const MEDPLUM_VERSION = "2.0.4-c4747b4e";
|
|
15
16
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
16
17
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
17
18
|
const DEFAULT_CACHE_TIME = 60000; // 60 seconds
|
|
18
19
|
const JSON_CONTENT_TYPE = 'application/json';
|
|
19
20
|
const FHIR_CONTENT_TYPE = 'application/fhir+json';
|
|
20
21
|
const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
22
|
+
const system = { resourceType: 'Device', id: 'system', deviceName: [{ name: 'System' }] };
|
|
21
23
|
/**
|
|
22
24
|
* The MedplumClient class provides a client for the Medplum FHIR server.
|
|
23
25
|
*
|
|
24
|
-
* The client can be used in the browser, in a
|
|
26
|
+
* The client can be used in the browser, in a Node.js application, or in a Medplum Bot.
|
|
25
27
|
*
|
|
26
28
|
* The client provides helpful methods for common operations such as:
|
|
27
29
|
* 1) Authenticating
|
|
@@ -429,16 +431,29 @@ class MedplumClient extends EventTarget {
|
|
|
429
431
|
* @param clientId The external client ID.
|
|
430
432
|
* @param redirectUri The external identity provider redirect URI.
|
|
431
433
|
* @param baseLogin The Medplum login request.
|
|
434
|
+
* @category Authentication
|
|
432
435
|
*/
|
|
433
436
|
async signInWithExternalAuth(authorizeUrl, clientId, redirectUri, baseLogin) {
|
|
434
437
|
const loginRequest = await this.ensureCodeChallenge(baseLogin);
|
|
438
|
+
window.location.assign(this.getExternalAuthRedirectUri(authorizeUrl, clientId, redirectUri, loginRequest));
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Builds the external identity provider redirect URI.
|
|
442
|
+
* @param authorizeUrl The external authorization URL.
|
|
443
|
+
* @param clientId The external client ID.
|
|
444
|
+
* @param redirectUri The external identity provider redirect URI.
|
|
445
|
+
* @param loginRequest The Medplum login request.
|
|
446
|
+
* @returns The external identity provider redirect URI.
|
|
447
|
+
* @category Authentication
|
|
448
|
+
*/
|
|
449
|
+
getExternalAuthRedirectUri(authorizeUrl, clientId, redirectUri, loginRequest) {
|
|
435
450
|
const url = new URL(authorizeUrl);
|
|
436
451
|
url.searchParams.set('response_type', 'code');
|
|
437
452
|
url.searchParams.set('client_id', clientId);
|
|
438
453
|
url.searchParams.set('redirect_uri', redirectUri);
|
|
439
454
|
url.searchParams.set('scope', 'openid profile email');
|
|
440
455
|
url.searchParams.set('state', JSON.stringify(loginRequest));
|
|
441
|
-
|
|
456
|
+
return url.toString();
|
|
442
457
|
}
|
|
443
458
|
/**
|
|
444
459
|
* Builds a FHIR URL from a collection of URL path components.
|
|
@@ -513,7 +528,23 @@ class MedplumClient extends EventTarget {
|
|
|
513
528
|
* @returns Promise to the search result bundle.
|
|
514
529
|
*/
|
|
515
530
|
search(resourceType, query, options = {}) {
|
|
516
|
-
|
|
531
|
+
const url = this.fhirSearchUrl(resourceType, query);
|
|
532
|
+
const cacheKey = url.toString() + '-search';
|
|
533
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, options);
|
|
534
|
+
if (cached) {
|
|
535
|
+
return cached.value;
|
|
536
|
+
}
|
|
537
|
+
const promise = new ReadablePromise((async () => {
|
|
538
|
+
const bundle = await this.get(url, options);
|
|
539
|
+
if (bundle.entry) {
|
|
540
|
+
for (const entry of bundle.entry) {
|
|
541
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_cacheResource).call(this, entry.resource);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return bundle;
|
|
545
|
+
})());
|
|
546
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
547
|
+
return promise;
|
|
517
548
|
}
|
|
518
549
|
/**
|
|
519
550
|
* Sends a FHIR search request for a single resource.
|
|
@@ -622,6 +653,9 @@ class MedplumClient extends EventTarget {
|
|
|
622
653
|
if (!refString) {
|
|
623
654
|
return undefined;
|
|
624
655
|
}
|
|
656
|
+
if (refString === 'system') {
|
|
657
|
+
return system;
|
|
658
|
+
}
|
|
625
659
|
const [resourceType, id] = refString.split('/');
|
|
626
660
|
if (!resourceType || !id) {
|
|
627
661
|
return undefined;
|
|
@@ -674,6 +708,9 @@ class MedplumClient extends EventTarget {
|
|
|
674
708
|
if (!refString) {
|
|
675
709
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
676
710
|
}
|
|
711
|
+
if (refString === 'system') {
|
|
712
|
+
return new ReadablePromise(Promise.resolve(system));
|
|
713
|
+
}
|
|
677
714
|
const [resourceType, id] = refString.split('/');
|
|
678
715
|
if (!resourceType || !id) {
|
|
679
716
|
return new ReadablePromise(Promise.reject(new Error('Invalid reference')));
|
|
@@ -698,11 +735,17 @@ class MedplumClient extends EventTarget {
|
|
|
698
735
|
* @param resourceType The FHIR resource type.
|
|
699
736
|
* @returns Promise to a schema with the requested resource type.
|
|
700
737
|
*/
|
|
701
|
-
|
|
738
|
+
requestSchema(resourceType) {
|
|
702
739
|
if (resourceType in globalSchema.types) {
|
|
703
|
-
return globalSchema;
|
|
740
|
+
return Promise.resolve(globalSchema);
|
|
741
|
+
}
|
|
742
|
+
const cacheKey = resourceType + '-requestSchema';
|
|
743
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_getCacheEntry).call(this, cacheKey, undefined);
|
|
744
|
+
if (cached) {
|
|
745
|
+
return cached.value;
|
|
704
746
|
}
|
|
705
|
-
const
|
|
747
|
+
const promise = new ReadablePromise((async () => {
|
|
748
|
+
const query = `{
|
|
706
749
|
StructureDefinitionList(name: "${resourceType}") {
|
|
707
750
|
name,
|
|
708
751
|
description,
|
|
@@ -731,14 +774,17 @@ class MedplumClient extends EventTarget {
|
|
|
731
774
|
target
|
|
732
775
|
}
|
|
733
776
|
}`.replace(/\s+/g, ' ');
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
777
|
+
const response = (await this.graphql(query));
|
|
778
|
+
for (const structureDefinition of response.data.StructureDefinitionList) {
|
|
779
|
+
indexStructureDefinition(structureDefinition);
|
|
780
|
+
}
|
|
781
|
+
for (const searchParameter of response.data.SearchParameterList) {
|
|
782
|
+
indexSearchParameter(searchParameter);
|
|
783
|
+
}
|
|
784
|
+
return globalSchema;
|
|
785
|
+
})());
|
|
786
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
787
|
+
return promise;
|
|
742
788
|
}
|
|
743
789
|
/**
|
|
744
790
|
* Reads resource history by resource type and ID.
|
|
@@ -1039,10 +1085,15 @@ class MedplumClient extends EventTarget {
|
|
|
1039
1085
|
throw new Error('Missing id');
|
|
1040
1086
|
}
|
|
1041
1087
|
this.invalidateSearches(resource.resourceType);
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1088
|
+
let result = await this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
1089
|
+
if (!result) {
|
|
1090
|
+
// On 304 not modified, result will be undefined
|
|
1091
|
+
// Return the user input instead
|
|
1092
|
+
// return result ?? resource;
|
|
1093
|
+
result = resource;
|
|
1094
|
+
}
|
|
1095
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_cacheResource).call(this, result);
|
|
1096
|
+
return result;
|
|
1046
1097
|
}
|
|
1047
1098
|
/**
|
|
1048
1099
|
* Updates a FHIR resource using JSONPatch operations.
|
|
@@ -1089,6 +1140,7 @@ class MedplumClient extends EventTarget {
|
|
|
1089
1140
|
* @returns The result of the delete operation.
|
|
1090
1141
|
*/
|
|
1091
1142
|
deleteResource(resourceType, id) {
|
|
1143
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_deleteCacheEntry).call(this, this.fhirUrl(resourceType, id).toString());
|
|
1092
1144
|
this.invalidateSearches(resourceType);
|
|
1093
1145
|
return this.delete(this.fhirUrl(resourceType, id));
|
|
1094
1146
|
}
|
|
@@ -1352,6 +1404,7 @@ class MedplumClient extends EventTarget {
|
|
|
1352
1404
|
/**
|
|
1353
1405
|
* Starts a new PKCE flow.
|
|
1354
1406
|
* These PKCE values are stateful, and must survive redirects and page refreshes.
|
|
1407
|
+
* @category Authentication
|
|
1355
1408
|
*/
|
|
1356
1409
|
async startPkce() {
|
|
1357
1410
|
const pkceState = getRandomString();
|
|
@@ -1367,6 +1420,7 @@ class MedplumClient extends EventTarget {
|
|
|
1367
1420
|
* Processes an OAuth authorization code.
|
|
1368
1421
|
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
|
|
1369
1422
|
* @param code The authorization code received by URL parameter.
|
|
1423
|
+
* @category Authentication
|
|
1370
1424
|
*/
|
|
1371
1425
|
processCode(code) {
|
|
1372
1426
|
const formBody = new URLSearchParams();
|
|
@@ -1374,9 +1428,11 @@ class MedplumClient extends EventTarget {
|
|
|
1374
1428
|
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
1375
1429
|
formBody.set('code', code);
|
|
1376
1430
|
formBody.set('redirect_uri', getWindowOrigin());
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1431
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
1432
|
+
const codeVerifier = sessionStorage.getItem('codeVerifier');
|
|
1433
|
+
if (codeVerifier) {
|
|
1434
|
+
formBody.set('code_verifier', codeVerifier);
|
|
1435
|
+
}
|
|
1380
1436
|
}
|
|
1381
1437
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
1382
1438
|
}
|
|
@@ -1428,6 +1484,14 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(),
|
|
|
1428
1484
|
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
1429
1485
|
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
|
|
1430
1486
|
}
|
|
1487
|
+
}, _MedplumClient_cacheResource = function _MedplumClient_cacheResource(resource) {
|
|
1488
|
+
if (resource?.id) {
|
|
1489
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, this.fhirUrl(resource.resourceType, resource.id).toString(), new ReadablePromise(Promise.resolve(resource)));
|
|
1490
|
+
}
|
|
1491
|
+
}, _MedplumClient_deleteCacheEntry = function _MedplumClient_deleteCacheEntry(key) {
|
|
1492
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
1493
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").delete(key);
|
|
1494
|
+
}
|
|
1431
1495
|
}, _MedplumClient_request =
|
|
1432
1496
|
/**
|
|
1433
1497
|
* Makes an HTTP request.
|
|
@@ -1445,7 +1509,7 @@ async function _MedplumClient_request(method, url, options = {}) {
|
|
|
1445
1509
|
}
|
|
1446
1510
|
options.method = method;
|
|
1447
1511
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1448
|
-
const response = await __classPrivateFieldGet(this,
|
|
1512
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchWithRetry).call(this, url, options);
|
|
1449
1513
|
if (response.status === 401) {
|
|
1450
1514
|
// Refresh and try again
|
|
1451
1515
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
|
|
@@ -1454,11 +1518,30 @@ async function _MedplumClient_request(method, url, options = {}) {
|
|
|
1454
1518
|
// No content or change
|
|
1455
1519
|
return undefined;
|
|
1456
1520
|
}
|
|
1457
|
-
|
|
1521
|
+
let obj = undefined;
|
|
1522
|
+
try {
|
|
1523
|
+
obj = await response.json();
|
|
1524
|
+
}
|
|
1525
|
+
catch (err) {
|
|
1526
|
+
console.error('Error parsing response', response.status, err);
|
|
1527
|
+
throw err;
|
|
1528
|
+
}
|
|
1458
1529
|
if (response.status >= 400) {
|
|
1459
1530
|
throw obj;
|
|
1460
1531
|
}
|
|
1461
1532
|
return obj;
|
|
1533
|
+
}, _MedplumClient_fetchWithRetry = async function _MedplumClient_fetchWithRetry(url, options) {
|
|
1534
|
+
const maxRetries = 3;
|
|
1535
|
+
const retryDelay = 200;
|
|
1536
|
+
let response = undefined;
|
|
1537
|
+
for (let retry = 0; retry < maxRetries; retry++) {
|
|
1538
|
+
response = (await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options));
|
|
1539
|
+
if (response.status < 500) {
|
|
1540
|
+
return response;
|
|
1541
|
+
}
|
|
1542
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
1543
|
+
}
|
|
1544
|
+
return response;
|
|
1462
1545
|
}, _MedplumClient_executeAutoBatch =
|
|
1463
1546
|
/**
|
|
1464
1547
|
* Executes a batch of requests that were automatically batched together.
|
|
@@ -1494,7 +1577,12 @@ async function _MedplumClient_executeAutoBatch() {
|
|
|
1494
1577
|
for (let i = 0; i < entries.length; i++) {
|
|
1495
1578
|
const entry = entries[i];
|
|
1496
1579
|
const responseEntry = response.entry?.[i];
|
|
1497
|
-
|
|
1580
|
+
if (responseEntry?.response?.outcome && !isOk(responseEntry.response.outcome)) {
|
|
1581
|
+
entry.reject(responseEntry.response.outcome);
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
entry.resolve(responseEntry?.resource);
|
|
1585
|
+
}
|
|
1498
1586
|
}
|
|
1499
1587
|
}, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
|
|
1500
1588
|
if (!options.headers) {
|