-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-hl7-send.php
More file actions
57 lines (44 loc) · 1.43 KB
/
test-hl7-send.php
File metadata and controls
57 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// Simple HL7 message sender for testing
$host = '127.0.0.1';
$port = 2575;
// Sample HL7 ORU^R01 message (Observation Result)
$message = "MSH|^~\\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20241201120000||ORU^R01|MSG00001|P|2.5\r"
. "PID|1||PATIENT123||DOE^JOHN||19800101|M\r"
. "OBR|1||ORDER123|TEST^Test Order\r"
. "OBX|1|NM|HR^Heart Rate||75|bpm|60-100|N|||F\r"
. "OBX|2|NM|BP_SYS^Blood Pressure Systolic||120|mmHg|90-140|N|||F\r"
. "OBX|3|NM|BP_DIA^Blood Pressure Diastolic||80|mmHg|60-90|N|||F\r";
// Wrap in MLLP
$mllpMessage = "\x0B" . $message . "\x1C\x0D";
echo "Connecting to {$host}:{$port}...\n";
$socket = @fsockopen($host, $port, $errno, $errstr, 5);
if (!$socket) {
die("ERROR: Could not connect: {$errstr} ({$errno})\n");
}
echo "Connected! Sending HL7 message...\n";
fwrite($socket, $mllpMessage);
echo "Message sent. Waiting for response...\n";
// Read response (ACK)
$response = '';
$timeout = time() + 5;
while (time() < $timeout) {
$chunk = fread($socket, 1024);
if ($chunk) {
$response .= $chunk;
if (str_contains($response, "\x1C\x0D")) {
break;
}
}
}
fclose($socket);
if ($response) {
// Remove MLLP wrappers
$response = trim($response, "\x0B\x1C\x0D");
echo "\nResponse received:\n";
echo str_replace("\r", "\n", $response);
echo "\n";
} else {
echo "No response received (ACK might be disabled)\n";
}
echo "\nDone!\n";