Stumbled on the need to do the same thing occasionally, although setup a GUI to just allow selecting any study as a parent and one or more children, usually for the same scenario you mentioned with the same AccessionNumber. This is via a “Merge” and not on the initial save to PACS because these have separate StudyInstanceUID’s, same AccessionNumber.
I just started looking into using that, and one issue I’ve noticed is:
If the parent has series say 1-10, and a child or children have overlapping series numbers, then the merged study will have duplicate series numbers, e.g. multiple series with a number 1, although they stay group together. Not sure how it affects references lines, etc., and not sure that Orthanc can renumber automatically.
Have a UI that sort of will helps with that:
The backend generates the CLI command and also can send to Orthanc using an API for PHP:
{
“cli”: “http://localhost:8042/studies/e3c3d16c-95d9604b-c563be4c-92f2c12e-a672c4a9/merge -d ‘{"Resources":["25faf75f-f69e214c-1d56e0d3-de130a58-dc6c40e4","5ccfcee7-c4e1f3cd-375c9087-e096dcb8-7b635b0c"]}’”
}
You can build a PHP library to make the CURL calls, e.g.
public function executeCURLPOSTJSON($JSONQuery, $url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->OrthancURL . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONQuery);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_ENCODING , “gzip”);
$headers = self::$headers;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
return $this->processCURLResults($ch);
}
Would be happy to go in further detail offline.