Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fhirpatch

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fhirpatch

Implementation of FHIR Patch for Javascript

  • 1.1.21
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64
decreased by-9.86%
Maintainers
1
Weekly downloads
 
Created
Source

fhirpatch

What's this?

This is a Javascript implementation of the FHIRPatch specification as described at https://www.hl7.org/fhir/fhirpatch.html. For FHIR Path parsing, it uses the excellent fhirpath.js library.

Usage

Please refer to test/fhirpatch.test.js for more examples.

const {FhirPatch} = require('fhirpatch');

# Create a new patch, to fix Fred Flintstone's birthdate from CE to BCE
const patch = {
  resourceType: 'Parameters',
  parameter: [{
    name: 'operation',
    part: [
      { name: 'path', valueString: 'Patient.birthDate' },
      { name: 'value', valueString: '-2020-01-01'},
      { name: 'type', valueString: 'replace' },
    ],
  }],       
};

const resource = {
  resourceType: 'Patient',
  name: [{
    given: ['Fred'],
    family: 'Flintstone'
  }],
  birthDate: '2020-01-01',
}

# Apply the patch in one step
let result = FhirPatch.apply(resource, patch); // returns a *copy* of resource with the patch applied.

# Prepare a patch which can be applied to many resources
let patcher = new FhirPatch(patch);
let result = patcher.apply(resource);

Apply operations will always return the resource in the format in which they received it. The following formats are supported:

  • Javascript objects
  • JSON
  • XML

The patcher will throw an exception whenever any of the following conditions obtains:

  1. The provided patch is not a valid FHIR parameters object.
  2. The provided patch isn't a valid FHIR patch.
  3. The path to be patched doesn't exist (except for delete operations).
  4. The required arguments for a given operation type are not present.
  5. The resource is invalid before patching.
  6. The resource is invalid after patching.

Authoring support

This library has support to help you create FHIR patches.

patch = new FhirPatch();
patch.operations.push(
  new Operation({
    type: 'delete',
    path: 'Practitioner.telecom.where(value="6564664444")',    
  }),
  new Operation({
    type: 'insert',
    value: {
      system: 'phone',
      value: '75774767896',
    },
    valueType: 'valueContactPoint',
    path: 'Practitioner.telecom',
    index: 0,
  });
)
patch.toString('json'); // generate json of patch
patch.describe(); // gernerate array of strings describing the patch operations in english

Known Limitations

  1. It could definitely be faster and probably more robust by doing our own fhirpath implementation.
  2. Two of HL7's test cases don't pass. In one case (@apply.27) I'm pretty sure the test case is at fault. In the other, it's an issue of the code that autogenerates the test case and it'ss just not worth the time to fix right now.
  3. This library has not been tested on a browser, since we need it for use in node.
  4. There may be a limitation inherent to using an external FHIRPath implementation, but it's not covered by the test cases and is not worth the time right now. See comment on Operation#tail for discussion.
  5. FHIR object validation is not what it should be, and may well miss some cases that the official FHIR validator would catch.

Examples

Patch with a complex value

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "operation",
      "parameter": [
        {
          "name": "type",
          "valueCode": "add"
        },
        {
          "name": "path",
          "valueString": "Patient"
        },
        {
          "name": "name",
          "valueString": "contact"
        },
        {
          "name": "value",
          "parameter": [
            {
              "name": "name",
              "valueHumanName": {
                "text": "a name"
              }
            }
          ]
        }
      ]
    }
  ]
}

FAQs

Package last updated on 20 Jul 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc