@medplum/core
Advanced tools
Comparing version 0.0.28 to 0.0.30
@@ -117,3 +117,3 @@ import { EventTarget } from './eventtarget'; | ||
fhirUrl(...path: string[]): string; | ||
search(search: string | SearchRequest): Promise<Bundle>; | ||
search<T extends Resource>(search: string | SearchRequest): Promise<Bundle<T>>; | ||
read(resourceType: string, id: string): Promise<Resource>; | ||
@@ -120,0 +120,0 @@ readCached(resourceType: string, id: string): Promise<Resource>; |
@@ -11,2 +11,31 @@ "use strict"; | ||
}; | ||
const patientStructureDefinition = { | ||
resourceType: 'StructureDefinition', | ||
name: 'Patient', | ||
snapshot: { | ||
element: [ | ||
{ | ||
path: 'Patient.id', | ||
type: [{ | ||
code: 'code' | ||
}] | ||
} | ||
] | ||
} | ||
}; | ||
const patientStructureDefinitionBundle = { | ||
resourceType: 'Bundle', | ||
entry: [{ resource: patientStructureDefinition }] | ||
}; | ||
const patientSearchParameter = { | ||
resourceType: 'SearchParameter', | ||
id: 'Patient-name', | ||
code: 'name', | ||
name: 'name', | ||
expression: 'Patient.name' | ||
}; | ||
const patientSearchParameterBundle = { | ||
resourceType: 'Bundle', | ||
entry: [{ resource: patientSearchParameter }] | ||
}; | ||
let canRefresh = true; | ||
@@ -57,35 +86,6 @@ let tokenExpired = false; | ||
else if (method === 'GET' && url.includes('/fhir/R4/StructureDefinition?name=Patient')) { | ||
result = { | ||
resourceType: 'Bundle', | ||
entry: [{ | ||
resource: { | ||
resourceType: 'StructureDefinition', | ||
name: 'Patient', | ||
snapshot: { | ||
element: [ | ||
{ | ||
path: 'Patient.id', | ||
type: [{ | ||
code: 'code' | ||
}] | ||
} | ||
] | ||
} | ||
} | ||
}] | ||
}; | ||
result = patientStructureDefinitionBundle; | ||
} | ||
else if (method === 'GET' && url.includes('/fhir/R4/SearchParameter?_count=100&base=Patient')) { | ||
result = { | ||
resourceType: 'Bundle', | ||
entry: [{ | ||
resource: { | ||
resourceType: 'SearchParameter', | ||
id: 'Patient-name', | ||
code: 'name', | ||
name: 'name', | ||
expression: 'Patient.name' | ||
} | ||
}] | ||
}; | ||
result = patientSearchParameterBundle; | ||
} | ||
@@ -92,0 +92,0 @@ const response = { |
@@ -9,3 +9,3 @@ import { Extension } from './Extension'; | ||
*/ | ||
export interface Bundle { | ||
export interface Bundle<T extends Resource = Resource> { | ||
/** | ||
@@ -66,3 +66,3 @@ * This is a Bundle resource | ||
*/ | ||
readonly entry?: BundleEntry[]; | ||
readonly entry?: BundleEntry<T>[]; | ||
/** | ||
@@ -76,3 +76,3 @@ * Digital Signature - base64 encoded. XML-DSig or a JWT. | ||
*/ | ||
export interface BundleEntry { | ||
export interface BundleEntry<T extends Resource = Resource> { | ||
/** | ||
@@ -130,3 +130,3 @@ * Unique id for the element within a resource (for internal references). | ||
*/ | ||
readonly resource?: Resource; | ||
readonly resource?: T; | ||
/** | ||
@@ -133,0 +133,0 @@ * Information about the search process that lead to the creation of this |
@@ -10,3 +10,3 @@ import { CodeableConcept } from './CodeableConcept'; | ||
*/ | ||
export interface OperationOutcome { | ||
export interface OperationOutcome<T extends Resource = Resource> { | ||
/** | ||
@@ -91,3 +91,3 @@ * This is a OperationOutcome resource | ||
*/ | ||
readonly resource?: Resource; | ||
readonly resource?: T; | ||
} | ||
@@ -94,0 +94,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseFhirPath = exports.FhirPathAtom = void 0; | ||
const functions_1 = require("./functions"); | ||
const tokenize_1 = require("./tokenize"); | ||
const utils_1 = require("./utils"); | ||
class ParserBuilder { | ||
@@ -98,13 +100,2 @@ prefixParselets = {}; | ||
} | ||
function applyMaybeArray(context, fn) { | ||
if (context === undefined) { | ||
return undefined; | ||
} | ||
if (Array.isArray(context)) { | ||
return context.map(e => fn(e)).filter(e => !!e).flat(); | ||
} | ||
else { | ||
return fn(context); | ||
} | ||
} | ||
class FhirPathAtom { | ||
@@ -119,3 +110,3 @@ original; | ||
try { | ||
const result = applyMaybeArray(context, e => this.child.eval(e)); | ||
const result = utils_1.applyMaybeArray(context, e => this.child.eval(e)); | ||
if (Array.isArray(result)) { | ||
@@ -152,3 +143,3 @@ return result.flat(); | ||
eval(context) { | ||
return applyMaybeArray(context, e => e.resourceType === this.name ? e : e[this.name]); | ||
return utils_1.applyMaybeArray(context, e => e.resourceType === this.name ? e : e[this.name]); | ||
} | ||
@@ -217,26 +208,9 @@ } | ||
eval(context) { | ||
return this.impl(context, ...this.args); | ||
} | ||
} | ||
const functions = { | ||
where(context, condition) { | ||
return applyMaybeArray(context, e => condition.eval(e) ? e : undefined); | ||
}, | ||
resolve(context) { | ||
// If context is a reference, turn it into a resource | ||
// Otherwise return undefined | ||
const refStr = context.reference; | ||
if (!refStr) { | ||
if (context === undefined) { | ||
return undefined; | ||
} | ||
const [resourceType, id] = refStr.split('/'); | ||
return { resourceType, id }; | ||
}, | ||
as(context, expression) { | ||
return context; | ||
}, | ||
exists(context) { | ||
return context !== undefined && (Array.isArray(context) && context.length > 0) || (!!context); | ||
const input = Array.isArray(context) ? context : [context]; | ||
return this.impl(input, ...this.args); | ||
} | ||
}; | ||
} | ||
const PARENTHESES_PARSELET = { | ||
@@ -256,3 +230,3 @@ parse(parser) { | ||
} | ||
if (!(left.name in functions)) { | ||
if (!(left.name in functions_1.functions)) { | ||
throw new Error('Unrecognized function: ' + left.name); | ||
@@ -264,3 +238,3 @@ } | ||
} | ||
return new FunctionAtom(left.name, args, functions[left.name]); | ||
return new FunctionAtom(left.name, args, functions_1.functions[left.name]); | ||
}, | ||
@@ -267,0 +241,0 @@ precedence: 8 /* FunctionCall */ |
{ | ||
"name": "@medplum/core", | ||
"version": "0.0.28", | ||
"version": "0.0.30", | ||
"description": "Medplum TS/JS Library", | ||
@@ -20,5 +20,5 @@ "author": "Medplum <hello@medplum.com>", | ||
"devDependencies": { | ||
"@medplum/definitions": "0.0.28", | ||
"@medplum/definitions": "0.0.30", | ||
"@types/jest": "26.0.24", | ||
"@types/node": "16.4.10", | ||
"@types/node": "16.4.12", | ||
"@typescript-eslint/eslint-plugin": "4.29.0", | ||
@@ -25,0 +25,0 @@ "@typescript-eslint/parser": "4.29.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2994568
660
66136