4.12.0 • Published 9 months ago

fhir v4.12.0

Weekly downloads
1,439
License
ISC
Repository
github
Last release
9 months ago

FHIR.js

Node.JS library for serializing/deserializing FHIR resources between JS and XML, and validating FHIR resources. The library uses technologies that are safe for use in browser-only applications (node.js is not required).

Build Status Build Status

Key features

  • Serialization between XML and JSON
  • Validation against core spec and custom profiles
  • Evaluation of FhirPath
  • Support for multiple FHIR versions (>= STU3)
    • Loading from specific downloadable definitions

Dependencies

  • q 1.4.1
  • underscore 1.8.3
  • path 0.12.7
  • xml-js 1.6.2

Installation

npm install fhir
or
bower install fhir-js

To use in a node.js application, require the "fhir" module.

var Fhir = require('fhir').Fhir;

To use in a browser application, reference dist/bundle.js.

<script type="text/javascript" src="node_modules/fhir/dist/bundle.js"></script>
or
<script type="text/javascript" src="bower_components/fhir-js/dist/bundle.js"></script>

Basic Usage

var resource = {
  resourceType: 'Patient',
  ...
};
var fhir = new Fhir();
var xml = fhir.objToXml(resource);
var json = fhir.xmlToJson(xml);
var obj = fhir.xmlToObj(xml);
var results = fhir.validate(xml, { errorOnUnexpected: true });
results = fhir.validate(obj, {});
fhir.generateSnapshot(SnapshotGenerator.createBundle(sd1, sd2, sd3));

FHIR Version

4.0.0

FHIR.js supports FHIR version 4.0.0 by default.

If your implementation needs to support a specific FHIR version (as long as it is 3.0.1 or newer), you may download the "FHIR Definitions" from the FHIR Downloads page in JSON format and load them into the FHIR.js module.

var ParseConformance = require('fhir').ParseConformance;
var FhirVersions = require('fhir').Versions;
var Fhir = require('fhir').Fhir;

// Get the data
var newValueSets = JSON.parse(fs.readFileSync('..path..to..valuesets.json').toString());
var newTypes = JSON.parse(fs.readFileSync('..path..to..profiles-types.json').toString());
var newResources = JSON.parse(fs.readFileSync('..path..to..profiles-resources.json').toString());

// Create a parser and parse it using the parser
var parser = new ParseConformance(false, FhirVersions.STU3);           // don't load pre-parsed data
parser.parseBundle(newValueSets);
parser.parseBundle(newTypes);
parser.parseResources(newResources);

var fhir = new Fhir(parser);
fhir.xmlToJson(...);
fhir.objToXml(...);
fhir.validate(...);
// etc.

Custom-loading a version like this may not work if the FHIR spec includes changes to the StructureDefinition resource that are not accounted for in this version of the FHIR.js module. For example, recently StructureDefinition.element.binding.valueSetReference#Reference was changed to StructureDefinition.element.binding.valueSet#canonical. The FHIR.js module had to be updated to respect this change before it could properly validate value sets referenced by the StructureDefinition.

Note: For validation to validate a value set referenced by a StructureDefinition, the ValueSet resource must be loaded into the parser before the StructureDefinition is loaded.

Documentation

API documentation can be found at http://lantanagroup.github.io/FHIR.js/

Decimal types

The FHIR specification requires that decimal values have arbitrary precision and be encoded in JSON as numbers. This is problematic since JavaScript numbers are 64-bit floating-point numbers that do lose precision. As a workaround:

  • xmlToObj keeps decimals as JavaScript strings so as to not lose precision
  • xmlToJson converts decimals to JSON numbers, obeying the specification. Consider using it instead of JSON.stringify(fhir.xmlToObj(xml)).
  • When parsing FHIR JSON strings, such as those produced by xmlToJson or other FHIR libraries, consider using an alternative to JSON.parse such as https://github.com/josdejong/lossless-json. This issue is mentioned in the FHIR specification: https://www.hl7.org/fhir/json.html#decimal

Implementation Notes

  • Compatible with FHIR Release 4 Candidate v3.2.0
  • FHIR profiles (within the "profiles" directory) are used to determine whether properties should be arrays, the data type and cardinality of each property, etc.. The profiles are first combined using packageProfiles.js into a single bundle of all profiles. A second pass over the profiles is performed to create a hierarchy (rather than a flat list) of the properties, and only includes information that validation is concerned about. The result of the second pass is stored in profiles/types.json and profiles/valueSets.json.

Test

npm test
4.12.0

9 months ago

4.11.4

9 months ago

4.11.3

10 months ago

4.11.2

1 year ago

4.11.0

2 years ago

4.11.1

2 years ago

4.10.3

3 years ago

4.10.2

3 years ago

4.10.1

3 years ago

4.10.0

3 years ago

4.9.0

3 years ago

4.8.3

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.11

3 years ago

4.7.10

4 years ago

4.7.9

4 years ago

4.7.8

4 years ago

4.7.7

4 years ago

4.7.6

4 years ago

4.7.5

4 years ago

4.7.4

4 years ago

4.7.3

4 years ago

4.7.2

4 years ago

4.7.1

4 years ago

4.7.0

5 years ago

4.6.0

5 years ago

4.5.0

5 years ago

4.4.9

5 years ago

4.4.8

5 years ago

4.4.7

5 years ago

4.4.6

5 years ago

4.4.5

5 years ago

4.4.4

5 years ago

4.4.3

5 years ago

4.4.2

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.11

6 years ago

4.3.10

6 years ago

4.3.9

6 years ago

4.3.8

6 years ago

4.3.7

6 years ago

4.3.6

6 years ago

4.3.5

6 years ago

4.3.4

6 years ago

4.3.3

6 years ago

4.3.2

6 years ago

4.3.1

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.6

6 years ago

3.3.1

6 years ago

4.1.5

6 years ago

4.1.4

6 years ago

4.1.3

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.2

6 years ago

3.3.0

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.2.0

6 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago

2.0.12

8 years ago

2.0.11

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago