diff --git a/ts/server/package.json b/ts/server/package.json index c8205cd..c017c60 100644 --- a/ts/server/package.json +++ b/ts/server/package.json @@ -24,7 +24,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@types/fhir": "^0.0.37", - "fhirpath": "^3.6.1", + "fhirpath": "^3.13.2", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" }, diff --git a/ts/server/src/utils/extract.ts b/ts/server/src/utils/extract.ts index 4571fb9..ace8824 100644 --- a/ts/server/src/utils/extract.ts +++ b/ts/server/src/utils/extract.ts @@ -2,20 +2,8 @@ import * as fhirpath from 'fhirpath'; type Resource = Record; - -type UserInvocationTable = { - [name: string]: { - fn: (...args: any) => any, - arity: { - [numberOfParams: number]: Array<'Expr' | 'AnyAtRoot' | 'Identifier' | 'TypeSpecifier' | 'Any' | 'Integer' | 'Boolean' | 'Number' | 'String'> - }, - nullable?: boolean, - internalStructures?: boolean - } - }; - interface FPOptions { - // userInvocationTable?: UserInvocationTable; + userInvocationTable?: UserInvocationTable; } interface Embedded { @@ -62,7 +50,7 @@ function resolveTemplateRecur( model?: Model, fpOptions?: FPOptions, ): any { - return iterateObject(template, initialContext?? {}, (node, context) => { + return iterateObject(template, initialContext ?? {}, (node, context) => { if (isPlainObject(node)) { const { node: newNode, context: newContext } = processAssignBlock( resource, @@ -94,7 +82,7 @@ function resolveTemplateRecur( fhirpath.evaluate( resource, embedded.expression, - context, + { ...context }, // fhirpath mutates context! model, fpOptions, )[0] ?? null; @@ -175,7 +163,13 @@ function processForBlock( const itemKey = hasIndexKey ? matches[2] : matches[1]; const expr = hasIndexKey ? matches[3] : matches[2]; - const answers = fhirpath.evaluate(resource, expr, context, model, fpOptions); + const answers = fhirpath.evaluate( + resource, + expr, + { ...context }, // fhirpath mutates context! + model, + fpOptions, + ); return { node: answers.map((answer, index) => resolveTemplate( @@ -212,7 +206,13 @@ function processContextBlock( const matches = contextKey.match(contextRegExp); const expr = matches[1]; - const answers = fhirpath.evaluate(resource, expr, context, model, fpOptions); + const answers = fhirpath.evaluate( + resource, + expr, + { ...context }, // fhirpath mutates context! + model, + fpOptions, + ); const result: any[] = answers.map((answer) => resolveTemplate(answer, node[contextKey], context, model, fpOptions), ); @@ -280,7 +280,7 @@ function processIfBlock( const answer = fhirpath.evaluate( resource, `iif(${expr}, true, false)`, - context, + { ...context }, // fhirpath mutates context! model, fpOptions, )[0]; diff --git a/ts/server/yarn.lock b/ts/server/yarn.lock index 81d8baf..cd9206c 100644 --- a/ts/server/yarn.lock +++ b/ts/server/yarn.lock @@ -677,10 +677,10 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@lhncbc/ucum-lhc@^4.1.3": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@lhncbc/ucum-lhc/-/ucum-lhc-4.2.0.tgz#522cc16fe37739d7da16c27c8b9ad039ee39c2d7" - integrity sha512-OEiWX7IHFHLTFs7+w5EvGtI5dhXhhL0341LqZ9WEBWErtoY0/9xl/vn+wwT9vnBHnjQ7Ux0o7iEUXvN8uVn4xg== +"@lhncbc/ucum-lhc@^5.0.0": + version "5.0.4" + resolved "https://registry.yarnpkg.com/@lhncbc/ucum-lhc/-/ucum-lhc-5.0.4.tgz#1357a039954e03154f89ce51f2d90c93b9c1a1f3" + integrity sha512-khuV9GV51DF80b0wJmhZTR5Bf23fhS6SSIWnyGT9X+Uvn0FsHFl2LKViQ2TTOuvwagUOUSq8/0SyoE2ZDGwrAA== dependencies: coffeescript "^2.7.0" csv-parse "^4.4.6" @@ -2455,12 +2455,12 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -fhirpath@^3.6.1: - version "3.6.1" - resolved "https://registry.yarnpkg.com/fhirpath/-/fhirpath-3.6.1.tgz#05843eacacb4b9d94d18154771a019c0e4d8122d" - integrity sha512-Sgneaohzc2IYun17OS4107GQXeXd6umVT9P5rn+9YD6v0JDJOvoDixqWeBEY3MokSk7Hpco5NQbTa61TWF4gtg== +fhirpath@^3.13.2: + version "3.13.2" + resolved "https://registry.yarnpkg.com/fhirpath/-/fhirpath-3.13.2.tgz#4c9e3a77267a1c080fc8d295f5aa6aabd26d1fb9" + integrity sha512-pPlMHEj1TlES+QaUdLlGmYgvSYiwecXTHbPjX4WKHj7nR1ZZr0YIj/jBo7k9ADrSKQizqvURGYCqufN7sHnnQA== dependencies: - "@lhncbc/ucum-lhc" "^4.1.3" + "@lhncbc/ucum-lhc" "^5.0.0" antlr4 "~4.9.3" commander "^2.18.0" date-fns "^1.30.1"