Skip to content

Commit

Permalink
feat: upgrade fhirpath
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed May 25, 2024
1 parent 19f4970 commit b15a73a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ts/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
36 changes: 18 additions & 18 deletions ts/server/src/utils/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@ import * as fhirpath from 'fhirpath';

type Resource = Record<string, any>;


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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -94,7 +82,7 @@ function resolveTemplateRecur(
fhirpath.evaluate(
resource,
embedded.expression,
context,
{ ...context }, // fhirpath mutates context!
model,
fpOptions,
)[0] ?? null;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
);
Expand Down Expand Up @@ -280,7 +280,7 @@ function processIfBlock(
const answer = fhirpath.evaluate(
resource,
`iif(${expr}, true, false)`,
context,
{ ...context }, // fhirpath mutates context!
model,
fpOptions,
)[0];
Expand Down
18 changes: 9 additions & 9 deletions ts/server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b15a73a

Please sign in to comment.