Move study to another patient with REST APi

HI,

Is there a way to move a whole study to another PatientID ?

It is not possible to use /studies/{id}/modify to change PatientID refereing to OrthancBook.
And, using merge is also not possible because need a target StudyInstanceUID and I don’t want to change the Study attributes.

Any idea ?

Thx

You might want to read through that whole section in the Orthanc Book, e.g. https://book.orthanc-server.com/users/anonymization.html#modification-of-patients

There is a ‘Force’ option that needs to be explicitly set to override modifications that might break the DICOM model: https://book.orthanc-server.com/dicom-guide.html#model-world

There is also a “Keep” option when performing modifications.

There is a way to do that, but you need to be careful when doing so.

I’ve experimented around with that previously and forgot what I tried. If you iterate through the instances (maybe the Series would work also) and change the tags that you want with the Force option, Orthanc logs notices in the log file that your are changing tags that you generally should not, but it will make the changes. I don’t think I ever tried that at the Patient level.

It is generally better to keep the original and make a copy with the modified tags, at least initially.

/sds

This might be an option with some caveats because it preserves the UID’s. Just a python script from the CLI. You’ll need to have Python
on your system and also the requests PIP module installed.

Might give you some ideas:

#!/usr/bin/python3

-- coding: utf-8 --

sudo python3 -m pip install requests

import requests
import json

url = ‘http://localhost:8042/’ # For example
headers = {‘Authorization’:‘Bearer —’} # if needed for some reason

res = requests.get(url+‘studies/the uid for the study’, headers=headers)
Study = json.loads(res.content)

command = dict()
command[‘Replace’] = dict()
command[‘Force’] = True

tags to alter

command[‘Replace’][‘PatientID’] = ‘PatientID’
command[‘Replace’][‘PatientBirthDate’] = ‘19000101’
command[‘Replace’][‘PatientName’] = ‘Test^Test^Test’
command[‘Replace’][‘PatientSex’] = ‘M’
command[‘Keep’] = [‘StudyInstanceUID’,‘SeriesInstanceUID’,‘SOPInstanceUID’]
imagecount = 0
print(command)
for uuid in Study[‘Series’]:
res = requests.get(url+‘series/%s’ % uuid, headers=headers)
Series = json.loads(res.content)
instances = Series[‘Instances’]
for instance in instances:
print(instance+‘\n’)
imagecount = imagecount + 1
modified = requests.post(url+‘instances/%s/modify’ % instance , data=json.dumps(command), headers=headers)
saved = requests.post(url+‘instances/’, data=modified, headers=headers)

res = requests.post(url+‘studies/’ + Study[‘ID’] + ‘/reconstruct’, data=‘{“Asynchronous”:true}’, headers=headers)

print(res.content)

Stephen D. Scotti

Hi Wilfried,

Stephen is right, as of Orthanc 1.11.2, it is not possible to change the PatientID tag when modifying a Study. Therefore, modifying each instance individually is currently the only valid option.

We have always been overly careful wrt DICOM modifications in Orthanc. I have just loosened some of the constraints but it means that users will have to be careful to make sure they preserve the DICOM model → if you modify the PatientID, make sure to update all Patient related tags as well.

The modification will be available in the next Orthanc release.

Best regards,

Alain.

Hi,

Thx for helping.

Hello,

For reference, as the manual modification of UID most probably breaks the DICOM model of the real world, which can cause important trouble for the standard workflow, I have just reintroduced the safety checks, but allowed their disabling using the “Force” option:
https://hg.orthanc-server.com/orthanc/rev/8638522eeda1

Regards,
Sébastien-