@medplum/mock 0.9.1 → 0.9.2
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 +51 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +51 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- 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',
|
|
@@ -6307,6 +6308,14 @@ const PatientSearchParameters = [
|
|
|
6307
6308
|
expression: 'ServiceRequest.subject',
|
|
6308
6309
|
target: ['Group', 'Device', 'Patient', 'Location'],
|
|
6309
6310
|
},
|
|
6311
|
+
{
|
|
6312
|
+
resourceType: 'SearchParameter',
|
|
6313
|
+
id: 'ServiceRequest-authored',
|
|
6314
|
+
code: 'authored',
|
|
6315
|
+
base: ['ServiceRequest'],
|
|
6316
|
+
type: 'date',
|
|
6317
|
+
expression: 'ServiceRequest.authoredOn',
|
|
6318
|
+
},
|
|
6310
6319
|
{
|
|
6311
6320
|
resourceType: 'SearchParameter',
|
|
6312
6321
|
id: 'Observation-value-quantity',
|
|
@@ -6964,6 +6973,23 @@ class FunctionAtom {
|
|
|
6964
6973
|
eval(context) {
|
|
6965
6974
|
return this.impl(ensureArray(context), ...this.args);
|
|
6966
6975
|
}
|
|
6976
|
+
}
|
|
6977
|
+
class IndexerAtom {
|
|
6978
|
+
constructor(left, expr) {
|
|
6979
|
+
this.left = left;
|
|
6980
|
+
this.expr = expr;
|
|
6981
|
+
}
|
|
6982
|
+
eval(context) {
|
|
6983
|
+
const index = this.expr.eval(context);
|
|
6984
|
+
if (typeof index !== 'number') {
|
|
6985
|
+
throw new Error(`Invalid indexer expression: should return integer}`);
|
|
6986
|
+
}
|
|
6987
|
+
const leftResult = this.left.eval(context);
|
|
6988
|
+
if (!(index in leftResult)) {
|
|
6989
|
+
return [];
|
|
6990
|
+
}
|
|
6991
|
+
return leftResult[index];
|
|
6992
|
+
}
|
|
6967
6993
|
}
|
|
6968
6994
|
|
|
6969
6995
|
function parseDateString(str) {
|
|
@@ -7226,7 +7252,7 @@ function where(input, criteria) {
|
|
|
7226
7252
|
* See: http://hl7.org/fhirpath/#selectprojection-expression-collection
|
|
7227
7253
|
*/
|
|
7228
7254
|
function select(input, criteria) {
|
|
7229
|
-
return ensureArray(criteria.eval(
|
|
7255
|
+
return ensureArray(input.map((e) => criteria.eval(e)).flat());
|
|
7230
7256
|
}
|
|
7231
7257
|
/**
|
|
7232
7258
|
* A version of select that will repeat the projection and add it to the output
|
|
@@ -8681,7 +8707,7 @@ class ParserBuilder {
|
|
|
8681
8707
|
prefix(tokenType, precedence, builder) {
|
|
8682
8708
|
return this.registerPrefix(tokenType, {
|
|
8683
8709
|
parse(parser, token) {
|
|
8684
|
-
const right = parser.
|
|
8710
|
+
const right = parser.consumeAndParse(precedence);
|
|
8685
8711
|
return builder(token, right);
|
|
8686
8712
|
},
|
|
8687
8713
|
});
|
|
@@ -8689,7 +8715,7 @@ class ParserBuilder {
|
|
|
8689
8715
|
infixLeft(tokenType, precedence, builder) {
|
|
8690
8716
|
return this.registerInfix(tokenType, {
|
|
8691
8717
|
parse(parser, left, token) {
|
|
8692
|
-
const right = parser.
|
|
8718
|
+
const right = parser.consumeAndParse(precedence);
|
|
8693
8719
|
return builder(left, token, right);
|
|
8694
8720
|
},
|
|
8695
8721
|
precedence,
|
|
@@ -8718,7 +8744,7 @@ class Parser {
|
|
|
8718
8744
|
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
8719
8745
|
return true;
|
|
8720
8746
|
}
|
|
8721
|
-
|
|
8747
|
+
consumeAndParse(precedence = 100 /* MaximumPrecedence */) {
|
|
8722
8748
|
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
8723
8749
|
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
8724
8750
|
if (!prefix) {
|
|
@@ -8753,13 +8779,23 @@ _Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser
|
|
|
8753
8779
|
};
|
|
8754
8780
|
const PARENTHESES_PARSELET = {
|
|
8755
8781
|
parse(parser) {
|
|
8756
|
-
const expr = parser.
|
|
8782
|
+
const expr = parser.consumeAndParse();
|
|
8757
8783
|
if (!parser.match(')')) {
|
|
8758
8784
|
throw new Error('Parse error: expected `)`');
|
|
8759
8785
|
}
|
|
8760
8786
|
return expr;
|
|
8761
8787
|
},
|
|
8762
8788
|
};
|
|
8789
|
+
const INDEXER_PARSELET = {
|
|
8790
|
+
parse(parser, left) {
|
|
8791
|
+
const expr = parser.consumeAndParse();
|
|
8792
|
+
if (!parser.match(']')) {
|
|
8793
|
+
throw new Error('Parse error: expected `]`');
|
|
8794
|
+
}
|
|
8795
|
+
return new IndexerAtom(left, expr);
|
|
8796
|
+
},
|
|
8797
|
+
precedence: 2 /* Indexer */,
|
|
8798
|
+
};
|
|
8763
8799
|
const FUNCTION_CALL_PARSELET = {
|
|
8764
8800
|
parse(parser, left) {
|
|
8765
8801
|
if (!(left instanceof SymbolAtom)) {
|
|
@@ -8770,7 +8806,7 @@ const FUNCTION_CALL_PARSELET = {
|
|
|
8770
8806
|
}
|
|
8771
8807
|
const args = [];
|
|
8772
8808
|
while (!parser.match(')')) {
|
|
8773
|
-
args.push(parser.
|
|
8809
|
+
args.push(parser.consumeAndParse());
|
|
8774
8810
|
parser.match(',');
|
|
8775
8811
|
}
|
|
8776
8812
|
return new FunctionAtom(left.name, args, functions[left.name]);
|
|
@@ -8815,6 +8851,7 @@ const parserBuilder = new ParserBuilder()
|
|
|
8815
8851
|
})
|
|
8816
8852
|
.registerPrefix('{}', { parse: () => new EmptySetAtom() })
|
|
8817
8853
|
.registerPrefix('(', PARENTHESES_PARSELET)
|
|
8854
|
+
.registerInfix('[', INDEXER_PARSELET)
|
|
8818
8855
|
.registerInfix('(', FUNCTION_CALL_PARSELET)
|
|
8819
8856
|
.prefix('+', 3 /* UnaryAdd */, (_, right) => new UnaryOperatorAtom(right, (x) => x))
|
|
8820
8857
|
.prefix('-', 3 /* UnarySubtract */, (_, right) => new ArithemticOperatorAtom(right, right, (_, y) => -y))
|
|
@@ -8867,7 +8904,7 @@ const parserBuilder = new ParserBuilder()
|
|
|
8867
8904
|
*/
|
|
8868
8905
|
function parseFhirPath(input) {
|
|
8869
8906
|
try {
|
|
8870
|
-
return new FhirPathAtom(input, parserBuilder.construct(input).
|
|
8907
|
+
return new FhirPathAtom(input, parserBuilder.construct(input).consumeAndParse());
|
|
8871
8908
|
}
|
|
8872
8909
|
catch (error) {
|
|
8873
8910
|
throw new Error(`FhirPathError on "${input}": ${error}`);
|
|
@@ -8995,14 +9032,10 @@ class MockClient extends MedplumClient {
|
|
|
8995
9032
|
if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
|
|
8996
9033
|
console.log('MockClient', method, path);
|
|
8997
9034
|
}
|
|
8998
|
-
const
|
|
8999
|
-
if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !
|
|
9035
|
+
const response = mockHandler(method, path, options);
|
|
9036
|
+
if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !response) {
|
|
9000
9037
|
console.log('MockClient: not found', method, path);
|
|
9001
9038
|
}
|
|
9002
|
-
const response = Object.assign({ request: {
|
|
9003
|
-
url,
|
|
9004
|
-
options,
|
|
9005
|
-
} }, result);
|
|
9006
9039
|
if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
|
|
9007
9040
|
console.log('MockClient', JSON.stringify(response, null, 2));
|
|
9008
9041
|
}
|
|
@@ -9091,6 +9124,11 @@ function mockAuthHandler(method, path, options) {
|
|
|
9091
9124
|
if (path.startsWith('auth/resetpassword')) {
|
|
9092
9125
|
return mockResetPasswordHandler(method, path, options);
|
|
9093
9126
|
}
|
|
9127
|
+
if (path.startsWith('auth/me')) {
|
|
9128
|
+
return {
|
|
9129
|
+
profile: { reference: 'Practitioner/123' },
|
|
9130
|
+
};
|
|
9131
|
+
}
|
|
9094
9132
|
return null;
|
|
9095
9133
|
}
|
|
9096
9134
|
function mockChangePasswordHandler(method, path, options) {
|