@medplum/core 2.1.4 → 2.1.6
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 +15 -6
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.mjs +15 -6
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/base-schema.d.ts +7 -0
- package/dist/types/client.d.ts +41 -13
- package/dist/types/eventtarget.d.ts +6 -0
- package/dist/types/fhircast/index.d.ts +115 -0
- package/dist/types/fhircast/test-utils.d.ts +2 -0
- package/dist/types/fhirmapper/tokenize.d.ts +1 -1
- package/dist/types/fhirpath/atoms.d.ts +1 -1
- package/dist/types/fhirpath/functions.d.ts +1 -1
- package/dist/types/fhirpath/parse.d.ts +1 -1
- package/dist/types/fhirpath/tokenize.d.ts +1 -1
- package/dist/types/filter/tokenize.d.ts +1 -1
- package/dist/types/index.d.ts +8 -4
- package/dist/types/outcomes.d.ts +1 -0
- package/dist/types/schema.d.ts +1 -104
- package/dist/types/search/details.d.ts +4 -3
- package/dist/types/types.d.ts +74 -92
- package/dist/types/typeschema/types.d.ts +32 -10
- package/dist/types/typeschema/validation.d.ts +1 -1
- package/package.json +3 -2
- package/dist/types/fhirlexer/index.d.ts +0 -2
- package/dist/types/fhirmapper/index.d.ts +0 -1
- package/dist/types/fhirpath/index.d.ts +0 -4
- package/dist/types/filter/index.d.ts +0 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InternalSchemaElement, InternalTypeSchema } from './typeschema/types';
|
|
2
|
+
export type BaseSchema = Record<string, {
|
|
3
|
+
elements: Record<string, Partial<InternalSchemaElement>>;
|
|
4
|
+
}>;
|
|
5
|
+
export declare function compressElement(element: InternalSchemaElement): Partial<InternalSchemaElement>;
|
|
6
|
+
export declare function inflateElement(partial: Partial<InternalSchemaElement>): InternalSchemaElement;
|
|
7
|
+
export declare function inflateBaseSchema(base: BaseSchema): Record<string, InternalTypeSchema>;
|
package/dist/types/client.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { AccessPolicy, Agent, Attachment, Binary, BulkDataExport, Bundle, Commun
|
|
|
2
2
|
/** @ts-ignore */
|
|
3
3
|
import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
|
|
4
4
|
import { EventTarget } from './eventtarget';
|
|
5
|
+
import { FhircastConnection, FhircastEventContext, FhircastEventName, SubscriptionRequest } from './fhircast';
|
|
5
6
|
import { Hl7Message } from './hl7';
|
|
6
7
|
import { ReadablePromise } from './readablepromise';
|
|
7
8
|
import { ClientStorage } from './storage';
|
|
8
|
-
import { IndexedStructureDefinition } from './types';
|
|
9
9
|
import { CodeChallengeMethod, ProfileResource } from './utils';
|
|
10
10
|
export declare const MEDPLUM_VERSION: string;
|
|
11
11
|
/**
|
|
@@ -907,15 +907,6 @@ export declare class MedplumClient extends EventTarget {
|
|
|
907
907
|
* @returns The resource if available; undefined otherwise.
|
|
908
908
|
*/
|
|
909
909
|
readReference<T extends Resource>(reference: Reference<T>, options?: RequestInit): ReadablePromise<T>;
|
|
910
|
-
/**
|
|
911
|
-
* Returns a cached schema for a resource type.
|
|
912
|
-
* If the schema is not cached, returns undefined.
|
|
913
|
-
* It is assumed that a client will call requestSchema before using this method.
|
|
914
|
-
* @category Schema
|
|
915
|
-
* @returns The schema if immediately available, undefined otherwise.
|
|
916
|
-
* @deprecated Use globalSchema instead.
|
|
917
|
-
*/
|
|
918
|
-
getSchema(): IndexedStructureDefinition;
|
|
919
910
|
/**
|
|
920
911
|
* Requests the schema for a resource type.
|
|
921
912
|
* If the schema is already cached, the promise is resolved immediately.
|
|
@@ -923,7 +914,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
923
914
|
* @param resourceType The FHIR resource type.
|
|
924
915
|
* @returns Promise to a schema with the requested resource type.
|
|
925
916
|
*/
|
|
926
|
-
requestSchema(resourceType: string): Promise<
|
|
917
|
+
requestSchema(resourceType: string): Promise<void>;
|
|
927
918
|
/**
|
|
928
919
|
* Reads resource history by resource type and ID.
|
|
929
920
|
*
|
|
@@ -1455,9 +1446,9 @@ export declare class MedplumClient extends EventTarget {
|
|
|
1455
1446
|
*/
|
|
1456
1447
|
getProfile(): ProfileResource | undefined;
|
|
1457
1448
|
/**
|
|
1458
|
-
* Returns the current user profile resource if
|
|
1449
|
+
* Returns the current user profile resource, retrieving form the server if necessary.
|
|
1459
1450
|
* This method waits for loading promises.
|
|
1460
|
-
* @returns The current user profile resource
|
|
1451
|
+
* @returns The current user profile resource.
|
|
1461
1452
|
* @category User Profile
|
|
1462
1453
|
*/
|
|
1463
1454
|
getProfileAsync(): Promise<ProfileResource | undefined>;
|
|
@@ -1667,6 +1658,43 @@ export declare class MedplumClient extends EventTarget {
|
|
|
1667
1658
|
* @param clientSecret The client secret.
|
|
1668
1659
|
*/
|
|
1669
1660
|
setBasicAuth(clientId: string, clientSecret: string): void;
|
|
1661
|
+
/**
|
|
1662
|
+
* Subscribes to a specified topic, listening for a list of specified events.
|
|
1663
|
+
*
|
|
1664
|
+
* Once you have the `SubscriptionRequest` returned from this method, you can call `fhircastConnect(subscriptionRequest)` to connect to the subscription stream.
|
|
1665
|
+
*
|
|
1666
|
+
* @category FHIRcast
|
|
1667
|
+
* @param topic The topic to publish to. Usually a UUID.
|
|
1668
|
+
* @param events An array of event names to listen for.
|
|
1669
|
+
* @returns A `Promise` that resolves once the request completes, or rejects if it fails.
|
|
1670
|
+
*/
|
|
1671
|
+
fhircastSubscribe(topic: string, events: FhircastEventName[]): Promise<SubscriptionRequest>;
|
|
1672
|
+
/**
|
|
1673
|
+
* Unsubscribes from the specified topic.
|
|
1674
|
+
*
|
|
1675
|
+
* @category FHIRcast
|
|
1676
|
+
* @param subRequest A `SubscriptionRequest` representing a subscription to cancel. Mode will be set to `unsubscribe` automatically.
|
|
1677
|
+
* @returns A `Promise` that resolves when request to unsubscribe is completed.
|
|
1678
|
+
*/
|
|
1679
|
+
fhircastUnsubscribe(subRequest: SubscriptionRequest): Promise<void>;
|
|
1680
|
+
/**
|
|
1681
|
+
* Connects to a `FHIRcast` session.
|
|
1682
|
+
*
|
|
1683
|
+
* @category FHIRcast
|
|
1684
|
+
* @param subRequest The `SubscriptionRequest` to use for connecting.
|
|
1685
|
+
* @returns A `FhircastConnection` which emits lifecycle events for the `FHIRcast` WebSocket connection.
|
|
1686
|
+
*/
|
|
1687
|
+
fhircastConnect(subRequest: SubscriptionRequest): FhircastConnection;
|
|
1688
|
+
/**
|
|
1689
|
+
* Publishes a new context to a given topic for a specified event type.
|
|
1690
|
+
*
|
|
1691
|
+
* @category FHIRcast
|
|
1692
|
+
* @param topic The topic to publish to. Usually a UUID.
|
|
1693
|
+
* @param event The name of the event to publish an updated context for, ie. `patient-open`.
|
|
1694
|
+
* @param context The updated context containing resources relevant to this event.
|
|
1695
|
+
* @returns A `Promise` that resolves once the request completes, or rejects if it fails.
|
|
1696
|
+
*/
|
|
1697
|
+
fhircastPublish(topic: string, event: FhircastEventName, context: FhircastEventContext | FhircastEventContext[]): Promise<void>;
|
|
1670
1698
|
/**
|
|
1671
1699
|
* Invite a user to a project.
|
|
1672
1700
|
* @param projectId The project ID.
|
|
@@ -10,3 +10,9 @@ export declare class EventTarget {
|
|
|
10
10
|
removeEventListener(type: string, callback: EventListener): void;
|
|
11
11
|
dispatchEvent(event: Event): boolean;
|
|
12
12
|
}
|
|
13
|
+
export declare class TypedEventTarget<TEvents extends Record<string, Event>> {
|
|
14
|
+
private emitter;
|
|
15
|
+
dispatchEvent<TEventType extends keyof TEvents & string>(event: TEvents[TEventType]): void;
|
|
16
|
+
addEventListener<TEventType extends keyof TEvents & string>(type: TEventType, handler: (event: TEvents[TEventType]) => void): void;
|
|
17
|
+
removeEventListener<TEventType extends keyof TEvents & string>(type: TEventType, handler: (event: TEvents[TEventType]) => void): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Resource } from '@medplum/fhirtypes';
|
|
2
|
+
import { TypedEventTarget } from '../eventtarget';
|
|
3
|
+
declare const FHIRCAST_EVENT_NAMES: {
|
|
4
|
+
readonly 'patient-open': "patient-open";
|
|
5
|
+
readonly 'patient-close': "patient-close";
|
|
6
|
+
readonly 'imagingstudy-open': "imagingstudy-open";
|
|
7
|
+
readonly 'imagingstudy-close': "imagingstudy-close";
|
|
8
|
+
};
|
|
9
|
+
declare const FHIRCAST_RESOURCE_TYPES: readonly ["Patient", "Encounter", "ImagingStudy"];
|
|
10
|
+
export type FhircastEventName = keyof typeof FHIRCAST_EVENT_NAMES;
|
|
11
|
+
export type FhircastResourceType = (typeof FHIRCAST_RESOURCE_TYPES)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a `ResourceType` can be used in a `FHIRcast` context.
|
|
14
|
+
*
|
|
15
|
+
* @param resourceType A `ResourceType` to test.
|
|
16
|
+
* @returns `true` if this is a resource type associated with `FHIRcast` contexts, otherwise returns `false`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isFhircastResourceType(resourceType: FhircastResourceType): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* A `FHIRcast` subscription request.
|
|
21
|
+
*
|
|
22
|
+
* Can be passed to `MedplumClient.fhircastConnect` or `MedplumClient.fhircastUnsubscribe` to either open a `FHIRcast` connection, or unsubscribe from the subscription.
|
|
23
|
+
*/
|
|
24
|
+
export type SubscriptionRequest = {
|
|
25
|
+
channelType: 'websocket';
|
|
26
|
+
mode: 'subscribe' | 'unsubscribe';
|
|
27
|
+
events: FhircastEventName[];
|
|
28
|
+
topic: string;
|
|
29
|
+
endpoint: string;
|
|
30
|
+
};
|
|
31
|
+
export type PendingSubscriptionRequest = Omit<SubscriptionRequest, 'endpoint'>;
|
|
32
|
+
declare const FHIRCAST_CONTEXT_KEY_LOOKUP: {
|
|
33
|
+
readonly study: "ImagingStudy";
|
|
34
|
+
readonly patient: "Patient";
|
|
35
|
+
readonly encounter: "Encounter";
|
|
36
|
+
};
|
|
37
|
+
type FhircastEventContextMap = typeof FHIRCAST_CONTEXT_KEY_LOOKUP;
|
|
38
|
+
type FhircastEventContextKey = keyof FhircastEventContextMap;
|
|
39
|
+
export type FhircastEventContext<K extends FhircastEventContextKey = FhircastEventContextKey> = {
|
|
40
|
+
key: K;
|
|
41
|
+
resource: Resource & {
|
|
42
|
+
resourceType: FhircastEventContextMap[K];
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type FhircastEventPayload = {
|
|
47
|
+
'hub.topic': string;
|
|
48
|
+
'hub.event': string;
|
|
49
|
+
context: FhircastEventContext[];
|
|
50
|
+
};
|
|
51
|
+
export type FhircastMessagePayload = {
|
|
52
|
+
timestamp: string;
|
|
53
|
+
id: string;
|
|
54
|
+
event: FhircastEventPayload;
|
|
55
|
+
};
|
|
56
|
+
export declare function isCompletedSubscriptionRequest(subscriptionRequest: SubscriptionRequest | PendingSubscriptionRequest): subscriptionRequest is SubscriptionRequest;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a serialized url-encoded payload for a `FHIRcast` subscription from a `SubscriptionRequest` object that can be directly used in an HTTP request to the Hub.
|
|
59
|
+
*
|
|
60
|
+
* @param subscriptionRequest An object representing a subscription request.
|
|
61
|
+
* @returns A serialized subscription in url-encoded form.
|
|
62
|
+
*/
|
|
63
|
+
export declare function serializeFhircastSubscriptionRequest(subscriptionRequest: SubscriptionRequest | PendingSubscriptionRequest): string;
|
|
64
|
+
/**
|
|
65
|
+
* Validates that a `SubscriptionRequest`.
|
|
66
|
+
*
|
|
67
|
+
* @param subscriptionRequest The `SubscriptionRequest` to validate.
|
|
68
|
+
* @returns A `boolean` indicating whether or not the `SubscriptionRequest` is valid.
|
|
69
|
+
*/
|
|
70
|
+
export declare function validateFhircastSubscriptionRequest(subscriptionRequest: SubscriptionRequest | PendingSubscriptionRequest): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a serializable JSON payload for the `FHIRcast` protocol
|
|
73
|
+
*
|
|
74
|
+
* @param topic The topic that this message will be published on. Usually a UUID.
|
|
75
|
+
* @param event The event name, ie. "patient-open" or "patient-close".
|
|
76
|
+
* @param context The updated context, containing new versions of resources related to this event.
|
|
77
|
+
* @returns A serializable `FhircastMessagePayload`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createFhircastMessagePayload(topic: string, event: FhircastEventName, context: FhircastEventContext | FhircastEventContext[]): FhircastMessagePayload;
|
|
80
|
+
export type FhircastConnectEvent = {
|
|
81
|
+
type: 'connect';
|
|
82
|
+
};
|
|
83
|
+
export type FhircastMessageEvent = {
|
|
84
|
+
type: 'message';
|
|
85
|
+
payload: FhircastMessagePayload;
|
|
86
|
+
};
|
|
87
|
+
export type FhircastDisconnectEvent = {
|
|
88
|
+
type: 'disconnect';
|
|
89
|
+
};
|
|
90
|
+
export type FhircastSubscriptionEventMap = {
|
|
91
|
+
connect: FhircastConnectEvent;
|
|
92
|
+
message: FhircastMessageEvent;
|
|
93
|
+
disconnect: FhircastDisconnectEvent;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A class representing a `FHIRcast` connection.
|
|
97
|
+
*
|
|
98
|
+
* `FhircastConnection` extends `EventTarget` and emits 3 lifecycle events:
|
|
99
|
+
* 1. `connect` - An event to signal when a WebSocket connection has been opened. Fired as soon as a WebSocket emits `open`.
|
|
100
|
+
* 2. `message` - Contains a `payload` field containing a `FHIRcast` message payload exactly as it comes in over WebSockets.
|
|
101
|
+
* 3. `disconnect` - An event to signal when a WebSocket connection has been closed. Fired as soon as a WebSocket emits `close`.
|
|
102
|
+
*
|
|
103
|
+
* To close the connection, call `connection.disconnect()` and listen to the `disconnect` event to know when the connection has been disconnected.
|
|
104
|
+
*/
|
|
105
|
+
export declare class FhircastConnection extends TypedEventTarget<FhircastSubscriptionEventMap> {
|
|
106
|
+
subRequest: SubscriptionRequest;
|
|
107
|
+
private websocket;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a new `FhircastConnection`.
|
|
110
|
+
* @param subRequest The subscription request to initialize the connection from.
|
|
111
|
+
*/
|
|
112
|
+
constructor(subRequest: SubscriptionRequest);
|
|
113
|
+
disconnect(): void;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Token } from '../fhirlexer';
|
|
1
|
+
import { Token } from '../fhirlexer/tokenize';
|
|
2
2
|
export declare function tokenize(str: string): Token[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Atom, AtomContext, InfixOperatorAtom, PrefixOperatorAtom } from '../fhirlexer';
|
|
1
|
+
import { Atom, AtomContext, InfixOperatorAtom, PrefixOperatorAtom } from '../fhirlexer/parse';
|
|
2
2
|
import { TypedValue } from '../types';
|
|
3
3
|
export declare class FhirPathAtom implements Atom {
|
|
4
4
|
readonly original: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Atom, AtomContext } from '../fhirlexer';
|
|
1
|
+
import { Atom, AtomContext } from '../fhirlexer/parse';
|
|
2
2
|
import { TypedValue } from '../types';
|
|
3
3
|
export type FhirPathFunction = (context: AtomContext, input: TypedValue[], ...args: Atom[]) => TypedValue[];
|
|
4
4
|
export declare const functions: Record<string, FhirPathFunction>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Token } from '../fhirlexer';
|
|
1
|
+
import { Token } from '../fhirlexer/tokenize';
|
|
2
2
|
export declare function tokenize(str: string): Token[];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './access';
|
|
2
2
|
export * from './base64';
|
|
3
|
+
export * from './base-schema';
|
|
3
4
|
export * from './bundle';
|
|
4
5
|
export * from './cache';
|
|
5
6
|
export * from './client';
|
|
@@ -8,10 +9,13 @@ export * from './constants';
|
|
|
8
9
|
export * from './contenttype';
|
|
9
10
|
export * from './crypto';
|
|
10
11
|
export * from './eventtarget';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
12
|
+
export * from './fhircast';
|
|
13
|
+
export * from './fhirlexer/parse';
|
|
14
|
+
export * from './fhirmapper/parse';
|
|
15
|
+
export * from './fhirpath/parse';
|
|
16
|
+
export * from './fhirpath/utils';
|
|
17
|
+
export * from './filter/parse';
|
|
18
|
+
export * from './filter/types';
|
|
15
19
|
export * from './format';
|
|
16
20
|
export * from './hl7';
|
|
17
21
|
export * from './jwt';
|
package/dist/types/outcomes.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function validationError(details: string): OperationOutcome;
|
|
|
14
14
|
export declare function serverError(err: Error): OperationOutcome;
|
|
15
15
|
export declare function isOperationOutcome(value: unknown): value is OperationOutcome;
|
|
16
16
|
export declare function isOk(outcome: OperationOutcome): boolean;
|
|
17
|
+
export declare function isCreated(outcome: OperationOutcome): boolean;
|
|
17
18
|
export declare function isAccepted(outcome: OperationOutcome): boolean;
|
|
18
19
|
export declare function isNotFound(outcome: OperationOutcome): boolean;
|
|
19
20
|
export declare function isGone(outcome: OperationOutcome): boolean;
|
package/dist/types/schema.d.ts
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
import { OperationOutcomeIssue
|
|
2
|
-
/**
|
|
3
|
-
* Returns true if the given string is a valid FHIR resource type.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* isResourceType('Patient'); // true
|
|
7
|
-
* isResourceType('XYZ'); // false
|
|
8
|
-
* ```
|
|
9
|
-
*
|
|
10
|
-
* Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
|
|
11
|
-
*
|
|
12
|
-
* In a server context, you can load all schema definitions:
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { indexStructureDefinitionBundle } from '@medplum/core';
|
|
16
|
-
* import { readJson } from '@medplum/definitions';
|
|
17
|
-
* import { Bundle } from '@medplum/fhirtypes';
|
|
18
|
-
*
|
|
19
|
-
* indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* In a client context, you can load the schema definitions using MedplumClient:
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { MedplumClient } from '@medplum/core';
|
|
26
|
-
*
|
|
27
|
-
* const medplum = new MedplumClient();
|
|
28
|
-
* await medplum.requestSchema('Patient');
|
|
29
|
-
* ```
|
|
30
|
-
* @param resourceType The candidate resource type string.
|
|
31
|
-
* @returns True if the resource type is a valid FHIR resource type.
|
|
32
|
-
*/
|
|
33
|
-
export declare function isResourceType(resourceType: string): boolean;
|
|
1
|
+
import { OperationOutcomeIssue } from '@medplum/fhirtypes';
|
|
34
2
|
/**
|
|
35
3
|
* Validates that the given string is a valid FHIR resource type.
|
|
36
4
|
* On success, silently returns void.
|
|
@@ -64,77 +32,6 @@ export declare function isResourceType(resourceType: string): boolean;
|
|
|
64
32
|
* @param resourceType The candidate resource type string.
|
|
65
33
|
*/
|
|
66
34
|
export declare function validateResourceType(resourceType: string): void;
|
|
67
|
-
/**
|
|
68
|
-
* Validates a candidate FHIR resource object.
|
|
69
|
-
* On success, silently returns void.
|
|
70
|
-
* On failure, throws an OperationOutcomeError with issues for each violation.
|
|
71
|
-
*
|
|
72
|
-
* ```ts
|
|
73
|
-
* validateResource({ resourceType: 'Patient' }); // nothing
|
|
74
|
-
* validateResource({ resourceType: 'XYZ' }); // throws OperationOutcomeError
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
|
|
78
|
-
*
|
|
79
|
-
* In a server context, you can load all schema definitions:
|
|
80
|
-
*
|
|
81
|
-
* ```ts
|
|
82
|
-
* import { indexStructureDefinitionBundle } from '@medplum/core';
|
|
83
|
-
* import { readJson } from '@medplum/definitions';
|
|
84
|
-
* import { Bundle } from '@medplum/fhirtypes';
|
|
85
|
-
*
|
|
86
|
-
* indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* In a client context, you can load the schema definitions using MedplumClient:
|
|
90
|
-
*
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { MedplumClient } from '@medplum/core';
|
|
93
|
-
*
|
|
94
|
-
* const medplum = new MedplumClient();
|
|
95
|
-
* await medplum.requestSchema('Patient');
|
|
96
|
-
* ```
|
|
97
|
-
* @param resource The candidate resource.
|
|
98
|
-
* @deprecated use validate() instead
|
|
99
|
-
*/
|
|
100
|
-
export declare function validateResource<T extends Resource>(resource: T): void;
|
|
101
|
-
export declare class FhirSchemaValidator<T extends Resource> {
|
|
102
|
-
private readonly issues;
|
|
103
|
-
private readonly root;
|
|
104
|
-
constructor(root: T);
|
|
105
|
-
validate(): void;
|
|
106
|
-
private validateObject;
|
|
107
|
-
private checkProperties;
|
|
108
|
-
private checkProperty;
|
|
109
|
-
private checkPropertyValue;
|
|
110
|
-
private validatePrimitiveType;
|
|
111
|
-
private validateString;
|
|
112
|
-
private validateNumber;
|
|
113
|
-
private checkAdditionalProperties;
|
|
114
|
-
/**
|
|
115
|
-
* Checks if the given property is allowed on the given object.
|
|
116
|
-
* @param path The path of the current object.
|
|
117
|
-
* @param key The key of a property to check.
|
|
118
|
-
* @param typedValue The current object.
|
|
119
|
-
* @param propertyDefinitions The property definitions of the current object.
|
|
120
|
-
*/
|
|
121
|
-
private checkAdditionalProperty;
|
|
122
|
-
/**
|
|
123
|
-
* Checks the element for a primitive.
|
|
124
|
-
*
|
|
125
|
-
* FHIR elements with primitive data types are represented in two parts:
|
|
126
|
-
* 1) A JSON property with the name of the element, which has a JSON type of number, boolean, or string
|
|
127
|
-
* 2) a JSON property with _ prepended to the name of the element, which, if present, contains the value's id and/or extensions
|
|
128
|
-
*
|
|
129
|
-
* See: https://hl7.org/fhir/json.html#primitive
|
|
130
|
-
* @param path The path to the property
|
|
131
|
-
* @param key The key in the current typed value.
|
|
132
|
-
* @param typedValue The current typed value.
|
|
133
|
-
* @returns True if the primitive element is valid.
|
|
134
|
-
*/
|
|
135
|
-
private checkPrimitiveElement;
|
|
136
|
-
private createIssue;
|
|
137
|
-
}
|
|
138
35
|
/**
|
|
139
36
|
* Recursively checks for null values in an object.
|
|
140
37
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Atom } from '../fhirlexer';
|
|
1
|
+
import { SearchParameter } from '@medplum/fhirtypes';
|
|
2
|
+
import { Atom } from '../fhirlexer/parse';
|
|
3
|
+
import { InternalSchemaElement } from '../typeschema/types';
|
|
3
4
|
export declare enum SearchParameterType {
|
|
4
5
|
BOOLEAN = "BOOLEAN",
|
|
5
6
|
NUMBER = "NUMBER",
|
|
@@ -15,7 +16,7 @@ export declare enum SearchParameterType {
|
|
|
15
16
|
export interface SearchParameterDetails {
|
|
16
17
|
readonly columnName: string;
|
|
17
18
|
readonly type: SearchParameterType;
|
|
18
|
-
readonly elementDefinitions?:
|
|
19
|
+
readonly elementDefinitions?: InternalSchemaElement[];
|
|
19
20
|
readonly array?: boolean;
|
|
20
21
|
}
|
|
21
22
|
/**
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter
|
|
1
|
+
import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter } from '@medplum/fhirtypes';
|
|
2
2
|
import { SearchParameterDetails } from './search/details';
|
|
3
|
+
import { InternalSchemaElement, InternalTypeSchema } from './typeschema/types';
|
|
3
4
|
export interface TypedValue {
|
|
4
5
|
readonly type: string;
|
|
5
6
|
readonly value: any;
|
|
@@ -9,67 +10,67 @@ export interface TypedValue {
|
|
|
9
10
|
* http://www.hl7.org/fhir/valueset-defined-types.html
|
|
10
11
|
* The list here includes additions found from StructureDefinition resources.
|
|
11
12
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
Address
|
|
14
|
-
Age
|
|
15
|
-
Annotation
|
|
16
|
-
Attachment
|
|
17
|
-
BackboneElement
|
|
18
|
-
CodeableConcept
|
|
19
|
-
Coding
|
|
20
|
-
ContactDetail
|
|
21
|
-
ContactPoint
|
|
22
|
-
Contributor
|
|
23
|
-
Count
|
|
24
|
-
DataRequirement
|
|
25
|
-
Distance
|
|
26
|
-
Dosage
|
|
27
|
-
Duration
|
|
28
|
-
Expression
|
|
29
|
-
Extension
|
|
30
|
-
HumanName
|
|
31
|
-
Identifier
|
|
32
|
-
MarketingStatus
|
|
33
|
-
Meta
|
|
34
|
-
Money
|
|
35
|
-
Narrative
|
|
36
|
-
ParameterDefinition
|
|
37
|
-
Period
|
|
38
|
-
Population
|
|
39
|
-
ProdCharacteristic
|
|
40
|
-
ProductShelfLife
|
|
41
|
-
Quantity
|
|
42
|
-
Range
|
|
43
|
-
Ratio
|
|
44
|
-
Reference
|
|
45
|
-
RelatedArtifact
|
|
46
|
-
SampledData
|
|
47
|
-
Signature
|
|
48
|
-
SubstanceAmount
|
|
49
|
-
SystemString
|
|
50
|
-
Timing
|
|
51
|
-
TriggerDefinition
|
|
52
|
-
UsageContext
|
|
53
|
-
base64Binary
|
|
54
|
-
boolean
|
|
55
|
-
canonical
|
|
56
|
-
code
|
|
57
|
-
date
|
|
58
|
-
dateTime
|
|
59
|
-
decimal
|
|
60
|
-
id
|
|
61
|
-
instant
|
|
62
|
-
integer
|
|
63
|
-
markdown
|
|
64
|
-
oid
|
|
65
|
-
positiveInt
|
|
66
|
-
string
|
|
67
|
-
time
|
|
68
|
-
unsignedInt
|
|
69
|
-
uri
|
|
70
|
-
url
|
|
71
|
-
uuid
|
|
72
|
-
}
|
|
13
|
+
export declare const PropertyType: {
|
|
14
|
+
Address: string;
|
|
15
|
+
Age: string;
|
|
16
|
+
Annotation: string;
|
|
17
|
+
Attachment: string;
|
|
18
|
+
BackboneElement: string;
|
|
19
|
+
CodeableConcept: string;
|
|
20
|
+
Coding: string;
|
|
21
|
+
ContactDetail: string;
|
|
22
|
+
ContactPoint: string;
|
|
23
|
+
Contributor: string;
|
|
24
|
+
Count: string;
|
|
25
|
+
DataRequirement: string;
|
|
26
|
+
Distance: string;
|
|
27
|
+
Dosage: string;
|
|
28
|
+
Duration: string;
|
|
29
|
+
Expression: string;
|
|
30
|
+
Extension: string;
|
|
31
|
+
HumanName: string;
|
|
32
|
+
Identifier: string;
|
|
33
|
+
MarketingStatus: string;
|
|
34
|
+
Meta: string;
|
|
35
|
+
Money: string;
|
|
36
|
+
Narrative: string;
|
|
37
|
+
ParameterDefinition: string;
|
|
38
|
+
Period: string;
|
|
39
|
+
Population: string;
|
|
40
|
+
ProdCharacteristic: string;
|
|
41
|
+
ProductShelfLife: string;
|
|
42
|
+
Quantity: string;
|
|
43
|
+
Range: string;
|
|
44
|
+
Ratio: string;
|
|
45
|
+
Reference: string;
|
|
46
|
+
RelatedArtifact: string;
|
|
47
|
+
SampledData: string;
|
|
48
|
+
Signature: string;
|
|
49
|
+
SubstanceAmount: string;
|
|
50
|
+
SystemString: string;
|
|
51
|
+
Timing: string;
|
|
52
|
+
TriggerDefinition: string;
|
|
53
|
+
UsageContext: string;
|
|
54
|
+
base64Binary: string;
|
|
55
|
+
boolean: string;
|
|
56
|
+
canonical: string;
|
|
57
|
+
code: string;
|
|
58
|
+
date: string;
|
|
59
|
+
dateTime: string;
|
|
60
|
+
decimal: string;
|
|
61
|
+
id: string;
|
|
62
|
+
instant: string;
|
|
63
|
+
integer: string;
|
|
64
|
+
markdown: string;
|
|
65
|
+
oid: string;
|
|
66
|
+
positiveInt: string;
|
|
67
|
+
string: string;
|
|
68
|
+
time: string;
|
|
69
|
+
unsignedInt: string;
|
|
70
|
+
uri: string;
|
|
71
|
+
url: string;
|
|
72
|
+
uuid: string;
|
|
73
|
+
};
|
|
73
74
|
/**
|
|
74
75
|
* An IndexedStructureDefinition is a lookup-optimized version of a StructureDefinition.
|
|
75
76
|
*
|
|
@@ -96,7 +97,7 @@ export declare enum PropertyType {
|
|
|
96
97
|
*/
|
|
97
98
|
export interface IndexedStructureDefinition {
|
|
98
99
|
types: {
|
|
99
|
-
[resourceType: string]:
|
|
100
|
+
[resourceType: string]: TypeInfo;
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
@@ -108,34 +109,14 @@ export interface IndexedStructureDefinition {
|
|
|
108
109
|
* 3) Patient_Communication
|
|
109
110
|
* 4) Patient_Link
|
|
110
111
|
*/
|
|
111
|
-
export interface
|
|
112
|
-
structureDefinition: StructureDefinition;
|
|
113
|
-
elementDefinition: ElementDefinition;
|
|
114
|
-
display: string;
|
|
115
|
-
properties: {
|
|
116
|
-
[name: string]: ElementDefinition;
|
|
117
|
-
};
|
|
112
|
+
export interface TypeInfo {
|
|
118
113
|
searchParams?: {
|
|
119
114
|
[code: string]: SearchParameter;
|
|
120
115
|
};
|
|
121
116
|
searchParamsDetails?: {
|
|
122
117
|
[code: string]: SearchParameterDetails;
|
|
123
118
|
};
|
|
124
|
-
description?: string;
|
|
125
|
-
parentType?: string;
|
|
126
119
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Indexes a bundle of StructureDefinitions for faster lookup.
|
|
129
|
-
* @param bundle A FHIR bundle StructureDefinition resources.
|
|
130
|
-
* @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
|
|
131
|
-
*/
|
|
132
|
-
export declare function indexStructureDefinitionBundle(bundle: Bundle): void;
|
|
133
|
-
/**
|
|
134
|
-
* Indexes a StructureDefinition for fast lookup.
|
|
135
|
-
* @param structureDefinition The original StructureDefinition.
|
|
136
|
-
* @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
|
|
137
|
-
*/
|
|
138
|
-
export declare function indexStructureDefinition(structureDefinition: StructureDefinition): void;
|
|
139
120
|
/**
|
|
140
121
|
* Indexes a bundle of SearchParameter resources for faster lookup.
|
|
141
122
|
* @param bundle A FHIR bundle SearchParameter resources.
|
|
@@ -161,25 +142,26 @@ export declare function buildTypeName(components: string[]): string;
|
|
|
161
142
|
* @param typeSchema The type schema to check.
|
|
162
143
|
* @returns True if the type schema is a non-abstract FHIR resource.
|
|
163
144
|
*/
|
|
164
|
-
export declare function isResourceTypeSchema(typeSchema:
|
|
145
|
+
export declare function isResourceTypeSchema(typeSchema: InternalTypeSchema): boolean;
|
|
165
146
|
/**
|
|
166
147
|
* Returns an array of all resource types.
|
|
167
148
|
* Note that this is based on globalSchema, and will only return resource types that are currently in memory.
|
|
168
149
|
* @returns An array of all resource types.
|
|
169
150
|
*/
|
|
170
151
|
export declare function getResourceTypes(): ResourceType[];
|
|
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
152
|
/**
|
|
178
153
|
* Returns the search parameters for the resource type indexed by search code.
|
|
179
154
|
* @param resourceType The resource type.
|
|
180
155
|
* @returns The search parameters for the resource type indexed by search code.
|
|
181
156
|
*/
|
|
182
157
|
export declare function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Returns a search parameter for a resource type by search code.
|
|
160
|
+
* @param resourceType The FHIR resource type.
|
|
161
|
+
* @param code The search parameter code.
|
|
162
|
+
* @returns The search parameter if found, otherwise undefined.
|
|
163
|
+
*/
|
|
164
|
+
export declare function getSearchParameter(resourceType: string, code: string): SearchParameter | undefined;
|
|
183
165
|
/**
|
|
184
166
|
* Returns a human friendly display name for a FHIR element definition path.
|
|
185
167
|
* @param path The FHIR element definition path.
|
|
@@ -193,7 +175,7 @@ export declare function getPropertyDisplayName(path: string): string;
|
|
|
193
175
|
* @param propertyName The property name.
|
|
194
176
|
* @returns The element definition if found.
|
|
195
177
|
*/
|
|
196
|
-
export declare function getElementDefinition(typeName: string, propertyName: string):
|
|
178
|
+
export declare function getElementDefinition(typeName: string, propertyName: string): InternalSchemaElement | undefined;
|
|
197
179
|
/**
|
|
198
180
|
* Typeguard to validate that an object is a FHIR resource
|
|
199
181
|
* @param value The object to check
|