|
1 | 1 | # fhirpath.js
|
2 | 2 |
|
3 |
| -[](https://travis-ci.org/HL7/fhirpath.js) |
4 |
| - |
5 | 3 | [FHIRPath](http://hl7.org/fhirpath/) implementation in JavaScript.
|
6 | 4 |
|
7 | 5 | ## Demo
|
8 | 6 | Try it out on the [demo page](https://hl7.github.io/fhirpath.js/).
|
9 | 7 |
|
10 |
| - |
| 8 | +## Table of Contents: |
| 9 | +- [Installation](#installation-) |
| 10 | + * [Server-side (Node.js)](#server-side--nodejs-) |
| 11 | + * [Web-browser](#web-browser-) |
| 12 | +- [API Usage](#api-usage) |
| 13 | + * [Asynchronous functions](#asynchronous-functions) |
| 14 | + * [User-defined functions](#user-defined-functions) |
| 15 | +- [fhirpath CLI](#fhirpath-cli) |
| 16 | +- [Implementation Status](#implementation-status) |
| 17 | +- [Development Notes](#development-notes) |
| 18 | + * [Building the demo page](#building-the-demo-page) |
| 19 | + * [Updating the FHIR module on a FHIR release](#updating-the-fhir-module-on-a-fhir-release) |
| 20 | +- [Credits](#credits) |
11 | 21 |
|
12 | 22 | ## Installation:
|
13 | 23 |
|
@@ -47,6 +57,37 @@ Evaluating FHIRPath:
|
47 | 57 | ```js
|
48 | 58 | evaluate(resourceObject, fhirPathExpression, environment, model, options);
|
49 | 59 | ```
|
| 60 | +where: |
| 61 | +* resourceObject - FHIR resource, part of a resource (in this case |
| 62 | + fhirPathExpression.base should be provided), bundle as js object or array |
| 63 | + of resources. |
| 64 | +* fhirPathExpression - string with FHIRPath expression, sample 'Patient.name.given', |
| 65 | + or object, if fhirData represents the part of the FHIR resource: |
| 66 | + * fhirPathExpression.base - base path in resource from which fhirData was extracted |
| 67 | + * fhirPathExpression.expression - FHIRPath expression relative to path.base |
| 68 | +* environment - a hash of variable name/value pairs. |
| 69 | +* model - the "model" data object specific to a domain, e.g. R4. |
| 70 | + For example, you could pass in the result of require("fhirpath/fhir-context/r4"); |
| 71 | +* options - additional options: |
| 72 | + * options.resolveInternalTypes - whether values of internal |
| 73 | + types should be converted to standard JavaScript types (true by default). |
| 74 | + If false is passed, this conversion can be done later by calling |
| 75 | + fhirpath.resolveInternalTypes(). |
| 76 | + * options.traceFn - An optional trace function to call when tracing. |
| 77 | + * options.userInvocationTable - a user invocation table used |
| 78 | + to replace any existing functions or define new ones. |
| 79 | + * options.async - defines how to support asynchronous functions: |
| 80 | + * false or similar to false, e.g. undefined, null, or 0 (default) - throw |
| 81 | + an exception, |
| 82 | + * true or similar to true - return Promise, only for asynchronous functions, |
| 83 | + * "always" - return Promise always. |
| 84 | + * options.terminologyUrl - a URL that points to a FHIR RESTful API that is |
| 85 | + used to create %terminologies that implements the Terminology Service API. |
| 86 | + * options.terminologyUrl - a URL that points to a terminology server. This |
| 87 | + URL is used to initialize %terminologies, as defined in the FHIR FHIRPath |
| 88 | + [Terminology Service API](https://www.hl7.org/fhir/fhirpath.html#txapi). |
| 89 | + See the [Implementation Status](#implementation-status) section for the |
| 90 | + currently supported %terminologies APIs. |
50 | 91 |
|
51 | 92 | Note: The resource will be modified by this function to add type information.
|
52 | 93 |
|
@@ -153,6 +194,27 @@ let tracefunction = function (x, label) {
|
153 | 194 | const res = fhirpath.evaluate(contextNode, path, environment, fhirpath_r4_model, { traceFn: tracefunction });
|
154 | 195 | ```
|
155 | 196 |
|
| 197 | +### Asynchronous functions |
| 198 | +
|
| 199 | +Some FHIRPath functions may be asynchronous. These functions throw exceptions by default. |
| 200 | +To enable these functions, we need to pass the `async` option to `evaluate` or `compile`. |
| 201 | +`async=true` enables return of a Promise only for expressions containing asynchronous functions. |
| 202 | +`async='always'` enables a Promise to be returned for any expression. |
| 203 | +
|
| 204 | +For example, using the `memberOf` function might look like this: |
| 205 | +```js |
| 206 | +fhirpath.evaluate( |
| 207 | + resource, |
| 208 | + "Observation.code.coding.where(memberOf('http://hl7.org/fhir/ValueSet/observation-vitalsignresult'))", |
| 209 | + {}, |
| 210 | + model, |
| 211 | + { async: true, terminologyUrl: 'https://lforms-fhir.nlm.nih.gov/baseR4' } |
| 212 | +) |
| 213 | +``` |
| 214 | +
|
| 215 | +Please note that for the `memberOf` function to work you must pass in |
| 216 | +a terminologyUrl option. |
| 217 | +
|
156 | 218 | ### User-defined functions
|
157 | 219 |
|
158 | 220 | You can also replace any existing functions or define new ones. To do this you
|
@@ -327,6 +389,11 @@ Completed sections:
|
327 | 389 | Supported additional functions from FHIR:
|
328 | 390 | - extension(url : string) : collection
|
329 | 391 | - hasValue() : Boolean
|
| 392 | +- memberOf(valueset : string) : Boolean |
| 393 | +
|
| 394 | +Supported Terminology Service APIs (https://build.fhir.org/fhirpath.html#txapi): |
| 395 | +- only `%terminologies.validateVS(valueSet, coded, params) : Parameters` is |
| 396 | + partially supported. `valueSet` can only be a URL. |
330 | 397 |
|
331 | 398 | ## Development Notes
|
332 | 399 |
|
|
0 commit comments