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

tiny-hl7

v1.0.7

Published

Incomplete, in progress, not fully spec compliant, but relatively tiny parse/serialize support for HL7 messages into a fairly simple to use JS format.

Downloads

3,262

Readme

tiny-hl7

Incomplete, in progress, not fully spec compliant, but relatively tiny parse/serialize support for HL7 messages into a fairly simple to use JS format.

It exports two main methods parse and serialize and a helper function getMessages for grabbing individual messages out of a group.

Motivation

  1. I wanted a lib small enough to do this in a browser as a tiny part of a clientside JS app.
  2. I wanted the simplest possible parsed structure that's easy to consume by address.

Parse/Serialize Example

import hl7 from 'tiny-hl7'

const message = `MSH|^~\&|5.0^IBI^L|^^|DBO^IBI^L|QS4444^^|20171025213259||ACK^V01^ACK|5465156441.100178620|P|2.3.1|
MSA|AR|QS444437861000000042|Not logged in: User login failed|||207^^HL70357|
ERR|^^^207^^HL70357|
`

const parsed = hl7.parse(message)

console.log(parsed)
/*
[
  {
    'MSH.2': '^~\\&',
    'MSH.3.1': '5.0',
    'MSH.3.2': 'IBI',
    'MSH.3.3': 'L',
    'MSH.4.1': '',
    'MSH.4.2': '',
    'MSH.4.3': '',
    'MSH.5.1': 'DBO',
    'MSH.5.2': 'IBI',
    'MSH.5.3': 'L',
    'MSH.6.1': 'QS4444',
    'MSH.6.2': '',
    'MSH.6.3': '',
    'MSH.7': '20171025213259',
    'MSH.8': '',
    'MSH.9.1': 'ACK',
    'MSH.9.2': 'V01',
    'MSH.9.3': 'ACK',
    'MSH.10': '5465156441.100178620',
    'MSH.11': 'P',
    'MSH.12': '2.3.1',
    'MSH.13': '',
  },
  {
    'MSA.1': 'AR',
    'MSA.2': 'QS444437861000000042',
    'MSA.3': 'Not logged in: User login failed',
    'MSA.4': '',
    'MSA.5': '',
    'MSA.6.1': '207',
    'MSA.6.2': '',
    'MSA.6.3': 'HL70357',
    'MSA.7': '',
  },
  {
    'ERR.1.1': '',
    'ERR.1.2': '',
    'ERR.1.3': '',
    'ERR.1.4': '207',
    'ERR.1.5': '',
    'ERR.1.6': 'HL70357',
    'ERR.2': '',
  },
]
*/

const reSerialized = hl7.serialize(parsed)

console.log(reSerialized === message) // true

Simple message generation example

Here we generate an "ack" acknowledging receipt of a message by combining parse to extract values to echo back:

import hl7 from 'tiny-hl7'
import { stringify as stringifyDate } from 'hl7-date'

const generateAck = incoming => {
  const messageHeader = hl7.parse(incoming)[0]

  return serialize([
    {
      'MSH.3': messageHeader['MSH.5'],
      'MSH.5': messageHeader['MSH.3'],
      'MSH.7': stringifyDate(new Date(), 'minute'),
      'MSH.9': 'ACK',
      'MSH.10': 'ACK' + stringifyDate(new Date(), 'second'),
      'MSH.11': 'P',
      'MSH.12': messageHeader['MSH.12'],
    },
    {
      'MSA.1': 'AA',
      'MSA.2': messageHeader['MSH.10'],
    },
  ])
}

Running tests

npm test

Changelog

  • 1.0.7 - inlining dset lib (including its license).
  • 1.0.3 - fixing regexp usage broken in safari
  • 1.0.2 - fixing dset import that was causing a bug in serialize
  • 1.0.1 - initial release

License

MIT