Skip to content

artifacthealth/hl7parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

HL7Parser

HL7Parser is a CommonJS module for working with HL7 2.x messages.

Table of contents

Installation

HL7Parser can be installed using npm:

$ npm install hl7parser --save

Examples

Parse an HL7 message.

var hl7parser = require("hl7parser");

var message = hl7parser.create("MSH|^~\&|||||20121031232617||ADT^A04|20381|P|2.3||||NE\rEVN|A04|20121031162617||01\rPID|1|16194|16194||Jones^Bob");
console.log(message.get("PID.5.2").toString()); // prints "Bob"

See the tests for more examples.

Documentation

"hl7parser" Module

Message Interface

An HL7 message.

addSegment(path)

Adds a segment to the message.

Parameters

  • path string - The name of the segment to add (e.g. "PID").

Returns: Node

name

The name of the node.

Type: string

length

The number of child nodes in the node.

Type: number

get(path)

Gets a child node with the given path.

Parameters

  • path string | number - The path of the child node to retrieve. The path can be a number or string. If the path is a number, then child node at the specified index is returned.

Returns: Node

set(path, value)

Sets a child node at the given path.

Parameters

  • path string - The path of the child node to set.
  • value any - The value to set at the given path.

Returns: void

exists(path)

Checks if a child node exists at the given path.

Parameters

  • path string | number - That path to check.

Returns: boolean

forEach(callback)

Iterates through all child nodes, calling the callback for each node. Similar to Array.forEach.

Parameters

  • callback - The function to call for each child node.

Returns: void

toString()

Returns a string representation of the node. If the node has child nodes then the raw representation of the node is returned; otherwise, the value of the node is returned with escape sequences resolved.

Returns: string

toRaw()

Returns the raw string representation of the node, including delimiters and escape sequences.

Returns: string

toArray()

Returns all child nodes as an array.

Returns: Node[]

isEmpty()

Returns true if the node is empty; otherwise, returns false.

Returns: boolean

toDate()

Returns the value of the node as a date. If the length of the string is exactly 8, the value is parsed using the format YYYYMMDD. If the length of the string is >= 14, the value is parsed using the format YYYYMMDDHHMMSS.

Returns: Date

toInteger()

Returns the value of the node as an integer.

Returns: number

toFloat()

Returns the value of the node as a floating point number.

Returns: number

toBoolean()

Returns the value of the node as a boolean. A value of "Y" is returned as true. A value of "N" is returned as false. All other values return null.

Returns: boolean

Node Interface

A node in an HL7 message. Can represent a message, segment, field, component, or sub-component.

name

The name of the node.

Type: string

length

The number of child nodes in the node.

Type: number

get(path)

Gets a child node with the given path.

Parameters

  • path string | number - The path of the child node to retrieve. The path can be a number or string. If the path is a number, then child node at the specified index is returned.

Returns: Node

set(path, value)

Sets a child node at the given path.

Parameters

  • path string - The path of the child node to set.
  • value any - The value to set at the given path.

Returns: void

exists(path)

Checks if a child node exists at the given path.

Parameters

  • path string | number - That path to check.

Returns: boolean

forEach(callback)

Iterates through all child nodes, calling the callback for each node. Similar to Array.forEach.

Parameters

  • callback - The function to call for each child node.

Returns: void

toString()

Returns a string representation of the node. If the node has child nodes then the raw representation of the node is returned; otherwise, the value of the node is returned with escape sequences resolved.

Returns: string

toRaw()

Returns the raw string representation of the node, including delimiters and escape sequences.

Returns: string

toArray()

Returns all child nodes as an array.

Returns: Node[]

isEmpty()

Returns true if the node is empty; otherwise, returns false.

Returns: boolean

toDate()

Returns the value of the node as a date. If the length of the string is exactly 8, the value is parsed using the format YYYYMMDD. If the length of the string is >= 14, the value is parsed using the format YYYYMMDDHHMMSS.

Returns: Date

toInteger()

Returns the value of the node as an integer.

Returns: number

toFloat()

Returns the value of the node as a floating point number.

Returns: number

toBoolean()

Returns the value of the node as a boolean. A value of "Y" is returned as true. A value of "N" is returned as false. All other values return null.

Returns: boolean

create(text)

Creates a new HL7 message. If the message text is not specified, an empty HL7 message is created.

Parameters

  • text string - Optional. The text to parse.

Returns: Message