Last active
April 23, 2024 09:20
-
-
Save Bugerman58/8344a80082454c0cdc38ab0112efae81 to your computer and use it in GitHub Desktop.
Store DICOM file to DCM4CHEE using PHP script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
define("BOUNDARY", bin2hex(random_bytes(10))); | |
$filePath = 'test.dcm'; | |
$baseUrl = 'http://127.0.0.1:8080'; | |
$AET = 'TESTAETITLE'; | |
/** | |
* Generate request body for a multipart/related | |
* | |
* @param string $filePath | |
*/ | |
function generateMultipartRelatedBody(string $filePath): string { | |
$rn = "\r\n"; | |
$basename = basename($filePath); | |
$body = '--' . BOUNDARY . $rn; | |
$body .= 'Content-Disposition: form-data;name="file";filename="' . $basename . '"' . $rn; | |
$body .= "Content-Type: application/dicom" . $rn . $rn; | |
$body .= file_get_contents($filePath) . $rn; | |
$body .= '--' . BOUNDARY . '--'; | |
return $body; | |
} | |
$ch = curl_init(); | |
curl_setopt_array($ch, array( | |
CURLOPT_HTTPHEADER => array( | |
'Content-Type: multipart/related;type="application/dicom";boundary="' . BOUNDARY .'"', | |
'Accept: application/dicom+json', | |
), | |
CURLOPT_POST => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => $baseUrl . '/dcm4chee-arc/aets/' . $AET . '/rs/studies', | |
CURLOPT_POSTFIELDS => generateMultipartRelatedBody($filePath), | |
)); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
$jsonString = json_encode(json_decode($result), JSON_PRETTY_PRINT); | |
print($jsonString . "\n"); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment