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
- I wanted a lib small enough to do this in a browser as a tiny part of a clientside JS app.
- 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)
const reSerialized = hl7.serialize(parsed)
console.log(reSerialized === message)
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.2
- fixing dset import that was causing a bug in serialize
1.0.1
- initial release
License
MIT