Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HL7/fhirpath.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.13.4
Choose a base ref
...
head repository: HL7/fhirpath.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Apr 1, 2024

  1. Added support for async functions

    LF-2985
    yuriy-sedinkin committed Apr 1, 2024
    Copy the full SHA
    877bc1c View commit details

Commits on May 10, 2024

  1. Added supplementary function weight()

    LF-2100
    yuriy-sedinkin committed May 10, 2024
    Copy the full SHA
    1bd0554 View commit details

Commits on May 17, 2024

  1. Changes as per review

    LF-2100
    yuriy-sedinkin committed May 17, 2024
    Copy the full SHA
    842367b View commit details

Commits on May 21, 2024

  1. Fix #136

    LF-2591
    yuriy-sedinkin committed May 21, 2024
    Copy the full SHA
    e58a1b6 View commit details

Commits on May 25, 2024

  1. Copy the full SHA
    85c9ab8 View commit details
  2. Copy the full SHA
    5794612 View commit details

Commits on May 28, 2024

  1. Merge remote-tracking branch 'lhc-git/master' into feature/LF-2985/as…

    …ync-functions
    
    # Conflicts:
    #	CHANGELOG.md
    #	package-lock.json
    #	package.json
    yuriy-sedinkin committed May 28, 2024
    Copy the full SHA
    4157c82 View commit details

Commits on May 30, 2024

  1. Added function memberOf

    LF-2985
    yuriy-sedinkin committed May 30, 2024
    Copy the full SHA
    90a4c64 View commit details

Commits on Jun 4, 2024

  1. Merge branch 'bugfix/LF-2591/attribute-name-that-starts-with-a-capita…

    …l-letter' into 'feature/LF-2100/supplementary-weight-function'
    
    Fix #136
    
    See merge request lfor/fhirpath.js!15
    yuriy-sedinkin committed Jun 4, 2024
    Copy the full SHA
    76e3d52 View commit details
  2. Revert "Fix #136"

    This reverts commit e58a1b6.
    yuriy-sedinkin committed Jun 4, 2024
    Copy the full SHA
    749fc98 View commit details

Commits on Jun 11, 2024

  1. Changes as per review

    LF-2985
    yuriy-sedinkin committed Jun 11, 2024
    Copy the full SHA
    f9956dc View commit details

Commits on Jun 13, 2024

  1. Changes as per review

    LF-2100
    yuriy-sedinkin committed Jun 13, 2024
    Copy the full SHA
    5d1c9a0 View commit details

Commits on Jun 24, 2024

  1. Changes as per review

    LF-2985
    yuriy-sedinkin committed Jun 24, 2024
    Copy the full SHA
    f659a71 View commit details

Commits on Jun 26, 2024

  1. Changes as per review

    LF-2100
    yuriy-sedinkin committed Jun 26, 2024
    Copy the full SHA
    187acf0 View commit details

Commits on Jun 27, 2024

  1. Changes as per review

    LF-2100
    yuriy-sedinkin committed Jun 27, 2024
    Copy the full SHA
    0d12999 View commit details

Commits on Jun 28, 2024

  1. Changes as per review and ability to directly call %termilologies.val…

    …idateVS from an expression
    
    LF-2985
    yuriy-sedinkin committed Jun 28, 2024
    Copy the full SHA
    7bdb289 View commit details

Commits on Jul 1, 2024

  1. Changes as per review

    LF-2100
    yuriy-sedinkin committed Jul 1, 2024
    Copy the full SHA
    b09f545 View commit details

Commits on Jul 2, 2024

  1. Removed unnecessary "webpack-serve" package that was causing problems…

    … after upgrading to NodeJS 18
    
    LF-2985
    yuriy-sedinkin committed Jul 2, 2024
    Copy the full SHA
    c62598f View commit details
  2. Changes as per review

    LF-2985
    yuriy-sedinkin committed Jul 2, 2024
    Copy the full SHA
    365df10 View commit details
  3. Revert "Revert "Fix #136""

    This reverts commit 749fc98
    yuriy-sedinkin committed Jul 2, 2024
    Copy the full SHA
    16ac94a View commit details
  4. Merge remote-tracking branch 'lhc-git/master' into feature/LF-2100/su…

    …pplementary-weight-function
    
    # Conflicts:
    #	CHANGELOG.md
    #	package-lock.json
    #	package.json
    #	src/fhirpath.js
    yuriy-sedinkin committed Jul 2, 2024
    Copy the full SHA
    ad7e71f View commit details
  5. Merge branch 'feature/LF-2100/supplementary-weight-function' into 'ma…

    …ster'
    
    Added supplementary function weight()
    
    See merge request lfor/fhirpath.js!14
    yuriy-sedinkin committed Jul 2, 2024
    Copy the full SHA
    3cd1c87 View commit details

