joi-fhir -- Work in progress
Node.js utility for validating FHIR resources.
Quick start
Prerequisites
- Node.js 6+
- npm
- Publish permission to
joi-fhir
on NPM (Only for deployment)
Installing
npm install --save joi-fhir
Examples
const validateFhir = require('joi-fhir');
const Encounter = {
resourceType: 'Encounter',
id: 'ENC001',
...
}
validateFhir(Encounter)
.then((validated) => console.log('Validated encounter', validated))
.catch((error) => console.log('Error validating encounter', error));
validateFhir(Encounter, { resourceType: 'Encounter' })
.then((validated) => console.log('Validated encounter', validated))
.catch((error) => console.log('Error validating encounter', error));
API
This module exports a single Function
that accepts a FHIR resource and an options
object. The function validates the FHIR resource matches the spec and returns a promise with either the validated/formatted FHIR resource or an error detailing the malformed data.
Definition
validateFhir(resource);
Parameters
Parameter | Type | Description |
---|
resource | Object | A FHIR resource |
options
Parameter | Type | Description | Default |
---|
resourceType | String | If provided, ensure the resource is of this type. Otherwise, allow any FHIR resource | none |
Examples
Input
encounterA
Data about an encounter.
{
"resourceType": "Encounter",
"status": "in-progress",
"subject": {
"reference": "Patient/P01"
},
"reason": [
{
"text": "Laceration to leg"
}
]
}
Invocation
const validateFhir = require('@agilemd/joi-fhir');
return validateFhir(encounter)
.then((validated) => {
...
})
.catch((err) => {
})
Output
validated/formatted Encounter
{
"id": "31a49ff9-2d10-481c-8720-a1a3e61fa981",
"resourceType": "Encounter",
"status": "in-progress",
"subject": {
"reference": "Patient/P01"
},
"reason": [
{
"text": "Laceration to leg"
}
]
}
Development
Install
Clone the source repository, cd
into the joi-fhir
directory, and install dependencies:
git clone git@github.com:agilemd/joi-fhir.git
cd joi-fhir
npm install
Tests
To run the unit tests:
npm test
Changes must not reduce coverage of statements, branches, and functions. To determine unit test coverage:
npm run coverage
Debug
The debug module is used for runtime logging. Omit the DEBUG
environment variable to squelch all logging. Set DEBUG
to the desired level (e.g. DEBUG=@agilemd/joi-fhir:SUBMODULE
) to restrict logging to a desired service. Or, use DEBUG=*
to get all debug output from everywhere, including dependencies.
DEBUG=@agilemd/joi-fhir* npm test
Workflow
- Feature development and bug fixing MUST occur on a non-master branch.
- All changes SHOULD be submitted to master via a Pull Request.
- Pull Requests SHOULD be merged via a merge commit. Local "in-process" commits may be squashed prior to pushing to the remote feature branch.
To enable a git hook that runs npm test
prior to pushing, cd
into the project repo and run:
touch .git/hooks/pre-push
chmod +x .git/hooks/pre-push
echo "npm test" > .git/hooks/pre-push
Build
This project follows semantic versioning. After committing the latest code to GitHub master, update the version:
npm version [major/minor/patch]
Then push the tag to GitHub and publish this package to npm:
git push origin --tags
npm publish
References
Implementation checklist
This project is a work in progress. Any defined FHIR resource will pass validation; however, only certain resources are fully validated. The table below describes which resources have complete validation and which are in progress
Support legend
Icon | Description |
---|
:white_check_mark: | Completely implemented |
:o: | Partially implemented |
:no_entry_sign: | Not yet implemented |