@medplum/core 3.0.3 → 3.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/dist/cjs/index.cjs +5 -5
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/cjs/index.d.ts +259 -1
- package/dist/esm/index.d.ts +259 -1
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/index.mjs.map +4 -4
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -142,6 +142,33 @@ export declare class AndAtom extends BooleanInfixOperatorAtom {
|
|
|
142
142
|
|
|
143
143
|
export declare function append<T>(array: T[] | undefined, value: T): T[];
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Adds default values to `existingValue` for the given `key` and its children. If `key` is undefined,
|
|
147
|
+
* default values are added to all elements in `elements`. Default values consist of all fixed and pattern
|
|
148
|
+
* values defined in the relevant elements.
|
|
149
|
+
* @param existingValue - The
|
|
150
|
+
* @param elements - The elements to which default values should be added.
|
|
151
|
+
* @param key - (optional) The key of the element(s) for which default values should be added. Elements with nested
|
|
152
|
+
* keys are also included. If undefined, default values for all elements are added.
|
|
153
|
+
* @returns `existingValue` with default values added
|
|
154
|
+
*/
|
|
155
|
+
export declare function applyDefaultValuesToElement(existingValue: object, elements: Record<string, InternalSchemaElement>, key?: string): object;
|
|
156
|
+
|
|
157
|
+
export declare function applyDefaultValuesToElementWithVisitor(existingValue: any, path: string, element: InternalSchemaElement, elements: Record<string, InternalSchemaElement>, schema: InternalTypeSchema): any;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Adds default values to `resource` based on the supplied `schema`. Default values includes all required fixed and pattern
|
|
161
|
+
* values specified on elements in the schema. If an element has a fixed/pattern value but is optional, i.e.
|
|
162
|
+
* `element.min === 0`, the default value is not added.
|
|
163
|
+
*
|
|
164
|
+
* @param resource - The resource to which default values should be added.
|
|
165
|
+
* @param schema - The schema to use for adding default values.
|
|
166
|
+
* @returns A clone of `resource` with default values added.
|
|
167
|
+
*/
|
|
168
|
+
export declare function applyDefaultValuesToResource(resource: Resource, schema: InternalTypeSchema): Resource;
|
|
169
|
+
|
|
170
|
+
export declare function applyFixedOrPatternValue(inputValue: any, key: string, element: InternalSchemaElement, elements: Record<string, InternalSchemaElement>): any;
|
|
171
|
+
|
|
145
172
|
export declare class ArithemticOperatorAtom extends BooleanInfixOperatorAtom {
|
|
146
173
|
readonly impl: (x: number, y: number) => number | boolean;
|
|
147
174
|
constructor(operator: string, left: Atom, right: Atom, impl: (x: number, y: number) => number | boolean);
|
|
@@ -237,8 +264,25 @@ export declare interface BotEvent<T = Resource | Hl7Message | string | Record<st
|
|
|
237
264
|
readonly contentType: string;
|
|
238
265
|
readonly input: T;
|
|
239
266
|
readonly secrets: Record<string, ProjectSecret>;
|
|
267
|
+
readonly traceId?: string;
|
|
240
268
|
}
|
|
241
269
|
|
|
270
|
+
export declare function buildElementsContext({ parentContext, path, elements, profileUrl, debugMode, }: {
|
|
271
|
+
/** The most recent `ElementsContextType` in which this context is being built. */
|
|
272
|
+
parentContext: ElementsContextType | undefined;
|
|
273
|
+
/** The FHIR path from the root resource to which the keys of `elements` are relative. */
|
|
274
|
+
path: string;
|
|
275
|
+
/**
|
|
276
|
+
* The mapping of keys to `InternalSchemaElement` at the current `path` relative to the
|
|
277
|
+
* root resource. This should be either `InternalTypeSchema.elements` or `SliceDefinition.elements`.
|
|
278
|
+
*/
|
|
279
|
+
elements: Record<string, InternalSchemaElement>;
|
|
280
|
+
/** The URL, if any, of the resource profile or extension from which the `elements` collection originated. */
|
|
281
|
+
profileUrl?: string;
|
|
282
|
+
/** Whether debug logging is enabled */
|
|
283
|
+
debugMode?: boolean;
|
|
284
|
+
}): ElementsContextType | undefined;
|
|
285
|
+
|
|
242
286
|
export declare function buildTypeName(components: string[]): string;
|
|
243
287
|
|
|
244
288
|
/**
|
|
@@ -520,6 +564,30 @@ export declare class DotAtom extends InfixOperatorAtom {
|
|
|
520
564
|
toString(): string;
|
|
521
565
|
}
|
|
522
566
|
|
|
567
|
+
/**
|
|
568
|
+
* Information for the set of elements at a given path within in a resource. This mostly exists to
|
|
569
|
+
* normalize access to elements regardless of whether they are from a profile, extension, or slice.
|
|
570
|
+
*/
|
|
571
|
+
export declare type ElementsContextType = {
|
|
572
|
+
/** The FHIR path from the root resource to which the keys of `elements` are relative. */
|
|
573
|
+
path: string;
|
|
574
|
+
/**
|
|
575
|
+
* The mapping of keys to `InternalSchemaElement` at the current `path` relative to the
|
|
576
|
+
* root resource. `elements` originate from either `InternalTypeSchema.elements` or
|
|
577
|
+
* `SliceDefinition.elements` when the elements context is created within a slice.
|
|
578
|
+
*/
|
|
579
|
+
elements: Record<string, InternalSchemaElement>;
|
|
580
|
+
/**
|
|
581
|
+
* Similar mapping as `elements`, but with keys being the full path from the root resource rather
|
|
582
|
+
* than relative to `path`, in other words, the keys of the Record are `${path}.${key}`.
|
|
583
|
+
*/
|
|
584
|
+
elementsByPath: Record<string, InternalSchemaElement>;
|
|
585
|
+
/** The URL, if any, of the resource profile or extension from which the `elements` collection originated. */
|
|
586
|
+
profileUrl: string | undefined;
|
|
587
|
+
/** Whether debug logging is enabled */
|
|
588
|
+
debugMode: boolean;
|
|
589
|
+
};
|
|
590
|
+
|
|
523
591
|
export declare interface ElementType {
|
|
524
592
|
code: string;
|
|
525
593
|
targetProfile?: string[];
|
|
@@ -1187,6 +1255,8 @@ export declare function getDataType(type: string, profileUrl?: string): Internal
|
|
|
1187
1255
|
*/
|
|
1188
1256
|
export declare function getDateProperty(date: string | undefined): Date | undefined;
|
|
1189
1257
|
|
|
1258
|
+
export declare function getDefaultValuesForNewSliceEntry(key: string, slice: SliceDefinition, slicing: SlicingRules, schema: InternalTypeSchema): Resource;
|
|
1259
|
+
|
|
1190
1260
|
/**
|
|
1191
1261
|
* Returns a display string for the resource.
|
|
1192
1262
|
* @param resource - The input resource.
|
|
@@ -1261,6 +1331,14 @@ export declare function getNestedProperty(value: TypedValue, key: string, option
|
|
|
1261
1331
|
profileUrl?: string;
|
|
1262
1332
|
}): (TypedValue | TypedValue[] | undefined)[];
|
|
1263
1333
|
|
|
1334
|
+
/**
|
|
1335
|
+
* Returns the difference between two paths which is often suitable to use as a key in a `Record<string, InternalSchemaElement>`
|
|
1336
|
+
* @param parentPath - The parent path that will be removed from `path`.
|
|
1337
|
+
* @param path - The element path that should be a child of `parentPath`.
|
|
1338
|
+
* @returns - The difference between `path` and `parentPath` or `undefined` if `path` is not a child of `parentPath`.
|
|
1339
|
+
*/
|
|
1340
|
+
export declare function getPathDifference(parentPath: string, path: string): string | undefined;
|
|
1341
|
+
|
|
1264
1342
|
/**
|
|
1265
1343
|
* Returns a human friendly display name for a FHIR element definition path.
|
|
1266
1344
|
* @param path - The FHIR element definition path.
|
|
@@ -1361,6 +1439,10 @@ export declare interface GetTypedPropertyValueOptions {
|
|
|
1361
1439
|
*/
|
|
1362
1440
|
export declare function getTypedPropertyValueWithSchema(typedValue: TypedValue, path: string, element: InternalSchemaElement): TypedValue[] | TypedValue | undefined;
|
|
1363
1441
|
|
|
1442
|
+
export declare function getValueSliceName(value: any, slices: SliceDefinitionWithTypes[], discriminators: SliceDiscriminator[], profileUrl: string | undefined): string | undefined;
|
|
1443
|
+
|
|
1444
|
+
export declare function getWebSocketUrl(path: string, baseUrl: URL | string): string;
|
|
1445
|
+
|
|
1364
1446
|
/**
|
|
1365
1447
|
* Global schema singleton.
|
|
1366
1448
|
*/
|
|
@@ -1782,6 +1864,8 @@ export declare class IsAtom extends BooleanInfixOperatorAtom {
|
|
|
1782
1864
|
|
|
1783
1865
|
export declare function isCompletedSubscriptionRequest(subscriptionRequest: SubscriptionRequest | PendingSubscriptionRequest): subscriptionRequest is SubscriptionRequest;
|
|
1784
1866
|
|
|
1867
|
+
export declare function isComplexTypeCode(code: string): boolean;
|
|
1868
|
+
|
|
1785
1869
|
export declare function isContextVersionRequired(event: string): event is FhircastEventVersionRequired;
|
|
1786
1870
|
|
|
1787
1871
|
export declare function isCreated(outcome: OperationOutcome): boolean;
|
|
@@ -1921,6 +2005,8 @@ export declare function isResourceType(resourceType: string): boolean;
|
|
|
1921
2005
|
*/
|
|
1922
2006
|
export declare function isResourceTypeSchema(typeSchema: InternalTypeSchema): boolean;
|
|
1923
2007
|
|
|
2008
|
+
export declare function isSliceDefinitionWithTypes(slice: SliceDefinition): slice is SliceDefinitionWithTypes;
|
|
2009
|
+
|
|
1924
2010
|
/**
|
|
1925
2011
|
* Returns true if the input array is an array of strings.
|
|
1926
2012
|
* @param arr - Input array.
|
|
@@ -2212,6 +2298,7 @@ export declare class MedplumClient extends EventTarget_2 {
|
|
|
2212
2298
|
private readonly onUnauthenticated?;
|
|
2213
2299
|
private readonly autoBatchTime;
|
|
2214
2300
|
private readonly autoBatchQueue;
|
|
2301
|
+
private subscriptionManager?;
|
|
2215
2302
|
private medplumServer?;
|
|
2216
2303
|
private clientId?;
|
|
2217
2304
|
private clientSecret?;
|
|
@@ -3333,10 +3420,11 @@ export declare class MedplumClient extends EventTarget_2 {
|
|
|
3333
3420
|
* @param method - The HTTP method (GET, POST, etc).
|
|
3334
3421
|
* @param url - The target URL.
|
|
3335
3422
|
* @param options - Optional fetch request init options.
|
|
3423
|
+
* @param state - Optional request state.
|
|
3336
3424
|
* @returns The JSON content body if available.
|
|
3337
3425
|
*/
|
|
3338
3426
|
private request;
|
|
3339
|
-
private
|
|
3427
|
+
private parseBody;
|
|
3340
3428
|
private fetchWithRetry;
|
|
3341
3429
|
private logRequest;
|
|
3342
3430
|
private logResponse;
|
|
@@ -3546,6 +3634,70 @@ export declare class MedplumClient extends EventTarget_2 {
|
|
|
3546
3634
|
*/
|
|
3547
3635
|
private setupStorageListener;
|
|
3548
3636
|
private retryCatch;
|
|
3637
|
+
/**
|
|
3638
|
+
* Gets the `SubscriptionManager` for WebSocket subscriptions.
|
|
3639
|
+
*
|
|
3640
|
+
* @category Subscriptions
|
|
3641
|
+
* @returns the `SubscriptionManager` for this client.
|
|
3642
|
+
*/
|
|
3643
|
+
getSubscriptionManager(): SubscriptionManager;
|
|
3644
|
+
/**
|
|
3645
|
+
* Subscribes to a given criteria, listening to notifications over WebSockets.
|
|
3646
|
+
*
|
|
3647
|
+
* This uses Medplum's `WebSocket Subscriptions` under the hood.
|
|
3648
|
+
*
|
|
3649
|
+
* A `SubscriptionEmitter` is returned from this function, which can be used to listen for updates to resources described by the given criteria.
|
|
3650
|
+
*
|
|
3651
|
+
* When subscribing to the same criteria multiple times, the same `SubscriptionEmitter` will be returned, and a reference count will be incremented.
|
|
3652
|
+
*
|
|
3653
|
+
* -----
|
|
3654
|
+
* @example
|
|
3655
|
+
* ```ts
|
|
3656
|
+
* const emitter = medplum.subscribeToCriteria('Communication');
|
|
3657
|
+
*
|
|
3658
|
+
* emitter.addEventListener('message', (bundle: Bundle) => {
|
|
3659
|
+
* // Called when a `Communication` resource is created or modified
|
|
3660
|
+
* console.log(bundle?.entry?.[1]?.resource); // Logs the `Communication` resource that was updated
|
|
3661
|
+
* });
|
|
3662
|
+
* ```
|
|
3663
|
+
*
|
|
3664
|
+
* @category Subscriptions
|
|
3665
|
+
* @param criteria - The criteria to subscribe to.
|
|
3666
|
+
* @returns a `SubscriptionEmitter` that emits `Bundle` resources containing changes to resources based on the given criteria.
|
|
3667
|
+
*/
|
|
3668
|
+
subscribeToCriteria(criteria: string): SubscriptionEmitter;
|
|
3669
|
+
/**
|
|
3670
|
+
* Unsubscribes from the given criteria.
|
|
3671
|
+
*
|
|
3672
|
+
* When called the same amount of times as proceeding calls to `subscribeToCriteria` on a given `criteria`,
|
|
3673
|
+
* the criteria is fully removed from the `SubscriptionManager`.
|
|
3674
|
+
*
|
|
3675
|
+
* @category Subscriptions
|
|
3676
|
+
* @param criteria - The criteria to unsubscribe from.
|
|
3677
|
+
*/
|
|
3678
|
+
unsubscribeFromCriteria(criteria: string): void;
|
|
3679
|
+
/**
|
|
3680
|
+
* Get the master `SubscriptionEmitter` for the `SubscriptionManager`.
|
|
3681
|
+
*
|
|
3682
|
+
* The master `SubscriptionEmitter` gets messages for all subscribed `criteria` as well as WebSocket errors, `connect` and `disconnect` events, and the `close` event.
|
|
3683
|
+
*
|
|
3684
|
+
* It can also be used to listen for `heartbeat` messages.
|
|
3685
|
+
*
|
|
3686
|
+
*------
|
|
3687
|
+
* @example
|
|
3688
|
+
* ### Listening for `heartbeat`:
|
|
3689
|
+
* ```ts
|
|
3690
|
+
* const masterEmitter = medplum.getMasterSubscriptionEmitter();
|
|
3691
|
+
*
|
|
3692
|
+
* masterEmitter.addEventListener('heartbeat', (bundle: Bundle<SubscriptionStatus>) => {
|
|
3693
|
+
* console.log(bundle?.entry?.[0]?.resource); // A `SubscriptionStatus` of type `heartbeat`
|
|
3694
|
+
* });
|
|
3695
|
+
*
|
|
3696
|
+
* ```
|
|
3697
|
+
* @category Subscriptions
|
|
3698
|
+
* @returns the master `SubscriptionEmitter` from the `SubscriptionManager`.
|
|
3699
|
+
*/
|
|
3700
|
+
getMasterSubscriptionEmitter(): SubscriptionEmitter;
|
|
3549
3701
|
}
|
|
3550
3702
|
|
|
3551
3703
|
/**
|
|
@@ -4516,6 +4668,26 @@ export declare interface ResourceVisitor {
|
|
|
4516
4668
|
|
|
4517
4669
|
export declare type ResourceWithCode = Resource & Code;
|
|
4518
4670
|
|
|
4671
|
+
export declare class RobustWebSocket extends TypedEventTarget<RobustWebSocketEventMap> {
|
|
4672
|
+
private ws;
|
|
4673
|
+
private messageBuffer;
|
|
4674
|
+
bufferedAmount: number;
|
|
4675
|
+
extensions: string;
|
|
4676
|
+
constructor(url: string);
|
|
4677
|
+
get readyState(): number;
|
|
4678
|
+
close(): void;
|
|
4679
|
+
send(message: string): void;
|
|
4680
|
+
}
|
|
4681
|
+
|
|
4682
|
+
export declare type RobustWebSocketEventMap = {
|
|
4683
|
+
open: {
|
|
4684
|
+
type: 'open';
|
|
4685
|
+
};
|
|
4686
|
+
message: MessageEvent;
|
|
4687
|
+
error: Event;
|
|
4688
|
+
close: CloseEvent;
|
|
4689
|
+
};
|
|
4690
|
+
|
|
4519
4691
|
export declare const RXNORM = "http://www.nlm.nih.gov/research/umls/rxnorm";
|
|
4520
4692
|
|
|
4521
4693
|
/**
|
|
@@ -4559,6 +4731,8 @@ export declare interface SearchRequest<T extends Resource = Resource> {
|
|
|
4559
4731
|
include?: IncludeTarget[];
|
|
4560
4732
|
revInclude?: IncludeTarget[];
|
|
4561
4733
|
summary?: 'true' | 'text' | 'data';
|
|
4734
|
+
format?: string;
|
|
4735
|
+
pretty?: boolean;
|
|
4562
4736
|
}
|
|
4563
4737
|
|
|
4564
4738
|
/**
|
|
@@ -4618,6 +4792,11 @@ export declare interface SliceDefinition {
|
|
|
4618
4792
|
binding?: ElementDefinitionBinding;
|
|
4619
4793
|
}
|
|
4620
4794
|
|
|
4795
|
+
export declare type SliceDefinitionWithTypes = SliceDefinition & {
|
|
4796
|
+
type: NonNullable<SliceDefinition['type']>;
|
|
4797
|
+
typeSchema?: InternalTypeSchema;
|
|
4798
|
+
};
|
|
4799
|
+
|
|
4621
4800
|
export declare interface SliceDiscriminator {
|
|
4622
4801
|
path: string;
|
|
4623
4802
|
type: string;
|
|
@@ -4689,6 +4868,85 @@ export declare type StringMap = {
|
|
|
4689
4868
|
*/
|
|
4690
4869
|
export declare function structureMapTransform(structureMap: StructureMap, input: TypedValue[], loader?: (url: string) => StructureMap[]): TypedValue[];
|
|
4691
4870
|
|
|
4871
|
+
/**
|
|
4872
|
+
* An `EventTarget` that emits events when new subscription notifications come in over WebSockets.
|
|
4873
|
+
*
|
|
4874
|
+
* -----
|
|
4875
|
+
*
|
|
4876
|
+
* ### Events emitted:
|
|
4877
|
+
*
|
|
4878
|
+
* - `connect` - A new subscription is connected to the `SubscriptionManager` and `message` events for this subscription can be expected.
|
|
4879
|
+
* - `disconnect` - The specified subscription is no longer being monitored by the `SubscriptionManager`.
|
|
4880
|
+
* - `error` - An error has occurred.
|
|
4881
|
+
* - `message` - A message containing a notification `Bundle` has been received.
|
|
4882
|
+
* - `close` - The WebSocket has been closed.
|
|
4883
|
+
* - `heartbeat` - A `heartbeat` message has been received.
|
|
4884
|
+
*/
|
|
4885
|
+
export declare class SubscriptionEmitter extends TypedEventTarget<SubscriptionEventMap> {
|
|
4886
|
+
private criteria;
|
|
4887
|
+
constructor(...criteria: string[]);
|
|
4888
|
+
getCriteria(): Set<string>;
|
|
4889
|
+
/**
|
|
4890
|
+
* @internal
|
|
4891
|
+
* @param criteria - The criteria to add to this `SubscriptionEmitter`.
|
|
4892
|
+
*/
|
|
4893
|
+
_addCriteria(criteria: string): void;
|
|
4894
|
+
/**
|
|
4895
|
+
* @internal
|
|
4896
|
+
* @param criteria - The criteria to remove from this `SubscriptionEmitter`.
|
|
4897
|
+
*/
|
|
4898
|
+
_removeCriteria(criteria: string): void;
|
|
4899
|
+
}
|
|
4900
|
+
|
|
4901
|
+
export declare type SubscriptionEventMap = {
|
|
4902
|
+
connect: {
|
|
4903
|
+
type: 'connect';
|
|
4904
|
+
payload: {
|
|
4905
|
+
subscriptionId: string;
|
|
4906
|
+
};
|
|
4907
|
+
};
|
|
4908
|
+
disconnect: {
|
|
4909
|
+
type: 'disconnect';
|
|
4910
|
+
payload: {
|
|
4911
|
+
subscriptionId: string;
|
|
4912
|
+
};
|
|
4913
|
+
};
|
|
4914
|
+
error: {
|
|
4915
|
+
type: 'error';
|
|
4916
|
+
payload: Error;
|
|
4917
|
+
};
|
|
4918
|
+
message: {
|
|
4919
|
+
type: 'message';
|
|
4920
|
+
payload: Bundle;
|
|
4921
|
+
};
|
|
4922
|
+
close: {
|
|
4923
|
+
type: 'close';
|
|
4924
|
+
};
|
|
4925
|
+
heartbeat: {
|
|
4926
|
+
type: 'heartbeat';
|
|
4927
|
+
payload: Bundle;
|
|
4928
|
+
};
|
|
4929
|
+
};
|
|
4930
|
+
|
|
4931
|
+
export declare class SubscriptionManager {
|
|
4932
|
+
private readonly medplum;
|
|
4933
|
+
private ws;
|
|
4934
|
+
private masterSubEmitter?;
|
|
4935
|
+
private criteriaEntries;
|
|
4936
|
+
private criteriaEntriesBySubscriptionId;
|
|
4937
|
+
private wsClosed;
|
|
4938
|
+
constructor(medplum: MedplumClient, wsUrl: URL | string);
|
|
4939
|
+
private setupWebSocketListeners;
|
|
4940
|
+
private emitConnect;
|
|
4941
|
+
private emitError;
|
|
4942
|
+
private getTokenForCriteria;
|
|
4943
|
+
addCriteria(criteria: string): SubscriptionEmitter;
|
|
4944
|
+
removeCriteria(criteria: string): void;
|
|
4945
|
+
closeWebSocket(): void;
|
|
4946
|
+
getCriteriaCount(): number;
|
|
4947
|
+
getMasterEmitter(): SubscriptionEmitter;
|
|
4948
|
+
}
|
|
4949
|
+
|
|
4692
4950
|
/**
|
|
4693
4951
|
* A `FHIRcast` subscription request.
|
|
4694
4952
|
*
|