@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/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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,YAAY,GAAG,UAAU,CAAC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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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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":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AACA,mCAAqC;AAErC;;;;GAIG;AACH,IAAY,YA6DX;AA7DD,WAAY,YAAY;IACtB,mCAAmB,CA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I,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"]}
|
package/dist/utils.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLowerCase = exports.capitalize = exports.arrayBufferToBase64 = exports.arrayBufferToHex = exports.deepEquals = exports.stringify = exports.getDateProperty = exports.getImageSrc = exports.getDisplayString = exports.isProfileResource = exports.getReferenceString = exports.createReference = void 0;
|
|
4
|
-
const format_1 = require("./format");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a reference resource.
|
|
7
|
-
* @param resource The FHIR reesource.
|
|
8
|
-
* @returns A reference resource.
|
|
9
|
-
*/
|
|
10
|
-
function createReference(resource) {
|
|
11
|
-
const reference = getReferenceString(resource);
|
|
12
|
-
const display = getDisplayString(resource);
|
|
13
|
-
return display === reference ? { reference } : { reference, display };
|
|
14
|
-
}
|
|
15
|
-
exports.createReference = createReference;
|
|
16
|
-
/**
|
|
17
|
-
* Returns a reference string for a resource.
|
|
18
|
-
* @param resource The FHIR resource.
|
|
19
|
-
* @returns A reference string of the form resourceType/id.
|
|
20
|
-
*/
|
|
21
|
-
function getReferenceString(resource) {
|
|
22
|
-
return resource.resourceType + '/' + resource.id;
|
|
23
|
-
}
|
|
24
|
-
exports.getReferenceString = getReferenceString;
|
|
25
|
-
/**
|
|
26
|
-
* Returns true if the resource is a "ProfileResource".
|
|
27
|
-
* @param resource The FHIR resource.
|
|
28
|
-
* @returns True if the resource is a "ProfileResource".
|
|
29
|
-
*/
|
|
30
|
-
function isProfileResource(resource) {
|
|
31
|
-
return (resource.resourceType === 'Patient' ||
|
|
32
|
-
resource.resourceType === 'Practitioner' ||
|
|
33
|
-
resource.resourceType === 'RelatedPerson');
|
|
34
|
-
}
|
|
35
|
-
exports.isProfileResource = isProfileResource;
|
|
36
|
-
/**
|
|
37
|
-
* Returns a display string for the resource.
|
|
38
|
-
* @param resource The input resource.
|
|
39
|
-
* @return Human friendly display string.
|
|
40
|
-
*/
|
|
41
|
-
function getDisplayString(resource) {
|
|
42
|
-
if (isProfileResource(resource)) {
|
|
43
|
-
const profileName = getProfileResourceDisplayString(resource);
|
|
44
|
-
if (profileName) {
|
|
45
|
-
return profileName;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (resource.resourceType === 'Device') {
|
|
49
|
-
const deviceName = getDeviceDisplayString(resource);
|
|
50
|
-
if (deviceName) {
|
|
51
|
-
return deviceName;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (resource.resourceType === 'User') {
|
|
55
|
-
if (resource.email) {
|
|
56
|
-
return resource.email;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const simpleName = resource.name;
|
|
60
|
-
if (simpleName && typeof simpleName === 'string') {
|
|
61
|
-
return simpleName;
|
|
62
|
-
}
|
|
63
|
-
return getReferenceString(resource);
|
|
64
|
-
}
|
|
65
|
-
exports.getDisplayString = getDisplayString;
|
|
66
|
-
/**
|
|
67
|
-
* Returns a display string for a profile resource if one is found.
|
|
68
|
-
* @param resource The profile resource.
|
|
69
|
-
* @returns The display name if one is found.
|
|
70
|
-
*/
|
|
71
|
-
function getProfileResourceDisplayString(resource) {
|
|
72
|
-
const names = resource.name;
|
|
73
|
-
if (names && names.length > 0) {
|
|
74
|
-
return (0, format_1.formatHumanName)(names[0]);
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Returns a display string for a device resource if one is found.
|
|
80
|
-
* @param device The device resource.
|
|
81
|
-
* @returns The display name if one is found.
|
|
82
|
-
*/
|
|
83
|
-
function getDeviceDisplayString(device) {
|
|
84
|
-
const names = device.deviceName;
|
|
85
|
-
if (names && names.length > 0) {
|
|
86
|
-
return names[0].name;
|
|
87
|
-
}
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Returns an image URL for the resource, if one is available.
|
|
92
|
-
* @param resource The input resource.
|
|
93
|
-
* @returns The image URL for the resource or undefined.
|
|
94
|
-
*/
|
|
95
|
-
function getImageSrc(resource) {
|
|
96
|
-
if (isProfileResource(resource)) {
|
|
97
|
-
const photos = resource.photo;
|
|
98
|
-
if (photos) {
|
|
99
|
-
for (const photo of photos) {
|
|
100
|
-
if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {
|
|
101
|
-
return photo.url;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
exports.getImageSrc = getImageSrc;
|
|
109
|
-
/**
|
|
110
|
-
* Returns a Date property as a Date.
|
|
111
|
-
* When working with JSON objects, Dates are often serialized as ISO-8601 strings.
|
|
112
|
-
* When that happens, we need to safely convert to a proper Date object.
|
|
113
|
-
* @param date The date property value, which could be a string or a Date object.
|
|
114
|
-
* @returns A Date object.
|
|
115
|
-
*/
|
|
116
|
-
function getDateProperty(date) {
|
|
117
|
-
return date ? new Date(date) : undefined;
|
|
118
|
-
}
|
|
119
|
-
exports.getDateProperty = getDateProperty;
|
|
120
|
-
/**
|
|
121
|
-
* FHIR JSON stringify.
|
|
122
|
-
* Removes properties with empty string values.
|
|
123
|
-
* Removes objects with zero properties.
|
|
124
|
-
* See: https://www.hl7.org/fhir/json.html
|
|
125
|
-
* @param value The input value.
|
|
126
|
-
* @param pretty Optional flag to pretty-print the JSON.
|
|
127
|
-
* @returns The resulting JSON string.
|
|
128
|
-
*/
|
|
129
|
-
function stringify(value, pretty) {
|
|
130
|
-
return JSON.stringify(value, stringifyReplacer, pretty ? 2 : undefined);
|
|
131
|
-
}
|
|
132
|
-
exports.stringify = stringify;
|
|
133
|
-
/**
|
|
134
|
-
* Evaluates JSON key/value pairs for FHIR JSON stringify.
|
|
135
|
-
* Removes properties with empty string values.
|
|
136
|
-
* Removes objects with zero properties.
|
|
137
|
-
* Replaces any key/value pair of key "__key" with value undefined.
|
|
138
|
-
* This function can be used as the 2nd argument to stringify to remove __key properties.
|
|
139
|
-
* We add __key properties to array elements to improve React render performance.
|
|
140
|
-
* @param {string} k Property key.
|
|
141
|
-
* @param {*} v Property value.
|
|
142
|
-
*/
|
|
143
|
-
function stringifyReplacer(k, v) {
|
|
144
|
-
return k === '__key' || isEmpty(v) ? undefined : v;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Returns true if the value is empty (null, undefined, empty string, or empty object).
|
|
148
|
-
* @param v Any value.
|
|
149
|
-
* @returns True if the value is an empty string or an empty object.
|
|
150
|
-
*/
|
|
151
|
-
function isEmpty(v) {
|
|
152
|
-
if (v === null || v === undefined) {
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
const t = typeof v;
|
|
156
|
-
return (t === 'string' && v === '') || (t === 'object' && Object.keys(v).length === 0);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Resource equality.
|
|
160
|
-
* Ignores meta.versionId and meta.lastUpdated.
|
|
161
|
-
* See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality
|
|
162
|
-
* @param object1 The first object.
|
|
163
|
-
* @param object2 The second object.
|
|
164
|
-
* @returns True if the objects are equal.
|
|
165
|
-
*/
|
|
166
|
-
function deepEquals(object1, object2, path) {
|
|
167
|
-
let keys1 = Object.keys(object1);
|
|
168
|
-
let keys2 = Object.keys(object2);
|
|
169
|
-
if (path === 'meta') {
|
|
170
|
-
keys1 = keys1.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
|
|
171
|
-
keys2 = keys2.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
|
|
172
|
-
}
|
|
173
|
-
if (keys1.length !== keys2.length) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
for (const key of keys1) {
|
|
177
|
-
const val1 = object1[key];
|
|
178
|
-
const val2 = object2[key];
|
|
179
|
-
if (isObject(val1) && isObject(val2)) {
|
|
180
|
-
if (!deepEquals(val1, val2, key)) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
if (val1 !== val2) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
exports.deepEquals = deepEquals;
|
|
193
|
-
function isObject(object) {
|
|
194
|
-
return object !== null && typeof object === 'object';
|
|
195
|
-
}
|
|
196
|
-
// Precompute hex octets
|
|
197
|
-
// See: https://stackoverflow.com/a/55200387
|
|
198
|
-
const byteToHex = [];
|
|
199
|
-
for (let n = 0; n < 256; n++) {
|
|
200
|
-
byteToHex.push(n.toString(16).padStart(2, '0'));
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Converts an ArrayBuffer to hex string.
|
|
204
|
-
* See: https://stackoverflow.com/a/55200387
|
|
205
|
-
* @param arrayBuffer The input array buffer.
|
|
206
|
-
* @returns The resulting hex string.
|
|
207
|
-
*/
|
|
208
|
-
function arrayBufferToHex(arrayBuffer) {
|
|
209
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
210
|
-
const result = new Array(bytes.length);
|
|
211
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
212
|
-
result[i] = byteToHex[bytes[i]];
|
|
213
|
-
}
|
|
214
|
-
return result.join('');
|
|
215
|
-
}
|
|
216
|
-
exports.arrayBufferToHex = arrayBufferToHex;
|
|
217
|
-
/**
|
|
218
|
-
* Converts an ArrayBuffer to a base-64 encoded string.
|
|
219
|
-
* @param arrayBuffer The input array buffer.
|
|
220
|
-
* @returns The base-64 encoded string.
|
|
221
|
-
*/
|
|
222
|
-
function arrayBufferToBase64(arrayBuffer) {
|
|
223
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
224
|
-
const result = [];
|
|
225
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
226
|
-
result[i] = String.fromCharCode(bytes[i]);
|
|
227
|
-
}
|
|
228
|
-
return window.btoa(result.join(''));
|
|
229
|
-
}
|
|
230
|
-
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
231
|
-
function capitalize(word) {
|
|
232
|
-
return word.charAt(0).toUpperCase() + word.substr(1);
|
|
233
|
-
}
|
|
234
|
-
exports.capitalize = capitalize;
|
|
235
|
-
function isLowerCase(c) {
|
|
236
|
-
return c === c.toLowerCase();
|
|
237
|
-
}
|
|
238
|
-
exports.isLowerCase = isLowerCase;
|
|
239
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,qCAA2C;AAI3C;;;;GAIG;AACH,SAAgB,eAAe,CAAqB,QAAW;IAC7D,MAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EA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APD,4CAOC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAC3C;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACtC,CAAC;AAPD,kDAOC;AAED,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAFD,gCAEC;AAED,SAAgB,WAAW,CAAC,CAAS;IACnC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/B,CAAC;AAFD,kCAEC","sourcesContent":["import { Device, Patient, Practitioner, Reference, RelatedPerson, Resource } from '@medplum/fhirtypes';\nimport { formatHumanName } from './format';\n\nexport type ProfileResource = Patient | Practitioner | RelatedPerson;\n\n/**\n * Creates a reference resource.\n * @param resource The FHIR reesource.\n * @returns A reference resource.\n */\nexport function createReference<T extends Resource>(resource: T): Reference<T> {\n const reference = getReferenceString(resource);\n const display = getDisplayString(resource);\n return display === reference ? { reference } : { reference, display };\n}\n\n/**\n * Returns a reference string for a resource.\n * @param resource The FHIR resource.\n * @returns A reference string of the form resourceType/id.\n */\nexport function getReferenceString(resource: Resource): string {\n return resource.resourceType + '/' + resource.id;\n}\n\n/**\n * Returns true if the resource is a \"ProfileResource\".\n * @param resource The FHIR resource.\n * @returns True if the resource is a \"ProfileResource\".\n */\nexport function isProfileResource(resource: Resource): boolean {\n return (\n resource.resourceType === 'Patient' ||\n resource.resourceType === 'Practitioner' ||\n resource.resourceType === 'RelatedPerson'\n );\n}\n\n/**\n * Returns a display string for the resource.\n * @param resource The input resource.\n * @return Human friendly display string.\n */\nexport function getDisplayString(resource: Resource): string {\n if (isProfileResource(resource)) {\n const profileName = getProfileResourceDisplayString(resource as ProfileResource);\n if (profileName) {\n return profileName;\n }\n }\n if (resource.resourceType === 'Device') {\n const deviceName = getDeviceDisplayString(resource);\n if (deviceName) {\n return deviceName;\n }\n }\n if (resource.resourceType === 'User') {\n if (resource.email) {\n return resource.email;\n }\n }\n const simpleName = (resource as any).name;\n if (simpleName && typeof simpleName === 'string') {\n return simpleName;\n }\n return getReferenceString(resource);\n}\n\n/**\n * Returns a display string for a profile resource if one is found.\n * @param resource The profile resource.\n * @returns The display name if one is found.\n */\nfunction getProfileResourceDisplayString(resource: ProfileResource): string | undefined {\n const names = resource.name;\n if (names && names.length > 0) {\n return formatHumanName(names[0]);\n }\n return undefined;\n}\n\n/**\n * Returns a display string for a device resource if one is found.\n * @param device The device resource.\n * @returns The display name if one is found.\n */\nfunction getDeviceDisplayString(device: Device): string | undefined {\n const names = device.deviceName;\n if (names && names.length > 0) {\n return names[0].name;\n }\n return undefined;\n}\n\n/**\n * Returns an image URL for the resource, if one is available.\n * @param resource The input resource.\n * @returns The image URL for the resource or undefined.\n */\nexport function getImageSrc(resource: Resource): string | undefined {\n if (isProfileResource(resource)) {\n const photos = (resource as ProfileResource).photo;\n if (photos) {\n for (const photo of photos) {\n if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {\n return photo.url;\n }\n }\n }\n }\n return undefined;\n}\n\n/**\n * Returns a Date property as a Date.\n * When working with JSON objects, Dates are often serialized as ISO-8601 strings.\n * When that happens, we need to safely convert to a proper Date object.\n * @param date The date property value, which could be a string or a Date object.\n * @returns A Date object.\n */\nexport function getDateProperty(date: string | undefined): Date | undefined {\n return date ? new Date(date) : undefined;\n}\n\n/**\n * FHIR JSON stringify.\n * Removes properties with empty string values.\n * Removes objects with zero properties.\n * See: https://www.hl7.org/fhir/json.html\n * @param value The input value.\n * @param pretty Optional flag to pretty-print the JSON.\n * @returns The resulting JSON string.\n */\nexport function stringify(value: any, pretty?: boolean): string {\n return JSON.stringify(value, stringifyReplacer, pretty ? 2 : undefined);\n}\n\n/**\n * Evaluates JSON key/value pairs for FHIR JSON stringify.\n * Removes properties with empty string values.\n * Removes objects with zero properties.\n * Replaces any key/value pair of key \"__key\" with value undefined.\n * This function can be used as the 2nd argument to stringify to remove __key properties.\n * We add __key properties to array elements to improve React render performance.\n * @param {string} k Property key.\n * @param {*} v Property value.\n */\nfunction stringifyReplacer(k: string, v: any): any {\n return k === '__key' || isEmpty(v) ? undefined : v;\n}\n\n/**\n * Returns true if the value is empty (null, undefined, empty string, or empty object).\n * @param v Any value.\n * @returns True if the value is an empty string or an empty object.\n */\nfunction isEmpty(v: any): boolean {\n if (v === null || v === undefined) {\n return true;\n }\n const t = typeof v;\n return (t === 'string' && v === '') || (t === 'object' && Object.keys(v).length === 0);\n}\n\n/**\n * Resource equality.\n * Ignores meta.versionId and meta.lastUpdated.\n * See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality\n * @param object1 The first object.\n * @param object2 The second object.\n * @returns True if the objects are equal.\n */\nexport function deepEquals(object1: any, object2: any, path?: string): boolean {\n let keys1 = Object.keys(object1);\n let keys2 = Object.keys(object2);\n if (path === 'meta') {\n keys1 = keys1.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');\n keys2 = keys2.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');\n }\n if (keys1.length !== keys2.length) {\n return false;\n }\n for (const key of keys1) {\n const val1 = object1[key];\n const val2 = object2[key];\n if (isObject(val1) && isObject(val2)) {\n if (!deepEquals(val1, val2, key)) {\n return false;\n }\n } else {\n if (val1 !== val2) {\n return false;\n }\n }\n }\n return true;\n}\n\nfunction isObject(object: any): boolean {\n return object !== null && typeof object === 'object';\n}\n\n// Precompute hex octets\n// See: https://stackoverflow.com/a/55200387\nconst byteToHex: string[] = [];\nfor (let n = 0; n < 256; n++) {\n byteToHex.push(n.toString(16).padStart(2, '0'));\n}\n\n/**\n * Converts an ArrayBuffer to hex string.\n * See: https://stackoverflow.com/a/55200387\n * @param arrayBuffer The input array buffer.\n * @returns The resulting hex string.\n */\nexport function arrayBufferToHex(arrayBuffer: ArrayBuffer): string {\n const bytes = new Uint8Array(arrayBuffer);\n const result: string[] = new Array(bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n result[i] = byteToHex[bytes[i]];\n }\n return result.join('');\n}\n\n/**\n * Converts an ArrayBuffer to a base-64 encoded string.\n * @param arrayBuffer The input array buffer.\n * @returns The base-64 encoded string.\n */\nexport function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string {\n const bytes = new Uint8Array(arrayBuffer);\n const result: string[] = [];\n for (let i = 0; i < bytes.length; i++) {\n result[i] = String.fromCharCode(bytes[i]);\n }\n return window.btoa(result.join(''));\n}\n\nexport function capitalize(word: string): string {\n return word.charAt(0).toUpperCase() + word.substr(1);\n}\n\nexport function isLowerCase(c: string): boolean {\n return c === c.toLowerCase();\n}\n"]}
|