npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synanetics/fhir-search-validator

v1.2.1

Published

Validates FHIR queries against standard or supplied search parameter definitions

Downloads

92

Readme

FHIR Search Validator

A package to validate FHIR search requests.

Quick Start

npm i @synanetics/fhir-search-validator

Purpose

There are plenty of packages that help validate FHIR request bodies against FHIR profiles and the core STU3 (etc.) schema, but none that validate incoming request parameters against FHIR schemas and servers' capability statements. This package addresses that shortcoming.

Limitations

  • Currently, only STU3 is supported.
  • Searching by multiple concurrent resource types (e.g. [base]?_type=Practitioner,Patient&name=Jekyll) is not currently supported.
  • User-defined profiles, against which to validate searches, are not currently supported.
  • Validating that _include:recurse (_include:iterate in R4 and beyond) and _revinclude:recurse refer to one of the possible returned types from another part of the query is not currently supported. All :recurse queries will pass validation.

Usage

The validate function expects at least two parameters, a "search" of the format shown in the example, below, and the HTTP verb or "method" with which the search was invoked:

import validate from '@synanetics/fhir-search-validator';

const search = 'Patient?nickname=Jonesy';
const method = 'GET';

const outcome = validate(search, method);
console.log(outcome.issue[0].details.display); // 'Parameter "nickname" not understood';

The validate function returns a FHIR OperationOutcome detailing the success/failure of validating the search.

The HTTP verb argument is a string. Any unsupported HTTP verb will result in an OperationOutcome. The supported HTTP verbs are:

  • GET
  • PUT
  • POST
  • PATCH
  • DELETE
  • HEAD

Note that in STU3, there is no "success" issue type for OperationOutcomes. As such, an empty "issue" array on the OperationOutcome indicates success.

Validation options

The validate function accepts an optional options argument, which is an object with the following properties:

| Property name | Description | Default | | --------------------- | ------------------------------------------------------------------------------- | -------- | | fhirVersion | The version of FHIR (e.g. STU3) against which this search should be validated. | 'STU3' | | capabilityStatement | A FHIR CapabilityStatement against which to validate incoming searches. | none, optional | | bypassParameters | An array of query parameter names that will be exempted from the FHIR-based validation. This has been included because there is no agreed-upon way of expressing "page" and "state" in the FHIR specification for paginated queries. | none, optional |

Example usage:

const outcome = validate('Encounter?patient.name=Spartacus&page=1', 'GET', {
  fhirVersion: 'STU3',
  capabilityStatement: {
    resourceType: 'CapabilityStatement',
    // and so on...
  },
  bypassParameters: ['page']
});

Capability Statements

Because CapabilityStatement resources can get quite large, it maybe of benefit to precompile a validate function, perhaps using the pattern below:

const compile = (
  capabilityStatement: CapabilityStatement,
) => (search: string, httpVerb: HttpVerb) => validate(search, httpVerb, capabilityStatement);

const compiledValidator = compile(myCapabilityStatement);
// the compiledValidator can now repeatedly use the supplied capabilityStatement without passing it in every time:
const outcome = compiledValidator('Patient?name=Inigo%20Montoya', 'GET');

Roadmap

  • [x] STU3 support
  • [x] CapabilityStatement support
  • [ ] multiple concurrent type ([base]?_type=Type1,Type2) support
  • [ ] _include:recurse and _revinclude:recurse validation support
  • [ ] R4 support
  • [ ] R4B support
  • [ ] R5 support
  • [ ] Ability to supply additional profiles against which to validate