Giter VIP home page Giter VIP logo

fhirpath.js's Introduction

fhirpath.js

Build Status

FHIRPath implementation in JavaScript.

Demo

Try it out on the demo page.

Installation:

Server-side (Node.js)

npm install –save fhirpath
const fhirpath = require('fhirpath');

Web-browser:

Download the zip file from the releases page. It contains a JavaScript file, fhirpath.min.js, which defines a global "fhirpath" variable, which you can then use as shown below.

Usage

// Evaluating FHIRPath
// API: evaluate(resourceObject, fhirPathExpression, environment)
fhirpath.evaluate({"resourceType": "Patient", ...}, 'Patient.name.given');

// Environment variables can be passed in as third argument as a hash of
// name/value pairs:
fhirpath.evaluate({}, '%a - 1', {a: 5});

// Precompiling fhirpath - result can be reused against multiple resources
const path = fhirpath.compile('Patient.name.given');
var res2 = path({"resourceType": "Patient", ...});

fhirpath CLI

bin/fhirpath is a command-line tool for experimenting with FHIRPath.

curl http://www.hl7.org/fhir/patient-example-a.json  > pt.json

fhirpath --expression 'Patient.name.given' --resourceFile pt.json

> fhirpath(Patient.name.family) =>
> [
>  "Donald"
> ]

Instead of passing a filename containing the resource, the string of JSON representing the resource can be passed directly via --resourceJSON (useful if the JSON is brief).

fhirpath --expression 'a.b + 2' --resourceJSON '{"a": {"b": 1}}'

> fhirpath(a.b + 2) =>
> [
>  3
> ]

Environment variables can be passed via --variables followed by the JSON for an object with variable names as keys.

fhirpath --expression '%v + 2' --resourceJSON '{}' --variables '{"v": 5}'

> fhirpath(%v + 2) =>
> [
>  7
> ]

If given just the FHIRPath expression, the utility will print the parsed tree:

fhirpath --expression 'Patient.name.given'

> ... will print fhirpath ast in yaml

Implementation Status

We are currently implementing version 1.0 (a.k.a STU1) of FHIRPath.

The core parser was generated from the FHIRPath ANTLR grammar.

Completed sections:

  • 3 (Path selection) - except that "is" and "as" are not supported yet
  • 5.1 (Existence)
  • 5.2 (Filtering and Projection) "ofType" - basic support for primitives
  • 5.3 (Subsetting)
  • 5.4 (Combining)
  • 5.6 (String Manipulation)
  • 5.7 (Tree Navigation)
  • 5.8 (Utility Functions)
  • 6.1 (Equality)
  • 6.4 (Collections)
  • 6.5 (Boolean logic)
  • 6.6 (Math)
  • 6.8 (Operator Precedence) - handled by ANTLR parser
  • 7 (Lexical Elements) - handled by ANTLR parser
  • 8 (Environment Variables)

Partially completed sections:

  • 6.2 (Comparison) - type checking is not completely performed, and dates are treated as strings (for now).

We are deferring handling information about FHIR resources, as much as possible. This affects implementation of the following sections:

  • 6.3 (Types) - deferred

Deviations:

  • The library compares dateTime strings as strings, because it does not know which strings are dates. If your times consistently use "Z" for their timezone, or consistently avoid using "Z", this should not cause a problem.

Development Notes

This section is for people doing development on this package (as opposed to using the package).

If you need to regenerate the parser from the ANTLR4 grammar (which is in parser/FHIRPath.g4), first download the ANTLR4 library from http://www.antlr.org/download/antlr-4.7.1-complete.jar into the root of the project directory, and then run "npm run generateParser".

Building the demo page

npm run build
cd demo
npm install && npm run start

open browser on localhost:8080

fhirpath.js's People

Contributors

plynchnlm avatar niquola avatar rende11 avatar traviscibot avatar

Watchers

James Cloos avatar Antti Kalliokoski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.