commit
22f15a3a97
3 changed files with 31 additions and 13 deletions
|
@ -9,7 +9,13 @@
|
||||||
UnplugIcon,
|
UnplugIcon,
|
||||||
UserIcon,
|
UserIcon,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { ConnectionState, type Message, MessageType, type ReceiveHl7v2Message } from '@hnu.de/hl7v2-shared';
|
import {
|
||||||
|
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';
|
||||||
|
@ -25,7 +31,7 @@
|
||||||
|
|
||||||
// client state
|
// client state
|
||||||
let composedMessage = $state(''); // content of text-box
|
let composedMessage = $state(''); // content of text-box
|
||||||
let sentMessages = $state<ReceiveHl7v2Message[]>([]); // sent messages stored as type ReceiveHl7v2Message because of the timestamp
|
let sentMessages = $state<DeliverySuccessMessage[]>([]);
|
||||||
let receivedMessages = $state<ReceiveHl7v2Message[]>([]);
|
let receivedMessages = $state<ReceiveHl7v2Message[]>([]);
|
||||||
let isSending = $state(false);
|
let isSending = $state(false);
|
||||||
let copySuccess = $state(false);
|
let copySuccess = $state(false);
|
||||||
|
@ -96,6 +102,12 @@
|
||||||
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;
|
||||||
|
@ -154,15 +166,6 @@
|
||||||
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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -11,6 +11,7 @@ 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',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,9 @@ 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 }>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue