Node.js package for parsing and writing HL7 files
install via NPM:
npm install hl7js
var Reader = require('hl7js').Reader;
var reader = new Reader();
/// Basic Parsing
var reader = new Reader('BASIC');
fs.readFile(hl7_file_path, function (err, buffer) {
reader.read(buffer.toString(), function (err, hl7Data) {
console.log(err);
console.log(hl7Data);
});
});
fs.readFile(hl7_file_path, function (err, buffer) {
reader.read(buffer.toString(), 'MSH PID [{OBR {OBX}}]', function (err, hl7Data, hl7Json) {
console.log(err);
if (!err) {
var patientName = hl7Json['PID'][5]; /// Similar pattern: hl7Json['PID'].fields[5].value ==> For advanced usage
console.log('ORU->Patient name: ', patientName);
}
});
});
var messageType = hl7Data.mshSegment.messageType;
var patientName = hl7Json['PID'][5];
/// (or)
var patientName = hl7Json['PID'].fields[5].value;
var Writer = require('hl7js').Writer;
/// Initializing writer with default delimiters
var writer = new Writer();
/// Initializing writer with user defined delimiters
var writer = new Writer({
lineSeparator: '0xD 0xA',
framePrefix: '',
frameSuffix: '',
fieldSeparater: '|',
componentSeparater: '^',
fieldRepeatSeparater: '~',
escapeCharacter: '\\',
subComponentSeparater: '&'
});
writer.addHeader({
sendingApplication: 's_app',
sendingFacility: 'a_facility',
receivingApplication: 'r_app',
receivingFacility: 'r_facility',
dateTimeOfMessage: 'dt',
security: '',
messageType: 'ADT^A01',
messageControlId: '123',
processingId: '',
versionId: '2.5',
sequenceNo: '',
continuationPointer: '',
acceptAckType: '',
applicationAckType: '',
countryCode: '',
characterSet: '',
messageLanguage: ''
});
writer.addSegment('PID', ['name', 1, 2, ['lname', 'fname'], 'eee']);
writer.addSegment('IN1', ['1']);
writer.addSegment('IN2');
var hl7Text = writer.toString();
console.log(hl7Text);
Contributions are welcome
Please file your issues here: