Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Demo HL7 listener with simple transformation
String.prototype.mapReplace = function(map) {
var regex = [];
for(var key in map)
regex.push(key.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"));
return this.replace(new RegExp(regex.join('|'),"g"),function(word){
return map[word];
});
};
var hl7 = require('simple-hl7');
var server = hl7.Server;
var tcpServer = server.createTcpServer();
tcpServer.on('msg', function(msg) {
var pid = msg.getSegment("PID");
var gender = pid.getField(8).toString();
gender = gender.mapReplace({"M":"Male","F":"Female"});
pid.editField(8, gender);
var tcpClient = server.createTcpClient();
tcpClient.connect('127.0.0.1', 1338);
tcpClient.send(msg);
tcpClient.close();
});
tcpServer.start(1337);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment