joi-fhir

0.0.5 • Public • Published

joi-fhir -- Work in progress

CircleCI experimental

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',
  ...
}
 
// Validate any generic FHIR resource
validateFhir(Encounter)
.then((validated) => console.log('Validated encounter', validated))
.catch((error) => console.log('Error validating encounter', error));
 
// Ensure FHIR resource matches a certain type
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) => {
  // Handle error
})

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

  1. Feature development and bug fixing MUST occur on a non-master branch.
  2. All changes SHOULD be submitted to master via a Pull Request.
  3. 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
Completely implemented
⭕️ Partially implemented
🚫 Not yet implemented
Resource Type Support
Account 🚫
ActivityDefinition 🚫
AllergyIntolerance 🚫
AdverseEvent 🚫
Appointment 🚫
AppointmentResponse 🚫
AuditEvent 🚫
Basic 🚫
Binary 🚫
BodySite 🚫
Bundle 🚫
CapabilityStatement 🚫
CarePlan 🚫
CareTeam 🚫
ChargeItem 🚫
Claim 🚫
ClaimResponse 🚫
ClinicalImpression 🚫
CodeSystem 🚫
Communication 🚫
CommunicationRequest 🚫
CompartmentDefinition 🚫
Composition 🚫
ConceptMap 🚫
Condition 🚫
Consent 🚫
Contract 🚫
Coverage 🚫
DataElement 🚫
DetectedIssue 🚫
Device 🚫
DeviceComponent 🚫
DeviceMetric 🚫
DeviceRequest 🚫
DeviceUseStatement 🚫
DiagnosticReport 🚫
DocumentManifest 🚫
DocumentReference 🚫
EligibilityRequest 🚫
EligibilityResponse 🚫
Encounter 🚫
Endpoint 🚫
EnrollmentRequest 🚫
EnrollmentResponse 🚫
EpisodeOfCare 🚫
ExpansionProfile 🚫
ExplanationOfBenefit 🚫
FamilyMemberHistory 🚫
Flag 🚫
Goal 🚫
GraphDefinition 🚫
Group 🚫
GuidanceResponse 🚫
HealthcareService 🚫
ImagingManifest 🚫
ImagingStudy 🚫
Immunization 🚫
ImmunizationRecommendation 🚫
ImplementationGuide 🚫
Library 🚫
Linkage 🚫
List 🚫
Location 🚫
Measure 🚫
MeasureReport 🚫
Media 🚫
Medication 🚫
MedicationAdministration 🚫
MedicationDispense 🚫
MedicationStatement 🚫
MessageDefinition 🚫
MessageHeader 🚫
NamingSystem 🚫
NutritionOrder 🚫
Observation 🚫
OperationDefinition 🚫
OperationOutcome 🚫
Organization 🚫
Parameters 🚫
Patient 🚫
PaymentNotice 🚫
PaymentReconciliation 🚫
Person 🚫
PlanDefinition 🚫
Practitioner 🚫
PractitionerRole 🚫
Procedure 🚫
ProcedureRequest 🚫
ProcessRequest 🚫
ProcessResponse 🚫
Provenance 🚫
Questionnaire 🚫
QuestionnaireResponse 🚫
ReferralRequest 🚫
RelatedPerson 🚫
RequestGroup 🚫
ResearchStudy 🚫
ResearchSubject 🚫
RiskAssessment 🚫
Schedule 🚫
SearchParameter 🚫
Sequence 🚫
ServiceDefinition 🚫
Slot 🚫
Specimen 🚫
StructureDefinition 🚫
StructureMap 🚫
Subscription 🚫
Substance 🚫
SupplyDelivery 🚫
SupplyRequest 🚫
Task 🚫
TestScript 🚫
TestReport 🚫
ValueSet 🚫
VisionPrescription 🚫

Readme

Keywords

none

Package Sidebar

Install

npm i joi-fhir

Weekly Downloads

0

Version

0.0.5

License

ISC

Unpacked Size

23.7 kB

Total Files

9

Last publish

Collaborators

  • kurttheviking
  • zackliston