send hl7 message problem
This code sets up a server that listens for incoming HL7 messages, specifically for QRY^Q02 requests. When a device scans a barcode and sends this query, the server constructs a response message containing patient information the problem here the device not affect or not receive my message the server code is below how can solove this problem.
var hl7 = require('simple-hl7');
/////////////////// SERVER ///////////////////// var app = hl7.tcp();
app.use(function(req, res, next) { console.log('****** Message Received '); console.log(req.msg.log()); // Log the received HL7 message console.log('* QRY^Q02 Message Detected *****');
// Construct the DSR^Q03 Response Message with the exact content you provided
var dsr = new hl7.Message(
"MSH", "|", "^~\\&", "", "", "", "", "20120508110131", "", "DSR^Q03", "4", "P", "2.3.1"
);
// Add MSA (Message Acknowledgment) Segment
dsr.addSegment(
"MSA",
"AA", // Application Accept
"4", // Message Control ID
"Message accepted", // MSA-3 message text
"", // Optional fields
"", // Optional fields
"0" // Optional fields
);
// Add ERR Segment
dsr.addSegment("ERR", "0");
// Add QAK (Query Acknowledgment) Segment
dsr.addSegment("QAK", "SR", "OK");
// Add QRD (Query Definition) Segment
dsr.addSegment("QRD", "20120508110131", "R", "D", "2", "", "", "RD", "8191299", "OTH", "", "", "T");
// Add QRF (Query Filter) Segment
dsr.addSegment("QRF", "", "", "", "", "", "RCT", "COR", "ALL", "");
// Add DSP (Display Data) Segments (with 31 DSP segments)
dsr.addSegment("DSP", "1", "", "1212", "", "", "");
dsr.addSegment("DSP", "2", "", "27", "", "", "");
dsr.addSegment("DSP", "3", "", "Tommy", "", "", "");
dsr.addSegment("DSP", "4", "", "19620824000000", "", "", "");
dsr.addSegment("DSP", "5", "", "M", "", "", "");
dsr.addSegment("DSP", "6", "", "O", "", "", "");
dsr.addSegment("DSP", "7", "", "", "", "", "");
dsr.addSegment("DSP", "8", "", "", "", "", "");
dsr.addSegment("DSP", "9", "", "", "", "", "");
dsr.addSegment("DSP", "10", "", "", "", "", "");
dsr.addSegment("DSP", "11", "", "", "", "", "");
dsr.addSegment("DSP", "12", "", "", "", "", "");
dsr.addSegment("DSP", "13", "", "", "", "", "");
dsr.addSegment("DSP", "14", "", "", "", "", "");
dsr.addSegment("DSP", "15", "", "outpatient", "", "", "");
dsr.addSegment("DSP", "16", "", "", "", "", "");
dsr.addSegment("DSP", "17", "", "own", "", "", "");
dsr.addSegment("DSP", "18", "", "", "", "", "");
dsr.addSegment("DSP", "19", "", "", "", "", "");
dsr.addSegment("DSP", "20", "", "", "", "", "");
dsr.addSegment("DSP", "21", "", "0019", "", "", "");
dsr.addSegment("DSP", "22", "", "3", "", "", "");
dsr.addSegment("DSP", "23", "", "20070301183500", "", "", "");
dsr.addSegment("DSP", "24", "", "N", "", "", "");
dsr.addSegment("DSP", "25", "", "1", "", "", "");
dsr.addSegment("DSP", "26", "", "serum", "", "", "");
dsr.addSegment("DSP", "27", "", "", "", "", "");
dsr.addSegment("DSP", "28", "", "", "", "", "");
dsr.addSegment("DSP", "29", "", "1^^^", "", "", "");
dsr.addSegment("DSP", "30", "", "2^^^", "", "", "");
dsr.addSegment("DSP", "31", "", "5^^^", "", "", "");
// Add DSC (Continuation Pointer) Segment
dsr.addSegment("DSC", "");
// Log the custom DSR^Q03 Response before sending
console.log('****** Sending Custom DSR^Q03 Response *****');
console.log(dsr.log());
// Send the DSR^Q03 Response to the client
res.end(dsr);
});
res.end does not take any arguments, https://github.com/hitgeek/simple-hl7/blob/master/lib/server/tcp-server.js#L48
to send back your own custom response you need to set it as the res.ack
res.ack = dsr;
res.end();
is not work i have Mindray CL900 and the Analyzer sent QRY message:
MSH|^~&|||||20241016231315||QRY^Q02|24|P|2.3.1||||||ASCII||| QRD|20241016231315|R|D|9|||RD|2742180|OTH|||T| QRF||||||RCT|COR|ALL|| and my code is
var hl7 = require('simple-hl7');
/////////////////// SERVER ///////////////////// var app = hl7.tcp();
app.use(function(req, res, next) { console.log('****** Message Received *****'); console.log(req.msg.log()); // Log the received HL7 message
var dsr = new hl7.Message(
"MSH", "|", "^~\\&", "", "", "", "", "20120508110131", "", "DSR^Q03",
"4", "P", "2.3.1" );
// Add MSA (Message Acknowledgment) Segment
dsr.addSegment(
"MSA",
"AA", // Application Accept
"4", // Message Control ID
"Message accepted", // MSA-3 message text
"", // Optional fields
"", // Optional fields
"0" // Optional fields
);
// Add ERR Segment
dsr.addSegment("ERR", "0");
// Add QAK (Query Acknowledgment) Segment
dsr.addSegment("QAK", "SR", "OK");
// Add QRD (Query Definition) Segment
dsr.addSegment("QRD", "20241016225812", "R", "D", "2", "", "", "RD",
"2742180", "OTH", "", "", "T");
// Add QRF (Query Filter) Segment
dsr.addSegment("QRF", "", "", "", "", "", "RCT", "COR", "ALL", "");
// Add DSP (Display Data) Segments (with 31 DSP segments)
dsr.addSegment("DSP", "1", "", "1212", "", "", "");
dsr.addSegment("DSP", "2", "", "27", "", "", "");
dsr.addSegment("DSP", "3", "", "REDHAAA aliiix", "", "", "");
dsr.addSegment("DSP", "4", "", "19620824000000", "", "", "");
dsr.addSegment("DSP", "5", "", "M", "", "", "");
dsr.addSegment("DSP", "6", "", "O", "", "", "");
dsr.addSegment("DSP", "7", "", "", "", "", "");
dsr.addSegment("DSP", "8", "", "", "", "", "");
dsr.addSegment("DSP", "9", "", "", "", "", "");
dsr.addSegment("DSP", "10", "", "", "", "", "");
dsr.addSegment("DSP", "11", "", "", "", "", "");
dsr.addSegment("DSP", "12", "", "", "", "", "");
dsr.addSegment("DSP", "13", "", "", "", "", "");
dsr.addSegment("DSP", "14", "", "", "", "", "");
dsr.addSegment("DSP", "15", "", "outpatient", "", "", "");
dsr.addSegment("DSP", "16", "", "", "", "", "");
dsr.addSegment("DSP", "17", "", "own", "", "", "");
dsr.addSegment("DSP", "18", "", "", "", "", "");
dsr.addSegment("DSP", "19", "", "", "", "", "");
dsr.addSegment("DSP", "20", "", "", "", "", "");
dsr.addSegment("DSP", "21", "", "2742180", "", "", "");
dsr.addSegment("DSP", "22", "", "3", "", "", "");
dsr.addSegment("DSP", "23", "", "20070301183500", "", "", "");
dsr.addSegment("DSP", "24", "", "N", "", "", "");
dsr.addSegment("DSP", "25", "", "1", "", "", "");
dsr.addSegment("DSP", "26", "", "serum", "", "", "");
dsr.addSegment("DSP", "27", "", "", "", "", "");
dsr.addSegment("DSP", "28", "", "", "", "", "");
dsr.addSegment("DSP", "29", "", "1^^^", "", "", "");
dsr.addSegment("DSP", "30", "", "2^^^", "", "", "");
dsr.addSegment("DSP", "31", "", "5^^^", "", "", "");
// Add DSC (Continuation Pointer) Segment
dsr.addSegment("DSC", "");
// Log the custom DSR^Q03 Response before sending
console.log('****** Sending Custom DSR^Q03 Response *****');
console.log(dsr.log());
res.ack = dsr;
res.end();
next();
});
app.use(function(err, req, res, next) { // Error handling middleware console.log('****** ERROR *****'); console.log(err);
// Modify the ACK to indicate an error var msa = res.ack.getSegment('MSA'); msa.setField(1, 'AR'); // AR = Application Reject res.ack.addSegment('ERR', err.message); // Add an ERR segment with the error message
res.end(); // Send the error ACK back to the client });
// Listen on port 5800 app.start(5800);
On Tue, Oct 15, 2024 at 11:11 PM Bob Rupp @.***> wrote:
res.end does not take any arguments, https://github.com/hitgeek/simple-hl7/blob/master/lib/server/tcp-server.js#L48
to send back your own custom response you need to set it as the res.ack
res.ack = dsr; res.end();
— Reply to this email directly, view it on GitHub https://github.com/hitgeek/simple-hl7/issues/98#issuecomment-2414913542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYH7PPL2UPSXKELKK4SC4BTZ3VZG7AVCNFSM6AAAAABP75IPYCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJUHEYTGNJUGI . You are receiving this because you authored the thread.Message ID: @.***>
MSH|^~&|||||20120508110131||DSR^Q03|4|P|2.3.1||||||ASCII||| MSA|AA|4|Message accepted|||0| ERR|0| QAK|SR|OK| QRD|20120508110131|R|D|2|||RD||OTH|||T| QRF||||||RCT|COR|ALL|| DSP|1||1212||| DSP|2||27||| DSP|3||Tommy||| DSP|4||19620824000000||| DSP|5||M||| DSP|6||O||| DSP|7||||| DSP|8||||| DSP|9||||| DSP|10||||| DSP|11||||| DSP|12||||| DSP|13||||| DSP|14||||| DSP|15||outpatient||| DSP|16||||| DSP|17||own||| DSP|18||||| DSP|19||||| DSP|20||||| DSP|21||0019||| DSP|22||3||| DSP|23||20070301183500||| DSP|24||N||| DSP|25||1||| DSP|26||serum||| DSP|27||||| DSP|28||||| DSP|29||1^^^||| DSP|30||2^^^||| DSP|31||5^^^||| DSC||
the message which i need send it to device like this how can send raw message not like dsr.addSegment("DSP", "31", "", "5^^^", "", "", "");
On Wed, Oct 16, 2024 at 11:25 PM Native Code @.***> wrote:
is not work i have Mindray CL900 and the Analyzer sent QRY message:
MSH|^~&|||||20241016231315||QRY^Q02|24|P|2.3.1||||||ASCII||| QRD|20241016231315|R|D|9|||RD|2742180|OTH|||T| QRF||||||RCT|COR|ALL|| and my code is
var hl7 = require('simple-hl7');
/////////////////// SERVER ///////////////////// var app = hl7.tcp();
app.use(function(req, res, next) { console.log('****** Message Received *****'); console.log(req.msg.log()); // Log the received HL7 message
var dsr = new hl7.Message( "MSH", "|", "^~\\&", "", "", "", "", "20120508110131", "","DSR^Q03", "4", "P", "2.3.1" );
// Add MSA (Message Acknowledgment) Segment dsr.addSegment( "MSA", "AA", // Application Accept "4", // Message Control ID "Message accepted", // MSA-3 message text "", // Optional fields "", // Optional fields "0" // Optional fields ); // Add ERR Segment dsr.addSegment("ERR", "0"); // Add QAK (Query Acknowledgment) Segment dsr.addSegment("QAK", "SR", "OK"); // Add QRD (Query Definition) Segment dsr.addSegment("QRD", "20241016225812", "R", "D", "2", "", "", "RD","2742180", "OTH", "", "", "T");
// Add QRF (Query Filter) Segment dsr.addSegment("QRF", "", "", "", "", "", "RCT", "COR", "ALL", ""); // Add DSP (Display Data) Segments (with 31 DSP segments) dsr.addSegment("DSP", "1", "", "1212", "", "", ""); dsr.addSegment("DSP", "2", "", "27", "", "", ""); dsr.addSegment("DSP", "3", "", "REDHAAA aliiix", "", "", ""); dsr.addSegment("DSP", "4", "", "19620824000000", "", "", ""); dsr.addSegment("DSP", "5", "", "M", "", "", ""); dsr.addSegment("DSP", "6", "", "O", "", "", ""); dsr.addSegment("DSP", "7", "", "", "", "", ""); dsr.addSegment("DSP", "8", "", "", "", "", ""); dsr.addSegment("DSP", "9", "", "", "", "", ""); dsr.addSegment("DSP", "10", "", "", "", "", ""); dsr.addSegment("DSP", "11", "", "", "", "", ""); dsr.addSegment("DSP", "12", "", "", "", "", ""); dsr.addSegment("DSP", "13", "", "", "", "", ""); dsr.addSegment("DSP", "14", "", "", "", "", ""); dsr.addSegment("DSP", "15", "", "outpatient", "", "", ""); dsr.addSegment("DSP", "16", "", "", "", "", ""); dsr.addSegment("DSP", "17", "", "own", "", "", ""); dsr.addSegment("DSP", "18", "", "", "", "", ""); dsr.addSegment("DSP", "19", "", "", "", "", ""); dsr.addSegment("DSP", "20", "", "", "", "", ""); dsr.addSegment("DSP", "21", "", "2742180", "", "", ""); dsr.addSegment("DSP", "22", "", "3", "", "", ""); dsr.addSegment("DSP", "23", "", "20070301183500", "", "", ""); dsr.addSegment("DSP", "24", "", "N", "", "", ""); dsr.addSegment("DSP", "25", "", "1", "", "", ""); dsr.addSegment("DSP", "26", "", "serum", "", "", ""); dsr.addSegment("DSP", "27", "", "", "", "", ""); dsr.addSegment("DSP", "28", "", "", "", "", ""); dsr.addSegment("DSP", "29", "", "1^^^", "", "", ""); dsr.addSegment("DSP", "30", "", "2^^^", "", "", ""); dsr.addSegment("DSP", "31", "", "5^^^", "", "", ""); // Add DSC (Continuation Pointer) Segment dsr.addSegment("DSC", ""); // Log the custom DSR^Q03 Response before sending console.log('****** Sending Custom DSR^Q03 Response *****'); console.log(dsr.log()); res.ack = dsr; res.end(); next();});
app.use(function(err, req, res, next) { // Error handling middleware console.log('****** ERROR *****'); console.log(err);
// Modify the ACK to indicate an error var msa = res.ack.getSegment('MSA'); msa.setField(1, 'AR'); // AR = Application Reject res.ack.addSegment('ERR', err.message); // Add an ERR segment with the error message
res.end(); // Send the error ACK back to the client });
// Listen on port 5800 app.start(5800);
On Tue, Oct 15, 2024 at 11:11 PM Bob Rupp @.***> wrote:
res.end does not take any arguments, https://github.com/hitgeek/simple-hl7/blob/master/lib/server/tcp-server.js#L48
to send back your own custom response you need to set it as the res.ack
res.ack = dsr; res.end();
— Reply to this email directly, view it on GitHub https://github.com/hitgeek/simple-hl7/issues/98#issuecomment-2414913542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYH7PPL2UPSXKELKK4SC4BTZ3VZG7AVCNFSM6AAAAABP75IPYCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJUHEYTGNJUGI . You are receiving this because you authored the thread.Message ID: @.***>
how can send two request to device
QCK^Q02 and DSR^Q03 in simple-hl7 in the same time
there isn't really a built in way to do that.
you can access the underlying node socket on the res object. and try to roll it yourself.
var VT = String.fromCharCode(0x0b);
var FS = String.fromCharCode(0x1c);
var CR = String.fromCharCode(0x0d);
var qck = new hl7.Message()
res.socket.write(VT + qck.toString() + FS + CR);
var drs = new hl7.Message();
res.socket.write(VT + drs.toString() + FS + CR);
you won't need to every call res.end(), res.end() just wraps socket.write with the MLLP.
https://github.com/hitgeek/simple-hl7/blob/master/lib/server/tcp-server.js#L48
or if you need to do something really custom, you can roll your own tcp server, and just use the parser from the library.
the server code is only like 25 lines.
https://github.com/hitgeek/simple-hl7/blob/master/lib/server/tcp-server.js#L55