Commits on Jul 17, 2024

  1. Changes as per review

    LF-2985
    yuriy-sedinkin committed Jul 17, 2024
    Copy the full SHA
    4ce191e View commit details

Commits on Jul 22, 2024

  1. Changes as per review and npm audit fix

    LF-2985
    yuriy-sedinkin committed Jul 22, 2024
    Copy the full SHA
    d98e640 View commit details

Commits on Aug 2, 2024

  1. Copy the full SHA
    fedb4de View commit details

Commits on Aug 5, 2024

  1. Merge branch 'refs/heads/master' into feature/LF-2985/async-functions

    # Conflicts:
    #	CHANGELOG.md
    #	demo/package-lock.json
    #	index.d.ts
    #	package-lock.json
    #	package.json
    #	src/fhirpath.js
    yuriy-sedinkin committed Aug 5, 2024
    Copy the full SHA
    20734f2 View commit details
  2. Resolved merge conflicts

    LF-2985
    yuriy-sedinkin committed Aug 5, 2024
    Copy the full SHA
    07fffc5 View commit details
  3. Merge branch 'feature/LF-2985/async-functions' into 'master'

    Added support for async functions
    
    See merge request lfor/fhirpath.js!17
    yuriy-sedinkin committed Aug 5, 2024
    Copy the full SHA
    3002a74 View commit details

Commits on Aug 6, 2024

  1. Copy the full SHA
    a4327cf View commit details
  2. Changes as per review

    yuriy-sedinkin committed Aug 6, 2024
    Copy the full SHA
    b17f35a View commit details
  3. Merge branch 'bugfix/return-type-in-ts-type-declarations' into 'master'

    Fixed return type for `evaluate` and `compile` in TypeScript type declarations
    
    See merge request lfor/fhirpath.js!20
    yuriy-sedinkin committed Aug 6, 2024
    Copy the full SHA
    c057867 View commit details

Commits on Aug 7, 2024

  1. Copy the full SHA
    06ac6b8 View commit details

Commits on Aug 13, 2024

  1. Copy the full SHA
    96ccd17 View commit details

Commits on Aug 16, 2024

  1. Update as per discussion

    LF-3081
    yuriy-sedinkin committed Aug 16, 2024
    Copy the full SHA
    cc86e57 View commit details
  2. Changes as per review

    LF-3098
    yuriy-sedinkin committed Aug 16, 2024
    Copy the full SHA
    9ba29fb View commit details
  3. Fixed the files section

    LF-3098
    yuriy-sedinkin committed Aug 16, 2024
    Copy the full SHA
    47ac4a5 View commit details

Commits on Aug 30, 2024

  1. Merge remote-tracking branch 'refs/remotes/lhc-git/master' into bugfi…

    …x/LF-3098/remove-npm-ci-in-demo
    
    # Conflicts:
    #	CHANGELOG.md
    #	package-lock.json
    #	package.json
    yuriy-sedinkin committed Aug 30, 2024
    Copy the full SHA
    7aebca5 View commit details
  2. npm audit fix

    LF-3098
    yuriy-sedinkin committed Aug 30, 2024
    Copy the full SHA
    f0cbc95 View commit details
  3. Merge branch 'bugfix/LF-3098/remove-npm-ci-in-demo' into 'master'

    Fixed package.json so we don't need to remember to run (cd demo && npm ci)
    
    See merge request lfor/fhirpath.js!19
    yuriy-sedinkin committed Aug 30, 2024
    Copy the full SHA
    c50b820 View commit details

Commits on Sep 25, 2024

  1. Changes as per review

    LF-3081
    yuriy-sedinkin committed Sep 25, 2024
    Copy the full SHA
    3ab8347 View commit details

