• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Javascript implementation of FHIRPath

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');
// For FHIR model data (choice type support) pull in the model file:
const fhirpath_r4_model = require('fhirpath/fhir-context/r4');

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. Note that this file is UTF-8 encoded, and the script needs to be loaded as such. For an example, see the browser-build/test/index.html file, which sets the page to be UTF-8.

For FHIR-specific features (e.g. handling of choice type fields), you will also want to include a second file with the desired FHIR version model data, e.g. fhirpath.r4.min.js for pulling in the R4 model. (At the moment, those files are small, but it would not be surprising if they grew as more support for FHIR type handling is added, so they are kept seperate from the main FHIRPath file.) These will define additional global variables like "fhirpath_dstu2_model", "fhirpath_stu3_model" or "fhirpath_r4_model".

API Usage

Evaluating FHIRPath:

evaluate(resourceObject, fhirPathExpression, environment, model, options);

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

Basic example:

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});

To include FHIR model data (for support of choice types), pass in the model data object as the fourth argument:

fhirpath.evaluate({"resourceType": "Observation", "valueString": "green"},
                  'Observation.value', null, fhirpath_r4_model);

If the first parameter is a part of a resource, the second parameter should be an object with properties "base" and "expression": base - the path in the resource that represents the partial resource being used as the context, expression - fhirpath expression relative to base.

fhirpath.evaluate({ "answer": { "valueQuantity": ...}},
                  { "base": "QuestionnaireResponse.item",
                    "expression": "answer.value = 2 year"},
                  null, fhirpath_r4_model);                  

Precompiling fhirpath - result can be reused against multiple resources:

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

If you are going to use the above "precompile" option with a part of a resource, the first parameter should be an object with properties "base" and "expression": base - the path in the resource that represents the partial resource being used as the context, 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, ...});

During expression evaluation, some values or parts of values may have internal data types (e.g. FP_DateTime, FP_Time, FP_Quantity). By default, all of these values are converted to standard JavaScript types, but if you need to use the result of evaluation as a context variable for another FHIRpath expression, it would be best to preserve the internal data types. To do this you can use the option "resolveInternalTypes" = false:

const contextVariable = fhirpath.evaluate(
  resource, expression, context, model, {resolveInternalTypes: false}
);

This option may also be passed to compile function:

const path = fhirpath.compile(
  expression, model, {resolveInternalTypes: false}
);

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":

const res = fhirpath.resolveInternalTypes(value);

Also, there is a special API function to get the type of each element in FHIRPath result array which was obtained from evaluate() (unless you resolve the internal types). This function returns an array of strings. In the next example, res will have a value like this: ['FHIR.dateTime', 'FHIR.string', ...].

const res = fhirpath.types(
  fhirpath.evaluate(resource, expression, context, model, {resolveInternalTypes: false})
);

If you want to capture evaluations of the trace method, you can include that in the options object.

let tracefunction = function (x, label) {
  console.log("Trace output [" + label + "]: ", x);
};

const res = fhirpath.evaluate(contextNode, path, environment, fhirpath_r4_model, { traceFn: tracefunction });

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
> ]

FHIR model data can be included via --model and the FHIR release version (in lower case, e.g., 'dstu2', 'stu3' or 'r4').

fhirpath --expression 'Observation.value' --resourceJSON '{"resourceType": "Observation", "valueString": "Green"}' --model r4

Also, you can pass in a filename or a string of JSON representing a part of the resource. In that case, you should pass in the base path from which this part of the resource was extracted.

fhirpath --basePath QuestionnaireResponse.item --expression 'answer.value' --model r4 --resourceFile questionnaire-part-example.json

> fhirpath(answer.value) =>
> [
>  "2 year"
> ]

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 working on implementing version 2.0.0 of FHIRPath; some behavior may still be following the previous version, STU1.

The core parser was generated from the FHIRPath ANTLR grammar.

Completed sections:

  • 3 (Path selection)
  • 5.1 (Existence)
  • 5.2 (Filtering and Projection) "ofType"
  • 5.3 (Subsetting)
  • 5.4 (Combining)
  • 5.5 (Conversion)
  • 5.6 (String Manipulation)
  • 5.7 (Tree Navigation)
  • 5.8 (Utility Functions)
  • 6.1 (Equality)
  • 6.2 (Comparison)
  • 6.3 (Types)
  • 6.4 (Collections)
  • 6.5 (Boolean logic)
  • 6.6 (Math)
  • 6.8 (Operator Precedence) - handled by ANTLR parser
  • 7 (Aggregates)
  • 8 (Lexical Elements) - handled by ANTLR parser
  • 9 (Environment Variables)

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 install && npm run build
cd demo
npm install && npm run build && npm run start

