Skip to content

Commit

Permalink
Merge pull request #30 from RyanQuey/master
Browse files Browse the repository at this point in the history
accommodate batch/irregular messages
  • Loading branch information
hitgeek authored Dec 29, 2017
2 parents 0863b27 + 0c60359 commit 8984e5c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/server/tcp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ function TcpServer(options, handler) {

util.inherits(TcpServer, EventEmitter);

function Req(msg) {
function Req(msg, raw) {
this.msg = msg;
this.raw = raw;
this.sender = msg.header.getField(1).length == 1 ?
msg.header.getField(1).toString() :
msg.header.getField(1);
Expand All @@ -43,12 +44,13 @@ function Res(socket, ack) {
this.ack = ack;

this.end = function() {
socket.write(VT + ack.toString() + FS + CR);
socket.write(VT + (this.ack).toString() + FS + CR);
}
}

TcpServer.prototype.start = function(port, encoding) {
TcpServer.prototype.start = function(port, encoding, options) {
var self = this;
options = options || {}
this.server = net.createServer(function(socket) {
var message = "";
socket.on('data', function(data) {
Expand All @@ -58,7 +60,7 @@ TcpServer.prototype.start = function(port, encoding) {
var hl7 = self.parser.parse(message.substring(1, message.length - 2));
var ack = self.createAckMessage(hl7);

var req = new Req(hl7);
var req = new Req(hl7, message);
var res = new Res(socket, ack);
self.handler(null, req, res);
message = "";
Expand Down

0 comments on commit 8984e5c

Please sign in to comment.