@medplum/core 0.3.0 → 0.4.0
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 +4 -2
- package/dist/cjs/index.js +1769 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/index.min.js +16 -0
- package/dist/cjs/index.min.js.map +1 -0
- package/dist/esm/index.js +1721 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.min.js +16 -0
- package/dist/esm/index.min.js.map +1 -0
- package/dist/{cache.d.ts → types/cache.d.ts} +0 -0
- package/dist/{client.d.ts → types/client.d.ts} +50 -8
- package/dist/{crypto.d.ts → types/crypto.d.ts} +0 -0
- package/dist/{eventtarget.d.ts → types/eventtarget.d.ts} +0 -0
- package/dist/{format.d.ts → types/format.d.ts} +0 -0
- package/dist/{index.d.ts → types/index.d.ts} +0 -0
- package/dist/types/jwt.d.ts +5 -0
- package/dist/{outcomes.d.ts → types/outcomes.d.ts} +6 -1
- package/dist/{search.d.ts → types/search.d.ts} +3 -0
- package/dist/{searchparams.d.ts → types/searchparams.d.ts} +0 -0
- package/dist/{storage.d.ts → types/storage.d.ts} +0 -0
- package/dist/{types.d.ts → types/types.d.ts} +17 -3
- package/dist/{utils.d.ts → types/utils.d.ts} +0 -0
- package/package.json +11 -5
- package/rollup.config.js +36 -0
- package/dist/cache.js +0 -39
- package/dist/cache.js.map +0 -1
- package/dist/client.js +0 -572
- package/dist/client.js.map +0 -1
- package/dist/crypto.js +0 -33
- package/dist/crypto.js.map +0 -1
- package/dist/eventtarget.js +0 -38
- package/dist/eventtarget.js.map +0 -1
- package/dist/format.js +0 -56
- package/dist/format.js.map +0 -1
- package/dist/index.js +0 -20
- package/dist/index.js.map +0 -1
- package/dist/jwt.d.ts +0 -5
- package/dist/jwt.js +0 -28
- package/dist/jwt.js.map +0 -1
- package/dist/outcomes.js +0 -154
- package/dist/outcomes.js.map +0 -1
- package/dist/search.js +0 -120
- package/dist/search.js.map +0 -1
- package/dist/searchparams.js +0 -128
- package/dist/searchparams.js.map +0 -1
- package/dist/storage.js +0 -90
- package/dist/storage.js.map +0 -1
- package/dist/types.js +0 -171
- package/dist/types.js.map +0 -1
- package/dist/utils.js +0 -239
- package/dist/utils.js.map +0 -1
package/dist/crypto.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.encryptSHA256 = exports.getRandomString = void 0;
|
|
13
|
-
const utils_1 = require("./utils");
|
|
14
|
-
/**
|
|
15
|
-
* Returns a cryptographically secure random string.
|
|
16
|
-
*/
|
|
17
|
-
function getRandomString() {
|
|
18
|
-
const randomItems = new Uint32Array(28);
|
|
19
|
-
crypto.getRandomValues(randomItems);
|
|
20
|
-
return (0, utils_1.arrayBufferToHex)(randomItems.buffer);
|
|
21
|
-
}
|
|
22
|
-
exports.getRandomString = getRandomString;
|
|
23
|
-
/**
|
|
24
|
-
* Encrypts a string with SHA256 encryption.
|
|
25
|
-
* @param str
|
|
26
|
-
*/
|
|
27
|
-
function encryptSHA256(str) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
exports.encryptSHA256 = encryptSHA256;
|
|
33
|
-
//# sourceMappingURL=crypto.js.map
|
package/dist/crypto.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA2C;AAE3C;;GAEG;AACH,SAAgB,eAAe;IAC7B,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IACxC,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IACpC,OAAO,IAAA,wBAAgB,EAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAJD,0CAIC;AAED;;;GAGG;AACH,SAAsB,aAAa,CAAC,GAAW;;QAC7C,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;CAAA;AAFD,sCAEC","sourcesContent":["import { arrayBufferToHex } from './utils';\n\n/**\n * Returns a cryptographically secure random string.\n */\nexport function getRandomString(): string {\n const randomItems = new Uint32Array(28);\n crypto.getRandomValues(randomItems);\n return arrayBufferToHex(randomItems.buffer);\n}\n\n/**\n * Encrypts a string with SHA256 encryption.\n * @param str\n */\nexport async function encryptSHA256(str: string): Promise<ArrayBuffer> {\n return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));\n}\n"]}
|
package/dist/eventtarget.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Based on: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EventTarget = void 0;
|
|
7
|
-
class EventTarget {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.listeners = {};
|
|
10
|
-
}
|
|
11
|
-
addEventListener(type, callback) {
|
|
12
|
-
if (!this.listeners[type]) {
|
|
13
|
-
this.listeners[type] = [];
|
|
14
|
-
}
|
|
15
|
-
this.listeners[type].push(callback);
|
|
16
|
-
}
|
|
17
|
-
removeEventListeneer(type, callback) {
|
|
18
|
-
const array = this.listeners[type];
|
|
19
|
-
if (!array) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
for (let i = 0; i < array.length; i++) {
|
|
23
|
-
if (array[i] === callback) {
|
|
24
|
-
array.splice(i, 1);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
dispatchEvent(event) {
|
|
30
|
-
const array = this.listeners[event.type];
|
|
31
|
-
if (array) {
|
|
32
|
-
array.forEach((listener) => listener.call(this, event));
|
|
33
|
-
}
|
|
34
|
-
return !event.defaultPrevented;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.EventTarget = EventTarget;
|
|
38
|
-
//# sourceMappingURL=eventtarget.js.map
|
package/dist/eventtarget.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eventtarget.js","sourceRoot":"","sources":["../src/eventtarget.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AASH,MAAa,WAAW;IAGtB;QACE,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,gBAAgB,CAAC,IAAY,EAAE,QAAuB;QACpD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;SAC3B;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,oBAAoB,CAAC,IAAY,EAAE,QAAuB;QACxD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;gBACzB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACnB,OAAO;aACR;SACF;IACH,CAAC;IAED,aAAa,CAAC,KAAY;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;SACzD;QACD,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACjC,CAAC;CACF;AAlCD,kCAkCC","sourcesContent":["/*\n * Based on: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget\n */\n\ninterface Event {\n type: string;\n defaultPrevented?: boolean;\n}\n\ntype EventListener = (e: Event) => void;\n\nexport class EventTarget {\n private readonly listeners: Record<string, EventListener[]>;\n\n constructor() {\n this.listeners = {};\n }\n\n addEventListener(type: string, callback: EventListener): void {\n if (!this.listeners[type]) {\n this.listeners[type] = [];\n }\n this.listeners[type].push(callback);\n }\n\n removeEventListeneer(type: string, callback: EventListener): void {\n const array = this.listeners[type];\n if (!array) {\n return;\n }\n for (let i = 0; i < array.length; i++) {\n if (array[i] === callback) {\n array.splice(i, 1);\n return;\n }\n }\n }\n\n dispatchEvent(event: Event): boolean {\n const array = this.listeners[event.type];\n if (array) {\n array.forEach((listener) => listener.call(this, event));\n }\n return !event.defaultPrevented;\n }\n}\n"]}
|
package/dist/format.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatFamilyName = exports.formatGivenName = exports.formatHumanName = exports.formatAddress = void 0;
|
|
4
|
-
function formatAddress(address, options) {
|
|
5
|
-
const builder = [];
|
|
6
|
-
if (address.line) {
|
|
7
|
-
builder.push(...address.line);
|
|
8
|
-
}
|
|
9
|
-
if (address.city) {
|
|
10
|
-
builder.push(address.city);
|
|
11
|
-
}
|
|
12
|
-
if (address.state) {
|
|
13
|
-
builder.push(address.state);
|
|
14
|
-
}
|
|
15
|
-
if (address.postalCode) {
|
|
16
|
-
builder.push(address.postalCode);
|
|
17
|
-
}
|
|
18
|
-
if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
|
|
19
|
-
builder.push('[' + address.use + ']');
|
|
20
|
-
}
|
|
21
|
-
return builder.join(', ').trim();
|
|
22
|
-
}
|
|
23
|
-
exports.formatAddress = formatAddress;
|
|
24
|
-
function formatHumanName(name, options) {
|
|
25
|
-
const builder = [];
|
|
26
|
-
if (name.prefix && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.prefix))) {
|
|
27
|
-
builder.push(...name.prefix);
|
|
28
|
-
}
|
|
29
|
-
if (name.given) {
|
|
30
|
-
builder.push(...name.given);
|
|
31
|
-
}
|
|
32
|
-
if (name.family) {
|
|
33
|
-
builder.push(name.family);
|
|
34
|
-
}
|
|
35
|
-
if (name.suffix && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.suffix))) {
|
|
36
|
-
builder.push(...name.suffix);
|
|
37
|
-
}
|
|
38
|
-
if (name.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
|
|
39
|
-
builder.push('[' + name.use + ']');
|
|
40
|
-
}
|
|
41
|
-
return builder.join(' ').trim();
|
|
42
|
-
}
|
|
43
|
-
exports.formatHumanName = formatHumanName;
|
|
44
|
-
function formatGivenName(name) {
|
|
45
|
-
const builder = [];
|
|
46
|
-
if (name.given) {
|
|
47
|
-
builder.push(...name.given);
|
|
48
|
-
}
|
|
49
|
-
return builder.join(' ').trim();
|
|
50
|
-
}
|
|
51
|
-
exports.formatGivenName = formatGivenName;
|
|
52
|
-
function formatFamilyName(name) {
|
|
53
|
-
return name.family || '';
|
|
54
|
-
}
|
|
55
|
-
exports.formatFamilyName = formatFamilyName;
|
|
56
|
-
//# sourceMappingURL=format.js.map
|
package/dist/format.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";;;AAcA,SAAgB,aAAa,CAAC,OAAgB,EAAE,OAA8B;IAC5E,MAAM,OAAO,GAAG,EAAE,CAAC;IAEnB,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/B;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC5B;IAED,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAC7B;IAED,IAAI,OAAO,CAAC,UAAU,EAAE;QACtB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;KAClC;IAED,IAAI,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,CAAC,EAAE;QACjD,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;KACvC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC;AAxBD,sCAwBC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AC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;KAC7B;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC;AAND,0CAMC;AAED,SAAgB,gBAAgB,CAAC,IAAe;IAC9C,OAAO,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;AAC3B,CAAC;AAFD,4CAEC","sourcesContent":["import { Address, HumanName } from '@medplum/fhirtypes';\n\nexport interface AddressFormatOptions {\n all?: boolean;\n use?: boolean;\n}\n\nexport interface HumanNameFormatOptions {\n all?: boolean;\n prefix?: boolean;\n suffix?: boolean;\n use?: boolean;\n}\n\nexport function formatAddress(address: Address, options?: AddressFormatOptions): string {\n const builder = [];\n\n if (address.line) {\n builder.push(...address.line);\n }\n\n if (address.city) {\n builder.push(address.city);\n }\n\n if (address.state) {\n builder.push(address.state);\n }\n\n if (address.postalCode) {\n builder.push(address.postalCode);\n }\n\n if (address.use && (options?.all || options?.use)) {\n builder.push('[' + address.use + ']');\n }\n\n return builder.join(', ').trim();\n}\n\nexport function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string {\n const builder = [];\n\n if (name.prefix && (options?.all || options?.prefix)) {\n builder.push(...name.prefix);\n }\n\n if (name.given) {\n builder.push(...name.given);\n }\n\n if (name.family) {\n builder.push(name.family);\n }\n\n if (name.suffix && (options?.all || options?.suffix)) {\n builder.push(...name.suffix);\n }\n\n if (name.use && (options?.all || options?.use)) {\n builder.push('[' + name.use + ']');\n }\n\n return builder.join(' ').trim();\n}\n\nexport function formatGivenName(name: HumanName): string {\n const builder: string[] = [];\n if (name.given) {\n builder.push(...name.given);\n }\n return builder.join(' ').trim();\n}\n\nexport function formatFamilyName(name: HumanName): string {\n return name.family || '';\n}\n"]}
|
package/dist/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./client"), exports);
|
|
14
|
-
__exportStar(require("./format"), exports);
|
|
15
|
-
__exportStar(require("./outcomes"), exports);
|
|
16
|
-
__exportStar(require("./search"), exports);
|
|
17
|
-
__exportStar(require("./searchparams"), exports);
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB","sourcesContent":["export * from './client';\nexport * from './format';\nexport * from './outcomes';\nexport * from './search';\nexport * from './searchparams';\nexport * from './types';\nexport * from './utils';\n"]}
|
package/dist/jwt.d.ts
DELETED
package/dist/jwt.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJWTPayload = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Decodes a section of a JWT.
|
|
6
|
-
* See: https://tools.ietf.org/html/rfc7519
|
|
7
|
-
* @param payload
|
|
8
|
-
*/
|
|
9
|
-
function decodePayload(payload) {
|
|
10
|
-
const cleanedPayload = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
11
|
-
const decodedPayload = window.atob(cleanedPayload);
|
|
12
|
-
const uriEncodedPayload = Array.from(decodedPayload).reduce((acc, char) => {
|
|
13
|
-
const uriEncodedChar = ('00' + char.charCodeAt(0).toString(16)).slice(-2);
|
|
14
|
-
return `${acc}%${uriEncodedChar}`;
|
|
15
|
-
}, '');
|
|
16
|
-
const jsonPayload = decodeURIComponent(uriEncodedPayload);
|
|
17
|
-
return JSON.parse(jsonPayload);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Parses the JWT payload.
|
|
21
|
-
* @param token JWT token
|
|
22
|
-
*/
|
|
23
|
-
function parseJWTPayload(token) {
|
|
24
|
-
const [_header, payload, _signature] = token.split('.');
|
|
25
|
-
return decodePayload(payload);
|
|
26
|
-
}
|
|
27
|
-
exports.parseJWTPayload = parseJWTPayload;
|
|
28
|
-
//# sourceMappingURL=jwt.js.map
|
package/dist/jwt.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAe;IACpC,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrE,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACnD,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACxE,MAAM,cAAc,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,OAAO,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IACpC,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,WAAW,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAHD,0CAGC","sourcesContent":["/**\n * Decodes a section of a JWT.\n * See: https://tools.ietf.org/html/rfc7519\n * @param payload\n */\nfunction decodePayload(payload: string) {\n const cleanedPayload = payload.replace(/-/g, '+').replace(/_/g, '/');\n const decodedPayload = window.atob(cleanedPayload);\n const uriEncodedPayload = Array.from(decodedPayload).reduce((acc, char) => {\n const uriEncodedChar = ('00' + char.charCodeAt(0).toString(16)).slice(-2);\n return `${acc}%${uriEncodedChar}`;\n }, '');\n const jsonPayload = decodeURIComponent(uriEncodedPayload);\n return JSON.parse(jsonPayload);\n}\n\n/**\n * Parses the JWT payload.\n * @param token JWT token\n */\nexport function parseJWTPayload(token: string) {\n const [_header, payload, _signature] = token.split('.');\n return decodePayload(payload);\n}\n"]}
|
package/dist/outcomes.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OperationOutcomeError = exports.assertOk = exports.getStatus = exports.isGone = exports.isNotFound = exports.isOk = exports.badRequest = exports.accessDenied = exports.gone = exports.notFound = exports.notModified = exports.created = exports.allOk = void 0;
|
|
4
|
-
const OK_ID = 'ok';
|
|
5
|
-
const CREATED_ID = 'created';
|
|
6
|
-
const GONE_ID = 'gone';
|
|
7
|
-
const NOT_MODIFIED_ID = 'not-modified';
|
|
8
|
-
const NOT_FOUND_ID = 'not-found';
|
|
9
|
-
const ACCESS_DENIED = 'access-denied';
|
|
10
|
-
exports.allOk = {
|
|
11
|
-
resourceType: 'OperationOutcome',
|
|
12
|
-
id: OK_ID,
|
|
13
|
-
issue: [
|
|
14
|
-
{
|
|
15
|
-
severity: 'information',
|
|
16
|
-
code: 'information',
|
|
17
|
-
details: {
|
|
18
|
-
text: 'All OK',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
};
|
|
23
|
-
exports.created = {
|
|
24
|
-
resourceType: 'OperationOutcome',
|
|
25
|
-
id: CREATED_ID,
|
|
26
|
-
issue: [
|
|
27
|
-
{
|
|
28
|
-
severity: 'information',
|
|
29
|
-
code: 'information',
|
|
30
|
-
details: {
|
|
31
|
-
text: 'Created',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
exports.notModified = {
|
|
37
|
-
resourceType: 'OperationOutcome',
|
|
38
|
-
id: NOT_MODIFIED_ID,
|
|
39
|
-
issue: [
|
|
40
|
-
{
|
|
41
|
-
severity: 'information',
|
|
42
|
-
code: 'information',
|
|
43
|
-
details: {
|
|
44
|
-
text: 'Not Modified',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
};
|
|
49
|
-
exports.notFound = {
|
|
50
|
-
resourceType: 'OperationOutcome',
|
|
51
|
-
id: NOT_FOUND_ID,
|
|
52
|
-
issue: [
|
|
53
|
-
{
|
|
54
|
-
severity: 'error',
|
|
55
|
-
code: 'not-found',
|
|
56
|
-
details: {
|
|
57
|
-
text: 'Not found',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
};
|
|
62
|
-
exports.gone = {
|
|
63
|
-
resourceType: 'OperationOutcome',
|
|
64
|
-
id: GONE_ID,
|
|
65
|
-
issue: [
|
|
66
|
-
{
|
|
67
|
-
severity: 'error',
|
|
68
|
-
code: 'gone',
|
|
69
|
-
details: {
|
|
70
|
-
text: 'Gone',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
};
|
|
75
|
-
exports.accessDenied = {
|
|
76
|
-
resourceType: 'OperationOutcome',
|
|
77
|
-
id: ACCESS_DENIED,
|
|
78
|
-
issue: [
|
|
79
|
-
{
|
|
80
|
-
severity: 'error',
|
|
81
|
-
code: 'access-denied',
|
|
82
|
-
details: {
|
|
83
|
-
text: 'Access Denied',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
};
|
|
88
|
-
function badRequest(details, expression) {
|
|
89
|
-
return {
|
|
90
|
-
resourceType: 'OperationOutcome',
|
|
91
|
-
issue: [
|
|
92
|
-
{
|
|
93
|
-
severity: 'error',
|
|
94
|
-
code: 'invalid',
|
|
95
|
-
details: {
|
|
96
|
-
text: details,
|
|
97
|
-
},
|
|
98
|
-
expression: expression ? [expression] : undefined,
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
exports.badRequest = badRequest;
|
|
104
|
-
function isOk(outcome) {
|
|
105
|
-
return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
|
|
106
|
-
}
|
|
107
|
-
exports.isOk = isOk;
|
|
108
|
-
function isNotFound(outcome) {
|
|
109
|
-
return outcome.id === NOT_FOUND_ID;
|
|
110
|
-
}
|
|
111
|
-
exports.isNotFound = isNotFound;
|
|
112
|
-
function isGone(outcome) {
|
|
113
|
-
return outcome.id === GONE_ID;
|
|
114
|
-
}
|
|
115
|
-
exports.isGone = isGone;
|
|
116
|
-
function getStatus(outcome) {
|
|
117
|
-
if (outcome.id === OK_ID) {
|
|
118
|
-
return 200;
|
|
119
|
-
}
|
|
120
|
-
else if (outcome.id === CREATED_ID) {
|
|
121
|
-
return 201;
|
|
122
|
-
}
|
|
123
|
-
else if (outcome.id === NOT_MODIFIED_ID) {
|
|
124
|
-
return 304;
|
|
125
|
-
}
|
|
126
|
-
else if (outcome.id === ACCESS_DENIED) {
|
|
127
|
-
return 403;
|
|
128
|
-
}
|
|
129
|
-
else if (outcome.id === NOT_FOUND_ID) {
|
|
130
|
-
return 404;
|
|
131
|
-
}
|
|
132
|
-
else if (outcome.id === GONE_ID) {
|
|
133
|
-
return 410;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
return 400;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.getStatus = getStatus;
|
|
140
|
-
function assertOk(outcome) {
|
|
141
|
-
if (!isOk(outcome)) {
|
|
142
|
-
throw new OperationOutcomeError(outcome);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.assertOk = assertOk;
|
|
146
|
-
class OperationOutcomeError extends Error {
|
|
147
|
-
constructor(outcome) {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
|
|
150
|
-
this.outcome = outcome;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.OperationOutcomeError = OperationOutcomeError;
|
|
154
|
-
//# sourceMappingURL=outcomes.js.map
|
package/dist/outcomes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"outcomes.js","sourceRoot":"","sources":["../src/outcomes.ts"],"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,aAAa,GAAG,eAAe,CAAC;AAEzB,QAAA,KAAK,GAAqB;IACrC,YAA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GAAG,CAAC;KACZ;SAAM;QACL,OAAO,GAAG,CAAC;KACZ;AACH,CAAC;AAhBD,8BAgBC;AAED,SAAgB,QAAQ,CAAC,OAAyB;IAChD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAClB,MAAM,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;KAC1C;AACH,CAAC;AAJD,4BAIC;AAED,MAAa,qBAAsB,SAAQ,KAAK;IAG9C,YAAY,OAAyB;;QACnC,KAAK,CAAC,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAG,CAAC,EAAE,OAAO,0CAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAPD,sDAOC","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 ACCESS_DENIED = 'access-denied';\n\nexport const allOk: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: OK_ID,\n issue: [\n {\n severity: 'information',\n code: 'information',\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: 'information',\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: 'information',\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 gone: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: GONE_ID,\n issue: [\n {\n severity: 'error',\n code: 'gone',\n details: {\n text: 'Gone',\n },\n },\n ],\n};\n\nexport const accessDenied: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: ACCESS_DENIED,\n issue: [\n {\n severity: 'error',\n code: 'access-denied',\n details: {\n text: 'Access Denied',\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 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 === ACCESS_DENIED) {\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 {\n return 400;\n }\n}\n\nexport function assertOk(outcome: OperationOutcome): void {\n if (!isOk(outcome)) {\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"]}
|
package/dist/search.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatSearchQuery = exports.parseSearchDefinition = exports.Operator = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Search operators.
|
|
6
|
-
* These operators represent "modifiers" and "prefixes" in FHIR search.
|
|
7
|
-
* See: https://www.hl7.org/fhir/search.html
|
|
8
|
-
*/
|
|
9
|
-
var Operator;
|
|
10
|
-
(function (Operator) {
|
|
11
|
-
Operator["EQUALS"] = "eq";
|
|
12
|
-
Operator["NOT_EQUALS"] = "ne";
|
|
13
|
-
// Numbers
|
|
14
|
-
Operator["GREATER_THAN"] = "gt";
|
|
15
|
-
Operator["LESS_THAN"] = "lt";
|
|
16
|
-
Operator["GREATER_THAN_OR_EQUALS"] = "ge";
|
|
17
|
-
Operator["LESS_THAN_OR_EQUALS"] = "le";
|
|
18
|
-
// Dates
|
|
19
|
-
Operator["STARTS_AFTER"] = "sa";
|
|
20
|
-
Operator["ENDS_BEFORE"] = "eb";
|
|
21
|
-
Operator["APPROXIMATELY"] = "ap";
|
|
22
|
-
// String
|
|
23
|
-
Operator["CONTAINS"] = "contains";
|
|
24
|
-
Operator["EXACT"] = "exact";
|
|
25
|
-
// Token
|
|
26
|
-
Operator["TEXT"] = "text";
|
|
27
|
-
Operator["ABOVE"] = "above";
|
|
28
|
-
Operator["BELOW"] = "below";
|
|
29
|
-
Operator["IN"] = "in";
|
|
30
|
-
Operator["NOT_IN"] = "not-in";
|
|
31
|
-
Operator["OF_TYPE"] = "of-type";
|
|
32
|
-
})(Operator = exports.Operator || (exports.Operator = {}));
|
|
33
|
-
/**
|
|
34
|
-
* Parses a URL into a SearchRequest.
|
|
35
|
-
* @param location The URL to parse.
|
|
36
|
-
* @returns Parsed search definition.
|
|
37
|
-
*/
|
|
38
|
-
function parseSearchDefinition(location) {
|
|
39
|
-
const resourceType = location.pathname.split('/').pop();
|
|
40
|
-
const params = new URLSearchParams(location.search);
|
|
41
|
-
const filters = [];
|
|
42
|
-
const sortRules = [];
|
|
43
|
-
let fields;
|
|
44
|
-
let page = 0;
|
|
45
|
-
let count = 10;
|
|
46
|
-
params.forEach((value, key) => {
|
|
47
|
-
if (key === '_fields') {
|
|
48
|
-
fields = value.split(',');
|
|
49
|
-
}
|
|
50
|
-
else if (key === '_sort') {
|
|
51
|
-
if (value.startsWith('-')) {
|
|
52
|
-
sortRules.push({ code: value.substr(1), descending: true });
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
sortRules.push({ code: value });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (key === '_page') {
|
|
59
|
-
page = parseInt(value);
|
|
60
|
-
}
|
|
61
|
-
else if (key === '_count') {
|
|
62
|
-
count = parseInt(value);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
filters.push({
|
|
66
|
-
code: key,
|
|
67
|
-
operator: Operator.EQUALS,
|
|
68
|
-
value: value,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
resourceType,
|
|
74
|
-
filters,
|
|
75
|
-
fields,
|
|
76
|
-
page,
|
|
77
|
-
count,
|
|
78
|
-
sortRules,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
exports.parseSearchDefinition = parseSearchDefinition;
|
|
82
|
-
/**
|
|
83
|
-
* Formats a search definition object into a query string.
|
|
84
|
-
* Note: The return value does not include the resource type.
|
|
85
|
-
* @param {!SearchRequest} definition The search definition.
|
|
86
|
-
* @returns Formatted URL.
|
|
87
|
-
*/
|
|
88
|
-
function formatSearchQuery(definition) {
|
|
89
|
-
const params = [];
|
|
90
|
-
if (definition.fields) {
|
|
91
|
-
params.push('_fields=' + definition.fields.join(','));
|
|
92
|
-
}
|
|
93
|
-
if (definition.filters) {
|
|
94
|
-
definition.filters.forEach((filter) => {
|
|
95
|
-
params.push(filter.code + '=' + filter.value);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (definition.sortRules) {
|
|
99
|
-
params.push(formatSortRules(definition.sortRules));
|
|
100
|
-
}
|
|
101
|
-
if (definition.page && definition.page > 0) {
|
|
102
|
-
params.push('_page=' + definition.page);
|
|
103
|
-
}
|
|
104
|
-
if (definition.count && definition.count > 0) {
|
|
105
|
-
params.push('_count=' + definition.count);
|
|
106
|
-
}
|
|
107
|
-
if (params.length === 0) {
|
|
108
|
-
return '';
|
|
109
|
-
}
|
|
110
|
-
params.sort();
|
|
111
|
-
return '?' + params.join('&');
|
|
112
|
-
}
|
|
113
|
-
exports.formatSearchQuery = formatSearchQuery;
|
|
114
|
-
function formatSortRules(sortRules) {
|
|
115
|
-
if (!sortRules || sortRules.length === 0) {
|
|
116
|
-
return '';
|
|
117
|
-
}
|
|
118
|
-
return '_sort=' + sortRules.map((sr) => (sr.descending ? '-' + sr.code : sr.code)).join(',');
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=search.js.map
|
package/dist/search.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":";;;AAuBA;;;;GAIG;AACH,IAAY,QA0BX;AA1BD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,6BAAiB,CAAA;IAEjB,UAAU;IACV,+BAAmB,CAAA;IACnB,4BAAgB,CAAA;IAChB,yCAA6B,CAAA;IAC7B,sCAA0B,CAAA;IAE1B,QAAQ;IACR,+BAAmB,CAAA;IACnB,8BAAkB,CAAA;IAClB,gCAAoB,CAAA;IAEpB,SAAS;IACT,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IAEf,QAAQ;IACR,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,qBAAS,CAAA;IACT,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;AACrB,CAAC,EA1BW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QA0BnB;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,QAA+C;IACnF,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAY,CAAC;IAClE,MAAM,MAAM,GAAG,IAAI,eAAe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,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["export interface SearchRequest {\n readonly resourceType: string;\n readonly filters?: Filter[];\n readonly sortRules?: SortRule[];\n readonly page?: number;\n readonly count?: number;\n readonly fields?: string[];\n readonly name?: string;\n}\n\nexport interface Filter {\n code: string;\n operator: Operator;\n value: string;\n unitSystem?: string;\n unitCode?: string;\n}\n\nexport interface SortRule {\n code: string;\n descending?: boolean;\n}\n\n/**\n * Search operators.\n * These operators represent \"modifiers\" and \"prefixes\" in FHIR search.\n * See: https://www.hl7.org/fhir/search.html\n */\nexport enum Operator {\n EQUALS = 'eq',\n NOT_EQUALS = 'ne',\n\n // Numbers\n GREATER_THAN = 'gt',\n LESS_THAN = 'lt',\n GREATER_THAN_OR_EQUALS = 'ge',\n LESS_THAN_OR_EQUALS = 'le',\n\n // Dates\n STARTS_AFTER = 'sa',\n ENDS_BEFORE = 'eb',\n APPROXIMATELY = 'ap',\n\n // String\n CONTAINS = 'contains',\n EXACT = 'exact',\n\n // Token\n TEXT = 'text',\n ABOVE = 'above',\n BELOW = 'below',\n IN = 'in',\n NOT_IN = 'not-in',\n OF_TYPE = 'of-type',\n}\n\n/**\n * Parses a URL into a SearchRequest.\n * @param location The URL to parse.\n * @returns Parsed search definition.\n */\nexport function parseSearchDefinition(location: { pathname: string; search?: string }): SearchRequest {\n const resourceType = location.pathname.split('/').pop() as string;\n const params = new URLSearchParams(location.search);\n const filters: Filter[] = [];\n const sortRules: SortRule[] = [];\n let fields;\n let page = 0;\n let count = 10;\n\n params.forEach((value, key) => {\n if (key === '_fields') {\n fields = value.split(',');\n } else if (key === '_sort') {\n if (value.startsWith('-')) {\n sortRules.push({ code: value.substr(1), descending: true });\n } else {\n sortRules.push({ code: value });\n }\n } else if (key === '_page') {\n page = parseInt(value);\n } else if (key === '_count') {\n count = parseInt(value);\n } else {\n filters.push({\n code: key,\n operator: Operator.EQUALS,\n value: value,\n });\n }\n });\n\n return {\n resourceType,\n filters,\n fields,\n page,\n count,\n sortRules,\n };\n}\n\n/**\n * Formats a search definition object into a query string.\n * Note: The return value does not include the resource type.\n * @param {!SearchRequest} definition The search definition.\n * @returns Formatted URL.\n */\nexport function formatSearchQuery(definition: SearchRequest): string {\n const params: string[] = [];\n\n if (definition.fields) {\n params.push('_fields=' + definition.fields.join(','));\n }\n\n if (definition.filters) {\n definition.filters.forEach((filter) => {\n params.push(filter.code + '=' + filter.value);\n });\n }\n\n if (definition.sortRules) {\n params.push(formatSortRules(definition.sortRules));\n }\n\n if (definition.page && definition.page > 0) {\n params.push('_page=' + definition.page);\n }\n\n if (definition.count && definition.count > 0) {\n params.push('_count=' + definition.count);\n }\n\n if (params.length === 0) {\n return '';\n }\n\n params.sort();\n return '?' + params.join('&');\n}\n\nfunction formatSortRules(sortRules: SortRule[] | undefined): string {\n if (!sortRules || sortRules.length === 0) {\n return '';\n }\n return '_sort=' + sortRules.map((sr) => (sr.descending ? '-' + sr.code : sr.code)).join(',');\n}\n"]}
|
package/dist/searchparams.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExpressionForResourceType = exports.getSearchParameterDetails = exports.SearchParameterType = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
var SearchParameterType;
|
|
6
|
-
(function (SearchParameterType) {
|
|
7
|
-
SearchParameterType["BOOLEAN"] = "BOOLEAN";
|
|
8
|
-
SearchParameterType["NUMBER"] = "NUMBER";
|
|
9
|
-
SearchParameterType["QUANTITY"] = "QUANTITY";
|
|
10
|
-
SearchParameterType["TEXT"] = "TEXT";
|
|
11
|
-
SearchParameterType["REFERENCE"] = "REFERENCE";
|
|
12
|
-
SearchParameterType["DATE"] = "DATE";
|
|
13
|
-
SearchParameterType["DATETIME"] = "DATETIME";
|
|
14
|
-
SearchParameterType["PERIOD"] = "PERIOD";
|
|
15
|
-
})(SearchParameterType = exports.SearchParameterType || (exports.SearchParameterType = {}));
|
|
16
|
-
/**
|
|
17
|
-
* Returns the type details of a SearchParameter.
|
|
18
|
-
*
|
|
19
|
-
* The SearchParameter resource has a "type" parameter, but that is missing some critical information.
|
|
20
|
-
*
|
|
21
|
-
* For example:
|
|
22
|
-
* 1) The "date" type includes "date", "datetime", and "period".
|
|
23
|
-
* 2) The "token" type includes enums and booleans.
|
|
24
|
-
* 3) Arrays/multiple values are not reflected at all.
|
|
25
|
-
*
|
|
26
|
-
* @param structureDefinitions Collection of StructureDefinition resources indexed by name.
|
|
27
|
-
* @param resourceType The root resource type.
|
|
28
|
-
* @param searchParam The search parameter.
|
|
29
|
-
* @returns The search parameter type details.
|
|
30
|
-
*/
|
|
31
|
-
function getSearchParameterDetails(structureDefinitions, resourceType, searchParam) {
|
|
32
|
-
var _a, _b, _c, _d;
|
|
33
|
-
const columnName = convertCodeToColumnName(searchParam.code);
|
|
34
|
-
const expression = (_a = getExpressionForResourceType(resourceType, searchParam.expression)) === null || _a === void 0 ? void 0 : _a.split('.');
|
|
35
|
-
if (!expression) {
|
|
36
|
-
// This happens on compound types
|
|
37
|
-
// In the future, explore returning multiple column definitions
|
|
38
|
-
return { columnName, type: SearchParameterType.TEXT };
|
|
39
|
-
}
|
|
40
|
-
let baseType = resourceType;
|
|
41
|
-
let propertyType = undefined;
|
|
42
|
-
let array = false;
|
|
43
|
-
for (let i = 1; i < expression.length; i++) {
|
|
44
|
-
const propertyName = expression[i];
|
|
45
|
-
const propertyDef = (_c = (_b = structureDefinitions.types[baseType]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[propertyName];
|
|
46
|
-
if (!propertyDef) {
|
|
47
|
-
// This happens on complex properties such as "collected[x]"/"collectedDateTime"/"collectedPeriod"
|
|
48
|
-
// In the future, explore returning multiple column definitions
|
|
49
|
-
return { columnName, type: SearchParameterType.TEXT, array };
|
|
50
|
-
}
|
|
51
|
-
if (propertyDef.max === '*') {
|
|
52
|
-
array = true;
|
|
53
|
-
}
|
|
54
|
-
propertyType = (_d = propertyDef.type) === null || _d === void 0 ? void 0 : _d[0].code;
|
|
55
|
-
if (!propertyType) {
|
|
56
|
-
// This happens when one of parent properties uses contentReference
|
|
57
|
-
// In the future, explore following the reference
|
|
58
|
-
return { columnName, type: SearchParameterType.TEXT, array };
|
|
59
|
-
}
|
|
60
|
-
if (i < expression.length - 1) {
|
|
61
|
-
if (propertyType === 'Element' || propertyType === 'BackboneElement') {
|
|
62
|
-
baseType = baseType + (0, utils_1.capitalize)(propertyName);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
baseType = propertyType;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const type = getSearchParameterType(searchParam, propertyType);
|
|
70
|
-
return { columnName, type, array };
|
|
71
|
-
}
|
|
72
|
-
exports.getSearchParameterDetails = getSearchParameterDetails;
|
|
73
|
-
/**
|
|
74
|
-
* Converts a hyphen-delimited code to camelCase string.
|
|
75
|
-
* @param code The search parameter code.
|
|
76
|
-
* @returns The SQL column name.
|
|
77
|
-
*/
|
|
78
|
-
function convertCodeToColumnName(code) {
|
|
79
|
-
return code.split('-').reduce((result, word, index) => result + (index ? (0, utils_1.capitalize)(word) : word), '');
|
|
80
|
-
}
|
|
81
|
-
function getSearchParameterType(searchParam, propertyType) {
|
|
82
|
-
let type = SearchParameterType.TEXT;
|
|
83
|
-
switch (searchParam.type) {
|
|
84
|
-
case 'date':
|
|
85
|
-
type = SearchParameterType.DATE;
|
|
86
|
-
break;
|
|
87
|
-
case 'number':
|
|
88
|
-
type = SearchParameterType.NUMBER;
|
|
89
|
-
break;
|
|
90
|
-
case 'quantity':
|
|
91
|
-
type = SearchParameterType.QUANTITY;
|
|
92
|
-
break;
|
|
93
|
-
case 'reference':
|
|
94
|
-
type = SearchParameterType.REFERENCE;
|
|
95
|
-
break;
|
|
96
|
-
case 'token':
|
|
97
|
-
if (propertyType === 'boolean') {
|
|
98
|
-
type = SearchParameterType.BOOLEAN;
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
return type;
|
|
103
|
-
}
|
|
104
|
-
function getExpressionForResourceType(resourceType, expression) {
|
|
105
|
-
const expressions = expression.split(' | ');
|
|
106
|
-
for (const e of expressions) {
|
|
107
|
-
const simplified = simplifyExpression(e);
|
|
108
|
-
if (simplified.startsWith(resourceType + '.')) {
|
|
109
|
-
return simplified;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
exports.getExpressionForResourceType = getExpressionForResourceType;
|
|
115
|
-
function simplifyExpression(input) {
|
|
116
|
-
let result = input.trim();
|
|
117
|
-
if (result.startsWith('(') && result.endsWith(')')) {
|
|
118
|
-
result = result.substring(1, result.length - 1);
|
|
119
|
-
}
|
|
120
|
-
if (result.includes(' as ')) {
|
|
121
|
-
result = result.substring(0, result.indexOf(' as '));
|
|
122
|
-
}
|
|
123
|
-
if (result.includes('.where(')) {
|
|
124
|
-
result = result.substring(0, result.indexOf('.where('));
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=searchparams.js.map
|