open browser on localhost:8080

Updating the FHIR module on a FHIR release

  • Download the FHIR StructureDefinitions (into the fhir-context directory - don't check these in)
    > wget http://hl7.org/fhir/profiles-types.json -O profiles-types.json
    > wget http://hl7.org/fhir/profiles-others.json -O profiles-others.json
    > wget http://hl7.org/fhir/profiles-resources.json -O profiles-resources.json
    
  • Create the new folder for the version you are importing
    > mkdir r5
    
  • Run the script `` with NodeJS
    > node ./extract-model-info.js --outputDir r5 --fhirDefDir .
    
  • Compare the output files in the new folder to those of the last release (looking for issues that might be due to changes in the StructureDefinition format)
  • Copy the index.js file from the last release into the new folder
    > cp ../r4/index.js r5
    
  • Update the /index.d.ts file to include the new module as an export
    declare module "fhirpath/fhir-context/r5" {
      export const {
        choiceTypePaths,
        pathsDefinedElsewhere,
        type2Parent,
        path2Type
      }: Model;
    }

Credits

This implemention of the FHIRPath specification was developed as a joint project between the U.S. National Library of Medicine (NLM) and Health Samurai, and was then donated to HL7. Current maintenance and additional development is being performed by NLM, but we welcome contributions from others. (For anything substantial, we recommend raising an issue first to coordinate with us.)

A complete list of contributors can be found at https://github.com/HL7/fhirpath.js/graphs/contributors

More Repositories

1

fhir

Official source for the HL7 FHIR Specification
HTML
563
star
2

C-CDA-Examples

SDWG Supported Samples
HTML
181
star
3

fhir-ig-publisher

Source code for the IG publisher
Java
69
star
4

v2-to-fhir

This repository supports tools and content for the V2 to FHIR project.
GLSL
55
star
5

fhir-shorthand

FHIR Shorthand
Batchfile
43
star
6

bulk-data

Bulk Data Implementation Guide
GLSL
38
star
7

smart-web-messaging

SMART Web Messaging Specification Development
Batchfile
36
star
8

CDA-core-2.0

Contains the latest CDA SDTC Extensions Schema along with the original Normative version
HTML
35
star
9

fhir-shc-vaccination-ig

FHIR Implementation Guide describing clinical and patient data contained within a SMART Health Card
GLSL
35
star
10

CDA-core-xsl

Informative stylesheet based on XSLT 1.0 to render all CDA documents
XSLT
30
star
11

US-Core

FHIR R4 version of US Core IG
HTML
29
star
12

ccda-on-fhir

CCDA on FHIR implementation Guide Source
JavaScript
26
star
13

dicom-sr

DICOM Structured Reports on FHIR implementation guide
GLSL
25
star
14

smart-app-launch

SMART on FHIR App Launch Protocol
Jupyter Notebook
24
star
15

cds-hooks-hl7-site

HL7 CDS Hooks website
Python
24
star
16

fhircast-docs

FHIRcast documentation
GLSL
22
star
17

carin-bb

CARIN Blue Button IG - joint work between CARIN Alliance and HL7
Python
20
star
18

genomics-reporting

Source for the HL7 Genomics work group's "Clinical Genomics-Reporting" FHIR implementation guide
GLSL
19
star
19

sdc

Structured Data Capture Implementation Guide
GLSL
17
star
20

cql

Clincal Quality Language Specification
HTML
16
star
21

fhir-ips

FHIR Implementation Guide for International Patient Summary
GLSL
16
star
22

fhir-mCODE-ig

Minimal Common Oncology Data Elements Implementation Guide
GLSL
15
star
23

ccda-to-fhir

Mappings between CCDA templates and FHIR resources
15
star
24

FHIRPath

Fluent Path Specification
HTML
15
star
25

emedicinal-product-info

Gravitate Health Project
GLSL
15
star
26

fhir-sdoh-clinicalcare

Gravity project FHIR implementation guide covering social determinants of health, including data capture, recording SDOH issues and making referrals
GLSL
15
star
27

cqf-recommendations

Representation of Clinical Practice Guideline Recommendations in FHIR
GLSL
14
star
28

cqf-measures

Clinical Quality Framework Measure Content
Liquid
14
star
29

ig-template-base

Base IG template managed by HL7 but usable by anyone (no logos). The foundation for most HL7-published IGs
HTML
12
star
30

UTG

Unified Terminology Governance
Java
12
star
31

CDA-ccda

Consolidated CDA IG for CDA using FHIR Tooling
GLSL
12
star
32

fhir-saner

Situation Awareness for Novel Epidemic Response (COVID-19 driven project to track resource availability)
GLSL
11
star
33

fhir-extensions

Official Repository of FHIR extensions
XSLT
10
star
34

fhir-cdisc-mapping

Joint CDISC/HL7 implementation guide covering official mappings between SDTM and CDASH and FHIR resources
XSLT
10
star
35

phd

Personal Healthcare Devices Implementation Guide
GLSL
9
star
36

JIRA-Spec-Artifacts

Manages the artifacts, pages and other lists associated with all HL7 projects managed through JIRA feedback projects
XSLT
9
star
37

hl7-tools

HL7 Tooling Catalogue web-app
Ruby
9
star
38

VhDir

A FHIR implementation guide enabling the exchange of validated healthcare directory information between a reference source (e.g. national directory) and 'local' workflow environments (e.g. local directories).
Python
9
star
39

phenomics-exchange-ig

Phenomics Exchange IG
GLSL
8
star
40

case-reporting

This project will determine and document a core, "Initial Public Health Case Report" standard for use in reporting from Electronic Health Records (EHR) to health departments and a "Reportability Response Report" from health departments to EHRs.
Batchfile
8
star
41

vrdr

Vital Records Death Reporting FHIR IG
GLSL
7
star
42

CDA-ccda-2.1

Schematron, samples, and other artifacts for C-CDA Release 2.1
7
star
43

davinci-epdx

FHIR IG Payer Data Exchange (PDex)
GLSL
7
star
44

davinci-dtr

Da Vinci Documentation Templates and Rules Implementation Guide
GLSL
7
star
45

davinci-crd

DaVinci Coverage Requirements Discovery Implementation Guide
GLSL
7
star
46

davinci-deqm

Data Exchange for Quality Measures
HTML
7
star
47

hl7-c-cda-ex

HL7 C-CDA Examples Search and Display Rails application
HTML
7
star
48

fhir-for-fair

FHIR FOR FAIR Implementation Guide
GLSL
7
star
49

CDA-ccda-companion

Schematron, samples, and other artifacts for C-CDA Companion Guide
6
star
50

fhir-identity-matching-ig

Repository for the U.S. Interoperable Digital Identity and Patient Matching FHIR implementation guide
GLSL
6
star
51

fhir-qi-core

Quality Improvement Core FHIR Profiles
HTML
6
star
52

ig-publisher-scripts

A repository of scripts used to launch the publisher, manage the local publishing environment and ensure both scripts and publisher are 'current'
Batchfile
6
star
53

US-Core-STU3

This repository contains the US Core Implementation Guide is based on FHIR STU3 and defines the minimum conformance requirements for accessing patient data. For the Continuous Integration Build of the US Core Implementation Guide use the following link:
HTML
6
star
54

cdmh

The repository will provide the implementation guidance for the Common Data Model Harmonization project which is sponsored by FDA and ONC.
HTML
6
star
55

fhir-project-mhealth

Gherkin
6
star
56

CDA-core-2.1

HTML
6
star
57

fhir-pacio-adi

PACIO (Post-Acute Care Interoperability) Advanced Directive Interoperability FHIR Implementation Guide
GLSL
6
star
58

CDA-core-sd

FHIR Logical Model representation of CDA core specification
HTML
6
star
59

fhir-us-mcc

Multiple Chronic Conditions Dynamic Electronic Care Plan FHIR IG
GLSL
5
star
60

fhir-medmorph

Making EHR Data More Available for Research and Public Health (MedMorph) Reference Architecture HL7 FHIR Implementation Guide
HTML
5
star
61

dental-data-exchange

CSS
5
star
62

davinci-ra

Da Vinci Chronic Illness Documentation for Risk Adjustment
Batchfile
5
star
63

PDDI-CDS

Documents and code related to the CDS and Pharmacy WG sponsored implementation guide for potential drug-drug interaction clinical decision support
Batchfile
5
star
64

fhir-ipa

International Patient Access Implementation Guide Source
Shell
5
star
65

davinci-pas

IG to use FHIR to support the exchange of information (between the provider and the payer) necessary to support the request for Prior-Authorization and the payers response.
GLSL
5
star
66

davinci-pdex-plan-net

Da Vinci Payor Data Exchange - Plan Network (Provider, Organization and Location registry)
GLSL
5
star
67

fhir-omop-ig

A FHIR implementation guide that supports conversion of data from FHIR to OMOP and OMOP to FHIR
GLSL
5
star
68

uv-pocd

Point of Care Devices FHIR IG Source
Batchfile
4
star
69

davinci-ecdx

FHIR IG Electronic Clinical Data Exchange
Jupyter Notebook
4
star
70

CDA-ccda-to-and-from-uscore

C-CDA to and from US Core
4
star
71

ehrsfm-tool

EHR FM Tool
XSLT
4
star
72

kindling

FHIR Publisher
Java
4
star
73

davinci-pdex-formulary

Da Vinci Provider Data Exchange - Drug Formulary
GLSL
4
star
74

cdisc-lab

CDISC Lab Model
HTML
4
star
75

fhir-directory-query

FAST directory query FHIR implementation guide
GLSL
4
star
76

fhir-radiation-dose-summary-ig

FHIR Radiation Dose Summary for Diagnostic Procedures implementation guide
GLSL
4
star
77

imaging-service-request-ig

See linked PSS: https://jira.hl7.org/browse/PSS-2135
GLSL
4
star
78

carin-digital-insurance-card

CARIN IG for Digital Insurance Card
Jinja
4
star
79

fhir-patient-correction

A FHIR implementation guide defining how patients and their agents can ask for corrections to their health record
GLSL
4
star
80

physical-activity

Repository for the HL7 FHIR Physical Activity implementation guide
GLSL
4
star
81

fhir-security-label-ds4p

FHIR data segmentation for privacy security label implementation guide (http://build.fhir.org/ig/HL7/fhir-security-label-ds4p/branches/master/index.html)
Batchfile
4
star
82

fhir-breast-radiology-ig

FHIR Breast Radiology IG
GLSL
4
star
83

FHIR-us-pq-cmc-fda

Pharmaceutical Quality/Chemistry, Manufacturing and Controls Implementation Guide
GLSL
4
star
84

cimi-vital-signs

CIMI Vital Signs
GLSL
4
star
85

ig-template-fhir

Template used for most HL7-defined FHIR implementation guides (based on ig-template-base). Adds HL7 logos.
HTML
4
star
86

fhir-ichom-breast-cancer-ig

Repository for the International Consortium for Health Outcomes Measurement (ICHOM) breast cancer FHIR implementation guide
GLSL
4
star
87

hl7-cimi-model

This repository contains artifacts for the CIMI Logical models
4
star
88

Vulcan-schedule-ig

An implementation guide for representation of the schedule of visits and other activities that take place in a clinical trial. Includes necessary extensions and profiles.
GLSL
4
star
89

patient-reported-outcomes

This is the repository for the Patient Reported Outcomes Initiative sponsored by ONC, AHRQ and NIH under the umbrella of the Patient Centered Outcome Research (PCOR) Trust Fund.
HTML
4
star
90

vr-common-library

Vital Records Common FHIR Profiles IG
GLSL
3
star
91

PhCP

Pharmacist Care Plan FHIR IG
HTML
3
star
92

HAI

Health Associated Infections Implementation Guide
3
star
93

CDA-phcaserpt-1.1.1

XSLT
3
star
94

fhir-bfdr

BFDR (Birth and Fetal Death Reporting) FHIR IG
GLSL
3
star
95

CDA-phcaserpt-1.3.0

3
star
96

davinci-ehrx

FHIR IG for Electronic Health Record Exchange
GLSL
3
star
97

ccda-on-fhir-r4

CCDA on FHIR implementation Guide Source for FHIR R4
3
star
98

CDA-hai

XSLT
3
star
99

fhir-order-catalog

Order Catalog IG source
GLSL
3
star
100

fhir-udap-security-ig

IG repository for UDAP Security for Registration, Authentication, and Authorization IG.
Batchfile
3
star