HL7-3: send ack-message to sending client on delivery

This commit is contained in:
Markus Thielker 2025-07-30 13:12:06 +02:00
parent 5e90c3b8ba
commit a892cbba46

View file

@ -39,7 +39,7 @@ const clients = new Map();
console.log(`Starting WebSocket server ...`); console.log(`Starting WebSocket server ...`);
console.log("Server configuration:", config); console.log('Server configuration:', config);
wss.on('connection', (ws) => { wss.on('connection', (ws) => {
@ -105,17 +105,29 @@ wss.on('connection', (ws) => {
// check if recipient exists and is connected // check if recipient exists and is connected
if (recipientWs && recipientWs.readyState === WebSocket.OPEN) { if (recipientWs && recipientWs.readyState === WebSocket.OPEN) {
const timestamp = new Date().toISOString();
// The recipient is connected. Forward the message. // The recipient is connected. Forward the message.
const forwardMessage = { const forwardMessage = {
type: MessageType.receive_hl7v2, type: MessageType.receive_hl7v2,
payload: { payload: {
message: message, message: message,
timestamp: new Date().toISOString(), timestamp: timestamp,
}, },
} as Message; } as Message;
recipientWs.send(JSON.stringify(forwardMessage)); recipientWs.send(JSON.stringify(forwardMessage));
console.log(`Forwarded message to ${recipientId}`); console.log(`Forwarded message to ${recipientId}`);
const ackMessage = {
type: MessageType.delivery_success,
payload: {
message: message,
timestamp: timestamp,
},
};
ws.send(JSON.stringify(ackMessage));
console.log(`Sent acknowledgment to ${stationId}`);
} else { } else {
// The recipient is not connected or not found. // The recipient is not connected or not found.