Skip to content

Instantly share code, notes, and snippets.

@TechnoTone TechnoTone/Listener.js
Last active May 15, 2016

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('', 1338);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.