I'm just trying to make a simple HL7 MLLP client using node.js I made some code that creates connection with HL7 server via socket. It sends some data to server. Then it waits for some answer. For testing purposes I use HAPI TestPanel 2.0.1. So, I have an issue. When I send data using my script to HAPI TestPanel, testpanel don't anwser me. In the testpanel's log it says that my client has connected to it and than nothing. When I turned on a debug option in testpanel, Log says that testpanel recieved bytes from my client, end then nothing else. What is the wrong with my script? Can anyone help me?
Thank you!
Here is my script:
const net = require('net');
const VT = String.fromCharCode(0x0b);
const FS = String.fromCharCode(0x1c);
const CR = String.fromCharCode(0x0d);
const clientOptions = {
host: '127.0.0.1',
port: 49360
};
const client = net.createConnection(clientOptions, () => {
var reqdata = 'MSH|^~\\&|HOSP|HIS|HOSP|PACS|20180104150804||ORM^O01|1|T|2.3\nZDS|1.2.398.7.1.1.2.494.0.1^^Application^DICOM';
reqdata = VT + reqdata + CR + FS + CR;
console.log(`${new Date()} connected to HL7 server!`);
console.log(reqdata);
client.write(new Buffer(reqdata, encoding = "utf8"));
});
client.on('data', (data) => {
var ansData = data.toString();
console.log(`${new Date()} HL7 answer data: ${ansData}`);
client.end();
});
client.on('error', (err) => {
var reqerror = `${new Date()} problem with request: ${err.message}`;
console.error(reqerror);
client.end();
console.log(`${new Date()} disconnected from HL7 server`);
});
client.on('end', () => {
console.log(`${new Date()} disconnected from HL7 server`);
});
Here is a screenshot of a testpanel's log:
Well, you are writing MLLP correctly:
reqdata = VT + reqdata + CR + FS + CR;
Though the first CR
is not needed and following is OK:
reqdata = VT + reqdata + FS + CR;
But, the message that is received on HAPI Test Panel looks gibberish. The message is being HTML formatted somewhere. Review your code to keep it simple text.