
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Library that assists in handling FHIR resources. Supports serialization between JSON and XML, validation and FhirPath evaluation.
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).
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>
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));
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.parseBundle(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.
API documentation can be found at http://lantanagroup.github.io/FHIR.js/
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 precisionxmlToJson
converts decimals to JSON numbers, obeying the specification. Consider using it instead of JSON.stringify(fhir.xmlToObj(xml))
.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#decimalnpm test
FAQs
Library that assists in handling FHIR resources. Supports serialization between JSON and XML, validation and FhirPath evaluation.
The npm package fhir receives a total of 8,628 weekly downloads. As such, fhir popularity was classified as popular.
We found that fhir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.