Compare commits

..

No commits in common. "fec77b73c3d1db5e63182cda2129e0c6fe2cf0f8" and "cf13b689c749985746d4af74260313af4685c06e" have entirely different histories.

3 changed files with 13 additions and 31 deletions

View file

@ -9,13 +9,7 @@
UnplugIcon, UnplugIcon,
UserIcon, UserIcon,
} from '@lucide/svelte'; } from '@lucide/svelte';
import { import { ConnectionState, type Message, MessageType, type ReceiveHl7v2Message } from '@hnu.de/hl7v2-shared';
ConnectionState,
type DeliverySuccessMessage,
type Message,
MessageType,
type ReceiveHl7v2Message,
} from '@hnu.de/hl7v2-shared';
import { Button } from '$lib/components/ui/button'; import { Button } from '$lib/components/ui/button';
import { Card, CardContent, CardHeader } from '$lib/components/ui/card'; import { Card, CardContent, CardHeader } from '$lib/components/ui/card';
import { Input } from '$lib/components/ui/input'; import { Input } from '$lib/components/ui/input';
@ -31,7 +25,7 @@
// client state // client state
let composedMessage = $state(''); // content of text-box let composedMessage = $state(''); // content of text-box
let sentMessages = $state<DeliverySuccessMessage[]>([]); let sentMessages = $state<ReceiveHl7v2Message[]>([]); // sent messages stored as type ReceiveHl7v2Message because of the timestamp
let receivedMessages = $state<ReceiveHl7v2Message[]>([]); let receivedMessages = $state<ReceiveHl7v2Message[]>([]);
let isSending = $state(false); let isSending = $state(false);
let copySuccess = $state(false); let copySuccess = $state(false);
@ -102,12 +96,6 @@
receivedMessages = [message, ...receivedMessages]; receivedMessages = [message, ...receivedMessages];
break; break;
// our message was successfully delivered
case MessageType.delivery_success:
sentMessages = [message, ...sentMessages];
isSending = false
break;
// message from server due to delivery error // message from server due to delivery error
case MessageType.delivery_error: case MessageType.delivery_error:
deliveryError = message.payload.error; deliveryError = message.payload.error;
@ -166,6 +154,15 @@
payload: { message }, payload: { message },
} as Message; } as Message;
ws.send(JSON.stringify(messageToSend)); ws.send(JSON.stringify(messageToSend));
sentMessages = [{
type: MessageType.receive_hl7v2,
payload: { message, timestamp: new Date().toISOString() },
} as ReceiveHl7v2Message, ...sentMessages];
composedMessage = segmentTemplates.MSH.template();
// reset UI state
isSending = false;
} }
// copies the stationId to the clipboard and handles UI state // copies the stationId to the clipboard and handles UI state

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,29 +105,17 @@ 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: timestamp, timestamp: new Date().toISOString(),
}, },
} 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.

View file

@ -11,7 +11,6 @@ export enum MessageType {
assign_id = 'assign_id', assign_id = 'assign_id',
send_hl7v2 = 'send_hl7v2', send_hl7v2 = 'send_hl7v2',
receive_hl7v2 = 'receive_hl7v2', receive_hl7v2 = 'receive_hl7v2',
delivery_success = 'delivery_success',
delivery_error = 'delivery_error', delivery_error = 'delivery_error',
} }
@ -20,9 +19,7 @@ export type Message =
| { type: MessageType.assign_id, payload: { stationId: string }} | { type: MessageType.assign_id, payload: { stationId: string }}
| { type: MessageType.send_hl7v2, payload: { message: string }} | { type: MessageType.send_hl7v2, payload: { message: string }}
| { type: MessageType.receive_hl7v2, payload: { message: string, timestamp: string }} | { type: MessageType.receive_hl7v2, payload: { message: string, timestamp: string }}
| { type: MessageType.delivery_success, payload: { message: string, timestamp: string }}
| { type: MessageType.delivery_error, payload: { error: string }} | { type: MessageType.delivery_error, payload: { error: string }}
// required to define list of this message type // required to define list of this message type
export type ReceiveHl7v2Message = Extract<Message, { type: MessageType.receive_hl7v2 }>; export type ReceiveHl7v2Message = Extract<Message, { type: MessageType.receive_hl7v2 }>;
export type DeliverySuccessMessage = Extract<Message, { type: MessageType.delivery_success }>;