Commits on Oct 10, 2024

  1. Changes as per review

    LF-3081
    yuriy-sedinkin committed Oct 10, 2024
    Copy the full SHA
    6c1f35b View commit details
  2. Merge remote-tracking branch 'refs/remotes/lhc-git/master' into bugfi…

    …x/LF-3081/search-for-item-weight-in-value-set-and-code-system
    
    # Conflicts:
    #	CHANGELOG.md
    yuriy-sedinkin committed Oct 10, 2024
    Copy the full SHA
    4e00c79 View commit details
  3. Resolved merge conflicts

    LF-3081
    yuriy-sedinkin committed Oct 10, 2024
    Copy the full SHA
    139250e View commit details

Commits on Oct 22, 2024

  1. Changes as per review and discussions

    LF-3081
    yuriy-sedinkin committed Oct 22, 2024
    Copy the full SHA
    12a5d91 View commit details

Commits on Nov 8, 2024

  1. Changes as per review

    LF-3081
    yuriy-sedinkin committed Nov 8, 2024
    Copy the full SHA
    1766195 View commit details

Commits on Nov 20, 2024

  1. Changes as per review and discussions

    LF-3081
    yuriy-sedinkin committed Nov 20, 2024
    Copy the full SHA
    2c6f4b4 View commit details
  2. Minor update

    LF-3081
    yuriy-sedinkin committed Nov 20, 2024
    Copy the full SHA
    c4a0602 View commit details

Commits on Nov 27, 2024

  1. Copy the full SHA
    2320dfd View commit details

Commits on Dec 10, 2024

  1. Added support for paging when expanding value sets, fixed "uri" for t…

    …he "itemWeight" property
    
    LF-3081
    yuriy-sedinkin committed Dec 10, 2024
    Copy the full SHA
    0cccc4b View commit details

Commits on Dec 24, 2024

  1. patch context processing

    axelv committed Dec 24, 2024
    Copy the full SHA
    149e4cd View commit details
