@medplum/core 2.0.4 → 2.0.5
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 +35 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/client.mjs +10 -17
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/outcomes.mjs +17 -2
- package/dist/esm/outcomes.mjs.map +1 -1
- package/dist/esm/search/match.mjs +9 -4
- package/dist/esm/search/match.mjs.map +1 -1
- package/dist/{esm → types}/outcomes.d.ts +7 -1
- package/package.json +4 -4
- package/tsconfig.build.json +9 -0
- package/dist/cjs/outcomes.d.ts +0 -31
- package/dist/esm/cache.d.ts +0 -34
- package/dist/esm/client.d.ts +0 -1218
- package/dist/esm/crypto.d.ts +0 -9
- package/dist/esm/eventtarget.d.ts +0 -13
- package/dist/esm/fhirlexer/index.d.ts +0 -2
- package/dist/esm/fhirlexer/parse.d.ts +0 -47
- package/dist/esm/fhirlexer/tokenize.d.ts +0 -14
- package/dist/esm/fhirmapper/parse.d.ts +0 -7
- package/dist/esm/fhirmapper/tokenize.d.ts +0 -2
- package/dist/esm/fhirpath/atoms.d.ts +0 -120
- package/dist/esm/fhirpath/date.d.ts +0 -1
- package/dist/esm/fhirpath/functions.d.ts +0 -6
- package/dist/esm/fhirpath/index.d.ts +0 -4
- package/dist/esm/fhirpath/parse.d.ts +0 -64
- package/dist/esm/fhirpath/tokenize.d.ts +0 -4
- package/dist/esm/fhirpath/utils.d.ts +0 -95
- package/dist/esm/format.d.ts +0 -118
- package/dist/esm/hl7.d.ts +0 -136
- package/dist/esm/index.d.ts +0 -14
- package/dist/esm/jwt.d.ts +0 -5
- package/dist/esm/readablepromise.d.ts +0 -48
- package/dist/esm/search/details.d.ts +0 -33
- package/dist/esm/search/match.d.ts +0 -9
- package/dist/esm/search/parse.d.ts +0 -17
- package/dist/esm/search/search.d.ts +0 -66
- package/dist/esm/storage.d.ts +0 -47
- package/dist/esm/types.d.ts +0 -200
- package/dist/esm/utils.d.ts +0 -259
- /package/dist/{cjs → types}/cache.d.ts +0 -0
- /package/dist/{cjs → types}/client.d.ts +0 -0
- /package/dist/{cjs → types}/crypto.d.ts +0 -0
- /package/dist/{cjs → types}/eventtarget.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/index.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirmapper/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirmapper/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/atoms.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/date.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/functions.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/index.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/utils.d.ts +0 -0
- /package/dist/{cjs → types}/format.d.ts +0 -0
- /package/dist/{cjs → types}/hl7.d.ts +0 -0
- /package/dist/{cjs → types}/index.d.ts +0 -0
- /package/dist/{cjs → types}/jwt.d.ts +0 -0
- /package/dist/{cjs → types}/readablepromise.d.ts +0 -0
- /package/dist/{cjs → types}/search/details.d.ts +0 -0
- /package/dist/{cjs → types}/search/match.d.ts +0 -0
- /package/dist/{cjs → types}/search/parse.d.ts +0 -0
- /package/dist/{cjs → types}/search/search.d.ts +0 -0
- /package/dist/{cjs → types}/storage.d.ts +0 -0
- /package/dist/{cjs → types}/types.d.ts +0 -0
- /package/dist/{cjs → types}/utils.d.ts +0 -0
package/dist/esm/outcomes.mjs
CHANGED
|
@@ -177,11 +177,26 @@ function assertOk(outcome, resource) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
class OperationOutcomeError extends Error {
|
|
180
|
-
constructor(outcome) {
|
|
180
|
+
constructor(outcome, cause) {
|
|
181
181
|
super(outcome?.issue?.[0].details?.text);
|
|
182
182
|
this.outcome = outcome;
|
|
183
|
+
this.cause = cause;
|
|
183
184
|
}
|
|
184
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Normalizes an error object into an OperationOutcome.
|
|
188
|
+
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
189
|
+
* @returns The normalized OperationOutcome.
|
|
190
|
+
*/
|
|
191
|
+
function normalizeOperationOutcome(error) {
|
|
192
|
+
if (error instanceof OperationOutcomeError) {
|
|
193
|
+
return error.outcome;
|
|
194
|
+
}
|
|
195
|
+
if (isOperationOutcome(error)) {
|
|
196
|
+
return error;
|
|
197
|
+
}
|
|
198
|
+
return badRequest(normalizeErrorString(error));
|
|
199
|
+
}
|
|
185
200
|
/**
|
|
186
201
|
* Normalizes an error object into a displayable error string.
|
|
187
202
|
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
@@ -203,5 +218,5 @@ function normalizeErrorString(error) {
|
|
|
203
218
|
return JSON.stringify(error);
|
|
204
219
|
}
|
|
205
220
|
|
|
206
|
-
export { OperationOutcomeError, allOk, assertOk, badRequest, created, forbidden, getStatus, gone, isGone, isNotFound, isOk, isOperationOutcome, normalizeErrorString, notFound, notModified, tooManyRequests, unauthorized };
|
|
221
|
+
export { OperationOutcomeError, allOk, assertOk, badRequest, created, forbidden, getStatus, gone, isGone, isNotFound, isOk, isOperationOutcome, normalizeErrorString, normalizeOperationOutcome, notFound, notModified, tooManyRequests, unauthorized };
|
|
207
222
|
//# sourceMappingURL=outcomes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcomes.mjs","sources":["../../src/outcomes.ts"],"sourcesContent":["import { OperationOutcome } from '@medplum/fhirtypes';\n\nconst OK_ID = 'ok';\nconst CREATED_ID = 'created';\nconst GONE_ID = 'gone';\nconst NOT_MODIFIED_ID = 'not-modified';\nconst NOT_FOUND_ID = 'not-found';\nconst UNAUTHORIZED_ID = 'unauthorized';\nconst FORBIDDEN_ID = 'forbidden';\nconst TOO_MANY_REQUESTS_ID = 'too-many-requests';\n\nexport const allOk: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: OK_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'All OK',\n },\n },\n ],\n};\n\nexport const created: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: CREATED_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'Created',\n },\n },\n ],\n};\n\nexport const notModified: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_MODIFIED_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'Not Modified',\n },\n },\n ],\n};\n\nexport const notFound: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_FOUND_ID,\n issue: [\n {\n severity: 'error',\n code: 'not-found',\n details: {\n text: 'Not found',\n },\n },\n ],\n};\n\nexport const unauthorized: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: UNAUTHORIZED_ID,\n issue: [\n {\n severity: 'error',\n code: 'login',\n details: {\n text: 'Unauthorized',\n },\n },\n ],\n};\n\nexport const forbidden: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: FORBIDDEN_ID,\n issue: [\n {\n severity: 'error',\n code: 'forbidden',\n details: {\n text: 'Forbidden',\n },\n },\n ],\n};\n\nexport const gone: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: GONE_ID,\n issue: [\n {\n severity: 'error',\n code: 'deleted',\n details: {\n text: 'Gone',\n },\n },\n ],\n};\n\nexport const tooManyRequests: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: TOO_MANY_REQUESTS_ID,\n issue: [\n {\n severity: 'error',\n code: 'throttled',\n details: {\n text: 'Too Many Requests',\n },\n },\n ],\n};\n\nexport function badRequest(details: string, expression?: string): OperationOutcome {\n return {\n resourceType: 'OperationOutcome',\n issue: [\n {\n severity: 'error',\n code: 'invalid',\n details: {\n text: details,\n },\n expression: expression ? [expression] : undefined,\n },\n ],\n };\n}\n\nexport function isOperationOutcome(value: unknown): value is OperationOutcome {\n return typeof value === 'object' && value !== null && (value as any).resourceType === 'OperationOutcome';\n}\n\nexport function isOk(outcome: OperationOutcome): boolean {\n return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;\n}\n\nexport function isNotFound(outcome: OperationOutcome): boolean {\n return outcome.id === NOT_FOUND_ID;\n}\n\nexport function isGone(outcome: OperationOutcome): boolean {\n return outcome.id === GONE_ID;\n}\n\nexport function getStatus(outcome: OperationOutcome): number {\n if (outcome.id === OK_ID) {\n return 200;\n } else if (outcome.id === CREATED_ID) {\n return 201;\n } else if (outcome.id === NOT_MODIFIED_ID) {\n return 304;\n } else if (outcome.id === UNAUTHORIZED_ID) {\n return 401;\n } else if (outcome.id === FORBIDDEN_ID) {\n return 403;\n } else if (outcome.id === NOT_FOUND_ID) {\n return 404;\n } else if (outcome.id === GONE_ID) {\n return 410;\n } else if (outcome.id === TOO_MANY_REQUESTS_ID) {\n return 429;\n } else {\n return 400;\n }\n}\n\n/**\n * Asserts that the operation completed successfully and that the resource is defined.\n * @param outcome The operation outcome.\n * @param resource The resource that may or may not have been returned.\n */\nexport function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T {\n if (!isOk(outcome) || resource === undefined) {\n throw new OperationOutcomeError(outcome);\n }\n}\n\nexport class OperationOutcomeError extends Error {\n readonly outcome: OperationOutcome;\n\n constructor(outcome: OperationOutcome) {\n super(outcome?.issue?.[0].details?.text);\n this.outcome = outcome;\n }\n}\n\n/**\n * Normalizes an error object into a displayable error string.\n * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.\n * @returns A display string for the error.\n */\nexport function normalizeErrorString(error: unknown): string {\n if (!error) {\n return 'Unknown error';\n }\n if (typeof error === 'string') {\n return error;\n }\n if (error instanceof Error) {\n return error.message;\n }\n if (isOperationOutcome(error)) {\n return error.issue?.[0]?.details?.text ?? 'Unknown error';\n }\n return JSON.stringify(error);\n}\n"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEpC,MAAA,KAAK,GAAqB;AACrC,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,EAAE,EAAE,KAAK;AACT,IAAA,KAAK,EAAE;AACL,QAAA;AACE,YAAA,QAAQ,EAAE,aAAa;AACvB,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,OAAO,EAAE;AACP,gBAAA,IAAI,EAAE,QAAQ;AACf,aAAA;AACF,SAAA;AACF,KAAA;EACD;AAEW,MAAA,OAAO,GAAqB;AACvC,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,EAAE,EAAE,UAAU;AACd,IAAA,KAAK,EAAE;AACL,QAAA;AACE,YAAA,QAAQ,EAAE,aAAa;AACvB,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,OAAO,EAAE;AACP,gBAAA,IAAI,EAAE,SAAS;AAChB,aAAA;AACF,SAAA;AACF,KAAA;EACD;AAEW,MAAA,WAAW,GAAqB;AAC3C,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,EAAE,EAAE,eAAe;AACnB,IAAA,KAAK,EAAE;AACL,QAAA;AACE,YAAA,QAAQ,EAAE,aAAa;AACvB,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,OAA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B;AACF,CAAA;AAED;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,KAAc,EAAA;IACjD,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,eAAe,CAAC;AACxB,KAAA;AACD,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC;AACd,KAAA;IACD,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,OAAO,KAAK,CAAC,OAAO,CAAC;AACtB,KAAA;AACD,IAAA,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,eAAe,CAAC;AAC3D,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B;;;;"}
|
|
1
|
+
{"version":3,"file":"outcomes.mjs","sources":["../../src/outcomes.ts"],"sourcesContent":["import { OperationOutcome } from '@medplum/fhirtypes';\n\nconst OK_ID = 'ok';\nconst CREATED_ID = 'created';\nconst GONE_ID = 'gone';\nconst NOT_MODIFIED_ID = 'not-modified';\nconst NOT_FOUND_ID = 'not-found';\nconst UNAUTHORIZED_ID = 'unauthorized';\nconst FORBIDDEN_ID = 'forbidden';\nconst TOO_MANY_REQUESTS_ID = 'too-many-requests';\n\nexport const allOk: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: OK_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'All OK',\n },\n },\n ],\n};\n\nexport const created: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: CREATED_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'Created',\n },\n },\n ],\n};\n\nexport const notModified: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_MODIFIED_ID,\n issue: [\n {\n severity: 'information',\n code: 'informational',\n details: {\n text: 'Not Modified',\n },\n },\n ],\n};\n\nexport const notFound: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_FOUND_ID,\n issue: [\n {\n severity: 'error',\n code: 'not-found',\n details: {\n text: 'Not found',\n },\n },\n ],\n};\n\nexport const unauthorized: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: UNAUTHORIZED_ID,\n issue: [\n {\n severity: 'error',\n code: 'login',\n details: {\n text: 'Unauthorized',\n },\n },\n ],\n};\n\nexport const forbidden: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: FORBIDDEN_ID,\n issue: [\n {\n severity: 'error',\n code: 'forbidden',\n details: {\n text: 'Forbidden',\n },\n },\n ],\n};\n\nexport const gone: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: GONE_ID,\n issue: [\n {\n severity: 'error',\n code: 'deleted',\n details: {\n text: 'Gone',\n },\n },\n ],\n};\n\nexport const tooManyRequests: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: TOO_MANY_REQUESTS_ID,\n issue: [\n {\n severity: 'error',\n code: 'throttled',\n details: {\n text: 'Too Many Requests',\n },\n },\n ],\n};\n\nexport function badRequest(details: string, expression?: string): OperationOutcome {\n return {\n resourceType: 'OperationOutcome',\n issue: [\n {\n severity: 'error',\n code: 'invalid',\n details: {\n text: details,\n },\n expression: expression ? [expression] : undefined,\n },\n ],\n };\n}\n\nexport function isOperationOutcome(value: unknown): value is OperationOutcome {\n return typeof value === 'object' && value !== null && (value as any).resourceType === 'OperationOutcome';\n}\n\nexport function isOk(outcome: OperationOutcome): boolean {\n return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;\n}\n\nexport function isNotFound(outcome: OperationOutcome): boolean {\n return outcome.id === NOT_FOUND_ID;\n}\n\nexport function isGone(outcome: OperationOutcome): boolean {\n return outcome.id === GONE_ID;\n}\n\nexport function getStatus(outcome: OperationOutcome): number {\n if (outcome.id === OK_ID) {\n return 200;\n } else if (outcome.id === CREATED_ID) {\n return 201;\n } else if (outcome.id === NOT_MODIFIED_ID) {\n return 304;\n } else if (outcome.id === UNAUTHORIZED_ID) {\n return 401;\n } else if (outcome.id === FORBIDDEN_ID) {\n return 403;\n } else if (outcome.id === NOT_FOUND_ID) {\n return 404;\n } else if (outcome.id === GONE_ID) {\n return 410;\n } else if (outcome.id === TOO_MANY_REQUESTS_ID) {\n return 429;\n } else {\n return 400;\n }\n}\n\n/**\n * Asserts that the operation completed successfully and that the resource is defined.\n * @param outcome The operation outcome.\n * @param resource The resource that may or may not have been returned.\n */\nexport function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T {\n if (!isOk(outcome) || resource === undefined) {\n throw new OperationOutcomeError(outcome);\n }\n}\n\nexport class OperationOutcomeError extends Error {\n readonly outcome: OperationOutcome;\n\n constructor(outcome: OperationOutcome, cause?: unknown) {\n super(outcome?.issue?.[0].details?.text);\n this.outcome = outcome;\n this.cause = cause;\n }\n}\n\n/**\n * Normalizes an error object into an OperationOutcome.\n * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.\n * @returns The normalized OperationOutcome.\n */\nexport function normalizeOperationOutcome(error: unknown): OperationOutcome {\n if (error instanceof OperationOutcomeError) {\n return error.outcome;\n }\n if (isOperationOutcome(error)) {\n return error;\n }\n return badRequest(normalizeErrorString(error));\n}\n\n/**\n * Normalizes an error object into a displayable error string.\n * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.\n * @returns A display string for the error.\n */\nexport function normalizeErrorString(error: unknown): string {\n if (!error) {\n return 'Unknown error';\n }\n if (typeof error === 'string') {\n return error;\n }\n if (error instanceof Error) {\n return error.message;\n }\n if (isOperationOutcome(error)) {\n return error.issue?.[0]?.details?.text ?? 'Unknown error';\n }\n return JSON.stringify(error);\n}\n"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,eAAe,GAAG,cAAc,CAAC;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B,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC;AAED;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,KAAc,EAAA;IACjD,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,eAAe,CAAC;AACxB,KAAA;AACD,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC;AACd,KAAA;IACD,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,OAAO,KAAK,CAAC,OAAO,CAAC;AACtB,KAAA;AACD,IAAA,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,eAAe,CAAC;AAC3D,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B;;;;"}
|
|
@@ -81,7 +81,7 @@ function matchesTokenFilter(resource, filter, searchParam) {
|
|
|
81
81
|
return matchesBooleanFilter(resource, filter, searchParam);
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
return matchesStringFilter(resource, filter, searchParam);
|
|
84
|
+
return matchesStringFilter(resource, filter, searchParam, true);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
function matchesBooleanFilter(resource, filter, searchParam) {
|
|
@@ -90,13 +90,13 @@ function matchesBooleanFilter(resource, filter, searchParam) {
|
|
|
90
90
|
const result = values.includes(expected);
|
|
91
91
|
return isNegated(filter.operator) ? !result : result;
|
|
92
92
|
}
|
|
93
|
-
function matchesStringFilter(resource, filter, searchParam) {
|
|
93
|
+
function matchesStringFilter(resource, filter, searchParam, asToken) {
|
|
94
94
|
const resourceValues = evalFhirPath(searchParam.expression, resource);
|
|
95
95
|
const filterValues = filter.value.split(',');
|
|
96
96
|
const negated = isNegated(filter.operator);
|
|
97
97
|
for (const resourceValue of resourceValues) {
|
|
98
98
|
for (const filterValue of filterValues) {
|
|
99
|
-
const match = matchesStringValue(resourceValue, filter.operator, filterValue);
|
|
99
|
+
const match = matchesStringValue(resourceValue, filter.operator, filterValue, asToken);
|
|
100
100
|
if (match) {
|
|
101
101
|
return !negated;
|
|
102
102
|
}
|
|
@@ -106,7 +106,12 @@ function matchesStringFilter(resource, filter, searchParam) {
|
|
|
106
106
|
// If "equals" and no matches, then return false
|
|
107
107
|
return negated;
|
|
108
108
|
}
|
|
109
|
-
function matchesStringValue(resourceValue, operator, filterValue) {
|
|
109
|
+
function matchesStringValue(resourceValue, operator, filterValue, asToken) {
|
|
110
|
+
if (asToken && filterValue.includes('|')) {
|
|
111
|
+
const [system, code] = filterValue.split('|');
|
|
112
|
+
return (matchesStringValue(resourceValue, operator, system, false) &&
|
|
113
|
+
(!code || matchesStringValue(resourceValue, operator, code, false)));
|
|
114
|
+
}
|
|
110
115
|
let str = '';
|
|
111
116
|
if (resourceValue) {
|
|
112
117
|
if (typeof resourceValue === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.mjs","sources":["../../../src/search/match.ts"],"sourcesContent":["import { Reference, Resource, SearchParameter } from '@medplum/fhirtypes';\nimport { evalFhirPath } from '../fhirpath';\nimport { globalSchema } from '../types';\nimport { getSearchParameterDetails, SearchParameterType } from './details';\nimport { Filter, Operator, SearchRequest } from './search';\n\n/**\n * Determines if the resource matches the search request.\n * @param resource The resource that was created or updated.\n * @param searchRequest The subscription criteria as a search request.\n * @returns True if the resource satisfies the search request.\n */\nexport function matchesSearchRequest(resource: Resource, searchRequest: SearchRequest): boolean {\n if (searchRequest.resourceType !== resource.resourceType) {\n return false;\n }\n if (searchRequest.filters) {\n for (const filter of searchRequest.filters) {\n if (!matchesSearchFilter(resource, searchRequest, filter)) {\n return false;\n }\n }\n }\n return true;\n}\n\n/**\n * Determines if the resource matches the search filter.\n * @param resource The resource that was created or updated.\n * @param filter One of the filters of a subscription criteria.\n * @returns True if the resource satisfies the search filter.\n */\nfunction matchesSearchFilter(resource: Resource, searchRequest: SearchRequest, filter: Filter): boolean {\n const searchParam = globalSchema.types[searchRequest.resourceType]?.searchParams?.[filter.code];\n switch (searchParam?.type) {\n case 'reference':\n return matchesReferenceFilter(resource, filter, searchParam);\n case 'string':\n return matchesStringFilter(resource, filter, searchParam);\n case 'token':\n return matchesTokenFilter(resource, filter, searchParam);\n case 'date':\n return matchesDateFilter(resource, filter, searchParam);\n }\n // Unknown search parameter or search parameter type\n // Default fail the check\n return false;\n}\n\nfunction matchesReferenceFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const values = evalFhirPath(searchParam.expression as string, resource) as (Reference | string)[];\n const negated = isNegated(filter.operator);\n\n if (filter.value === '' && values.length === 0) {\n // If the filter operator is \"equals\", then the filter matches.\n // If the filter operator is \"not equals\", then the filter does not match.\n return filter.operator === Operator.EQUALS;\n }\n\n // Normalize the values array into reference strings\n const references = values.map((value) => (typeof value === 'string' ? value : value.reference));\n\n for (const filterValue of filter.value.split(',')) {\n let match = references.includes(filterValue);\n if (!match && filter.code === '_compartment') {\n // Backwards compability for compartment search parameter\n // In previous versions, the resource type was not required in compartment values\n // So, \"123\" would match \"Patient/123\"\n // We need to maintain this behavior for backwards compatibility\n match = references.some((reference) => reference?.endsWith('/' + filterValue));\n }\n if (match) {\n return !negated;\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesTokenFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const details = getSearchParameterDetails(resource.resourceType, searchParam);\n if (details.type === SearchParameterType.BOOLEAN) {\n return matchesBooleanFilter(resource, filter, searchParam);\n } else {\n return matchesStringFilter(resource, filter, searchParam);\n }\n}\n\nfunction matchesBooleanFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const values = evalFhirPath(searchParam.expression as string, resource);\n const expected = filter.value === 'true';\n const result = values.includes(expected);\n return isNegated(filter.operator) ? !result : result;\n}\n\nfunction matchesStringFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const resourceValues = evalFhirPath(searchParam.expression as string, resource);\n const filterValues = filter.value.split(',');\n const negated = isNegated(filter.operator);\n for (const resourceValue of resourceValues) {\n for (const filterValue of filterValues) {\n const match = matchesStringValue(resourceValue, filter.operator, filterValue);\n if (match) {\n return !negated;\n }\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesStringValue(resourceValue: unknown, operator: Operator, filterValue: string): boolean {\n let str = '';\n if (resourceValue) {\n if (typeof resourceValue === 'string') {\n str = resourceValue;\n } else if (typeof resourceValue === 'object') {\n str = JSON.stringify(resourceValue);\n }\n }\n return str.toLowerCase().includes(filterValue.toLowerCase());\n}\n\nfunction matchesDateFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const resourceValues = evalFhirPath(searchParam.expression as string, resource);\n const filterValues = filter.value.split(',');\n const negated = isNegated(filter.operator);\n for (const resourceValue of resourceValues) {\n for (const filterValue of filterValues) {\n const match = matchesDateValue(resourceValue as string, filter.operator, filterValue);\n if (match) {\n return !negated;\n }\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesDateValue(resourceValue: string, operator: Operator, filterValue: string): boolean {\n switch (operator) {\n case Operator.STARTS_AFTER:\n case Operator.GREATER_THAN:\n return resourceValue > filterValue;\n case Operator.GREATER_THAN_OR_EQUALS:\n return resourceValue >= filterValue;\n case Operator.ENDS_BEFORE:\n case Operator.LESS_THAN:\n return resourceValue < filterValue;\n case Operator.LESS_THAN_OR_EQUALS:\n return resourceValue <= filterValue;\n case Operator.EQUALS:\n case Operator.NOT_EQUALS:\n return resourceValue === filterValue;\n }\n return false;\n}\n\nfunction isNegated(operator: Operator): boolean {\n return operator === Operator.NOT_EQUALS || operator === Operator.NOT;\n}\n"],"names":[],"mappings":";;;;;;;;;AAMA;;;;;AAKG;AACa,S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AQ,CAAC,WAAW,CAAC;QAC1B,KAAK,QAAQ,CAAC,SAAS;YACrB,OAAO,aAAa,GAAG,WAAW,CAAC;QACrC,KAAK,QAAQ,CAAC,mBAAmB;YAC/B,OAAO,aAAa,IAAI,WAAW,CAAC;QACtC,KAAK,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,QAAQ,CAAC,UAAU;YACtB,OAAO,aAAa,KAAK,WAAW,CAAC;AACxC,KAAA;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,QAAkB,EAAA;IACnC,OAAO,QAAQ,KAAK,QAAQ,CAAC,UAAU,IAAI,QAAQ,KAAK,QAAQ,CAAC,GAAG,CAAC;AACvE;;;;"}
|
|
1
|
+
{"version":3,"file":"match.mjs","sources":["../../../src/search/match.ts"],"sourcesContent":["import { Reference, Resource, SearchParameter } from '@medplum/fhirtypes';\nimport { evalFhirPath } from '../fhirpath';\nimport { globalSchema } from '../types';\nimport { getSearchParameterDetails, SearchParameterType } from './details';\nimport { Filter, Operator, SearchRequest } from './search';\n\n/**\n * Determines if the resource matches the search request.\n * @param resource The resource that was created or updated.\n * @param searchRequest The subscription criteria as a search request.\n * @returns True if the resource satisfies the search request.\n */\nexport function matchesSearchRequest(resource: Resource, searchRequest: SearchRequest): boolean {\n if (searchRequest.resourceType !== resource.resourceType) {\n return false;\n }\n if (searchRequest.filters) {\n for (const filter of searchRequest.filters) {\n if (!matchesSearchFilter(resource, searchRequest, filter)) {\n return false;\n }\n }\n }\n return true;\n}\n\n/**\n * Determines if the resource matches the search filter.\n * @param resource The resource that was created or updated.\n * @param filter One of the filters of a subscription criteria.\n * @returns True if the resource satisfies the search filter.\n */\nfunction matchesSearchFilter(resource: Resource, searchRequest: SearchRequest, filter: Filter): boolean {\n const searchParam = globalSchema.types[searchRequest.resourceType]?.searchParams?.[filter.code];\n switch (searchParam?.type) {\n case 'reference':\n return matchesReferenceFilter(resource, filter, searchParam);\n case 'string':\n return matchesStringFilter(resource, filter, searchParam);\n case 'token':\n return matchesTokenFilter(resource, filter, searchParam);\n case 'date':\n return matchesDateFilter(resource, filter, searchParam);\n }\n // Unknown search parameter or search parameter type\n // Default fail the check\n return false;\n}\n\nfunction matchesReferenceFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const values = evalFhirPath(searchParam.expression as string, resource) as (Reference | string)[];\n const negated = isNegated(filter.operator);\n\n if (filter.value === '' && values.length === 0) {\n // If the filter operator is \"equals\", then the filter matches.\n // If the filter operator is \"not equals\", then the filter does not match.\n return filter.operator === Operator.EQUALS;\n }\n\n // Normalize the values array into reference strings\n const references = values.map((value) => (typeof value === 'string' ? value : value.reference));\n\n for (const filterValue of filter.value.split(',')) {\n let match = references.includes(filterValue);\n if (!match && filter.code === '_compartment') {\n // Backwards compability for compartment search parameter\n // In previous versions, the resource type was not required in compartment values\n // So, \"123\" would match \"Patient/123\"\n // We need to maintain this behavior for backwards compatibility\n match = references.some((reference) => reference?.endsWith('/' + filterValue));\n }\n if (match) {\n return !negated;\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesTokenFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const details = getSearchParameterDetails(resource.resourceType, searchParam);\n if (details.type === SearchParameterType.BOOLEAN) {\n return matchesBooleanFilter(resource, filter, searchParam);\n } else {\n return matchesStringFilter(resource, filter, searchParam, true);\n }\n}\n\nfunction matchesBooleanFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const values = evalFhirPath(searchParam.expression as string, resource);\n const expected = filter.value === 'true';\n const result = values.includes(expected);\n return isNegated(filter.operator) ? !result : result;\n}\n\nfunction matchesStringFilter(\n resource: Resource,\n filter: Filter,\n searchParam: SearchParameter,\n asToken?: boolean\n): boolean {\n const resourceValues = evalFhirPath(searchParam.expression as string, resource);\n const filterValues = filter.value.split(',');\n const negated = isNegated(filter.operator);\n for (const resourceValue of resourceValues) {\n for (const filterValue of filterValues) {\n const match = matchesStringValue(resourceValue, filter.operator, filterValue, asToken);\n if (match) {\n return !negated;\n }\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesStringValue(\n resourceValue: unknown,\n operator: Operator,\n filterValue: string,\n asToken?: boolean\n): boolean {\n if (asToken && filterValue.includes('|')) {\n const [system, code] = filterValue.split('|');\n return (\n matchesStringValue(resourceValue, operator, system, false) &&\n (!code || matchesStringValue(resourceValue, operator, code, false))\n );\n }\n let str = '';\n if (resourceValue) {\n if (typeof resourceValue === 'string') {\n str = resourceValue;\n } else if (typeof resourceValue === 'object') {\n str = JSON.stringify(resourceValue);\n }\n }\n return str.toLowerCase().includes(filterValue.toLowerCase());\n}\n\nfunction matchesDateFilter(resource: Resource, filter: Filter, searchParam: SearchParameter): boolean {\n const resourceValues = evalFhirPath(searchParam.expression as string, resource);\n const filterValues = filter.value.split(',');\n const negated = isNegated(filter.operator);\n for (const resourceValue of resourceValues) {\n for (const filterValue of filterValues) {\n const match = matchesDateValue(resourceValue as string, filter.operator, filterValue);\n if (match) {\n return !negated;\n }\n }\n }\n // If \"not equals\" and no matches, then return true\n // If \"equals\" and no matches, then return false\n return negated;\n}\n\nfunction matchesDateValue(resourceValue: string, operator: Operator, filterValue: string): boolean {\n switch (operator) {\n case Operator.STARTS_AFTER:\n case Operator.GREATER_THAN:\n return resourceValue > filterValue;\n case Operator.GREATER_THAN_OR_EQUALS:\n return resourceValue >= filterValue;\n case Operator.ENDS_BEFORE:\n case Operator.LESS_THAN:\n return resourceValue < filterValue;\n case Operator.LESS_THAN_OR_EQUALS:\n return resourceValue <= filterValue;\n case Operator.EQUALS:\n case Operator.NOT_EQUALS:\n return resourceValue === filterValue;\n }\n return false;\n}\n\nfunction isNegated(operator: Operator): boolean {\n return operator === Operator.NOT_EQUALS || operator === Operator.NOT;\n}\n"],"names":[],"mappings":";;;;;;;;;AAMA;;;;;AAKG;AACa,SA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AAI,KAAK,EAAE;gBACT,OAAO,CAAC,OAAO,CAAC;AACjB,aAAA;AACF,SAAA;AACF,KAAA;;;AAGD,IAAA,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,aAAqB,EAAE,QAAkB,EAAE,WAAmB,EAAA;AACtF,IAAA,QAAQ,QAAQ;QACd,KAAK,QAAQ,CAAC,YAAY,CAAC;QAC3B,KAAK,QAAQ,CAAC,YAAY;YACxB,OAAO,aAAa,GAAG,WAAW,CAAC;QACrC,KAAK,QAAQ,CAAC,sBAAsB;YAClC,OAAO,aAAa,IAAI,WAAW,CAAC;QACtC,KAAK,QAAQ,CAAC,WAAW,CAAC;QAC1B,KAAK,QAAQ,CAAC,SAAS;YACrB,OAAO,aAAa,GAAG,WAAW,CAAC;QACrC,KAAK,QAAQ,CAAC,mBAAmB;YAC/B,OAAO,aAAa,IAAI,WAAW,CAAC;QACtC,KAAK,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,QAAQ,CAAC,UAAU;YACtB,OAAO,aAAa,KAAK,WAAW,CAAC;AACxC,KAAA;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,QAAkB,EAAA;IACnC,OAAO,QAAQ,KAAK,QAAQ,CAAC,UAAU,IAAI,QAAQ,KAAK,QAAQ,CAAC,GAAG,CAAC;AACvE;;;;"}
|
|
@@ -21,8 +21,14 @@ export declare function getStatus(outcome: OperationOutcome): number;
|
|
|
21
21
|
export declare function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T;
|
|
22
22
|
export declare class OperationOutcomeError extends Error {
|
|
23
23
|
readonly outcome: OperationOutcome;
|
|
24
|
-
constructor(outcome: OperationOutcome);
|
|
24
|
+
constructor(outcome: OperationOutcome, cause?: unknown);
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes an error object into an OperationOutcome.
|
|
28
|
+
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
29
|
+
* @returns The normalized OperationOutcome.
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizeOperationOutcome(error: unknown): OperationOutcome;
|
|
26
32
|
/**
|
|
27
33
|
* Normalizes an error object into a displayable error string.
|
|
28
34
|
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Medplum TS/JS Library",
|
|
5
5
|
"author": "Medplum <hello@medplum.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"clean": "rimraf dist",
|
|
15
|
-
"build": "npm run clean &&
|
|
16
|
-
"rollup": "rollup --config rollup.config.mjs",
|
|
15
|
+
"build": "npm run clean && tsc --project tsconfig.build.json && rollup --config rollup.config.mjs",
|
|
17
16
|
"test": "jest"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
@@ -28,13 +27,14 @@
|
|
|
28
27
|
"optional": true
|
|
29
28
|
}
|
|
30
29
|
},
|
|
30
|
+
"types": "dist/types/index.d.ts",
|
|
31
31
|
"main": "dist/cjs/index.cjs",
|
|
32
32
|
"module": "dist/esm/index.mjs",
|
|
33
33
|
"exports": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
34
35
|
"require": "./dist/cjs/index.cjs",
|
|
35
36
|
"import": "./dist/esm/index.mjs"
|
|
36
37
|
},
|
|
37
|
-
"types": "dist/esm/index.d.ts",
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"keywords": [
|
|
40
40
|
"medplum",
|
package/dist/cjs/outcomes.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { OperationOutcome } from '@medplum/fhirtypes';
|
|
2
|
-
export declare const allOk: OperationOutcome;
|
|
3
|
-
export declare const created: OperationOutcome;
|
|
4
|
-
export declare const notModified: OperationOutcome;
|
|
5
|
-
export declare const notFound: OperationOutcome;
|
|
6
|
-
export declare const unauthorized: OperationOutcome;
|
|
7
|
-
export declare const forbidden: OperationOutcome;
|
|
8
|
-
export declare const gone: OperationOutcome;
|
|
9
|
-
export declare const tooManyRequests: OperationOutcome;
|
|
10
|
-
export declare function badRequest(details: string, expression?: string): OperationOutcome;
|
|
11
|
-
export declare function isOperationOutcome(value: unknown): value is OperationOutcome;
|
|
12
|
-
export declare function isOk(outcome: OperationOutcome): boolean;
|
|
13
|
-
export declare function isNotFound(outcome: OperationOutcome): boolean;
|
|
14
|
-
export declare function isGone(outcome: OperationOutcome): boolean;
|
|
15
|
-
export declare function getStatus(outcome: OperationOutcome): number;
|
|
16
|
-
/**
|
|
17
|
-
* Asserts that the operation completed successfully and that the resource is defined.
|
|
18
|
-
* @param outcome The operation outcome.
|
|
19
|
-
* @param resource The resource that may or may not have been returned.
|
|
20
|
-
*/
|
|
21
|
-
export declare function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T;
|
|
22
|
-
export declare class OperationOutcomeError extends Error {
|
|
23
|
-
readonly outcome: OperationOutcome;
|
|
24
|
-
constructor(outcome: OperationOutcome);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Normalizes an error object into a displayable error string.
|
|
28
|
-
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
29
|
-
* @returns A display string for the error.
|
|
30
|
-
*/
|
|
31
|
-
export declare function normalizeErrorString(error: unknown): string;
|
package/dist/esm/cache.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LRU cache (least recently used)
|
|
3
|
-
* Source: https://stackoverflow.com/a/46432113
|
|
4
|
-
*/
|
|
5
|
-
export declare class LRUCache<T> {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(max?: number);
|
|
8
|
-
/**
|
|
9
|
-
* Deletes all values from the cache.
|
|
10
|
-
*/
|
|
11
|
-
clear(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Returns the value for the given key.
|
|
14
|
-
* @param key The key to retrieve.
|
|
15
|
-
* @returns The value if found; undefined otherwise.
|
|
16
|
-
*/
|
|
17
|
-
get(key: string): T | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Sets the value for the given key.
|
|
20
|
-
* @param key The key to set.
|
|
21
|
-
* @param val The value to set.
|
|
22
|
-
*/
|
|
23
|
-
set(key: string, val: T): void;
|
|
24
|
-
/**
|
|
25
|
-
* Deletes the value for the given key.
|
|
26
|
-
* @param key The key to delete.
|
|
27
|
-
*/
|
|
28
|
-
delete(key: string): void;
|
|
29
|
-
/**
|
|
30
|
-
* Returns the list of all keys in the cache.
|
|
31
|
-
* @returns The array of keys in the cache.
|
|
32
|
-
*/
|
|
33
|
-
keys(): IterableIterator<string>;
|
|
34
|
-
}
|