@medplum/mock 0.9.0 → 0.9.3
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 +32 -0
- package/dist/cjs/index.js +194 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -30
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +194 -26
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -30
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/client.d.ts +1 -1
- package/dist/types/mocks/types.d.ts +20 -2
- package/package.json +6 -7
package/dist/esm/index.js
CHANGED
|
@@ -440,6 +440,7 @@ const HomerServiceRequest = {
|
|
|
440
440
|
},
|
|
441
441
|
],
|
|
442
442
|
specimen: [createReference(HomerSimpsonSpecimen)],
|
|
443
|
+
authoredOn: '2020-01-01T12:00:00Z',
|
|
443
444
|
};
|
|
444
445
|
const BartSimpson = {
|
|
445
446
|
resourceType: 'Patient',
|
|
@@ -6212,6 +6213,136 @@ var StructureDefinitionList = [
|
|
|
6212
6213
|
}
|
|
6213
6214
|
]
|
|
6214
6215
|
}
|
|
6216
|
+
},
|
|
6217
|
+
{
|
|
6218
|
+
resourceType: "StructureDefinition",
|
|
6219
|
+
id: "Bot",
|
|
6220
|
+
name: "Bot",
|
|
6221
|
+
description: "Bot account for automated actions.",
|
|
6222
|
+
snapshot: {
|
|
6223
|
+
element: [
|
|
6224
|
+
{
|
|
6225
|
+
id: "Bot.id",
|
|
6226
|
+
path: "Bot.id",
|
|
6227
|
+
definition: "The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.",
|
|
6228
|
+
min: 0,
|
|
6229
|
+
max: "1",
|
|
6230
|
+
type: [
|
|
6231
|
+
{
|
|
6232
|
+
code: "string"
|
|
6233
|
+
}
|
|
6234
|
+
]
|
|
6235
|
+
},
|
|
6236
|
+
{
|
|
6237
|
+
id: "Bot.meta",
|
|
6238
|
+
path: "Bot.meta",
|
|
6239
|
+
definition: "The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.",
|
|
6240
|
+
min: 0,
|
|
6241
|
+
max: "1",
|
|
6242
|
+
type: [
|
|
6243
|
+
{
|
|
6244
|
+
code: "Meta"
|
|
6245
|
+
}
|
|
6246
|
+
]
|
|
6247
|
+
},
|
|
6248
|
+
{
|
|
6249
|
+
id: "Bot.implicitRules",
|
|
6250
|
+
path: "Bot.implicitRules",
|
|
6251
|
+
definition: "A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.",
|
|
6252
|
+
min: 0,
|
|
6253
|
+
max: "1",
|
|
6254
|
+
type: [
|
|
6255
|
+
{
|
|
6256
|
+
code: "uri"
|
|
6257
|
+
}
|
|
6258
|
+
]
|
|
6259
|
+
},
|
|
6260
|
+
{
|
|
6261
|
+
id: "Bot.language",
|
|
6262
|
+
path: "Bot.language",
|
|
6263
|
+
definition: "The base language in which the resource is written.",
|
|
6264
|
+
min: 0,
|
|
6265
|
+
max: "1",
|
|
6266
|
+
type: [
|
|
6267
|
+
{
|
|
6268
|
+
code: "code"
|
|
6269
|
+
}
|
|
6270
|
+
]
|
|
6271
|
+
},
|
|
6272
|
+
{
|
|
6273
|
+
id: "Bot.name",
|
|
6274
|
+
path: "Bot.name",
|
|
6275
|
+
definition: "A name associated with the Bot.",
|
|
6276
|
+
min: 0,
|
|
6277
|
+
max: "1",
|
|
6278
|
+
type: [
|
|
6279
|
+
{
|
|
6280
|
+
code: "string"
|
|
6281
|
+
}
|
|
6282
|
+
]
|
|
6283
|
+
},
|
|
6284
|
+
{
|
|
6285
|
+
id: "Bot.description",
|
|
6286
|
+
path: "Bot.description",
|
|
6287
|
+
definition: "A summary, characterization or explanation of the Bot.",
|
|
6288
|
+
min: 0,
|
|
6289
|
+
max: "1",
|
|
6290
|
+
type: [
|
|
6291
|
+
{
|
|
6292
|
+
code: "string"
|
|
6293
|
+
}
|
|
6294
|
+
]
|
|
6295
|
+
},
|
|
6296
|
+
{
|
|
6297
|
+
id: "Bot.runtimeVersion",
|
|
6298
|
+
path: "Bot.runtimeVersion",
|
|
6299
|
+
definition: "The identifier of the bot runtime environment (i.e., vmcontext, awslambda, etc).",
|
|
6300
|
+
min: 0,
|
|
6301
|
+
max: "1",
|
|
6302
|
+
type: [
|
|
6303
|
+
{
|
|
6304
|
+
code: "string"
|
|
6305
|
+
}
|
|
6306
|
+
]
|
|
6307
|
+
},
|
|
6308
|
+
{
|
|
6309
|
+
id: "Bot.photo",
|
|
6310
|
+
path: "Bot.photo",
|
|
6311
|
+
definition: "Image of the bot.",
|
|
6312
|
+
min: 0,
|
|
6313
|
+
max: "1",
|
|
6314
|
+
type: [
|
|
6315
|
+
{
|
|
6316
|
+
code: "Attachment"
|
|
6317
|
+
}
|
|
6318
|
+
]
|
|
6319
|
+
},
|
|
6320
|
+
{
|
|
6321
|
+
id: "Bot.code",
|
|
6322
|
+
path: "Bot.code",
|
|
6323
|
+
definition: "Bot logic script.",
|
|
6324
|
+
min: 0,
|
|
6325
|
+
max: "1",
|
|
6326
|
+
type: [
|
|
6327
|
+
{
|
|
6328
|
+
code: "string"
|
|
6329
|
+
}
|
|
6330
|
+
]
|
|
6331
|
+
},
|
|
6332
|
+
{
|
|
6333
|
+
id: "Bot.runAsUser",
|
|
6334
|
+
path: "Bot.runAsUser",
|
|
6335
|
+
definition: "Optional flag to indicate that the bot should be run as the user.",
|
|
6336
|
+
min: 0,
|
|
6337
|
+
max: "1",
|
|
6338
|
+
type: [
|
|
6339
|
+
{
|
|
6340
|
+
code: "boolean"
|
|
6341
|
+
}
|
|
6342
|
+
]
|
|
6343
|
+
}
|
|
6344
|
+
]
|
|
6345
|
+
}
|
|
6215
6346
|
}
|
|
6216
6347
|
];
|
|
6217
6348
|
|
|
@@ -6307,6 +6438,14 @@ const PatientSearchParameters = [
|
|
|
6307
6438
|
expression: 'ServiceRequest.subject',
|
|
6308
6439
|
target: ['Group', 'Device', 'Patient', 'Location'],
|
|
6309
6440
|
},
|
|
6441
|
+
{
|
|
6442
|
+
resourceType: 'SearchParameter',
|
|
6443
|
+
id: 'ServiceRequest-authored',
|
|
6444
|
+
code: 'authored',
|
|
6445
|
+
base: ['ServiceRequest'],
|
|
6446
|
+
type: 'date',
|
|
6447
|
+
expression: 'ServiceRequest.authoredOn',
|
|
6448
|
+
},
|
|
6310
6449
|
{
|
|
6311
6450
|
resourceType: 'SearchParameter',
|
|
6312
6451
|
id: 'Observation-value-quantity',
|
|
@@ -6344,7 +6483,7 @@ const exampleValueSet = {
|
|
|
6344
6483
|
},
|
|
6345
6484
|
};
|
|
6346
6485
|
|
|
6347
|
-
|
|
6486
|
+
/******************************************************************************
|
|
6348
6487
|
Copyright (c) Microsoft Corporation.
|
|
6349
6488
|
|
|
6350
6489
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -6372,7 +6511,7 @@ function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
|
|
|
6372
6511
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6373
6512
|
}
|
|
6374
6513
|
|
|
6375
|
-
|
|
6514
|
+
/******************************************************************************
|
|
6376
6515
|
Copyright (c) Microsoft Corporation.
|
|
6377
6516
|
|
|
6378
6517
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -6964,6 +7103,23 @@ class FunctionAtom {
|
|
|
6964
7103
|
eval(context) {
|
|
6965
7104
|
return this.impl(ensureArray(context), ...this.args);
|
|
6966
7105
|
}
|
|
7106
|
+
}
|
|
7107
|
+
class IndexerAtom {
|
|
7108
|
+
constructor(left, expr) {
|
|
7109
|
+
this.left = left;
|
|
7110
|
+
this.expr = expr;
|
|
7111
|
+
}
|
|
7112
|
+
eval(context) {
|
|
7113
|
+
const index = this.expr.eval(context);
|
|
7114
|
+
if (typeof index !== 'number') {
|
|
7115
|
+
throw new Error(`Invalid indexer expression: should return integer}`);
|
|
7116
|
+
}
|
|
7117
|
+
const leftResult = this.left.eval(context);
|
|
7118
|
+
if (!(index in leftResult)) {
|
|
7119
|
+
return [];
|
|
7120
|
+
}
|
|
7121
|
+
return leftResult[index];
|
|
7122
|
+
}
|
|
6967
7123
|
}
|
|
6968
7124
|
|
|
6969
7125
|
function parseDateString(str) {
|
|
@@ -7226,7 +7382,7 @@ function where(input, criteria) {
|
|
|
7226
7382
|
* See: http://hl7.org/fhirpath/#selectprojection-expression-collection
|
|
7227
7383
|
*/
|
|
7228
7384
|
function select(input, criteria) {
|
|
7229
|
-
return ensureArray(criteria.eval(
|
|
7385
|
+
return ensureArray(input.map((e) => criteria.eval(e)).flat());
|
|
7230
7386
|
}
|
|
7231
7387
|
/**
|
|
7232
7388
|
* A version of select that will repeat the projection and add it to the output
|
|
@@ -8681,7 +8837,7 @@ class ParserBuilder {
|
|
|
8681
8837
|
prefix(tokenType, precedence, builder) {
|
|
8682
8838
|
return this.registerPrefix(tokenType, {
|
|
8683
8839
|
parse(parser, token) {
|
|
8684
|
-
const right = parser.
|
|
8840
|
+
const right = parser.consumeAndParse(precedence);
|
|
8685
8841
|
return builder(token, right);
|
|
8686
8842
|
},
|
|
8687
8843
|
});
|
|
@@ -8689,7 +8845,7 @@ class ParserBuilder {
|
|
|
8689
8845
|
infixLeft(tokenType, precedence, builder) {
|
|
8690
8846
|
return this.registerInfix(tokenType, {
|
|
8691
8847
|
parse(parser, left, token) {
|
|
8692
|
-
const right = parser.
|
|
8848
|
+
const right = parser.consumeAndParse(precedence);
|
|
8693
8849
|
return builder(left, token, right);
|
|
8694
8850
|
},
|
|
8695
8851
|
precedence,
|
|
@@ -8718,7 +8874,7 @@ class Parser {
|
|
|
8718
8874
|
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
8719
8875
|
return true;
|
|
8720
8876
|
}
|
|
8721
|
-
|
|
8877
|
+
consumeAndParse(precedence = 100 /* MaximumPrecedence */) {
|
|
8722
8878
|
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
8723
8879
|
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
8724
8880
|
if (!prefix) {
|
|
@@ -8753,13 +8909,23 @@ _Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser
|
|
|
8753
8909
|
};
|
|
8754
8910
|
const PARENTHESES_PARSELET = {
|
|
8755
8911
|
parse(parser) {
|
|
8756
|
-
const expr = parser.
|
|
8912
|
+
const expr = parser.consumeAndParse();
|
|
8757
8913
|
if (!parser.match(')')) {
|
|
8758
8914
|
throw new Error('Parse error: expected `)`');
|
|
8759
8915
|
}
|
|
8760
8916
|
return expr;
|
|
8761
8917
|
},
|
|
8762
8918
|
};
|
|
8919
|
+
const INDEXER_PARSELET = {
|
|
8920
|
+
parse(parser, left) {
|
|
8921
|
+
const expr = parser.consumeAndParse();
|
|
8922
|
+
if (!parser.match(']')) {
|
|
8923
|
+
throw new Error('Parse error: expected `]`');
|
|
8924
|
+
}
|
|
8925
|
+
return new IndexerAtom(left, expr);
|
|
8926
|
+
},
|
|
8927
|
+
precedence: 2 /* Indexer */,
|
|
8928
|
+
};
|
|
8763
8929
|
const FUNCTION_CALL_PARSELET = {
|
|
8764
8930
|
parse(parser, left) {
|
|
8765
8931
|
if (!(left instanceof SymbolAtom)) {
|
|
@@ -8770,7 +8936,7 @@ const FUNCTION_CALL_PARSELET = {
|
|
|
8770
8936
|
}
|
|
8771
8937
|
const args = [];
|
|
8772
8938
|
while (!parser.match(')')) {
|
|
8773
|
-
args.push(parser.
|
|
8939
|
+
args.push(parser.consumeAndParse());
|
|
8774
8940
|
parser.match(',');
|
|
8775
8941
|
}
|
|
8776
8942
|
return new FunctionAtom(left.name, args, functions[left.name]);
|
|
@@ -8815,6 +8981,7 @@ const parserBuilder = new ParserBuilder()
|
|
|
8815
8981
|
})
|
|
8816
8982
|
.registerPrefix('{}', { parse: () => new EmptySetAtom() })
|
|
8817
8983
|
.registerPrefix('(', PARENTHESES_PARSELET)
|
|
8984
|
+
.registerInfix('[', INDEXER_PARSELET)
|
|
8818
8985
|
.registerInfix('(', FUNCTION_CALL_PARSELET)
|
|
8819
8986
|
.prefix('+', 3 /* UnaryAdd */, (_, right) => new UnaryOperatorAtom(right, (x) => x))
|
|
8820
8987
|
.prefix('-', 3 /* UnarySubtract */, (_, right) => new ArithemticOperatorAtom(right, right, (_, y) => -y))
|
|
@@ -8867,7 +9034,7 @@ const parserBuilder = new ParserBuilder()
|
|
|
8867
9034
|
*/
|
|
8868
9035
|
function parseFhirPath(input) {
|
|
8869
9036
|
try {
|
|
8870
|
-
return new FhirPathAtom(input, parserBuilder.construct(input).
|
|
9037
|
+
return new FhirPathAtom(input, parserBuilder.construct(input).consumeAndParse());
|
|
8871
9038
|
}
|
|
8872
9039
|
catch (error) {
|
|
8873
9040
|
throw new Error(`FhirPathError on "${input}": ${error}`);
|
|
@@ -8964,7 +9131,7 @@ function matchesSearchRequest(resource, searchRequest) {
|
|
|
8964
9131
|
}
|
|
8965
9132
|
if (searchRequest.filters) {
|
|
8966
9133
|
for (const filter of searchRequest.filters) {
|
|
8967
|
-
if (!matchesSearchFilter(resource,
|
|
9134
|
+
if (!matchesSearchFilter(resource, filter)) {
|
|
8968
9135
|
return false;
|
|
8969
9136
|
}
|
|
8970
9137
|
}
|
|
@@ -8977,7 +9144,7 @@ function matchesSearchRequest(resource, searchRequest) {
|
|
|
8977
9144
|
* @param filter One of the filters of a subscription criteria.
|
|
8978
9145
|
* @returns True if the resource satisfies the search filter.
|
|
8979
9146
|
*/
|
|
8980
|
-
function matchesSearchFilter(resource,
|
|
9147
|
+
function matchesSearchFilter(resource, filter) {
|
|
8981
9148
|
const expression = filter.code.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
8982
9149
|
const values = evalFhirPath(expression, resource);
|
|
8983
9150
|
const result = values.some((value) => JSON.stringify(value).toLowerCase().includes(filter.value.toLowerCase()));
|
|
@@ -8990,19 +9157,15 @@ class MockClient extends MedplumClient {
|
|
|
8990
9157
|
baseUrl: 'https://example.com/',
|
|
8991
9158
|
clientId: 'my-client-id',
|
|
8992
9159
|
fetch: (url, options) => {
|
|
8993
|
-
const method = options.method;
|
|
9160
|
+
const method = options.method || 'GET';
|
|
8994
9161
|
const path = url.replace('https://example.com/', '');
|
|
8995
9162
|
if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
|
|
8996
9163
|
console.log('MockClient', method, path);
|
|
8997
9164
|
}
|
|
8998
|
-
const
|
|
8999
|
-
if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !
|
|
9165
|
+
const response = mockHandler(method, path, options);
|
|
9166
|
+
if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !response) {
|
|
9000
9167
|
console.log('MockClient: not found', method, path);
|
|
9001
9168
|
}
|
|
9002
|
-
const response = Object.assign({ request: {
|
|
9003
|
-
url,
|
|
9004
|
-
options,
|
|
9005
|
-
} }, result);
|
|
9006
9169
|
if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
|
|
9007
9170
|
console.log('MockClient', JSON.stringify(response, null, 2));
|
|
9008
9171
|
}
|
|
@@ -9035,7 +9198,7 @@ class MockClient extends MedplumClient {
|
|
|
9035
9198
|
}
|
|
9036
9199
|
return super.getActiveLogin();
|
|
9037
9200
|
}
|
|
9038
|
-
createBinary(
|
|
9201
|
+
createBinary(_data, filename, contentType) {
|
|
9039
9202
|
if (filename.endsWith('.exe')) {
|
|
9040
9203
|
return Promise.reject(badRequest('Invalid file type'));
|
|
9041
9204
|
}
|
|
@@ -9061,7 +9224,7 @@ function mockHandler(method, path, options) {
|
|
|
9061
9224
|
return null;
|
|
9062
9225
|
}
|
|
9063
9226
|
}
|
|
9064
|
-
function mockAdminHandler(
|
|
9227
|
+
function mockAdminHandler(_method, path) {
|
|
9065
9228
|
if (path.startsWith('admin/projects/123')) {
|
|
9066
9229
|
return {
|
|
9067
9230
|
project: { id: '123', name: 'Project 123' },
|
|
@@ -9091,9 +9254,14 @@ function mockAuthHandler(method, path, options) {
|
|
|
9091
9254
|
if (path.startsWith('auth/resetpassword')) {
|
|
9092
9255
|
return mockResetPasswordHandler(method, path, options);
|
|
9093
9256
|
}
|
|
9257
|
+
if (path.startsWith('auth/me')) {
|
|
9258
|
+
return {
|
|
9259
|
+
profile: { reference: 'Practitioner/123' },
|
|
9260
|
+
};
|
|
9261
|
+
}
|
|
9094
9262
|
return null;
|
|
9095
9263
|
}
|
|
9096
|
-
function mockChangePasswordHandler(
|
|
9264
|
+
function mockChangePasswordHandler(_method, _path, options) {
|
|
9097
9265
|
const { body } = options;
|
|
9098
9266
|
const { oldPassword } = JSON.parse(body);
|
|
9099
9267
|
if (oldPassword === 'orange') {
|
|
@@ -9113,7 +9281,7 @@ function mockChangePasswordHandler(method, path, options) {
|
|
|
9113
9281
|
};
|
|
9114
9282
|
}
|
|
9115
9283
|
}
|
|
9116
|
-
function mockLoginHandler(
|
|
9284
|
+
function mockLoginHandler(_method, _path, options) {
|
|
9117
9285
|
const { body } = options;
|
|
9118
9286
|
const { password } = JSON.parse(body);
|
|
9119
9287
|
if (password === 'password') {
|
|
@@ -9135,7 +9303,7 @@ function mockLoginHandler(method, path, options) {
|
|
|
9135
9303
|
};
|
|
9136
9304
|
}
|
|
9137
9305
|
}
|
|
9138
|
-
function mockSetPasswordHandler(
|
|
9306
|
+
function mockSetPasswordHandler(_method, _path, options) {
|
|
9139
9307
|
const { body } = options;
|
|
9140
9308
|
const { password } = JSON.parse(body);
|
|
9141
9309
|
if (password === 'orange') {
|
|
@@ -9155,7 +9323,7 @@ function mockSetPasswordHandler(method, path, options) {
|
|
|
9155
9323
|
};
|
|
9156
9324
|
}
|
|
9157
9325
|
}
|
|
9158
|
-
function mockRegisterHandler(
|
|
9326
|
+
function mockRegisterHandler(_method, _path, options) {
|
|
9159
9327
|
const { body } = options;
|
|
9160
9328
|
const { email, password } = JSON.parse(body);
|
|
9161
9329
|
if (email === 'george@example.com' && password === 'password') {
|
|
@@ -9174,7 +9342,7 @@ function mockRegisterHandler(method, path, options) {
|
|
|
9174
9342
|
};
|
|
9175
9343
|
}
|
|
9176
9344
|
}
|
|
9177
|
-
function mockResetPasswordHandler(
|
|
9345
|
+
function mockResetPasswordHandler(_method, _path, options) {
|
|
9178
9346
|
const { body } = options;
|
|
9179
9347
|
const { email } = JSON.parse(body);
|
|
9180
9348
|
if (email === 'admin@example.com') {
|
|
@@ -9265,7 +9433,7 @@ function mockFhirHandler(method, url, options) {
|
|
|
9265
9433
|
return mockRepo.createResource(JSON.parse(options.body));
|
|
9266
9434
|
}
|
|
9267
9435
|
}
|
|
9268
|
-
function mockFhirBatchHandler(
|
|
9436
|
+
function mockFhirBatchHandler(_method, _path, options) {
|
|
9269
9437
|
var _a;
|
|
9270
9438
|
const { body } = options;
|
|
9271
9439
|
const request = JSON.parse(body);
|