Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmandel/fhirpath.js
FHIR Path implementation in JavaScript
https://github.com/jmandel/fhirpath.js
Last synced: 19 days ago
JSON representation
FHIR Path implementation in JavaScript
- Host: GitHub
- URL: https://github.com/jmandel/fhirpath.js
- Owner: jmandel
- Created: 2015-11-19T09:44:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-21T01:09:57.000Z (almost 9 years ago)
- Last Synced: 2024-10-06T15:43:06.121Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 183 KB
- Stars: 14
- Watchers: 2
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## fhirpath.js
To use it, `npm install fhirpath.js`. Then:
```js
var fp = require('fhirpath.js')
var result = fp.evaluate({ // the target to evaluate against
"a": 1,
"b": [2, 3]
}, "a | b | a") // the path expression to evaluateassert.deepEqual(result, [1, 2, 3, 1])
```To add you own custom constants to the lookup table, pass along a third argument like:
```js
var result = fp.evaluate({ // the target to evaluate against
"a": "some great value",
"b": [2, 3]
}, "a=%my-constant", {
"my-constant": "some great value"
})
assert.deepEqual(result, [true])
```If passing a lookup table with every call gets tedious, you can create a new execution context with the table baked in:
```js
var myfp = fp.withConstants({"my-constant": "some great value"})
var result = myfp.evaluate({ // the target to evaluate against
"a": "some great value",
"b": [2, 3]
}, "a=%my-constant")
assert.deepEqual(result, [true])
```## Try it
Live demo at https://niquola.github.io/fhirpath-demo/#/
## Develop it
Generate the lexer and parser from the included Antlr grammer via:
sh ./setup.sh
Run tests:
npm test
Regenerate test case file:
npm run-script generate-test-cases