@medplum/core 0.3.0 → 0.5.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 +5 -3
- package/dist/cjs/index.js +1842 -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 +1792 -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} +1 -3
- package/dist/{client.d.ts → types/client.d.ts} +54 -69
- package/dist/{crypto.d.ts → types/crypto.d.ts} +0 -0
- package/dist/{eventtarget.d.ts → types/eventtarget.d.ts} +3 -3
- 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} +4 -0
- package/dist/{searchparams.d.ts → types/searchparams.d.ts} +2 -1
- package/dist/{storage.d.ts → types/storage.d.ts} +2 -2
- package/dist/{types.d.ts → types/types.d.ts} +18 -3
- package/dist/{utils.d.ts → types/utils.d.ts} +6 -0
- package/package.json +11 -5
- 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/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
|
package/dist/searchparams.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"searchparams.js","sourceRoot":"","sources":["../src/searchparams.ts"],"names":[],"mappings":";;;AAEA,mCAAqC;AAErC,IAAY,mBASX;AATD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,wCAAiB,CAAA;IACjB,4CAAqB,CAAA;IACrB,oCAAa,CAAA;IACb,8CAAuB,CAAA;IACvB,oCAAa,CAAA;IACb,4CAAqB,CAAA;IACrB,wCAAiB,CAAA;AACnB,CAAC,EATW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAS9B;AAQD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,yBAAyB,CACvC,oBAAgD,EAChD,YAAoB,EACpB,WAA4B;;IAE5B,MAAM,UAAU,GAAG,uBAAuB,CAAC,WAAW,CAAC,IAAc,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,MAAA,4BAA4B,CAAC,YAAY,EAAE,WAAW,CAAC,UAAoB,CAAC,0CAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5G,IAAI,CAAC,UAAU,EAAE;QACf,iCAAiC;QACjC,+DAA+D;QAC/D,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,CAAC;KACvD;IAED,IAAI,QAAQ,GAAG,YAAY,CAAC;IAC5B,IAAI,YAAY,GAAG,SAAS,CAAC;IAC7B,IAAI,KAAK,GAAG,KAAK,CAAC;IAElB,KAAK,IAA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,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAClD,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KACjD;IAED,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC3B,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;KACtD;IAED,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;QAC9B,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;KACzD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { SearchParameter } from '@medplum/fhirtypes';\nimport { IndexedStructureDefinition } from './types';\nimport { capitalize } from './utils';\n\nexport enum SearchParameterType {\n BOOLEAN = 'BOOLEAN',\n NUMBER = 'NUMBER',\n QUANTITY = 'QUANTITY',\n TEXT = 'TEXT',\n REFERENCE = 'REFERENCE',\n DATE = 'DATE',\n DATETIME = 'DATETIME',\n PERIOD = 'PERIOD',\n}\n\nexport interface SearchParameterDetails {\n readonly columnName: string;\n readonly type: SearchParameterType;\n readonly array?: boolean;\n}\n\n/**\n * Returns the type details of a SearchParameter.\n *\n * The SearchParameter resource has a \"type\" parameter, but that is missing some critical information.\n *\n * For example:\n * 1) The \"date\" type includes \"date\", \"datetime\", and \"period\".\n * 2) The \"token\" type includes enums and booleans.\n * 3) Arrays/multiple values are not reflected at all.\n *\n * @param structureDefinitions Collection of StructureDefinition resources indexed by name.\n * @param resourceType The root resource type.\n * @param searchParam The search parameter.\n * @returns The search parameter type details.\n */\nexport function getSearchParameterDetails(\n structureDefinitions: IndexedStructureDefinition,\n resourceType: string,\n searchParam: SearchParameter\n): SearchParameterDetails {\n const columnName = convertCodeToColumnName(searchParam.code as string);\n const expression = getExpressionForResourceType(resourceType, searchParam.expression as string)?.split('.');\n if (!expression) {\n // This happens on compound types\n // In the future, explore returning multiple column definitions\n return { columnName, type: SearchParameterType.TEXT };\n }\n\n let baseType = resourceType;\n let propertyType = undefined;\n let array = false;\n\n for (let i = 1; i < expression.length; i++) {\n const propertyName = expression[i];\n const propertyDef = structureDefinitions.types[baseType]?.properties?.[propertyName];\n if (!propertyDef) {\n // This happens on complex properties such as \"collected[x]\"/\"collectedDateTime\"/\"collectedPeriod\"\n // In the future, explore returning multiple column definitions\n return { columnName, type: SearchParameterType.TEXT, array };\n }\n\n if (propertyDef.max === '*') {\n array = true;\n }\n\n propertyType = propertyDef.type?.[0].code;\n if (!propertyType) {\n // This happens when one of parent properties uses contentReference\n // In the future, explore following the reference\n return { columnName, type: SearchParameterType.TEXT, array };\n }\n\n if (i < expression.length - 1) {\n if (propertyType === 'Element' || propertyType === 'BackboneElement') {\n baseType = baseType + capitalize(propertyName);\n } else {\n baseType = propertyType;\n }\n }\n }\n\n const type = getSearchParameterType(searchParam, propertyType as string);\n return { columnName, type, array };\n}\n\n/**\n * Converts a hyphen-delimited code to camelCase string.\n * @param code The search parameter code.\n * @returns The SQL column name.\n */\nfunction convertCodeToColumnName(code: string): string {\n return code.split('-').reduce((result, word, index) => result + (index ? capitalize(word) : word), '');\n}\n\nfunction getSearchParameterType(searchParam: SearchParameter, propertyType: string): SearchParameterType {\n let type = SearchParameterType.TEXT;\n switch (searchParam.type) {\n case 'date':\n type = SearchParameterType.DATE;\n break;\n case 'number':\n type = SearchParameterType.NUMBER;\n break;\n case 'quantity':\n type = SearchParameterType.QUANTITY;\n break;\n case 'reference':\n type = SearchParameterType.REFERENCE;\n break;\n case 'token':\n if (propertyType === 'boolean') {\n type = SearchParameterType.BOOLEAN;\n }\n break;\n }\n return type;\n}\n\nexport function getExpressionForResourceType(resourceType: string, expression: string): string | undefined {\n const expressions = expression.split(' | ');\n for (const e of expressions) {\n const simplified = simplifyExpression(e);\n if (simplified.startsWith(resourceType + '.')) {\n return simplified;\n }\n }\n return undefined;\n}\n\nfunction simplifyExpression(input: string): string {\n let result = input.trim();\n\n if (result.startsWith('(') && result.endsWith(')')) {\n result = result.substring(1, result.length - 1);\n }\n\n if (result.includes(' as ')) {\n result = result.substring(0, result.indexOf(' as '));\n }\n\n if (result.includes('.where(')) {\n result = result.substring(0, result.indexOf('.where('));\n }\n\n return result;\n}\n"]}
|
package/dist/storage.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryStorage = exports.ClientStorage = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
/**
|
|
6
|
-
* The ClientStorage class is a utility class for storing strings and objects.
|
|
7
|
-
*
|
|
8
|
-
* When using MedplumClient in the browser, it will be backed by browser localStorage.
|
|
9
|
-
*
|
|
10
|
-
* When Using MedplumClient in the server, it will be backed by the MemoryStorage class.
|
|
11
|
-
*/
|
|
12
|
-
class ClientStorage {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.storage = typeof localStorage !== 'undefined' ? localStorage : new MemoryStorage();
|
|
15
|
-
}
|
|
16
|
-
clear() {
|
|
17
|
-
this.storage.clear();
|
|
18
|
-
}
|
|
19
|
-
getString(key) {
|
|
20
|
-
return this.storage.getItem(key) || undefined;
|
|
21
|
-
}
|
|
22
|
-
setString(key, value) {
|
|
23
|
-
if (value) {
|
|
24
|
-
this.storage.setItem(key, value);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.storage.removeItem(key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
getObject(key) {
|
|
31
|
-
const str = this.getString(key);
|
|
32
|
-
return str ? JSON.parse(str) : undefined;
|
|
33
|
-
}
|
|
34
|
-
setObject(key, value) {
|
|
35
|
-
this.setString(key, value ? (0, utils_1.stringify)(value) : undefined);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.ClientStorage = ClientStorage;
|
|
39
|
-
/**
|
|
40
|
-
* The MemoryStorage class is a minimal in-memory implementation of the Storage interface.
|
|
41
|
-
*/
|
|
42
|
-
class MemoryStorage {
|
|
43
|
-
constructor() {
|
|
44
|
-
this.data = new Map();
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns the number of key/value pairs.
|
|
48
|
-
*/
|
|
49
|
-
get length() {
|
|
50
|
-
return this.data.size;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Removes all key/value pairs, if there are any.
|
|
54
|
-
*/
|
|
55
|
-
clear() {
|
|
56
|
-
this.data.clear();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns the current value associated with the given key, or null if the given key does not exist.
|
|
60
|
-
*/
|
|
61
|
-
getItem(key) {
|
|
62
|
-
var _a;
|
|
63
|
-
return (_a = this.data.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
67
|
-
*/
|
|
68
|
-
setItem(key, value) {
|
|
69
|
-
if (value) {
|
|
70
|
-
this.data.set(key, value);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.data.delete(key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Removes the key/value pair with the given key, if a key/value pair with the given key exists.
|
|
78
|
-
*/
|
|
79
|
-
removeItem(key) {
|
|
80
|
-
this.data.delete(key);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns the name of the nth key, or null if n is greater than or equal to the number of key/value pairs.
|
|
84
|
-
*/
|
|
85
|
-
key(index) {
|
|
86
|
-
return Array.from(this.data.keys())[index];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.MemoryStorage = MemoryStorage;
|
|
90
|
-
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC;;;;;;GAMG;AACH,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,OAAO,GAAG,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,aAAa,EAAE,CAAC;IAC1F,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IAChD,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,KAAyB;QAC9C,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAClC;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SAC9B;IACH,CAAC;IAED,SAAS,CAAI,GAAW;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,GAAG,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC;IAED,SAAS,CAAI,GAAW,EAAE,KAAQ;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;CACF;AA/BD,sCA+BC;AAED;;GAEG;AACH,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAW;;QACjB,OAAO,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,IAAI,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAW,EAAE,KAAoB;QACvC,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAC3B;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SACvB;IACH,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,GAAW;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,KAAa;QACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;CACF;AApDD,sCAoDC","sourcesContent":["import { stringify } from './utils';\n\n/**\n * The ClientStorage class is a utility class for storing strings and objects.\n *\n * When using MedplumClient in the browser, it will be backed by browser localStorage.\n *\n * When Using MedplumClient in the server, it will be backed by the MemoryStorage class.\n */\nexport class ClientStorage {\n private readonly storage: Storage;\n\n constructor() {\n this.storage = typeof localStorage !== 'undefined' ? localStorage : new MemoryStorage();\n }\n\n clear(): void {\n this.storage.clear();\n }\n\n getString(key: string): string | undefined {\n return this.storage.getItem(key) || undefined;\n }\n\n setString(key: string, value: string | undefined): void {\n if (value) {\n this.storage.setItem(key, value);\n } else {\n this.storage.removeItem(key);\n }\n }\n\n getObject<T>(key: string): T | undefined {\n const str = this.getString(key);\n return str ? (JSON.parse(str) as T) : undefined;\n }\n\n setObject<T>(key: string, value: T) {\n this.setString(key, value ? stringify(value) : undefined);\n }\n}\n\n/**\n * The MemoryStorage class is a minimal in-memory implementation of the Storage interface.\n */\nexport class MemoryStorage implements Storage {\n private data: Map<string, string>;\n\n constructor() {\n this.data = new Map<string, string>();\n }\n\n /**\n * Returns the number of key/value pairs.\n */\n get length(): number {\n return this.data.size;\n }\n\n /**\n * Removes all key/value pairs, if there are any.\n */\n clear(): void {\n this.data.clear();\n }\n\n /**\n * Returns the current value associated with the given key, or null if the given key does not exist.\n */\n getItem(key: string): string | null {\n return this.data.get(key) ?? null;\n }\n\n /**\n * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.\n */\n setItem(key: string, value: string | null): void {\n if (value) {\n this.data.set(key, value);\n } else {\n this.data.delete(key);\n }\n }\n\n /**\n * Removes the key/value pair with the given key, if a key/value pair with the given key exists.\n */\n removeItem(key: string): void {\n this.data.delete(key);\n }\n\n /**\n * Returns the name of the nth key, or null if n is greater than or equal to the number of key/value pairs.\n */\n key(index: number): string | null {\n return Array.from(this.data.keys())[index];\n }\n}\n"]}
|
package/dist/types.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPropertyDisplayName = exports.buildTypeName = exports.indexStructureDefinition = exports.PropertyType = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
/**
|
|
6
|
-
* List of property types.
|
|
7
|
-
* http://www.hl7.org/fhir/valueset-defined-types.html
|
|
8
|
-
* The list here includes additions found from StructureDefinition resources.
|
|
9
|
-
*/
|
|
10
|
-
var PropertyType;
|
|
11
|
-
(function (PropertyType) {
|
|
12
|
-
PropertyType["Address"] = "Address";
|
|
13
|
-
PropertyType["Age"] = "Age";
|
|
14
|
-
PropertyType["Annotation"] = "Annotation";
|
|
15
|
-
PropertyType["Attachment"] = "Attachment";
|
|
16
|
-
PropertyType["BackboneElement"] = "BackboneElement";
|
|
17
|
-
PropertyType["CodeableConcept"] = "CodeableConcept";
|
|
18
|
-
PropertyType["Coding"] = "Coding";
|
|
19
|
-
PropertyType["ContactDetail"] = "ContactDetail";
|
|
20
|
-
PropertyType["ContactPoint"] = "ContactPoint";
|
|
21
|
-
PropertyType["Contributor"] = "Contributor";
|
|
22
|
-
PropertyType["Count"] = "Count";
|
|
23
|
-
PropertyType["DataRequirement"] = "DataRequirement";
|
|
24
|
-
PropertyType["Distance"] = "Distance";
|
|
25
|
-
PropertyType["Dosage"] = "Dosage";
|
|
26
|
-
PropertyType["Duration"] = "Duration";
|
|
27
|
-
PropertyType["Expression"] = "Expression";
|
|
28
|
-
PropertyType["Extension"] = "Extension";
|
|
29
|
-
PropertyType["HumanName"] = "HumanName";
|
|
30
|
-
PropertyType["Identifier"] = "Identifier";
|
|
31
|
-
PropertyType["MarketingStatus"] = "MarketingStatus";
|
|
32
|
-
PropertyType["Meta"] = "Meta";
|
|
33
|
-
PropertyType["Money"] = "Money";
|
|
34
|
-
PropertyType["Narrative"] = "Narrative";
|
|
35
|
-
PropertyType["ParameterDefinition"] = "ParameterDefinition";
|
|
36
|
-
PropertyType["Period"] = "Period";
|
|
37
|
-
PropertyType["Population"] = "Population";
|
|
38
|
-
PropertyType["ProdCharacteristic"] = "ProdCharacteristic";
|
|
39
|
-
PropertyType["ProductShelfLife"] = "ProductShelfLife";
|
|
40
|
-
PropertyType["Quantity"] = "Quantity";
|
|
41
|
-
PropertyType["Range"] = "Range";
|
|
42
|
-
PropertyType["Ratio"] = "Ratio";
|
|
43
|
-
PropertyType["Reference"] = "Reference";
|
|
44
|
-
PropertyType["RelatedArtifact"] = "RelatedArtifact";
|
|
45
|
-
PropertyType["Resource"] = "Resource";
|
|
46
|
-
PropertyType["SampledData"] = "SampledData";
|
|
47
|
-
PropertyType["Signature"] = "Signature";
|
|
48
|
-
PropertyType["SubstanceAmount"] = "SubstanceAmount";
|
|
49
|
-
PropertyType["SystemString"] = "http://hl7.org/fhirpath/System.String";
|
|
50
|
-
PropertyType["Timing"] = "Timing";
|
|
51
|
-
PropertyType["TriggerDefinition"] = "TriggerDefinition";
|
|
52
|
-
PropertyType["UsageContext"] = "UsageContext";
|
|
53
|
-
PropertyType["base64Binary"] = "base64Binary";
|
|
54
|
-
PropertyType["boolean"] = "boolean";
|
|
55
|
-
PropertyType["canonical"] = "canonical";
|
|
56
|
-
PropertyType["code"] = "code";
|
|
57
|
-
PropertyType["date"] = "date";
|
|
58
|
-
PropertyType["dateTime"] = "dateTime";
|
|
59
|
-
PropertyType["decimal"] = "decimal";
|
|
60
|
-
PropertyType["id"] = "id";
|
|
61
|
-
PropertyType["instant"] = "instant";
|
|
62
|
-
PropertyType["integer"] = "integer";
|
|
63
|
-
PropertyType["markdown"] = "markdown";
|
|
64
|
-
PropertyType["oid"] = "oid";
|
|
65
|
-
PropertyType["positiveInt"] = "positiveInt";
|
|
66
|
-
PropertyType["string"] = "string";
|
|
67
|
-
PropertyType["time"] = "time";
|
|
68
|
-
PropertyType["unsignedInt"] = "unsignedInt";
|
|
69
|
-
PropertyType["uri"] = "uri";
|
|
70
|
-
PropertyType["url"] = "url";
|
|
71
|
-
PropertyType["uuid"] = "uuid";
|
|
72
|
-
})(PropertyType = exports.PropertyType || (exports.PropertyType = {}));
|
|
73
|
-
/**
|
|
74
|
-
* Indexes a StructureDefinition for fast lookup.
|
|
75
|
-
* See comments on IndexedStructureDefinition for more details.
|
|
76
|
-
* @param structureDefinition The original StructureDefinition.
|
|
77
|
-
* @return An indexed IndexedStructureDefinition.
|
|
78
|
-
*/
|
|
79
|
-
function indexStructureDefinition(structureDefinition, output) {
|
|
80
|
-
var _a;
|
|
81
|
-
const typeName = structureDefinition.name;
|
|
82
|
-
if (!typeName) {
|
|
83
|
-
throw new Error('Invalid StructureDefinition');
|
|
84
|
-
}
|
|
85
|
-
if (!output) {
|
|
86
|
-
output = {
|
|
87
|
-
types: {},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
output.types[typeName] = {
|
|
91
|
-
display: typeName,
|
|
92
|
-
description: structureDefinition.description,
|
|
93
|
-
properties: {},
|
|
94
|
-
};
|
|
95
|
-
const elements = (_a = structureDefinition.snapshot) === null || _a === void 0 ? void 0 : _a.element;
|
|
96
|
-
if (elements) {
|
|
97
|
-
// Filter out any elements missing path or type
|
|
98
|
-
const filtered = elements.filter((e) => e.path !== typeName && e.path); // && e.type && e.type.length > 0);
|
|
99
|
-
// First pass, build types
|
|
100
|
-
filtered.forEach((element) => indexType(output, element));
|
|
101
|
-
// Second pass, build properties
|
|
102
|
-
filtered.forEach((element) => indexProperty(output, element));
|
|
103
|
-
}
|
|
104
|
-
return output;
|
|
105
|
-
}
|
|
106
|
-
exports.indexStructureDefinition = indexStructureDefinition;
|
|
107
|
-
/**
|
|
108
|
-
* Indexes TypeSchema from an ElementDefinition.
|
|
109
|
-
* In the common case, there will be many ElementDefinition instances per TypeSchema.
|
|
110
|
-
* Only the first occurrence is saved.
|
|
111
|
-
* @param output The work-in-progress IndexedStructureDefinition.
|
|
112
|
-
* @param element The input ElementDefinition.
|
|
113
|
-
*/
|
|
114
|
-
function indexType(output, element) {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
const path = element.path;
|
|
117
|
-
const typeCode = (_b = (_a = element.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code;
|
|
118
|
-
if (typeCode !== 'Element' && typeCode !== 'BackboneElement') {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const parts = path.split('.');
|
|
122
|
-
const typeName = buildTypeName(parts);
|
|
123
|
-
if (!(typeName in output.types)) {
|
|
124
|
-
output.types[typeName] = {
|
|
125
|
-
display: typeName,
|
|
126
|
-
description: element.definition,
|
|
127
|
-
parentType: buildTypeName(parts.slice(0, parts.length - 1)),
|
|
128
|
-
properties: {},
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Indexes PropertySchema from an ElementDefinition.
|
|
134
|
-
* @param output The work-in-progress IndexedStructureDefinition.
|
|
135
|
-
* @param element The input ElementDefinition.
|
|
136
|
-
*/
|
|
137
|
-
function indexProperty(output, element) {
|
|
138
|
-
const path = element.path;
|
|
139
|
-
const parts = path.split('.');
|
|
140
|
-
if (parts.length === 1) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const typeName = buildTypeName(parts.slice(0, parts.length - 1));
|
|
144
|
-
const typeSchema = output.types[typeName];
|
|
145
|
-
const key = parts[parts.length - 1];
|
|
146
|
-
typeSchema.properties[key] = element;
|
|
147
|
-
}
|
|
148
|
-
function buildTypeName(components) {
|
|
149
|
-
return components.map(utils_1.capitalize).join('');
|
|
150
|
-
}
|
|
151
|
-
exports.buildTypeName = buildTypeName;
|
|
152
|
-
function getPropertyDisplayName(property) {
|
|
153
|
-
// Get the property name, which is the remainder after the last period
|
|
154
|
-
// For example, for path "Patient.birthDate"
|
|
155
|
-
// the property name is "birthDate"
|
|
156
|
-
const propertyName = property.path.split('.').pop();
|
|
157
|
-
// Split by capital letters
|
|
158
|
-
// Capitalize the first letter of each word
|
|
159
|
-
// Join together with spaces in between
|
|
160
|
-
// Then normalize whitespace to single space character
|
|
161
|
-
// For example, for property name "birthDate",
|
|
162
|
-
// the display name is "Birth Date".
|
|
163
|
-
return propertyName
|
|
164
|
-
.split(/(?=[A-Z])/)
|
|
165
|
-
.map(utils_1.capitalize)
|
|
166
|
-
.join(' ')
|
|
167
|
-
.replace('_', ' ')
|
|
168
|
-
.replace(/\s+/g, ' ');
|
|
169
|
-
}
|
|
170
|
-
exports.getPropertyDisplayName = getPropertyDisplayName;
|
|
171
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":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G,OAAO,CAAC;AACvC,CAAC;AAED,SAAgB,aAAa,CAAC,UAAoB;IAChD,OAAO,UAAU,CAAC,GAAG,CAAC,kBAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7C,CAAC;AAFD,sCAEC;AAED,SAAgB,sBAAsB,CAAC,QAA2B;IAChE,sEAAsE;IACtE,4CAA4C;IAC5C,mCAAmC;IACnC,MAAM,YAAY,GAAI,QAAQ,CAAC,IAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAY,CAAC;IAE1E,2BAA2B;IAC3B,2CAA2C;IAC3C,uCAAuC;IACvC,sDAAsD;IACtD,8CAA8C;IAC9C,oCAAoC;IACpC,OAAO,YAAY;SAChB,KAAK,CAAC,WAAW,CAAC;SAClB,GAAG,CAAC,kBAAU,CAAC;SACf,IAAI,CAAC,GAAG,CAAC;SACT,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;SACjB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC1B,CAAC;AAlBD,wDAkBC","sourcesContent":["import { ElementDefinition, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';\nimport { capitalize } from './utils';\n\n/**\n * List of property types.\n * http://www.hl7.org/fhir/valueset-defined-types.html\n * The list here includes additions found from StructureDefinition resources.\n */\nexport enum PropertyType {\n Address = 'Address',\n Age = 'Age',\n Annotation = 'Annotation',\n Attachment = 'Attachment',\n BackboneElement = 'BackboneElement',\n CodeableConcept = 'CodeableConcept',\n Coding = 'Coding',\n ContactDetail = 'ContactDetail',\n ContactPoint = 'ContactPoint',\n Contributor = 'Contributor',\n Count = 'Count',\n DataRequirement = 'DataRequirement',\n Distance = 'Distance',\n Dosage = 'Dosage',\n Duration = 'Duration',\n Expression = 'Expression',\n Extension = 'Extension',\n HumanName = 'HumanName',\n Identifier = 'Identifier',\n MarketingStatus = 'MarketingStatus',\n Meta = 'Meta',\n Money = 'Money',\n Narrative = 'Narrative',\n ParameterDefinition = 'ParameterDefinition',\n Period = 'Period',\n Population = 'Population',\n ProdCharacteristic = 'ProdCharacteristic',\n ProductShelfLife = 'ProductShelfLife',\n Quantity = 'Quantity',\n Range = 'Range',\n Ratio = 'Ratio',\n Reference = 'Reference',\n RelatedArtifact = 'RelatedArtifact',\n Resource = 'Resource',\n SampledData = 'SampledData',\n Signature = 'Signature',\n SubstanceAmount = 'SubstanceAmount',\n SystemString = 'http://hl7.org/fhirpath/System.String',\n Timing = 'Timing',\n TriggerDefinition = 'TriggerDefinition',\n UsageContext = 'UsageContext',\n base64Binary = 'base64Binary',\n boolean = 'boolean',\n canonical = 'canonical',\n code = 'code',\n date = 'date',\n dateTime = 'dateTime',\n decimal = 'decimal',\n id = 'id',\n instant = 'instant',\n integer = 'integer',\n markdown = 'markdown',\n oid = 'oid',\n positiveInt = 'positiveInt',\n string = 'string',\n time = 'time',\n unsignedInt = 'unsignedInt',\n uri = 'uri',\n url = 'url',\n uuid = 'uuid',\n}\n\n/**\n * An IndexedStructureDefinition is a lookup-optimized version of a StructureDefinition.\n *\n * StructureDefinition resources contain schema information for other resource types.\n * These schemas can be used to automatically generate user interface elements for\n * resources.\n *\n * However, a StructureDefinition resource is not optimized for realtime lookups. All\n * resource types, sub types, and property definitions are stored in a flat array of\n * ElementDefinition objects. Therefore, to lookup the schema for a property (i.e., \"Patient.name\")\n * requires a linear scan of all ElementDefinition objects\n *\n * A StructureDefinition resource contains information about one or more types.\n * For example, the \"Patient\" StructureDefinition includes \"Patient\", \"Patient_Contact\",\n * \"Patient_Communication\", and \"Patient_Link\". This is inefficient.\n *\n * Instead, we create an indexed version of the StructureDefinition, called IndexedStructureDefinition.\n * In an IndexedStructureDefinition, retrieving a property definition is a hashtable lookup.\n *\n * The hierarchy is:\n * IndexedStructureDefinition - top level for one resource type\n * TypeSchema - one per resource type and all contained BackboneElements\n * PropertySchema - one per property/field\n */\nexport interface IndexedStructureDefinition {\n types: { [resourceType: string]: TypeSchema };\n}\n\n/**\n * An indexed TypeSchema.\n *\n * Example: The IndexedStructureDefinition for \"Patient\" would include the following TypeSchemas:\n * 1) Patient\n * 2) Patient_Contact\n * 3) Patient_Communication\n * 4) Patient_Link\n */\nexport interface TypeSchema {\n display: string;\n properties: { [name: string]: ElementDefinition };\n searchParams?: SearchParameter[];\n description?: string;\n parentType?: string;\n}\n\n/**\n * Indexes a StructureDefinition for fast lookup.\n * See comments on IndexedStructureDefinition for more details.\n * @param structureDefinition The original StructureDefinition.\n * @return An indexed IndexedStructureDefinition.\n */\nexport function indexStructureDefinition(\n structureDefinition: StructureDefinition,\n output?: IndexedStructureDefinition\n): IndexedStructureDefinition {\n const typeName = structureDefinition.name;\n if (!typeName) {\n throw new Error('Invalid StructureDefinition');\n }\n\n if (!output) {\n output = {\n types: {},\n } as IndexedStructureDefinition;\n }\n\n output.types[typeName] = {\n display: typeName,\n description: structureDefinition.description,\n properties: {},\n };\n\n const elements = structureDefinition.snapshot?.element;\n if (elements) {\n // Filter out any elements missing path or type\n const filtered = elements.filter((e) => e.path !== typeName && e.path); // && e.type && e.type.length > 0);\n\n // First pass, build types\n filtered.forEach((element) => indexType(output as IndexedStructureDefinition, element));\n\n // Second pass, build properties\n filtered.forEach((element) => indexProperty(output as IndexedStructureDefinition, element));\n }\n\n return output;\n}\n\n/**\n * Indexes TypeSchema from an ElementDefinition.\n * In the common case, there will be many ElementDefinition instances per TypeSchema.\n * Only the first occurrence is saved.\n * @param output The work-in-progress IndexedStructureDefinition.\n * @param element The input ElementDefinition.\n */\nfunction indexType(output: IndexedStructureDefinition, element: ElementDefinition): void {\n const path = element.path as string;\n const typeCode = element.type?.[0]?.code;\n if (typeCode !== 'Element' && typeCode !== 'BackboneElement') {\n return;\n }\n const parts = path.split('.');\n const typeName = buildTypeName(parts);\n if (!(typeName in output.types)) {\n output.types[typeName] = {\n display: typeName,\n description: element.definition,\n parentType: buildTypeName(parts.slice(0, parts.length - 1)),\n properties: {},\n };\n }\n}\n\n/**\n * Indexes PropertySchema from an ElementDefinition.\n * @param output The work-in-progress IndexedStructureDefinition.\n * @param element The input ElementDefinition.\n */\nfunction indexProperty(output: IndexedStructureDefinition, element: ElementDefinition): void {\n const path = element.path as string;\n const parts = path.split('.');\n if (parts.length === 1) {\n return;\n }\n const typeName = buildTypeName(parts.slice(0, parts.length - 1));\n const typeSchema = output.types[typeName];\n const key = parts[parts.length - 1];\n typeSchema.properties[key] = element;\n}\n\nexport function buildTypeName(components: string[]): string {\n return components.map(capitalize).join('');\n}\n\nexport function getPropertyDisplayName(property: ElementDefinition): string {\n // Get the property name, which is the remainder after the last period\n // For example, for path \"Patient.birthDate\"\n // the property name is \"birthDate\"\n const propertyName = (property.path as string).split('.').pop() as string;\n\n // Split by capital letters\n // Capitalize the first letter of each word\n // Join together with spaces in between\n // Then normalize whitespace to single space character\n // For example, for property name \"birthDate\",\n // the display name is \"Birth Date\".\n return propertyName\n .split(/(?=[A-Z])/)\n .map(capitalize)\n .join(' ')\n .replace('_', ' ')\n .replace(/\\s+/g, ' ');\n}\n"]}
|