Showing with 11,764 additions and 9,708 deletions.
  1. +3 −0 .eslintrc.yml
  2. +82 −0 CHANGELOG.md
  3. +102 −9 README.md
  4. +1 −1 bashrc.fhirpath
  5. +20 −3 bin/fhirpath
  6. +18 −0 bin/install-demo.js
  7. +77 −10 converter/dataset/fhir-r4.xml
  8. +1,001 −3,414 demo/package-lock.json
  9. +1 −2 demo/package.json
  10. +87 −5 demo/public/app.css
  11. +232 −30 demo/public/app.js
  12. +39 −5 demo/public/index.html
  13. +2 −1 demo/webpack.config.js
  14. +46 −0 docs/weight.md
  15. +2 −1 fhir-context/dstu2/index.d.ts
  16. +2 −0 fhir-context/dstu2/index.js
  17. +3 −1 fhir-context/r4/index.d.ts
  18. +11 −0 fhir-context/r4/index.js
  19. +3 −1 fhir-context/r5/index.d.ts
  20. +11 −0 fhir-context/r5/index.js
  21. +2 −1 fhir-context/stu3/index.d.ts
  22. +2 −0 fhir-context/stu3/index.js
  23. +4,205 −5,901 package-lock.json
  24. +16 −4 package.json
  25. +45 −0 src/additional.js
  26. +10 −2 src/aggregate.js
  27. +9 −3 src/combining.js
  28. +39 −15 src/deep-equal.js
  29. +18 −5 src/existence.js
  30. +762 −0 src/factory.js
  31. +74 −16 src/fhirpath.d.ts
  32. +252 −97 src/fhirpath.js
  33. +65 −26 src/filtering.js
  34. +43 −37 src/misc.js
  35. +725 −0 src/sdc-ig-supplements.js
  36. +197 −0 src/terminologies.js
  37. +118 −45 src/types.js
  38. +94 −16 src/utilities.js
  39. +30 −0 test/api.test.js
  40. +439 −0 test/async-functions.test.js
  41. +9 −0 test/cases/3.2_paths.yaml
  42. +2 −2 test/cases/5.1_existence.yaml
  43. +1 −2 test/cases/5.3_subsetting.yaml
  44. +2 −2 test/cases/5.4_combining.yaml
  45. +6 −0 test/cases/5.5_conversion.yaml
  46. +41 −7 test/cases/6.1_equality.yaml
  47. +6 −1 test/cases/8_variables.yaml
  48. +672 −0 test/cases/factory.yaml
  49. +168 −11 test/cases/fhir-r4.yaml
  50. +89 −0 test/cases/getValue.yaml
  51. +6 −6 test/cases/hasValue.yaml
  52. +35 −7 test/cypress/e2e/demo.cy.js
  53. +33 −19 test/fhirpath.test.js
  54. +89 −0 test/mock-fetch-results.js
  55. +8 −0 test/resources/patient-example-2.json
  56. +140 −0 test/resources/weight-examples/questionnaire-R4.json
  57. +146 −0 test/resources/weight-examples/questionnaire-R5.json
  58. +106 −0 test/resources/weight-examples/questionnaire-response-R4.json
  59. +109 −0 test/resources/weight-examples/questionnaire-response-R5.json
  60. +1,103 −0 test/supplements.test.js
  61. +60 −0 test/typescript/fhirpath.test-d.ts
  62. +45 −0 test/user-invocation-table.test.js
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ parserOptions:
ecmaVersion: 2016
requireConfigFile: false
sourceType: module
globals:
Headers: true
fetch: true
rules:
indent:
- error
82 changes: 82 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,88 @@
This log documents significant changes for each release. This project follows
[Semantic Versioning](http://semver.org/).

## [3.18.0] - 2024-03-21
### Added
- The `signal` option to the `evaluate()` function and the function that is the
result of executing the `compile()` function to allow the user to cancel the
evaluation of an asynchronous expression.
### Changed
- The demo application now allows you to select a model, terminology server,
environment variables and can evaluate asynchronous expressions.
### Fixed
- The `weight()`/`ordinal()` function can now search for item weight in value
set and code system.
- Removed creation of global `TypeInfo.model` value to allow asynchronous
evaluations using different models.

## [3.17.3] - 2025-03-13
### Fixed
- an issue where the "not implemented" exception was not raised when it should
have been raised.

## [3.17.2] - 2025-02-25
### Changed
- Adjusted equality operation to take into account "id" and "extension"
properties for primitive types.

## [3.17.1] - 2025-02-12
### Fixed
- exception in `toString()` for node of type `date`, `dateTime`, `instant` or
`time` without value but with extension and/or id.

## [3.17.0] - 2025-02-03
### Added
- getValue() function.

## [3.16.4] - 2025-01-24
### Fixed
- Bug where single-quoted variable names were not supported.

## [3.16.3] - 2025-01-21
### Fixed
- Bug with async boolean expressions (when an operator takes an async value as
a singleton parameter).

## [3.16.2] - 2025-01-16
### Fixed
- Bug with toString when userInvocationTable passed.

## [3.16.1] - 2025-01-09
### Fixed
- Read environment variables only when they are used in an expression, avoiding
unnecessary getter calls when working with libraries like Jotai.

## [3.16.0] - 2024-10-10
### Added
- Support for type factory API (%factory).

## [3.15.2] - 2024-08-30
### Fixed
- Removed the need to run `(cd demo && npm ci)`.
- Excluded unnecessary files from the npm package.

## [3.15.1] - 2024-08-06
### Fixed
- Return data type for `evaluate` and `compile` in TypeScript type declarations.
The return data type now depends on the `async` option.

## [3.15.0] - 2024-08-05
### Added
- option `async`, which allows us to get the result of an expression evaluation
asynchronously.
- Support for asynchronous functions: if any function in an expression returns
a Promise and option `async=true`, then the result of evaluating
the expression is a Promise.
- async function `memberOf`.

## [3.14.1] - 2024-07-02
### Fixed
- impossibility to use attribute name that starts with a capital letter.

## [3.14.0] - 2024-07-02
### Added
- supplementary function `weight()` with alternative name `ordinal()`.

## [3.13.4] - 2024-06-13
### Fixed
- a bug that could cause the context input parameter containing environment
111 changes: 102 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# fhirpath.js

[![Build Status](https://travis-ci.org/HL7/fhirpath.js.svg?branch=master)](https://travis-ci.org/HL7/fhirpath.js)

[FHIRPath](http://hl7.org/fhirpath/) implementation in JavaScript.

## Demo
Try it out on the [demo page](https://hl7.github.io/fhirpath.js/).


## Table of Contents:
- [Installation](#installation-)
* [Server-side (Node.js)](#server-side--nodejs-)
* [Web-browser](#web-browser-)
- [API Usage](#api-usage)
* [Asynchronous functions](#asynchronous-functions)
* [User-defined functions](#user-defined-functions)
- [fhirpath CLI](#fhirpath-cli)
- [Implementation Status](#implementation-status)
- [Development Notes](#development-notes)
* [Building the demo page](#building-the-demo-page)
* [Updating the FHIR module on a FHIR release](#updating-the-fhir-module-on-a-fhir-release)
- [Credits](#credits)

## Installation:

@@ -45,8 +55,45 @@ These will define additional global variables like "fhirpath_dstu2_model",
Evaluating FHIRPath:

```js
evaluate(resourceObject, fhirPathExpression, environment, model, options);
evaluate(resourceObject, fhirPathExpression, envVars, model, options);
```
where:
* resourceObject - FHIR resource, part of a resource (in this case
fhirPathExpression.base should be provided), bundle as js object or array
of resources.
* fhirPathExpression - string with FHIRPath expression, sample 'Patient.name.given',
or object, if fhirData represents the part of the FHIR resource:
* fhirPathExpression.base - base path in resource from which fhirData was extracted
* fhirPathExpression.expression - FHIRPath expression relative to path.base
* envVars - a hash of variable name/value pairs. It is not recommended to
modify the internal fields of a variable after passing it to the evaluation
function, since these changes may not be taken into account in further
evaluations due to caching of the evaluation results.
We currently cache `%questionnaire` scores for the `weight()` function.
* model - the "model" data object specific to a domain, e.g. R4.
For example, you could pass in the result of require("fhirpath/fhir-context/r4");
* options - additional options:
* options.resolveInternalTypes - whether values of internal
types should be converted to standard JavaScript types (true by default).
If false is passed, this conversion can be done later by calling
fhirpath.resolveInternalTypes().
* options.traceFn - An optional trace function to call when tracing.
* options.userInvocationTable - a user invocation table used
to replace any existing functions or define new ones.
* options.async - defines how to support asynchronous functions:
* false or similar to false, e.g. undefined, null, or 0 (default) - throw
an exception,
* true or similar to true - return Promise, only for asynchronous functions,
* "always" - return Promise always.
* options.terminologyUrl - a URL that points to a FHIR RESTful API that is
used to create %terminologies that implements the Terminology Service API.
* options.terminologyUrl - a URL that points to a terminology server. This
URL is used to initialize %terminologies, as defined in the FHIR FHIRPath
[Terminology Service API](https://www.hl7.org/fhir/fhirpath.html#txapi).
See the [Implementation Status](#implementation-status) section for the
currently supported %terminologies APIs.
* options.signal - an AbortSignal object that allows you to abort the
asynchronous FHIRPath expression evaluation.

Note: The resource will be modified by this function to add type information.

@@ -88,7 +135,7 @@ Precompiling fhirpath - result can be reused against multiple resources:

```js
const path = fhirpath.compile('Patient.name.given', fhirpath_r4_model);
var res = path({"resourceType": "Patient", ...}, {a: 5, ...});
let res = path({"resourceType": "Patient", ...}, {a: 5, ...});
```

If you are going to use the above "precompile" option with a part of a resource,
@@ -101,7 +148,7 @@ expression - fhirpath expression relative to base.
const path = fhirpath.compile({ "base": "QuestionnaireResponse.item",
"expression": "answer.value = 2 year"},
fhirpath_r4_model);
var res = path({ "answer": { "valueQuantity": ...}, {a: 5, ...});
let res = path({ "answer": { "valueQuantity": ...}, {a: 5, ...});
```
During expression evaluation, some values or parts of values may have internal
@@ -113,7 +160,7 @@ the option "resolveInternalTypes" = false:
```js
const contextVariable = fhirpath.evaluate(
resource, expression, context, model, {resolveInternalTypes: false}
resource, expression, envVars, model, {resolveInternalTypes: false}
);
```
@@ -125,6 +172,22 @@ const path = fhirpath.compile(
);
```
But passing the `signal` option to compile() whose result is used more than once
will cause abortion problems. If you need to abort the evaluation of the compiled
expression, you should pass the signal option to the function that is returned
by compile():
```js
const path = fhirpath.compile(
expression, model, {async: true}
);
const abortController = new AbortController();
const signal = abortController.signal;
let res = path(resource, environment, {signal});
// Abort the evaluation of the compiled expression
abortController.abort();
```
If at some point you decide to convert all values which have internal types to
standard JavaScript types you can use the special function "resolveInternalTypes":
@@ -140,7 +203,7 @@ In the next example, `res` will have a value like this:
```js
const res = fhirpath.types(
fhirpath.evaluate(resource, expression, context, model, {resolveInternalTypes: false})
fhirpath.evaluate(resource, expression, envVars, model, {resolveInternalTypes: false})
);
```
@@ -150,9 +213,30 @@ let tracefunction = function (x, label) {
console.log("Trace output [" + label + "]: ", x);
};

const res = fhirpath.evaluate(contextNode, path, environment, fhirpath_r4_model, { traceFn: tracefunction });
const res = fhirpath.evaluate(contextNode, path, envVars, fhirpath_r4_model, { traceFn: tracefunction });
```
### Asynchronous functions
Some FHIRPath functions may be asynchronous. These functions throw exceptions by default.
To enable these functions, we need to pass the `async` option to `evaluate` or `compile`.
`async=true` enables return of a Promise only for expressions containing asynchronous functions.
`async='always'` enables a Promise to be returned for any expression.
For example, using the `memberOf` function might look like this:
```js
fhirpath.evaluate(
resource,
"Observation.code.coding.where(memberOf('http://hl7.org/fhir/ValueSet/observation-vitalsignresult'))",
{},
model,
{ async: true, terminologyUrl: 'https://lforms-fhir.nlm.nih.gov/baseR4' }
)
```
Please note that for the `memberOf` function to work you must pass in
a terminologyUrl option.
### User-defined functions
You can also replace any existing functions or define new ones. To do this you
@@ -327,6 +411,15 @@ Completed sections:
Supported additional functions from FHIR:
- extension(url : string) : collection
- hasValue() : Boolean
- memberOf(valueset : string) : Boolean
Supported [Terminology Service APIs](https://build.fhir.org/fhirpath.html#txapi):
- only `%terminologies.validateVS(valueSet, coded, params) : Parameters` is
partially supported. `valueSet` can only be a URL.
Supported [FHIRPath supplements](https://hl7.org/fhir/uv/sdc/expressions.html#fhirpath-supplements):
- sum(), min(), max(), count(), avg() - short-cuts for the equivalent .aggregate().
- ordinal()/weight() - see [description of the weight() function](docs/weight.md).
## Development Notes
2 changes: 1 addition & 1 deletion bashrc.fhirpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The following is the standard bashrc file for the
# development team for this repository.

NODE=node-v16.15.0-linux-x64
NODE=node-v22.11.0-linux-x64
#
# Set path
PATH=~/${NODE}/bin:/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/etc
23 changes: 20 additions & 3 deletions bin/fhirpath
Original file line number Diff line number Diff line change
@@ -45,8 +45,25 @@ else {
throw new Error('FHIR model must be one of '+supportedVersions);
model = require('../fhir-context/'+options.model);
}
let res = fp.evaluate(resource, base ? {base, expression} : expression, context, model);
console.log('fhirpath(' + expression + ') =>');
console.log(JSON.stringify(res, null, " "));
let res = fp.evaluate(
resource, base ? {base, expression} : expression, context, model,
{ async: true }
);

if (res instanceof Promise) {
res.then((r) => printResult(expression, r))
} else {
printResult(expression, res);
}
}
}

/**
* Prints the result to the console.
* @param {string} expression - input expression
* @param {Array} result - result of evaluating the expression
*/
function printResult(expression, result) {
console.log('fhirpath(' + expression + ') =>');
console.log(JSON.stringify(result, null, " "));
}
18 changes: 18 additions & 0 deletions bin/install-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This file contains code to run "npm ci" in the demo directory if it exists.
* The demo directory has been excluded from the npm package, and the presence
* of the demo directory is a signal that we are working with the source code.
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require("fs"); // Or `import fs from "fs";` with ESM

const demoDir = path.join(__dirname, '../demo');

if (fs.existsSync(demoDir)) {
console.log('Installing node modules in the demo directory...');
spawn('npm', ['ci'], {
cwd: demoDir,
stdio: 'inherit'
});
}
Loading