This is a simple HL7 builder.
npm installnpm install -g grunt-cli
var Builder = require('./app');
var message = new Builder.Message({
messageType: 'ADT', // Required
messageEvent: 'A03', // Required
eventSegment: true,
delimiters: {
segment: '\n'
// field, component, repeat, escape, subComponent (unused)
},
sendingApplication: 'Builder',
sendingFacility: 'UnitA',
receivingApplication: 'Consumer',
receivingFacility: 'UnitB',
messageId: Math.floor((Math.random() * 1000) + 1),
version: '2.3' // Default: 2.3
});
var pid = new Builder.Segment('PID');
// Add fields with a single component
pid.set(3, '234234');
pid.set(18, '55555');
// Add field with multiple components
var address = new Builder.Field();
address.set(0, '0000 main street');
address.set(2, 'Last Vegas');
address.set(3, 'NV');
address.set(4, '12345');
// Add a repeat inside a field
address.repeat();
address.set(0, '1111 alternate street');
address.set(2, 'Last Vegas');
address.set(3, 'NV');
address.set(4, '12345');
pid.set(11, address);
var pv1 = new Builder.Segment('PV1');
pv1.set(1, 'Testable');
message.add(pid);
message.add(pv1);
// Getters
console.log(address.get(0)); // 1111 alternative street
console.log(address.get(0, 0)); // 1234 main street
console.log(pid.get(3)); // 234234
// toStrings
console.log(address.toString()); // 0000 main street^Last Vegas^NV^12345~1111 alternate street^Last Vegas^NV^12345
console.log(pv1.toString()); // PV1|Testable
console.log(message.toString()); // MSH|.....
// Create an L7 query object
var parsedMessage = message.toQuery();
console.log(parsedMessage.query('PID|3'));
grunt- Runs eslint & mocha testsgrunt lint- Runs eslint onlygrunt test- Runs mocha tests only
Creates a new HL7 builder. options are required and define the MSH header.
messageType(string) - [3 Character event type](http://www.hosinc.com/products/interfaces/interface_documentation.htm#Message type)messageEvent(string) - [3 Character trigger event](http://www.hosinc.com/products/interfaces/interface_documentation.htm#Message type)eventSegment(boolean?) - If true, automatically adds an event segmentdelimieters(object?) - Delimiters used to separate parts. Defaults:segment-\nfield-|component-^repeat-~escape-\subComponent-&
sendingApplication- App that sent the messagesendingFacility- Facility that sent the messagereceivingApplication- App that should receive the messagereceivingFacility- Facility that should receive the messagemessageId- Unique message identifier. default:Math.floor((Math.random() * 1000) + 1)version- HL7 version, Default:2.3
Creates a new HL7 segment builder with a required 3 character segmentName identifier. Examples: MSH, PID, PV1, OBR, OBX.
Sets a field at location (number) to the value of field (string or instance of Builder.Field).
Gets a field at index (number) with optional delimiters.
Returns the segment name.
Returns the segment as a string with optional delimiters.
Creates a new HL7 field builder with an optional length.
Sets a component at location (number) with data (string).
Gets a component at index (number) for the repeated field repeat. If repeat is not defined, it will use the last repeat specified.
Adds a new field in the same position (repeated). Use set for adding new data to this repeated field.
Returns the field as a string with optional delimiters.