Automate replacing one DICOM tag with another

Hello!

First, thank you very much for Orthanc!

Could someone give me hints how to achieve this...
I want to replace one DICOM tag in all patients stored in Orthanc with another DICOM tag. What would be the correct REST call/curl command? To be more precise... I have a lot of patients/studies in my database where the comments are wrongly stored in the "RETIRED_StudyComments" tag, and I want to copy the data from this tag to the "StudyDescription" tag. Is there a way to automate it?

Thank you very much for your help!

Hello,

Here is a sample Python script that should meet your requirement:

import json
import sys

sys.path.append(‘/home/jodogne/Orthanc/Resources/Samples/Python’)
from RestToolbox import *

SOURCE = ‘RETIRED_StudyComments’
TARGET = ‘StudyDescription’

for study in DoGet(‘http://localhost:8042/studies’):
instance = DoGet(‘http://localhost:8042/studies/%s/instances’ % study)[0][‘ID’]
tags = DoGet(‘http://localhost:8042/instances/%s/tags?simplify’ % instance)
if SOURCE in tags:
print(‘Modifying study %s’ % study)
modified = DoPost(‘http://localhost:8042/studies/%s/modify’ % study,
{ ‘Replace’ : { TARGET : tags[SOURCE] },
‘Remove’ : [ SOURCE ]})
DoDelete(‘http://localhost:8042/studies/%s’ % study)

In a nutshell, this script loops over the studies stored by Orthanc. For each study, it selects one of its instance to read the content of the “RETIRED_StudyComments” tag. If this tag is present, the study is modified to put this value into “StudyDescription”. Note that the file “RestToolbox.py” is shipped with the source distribution of Orthanc.

HTH,
Sébastien-

Thank you so much for your very fast response! I'll try it with your script! Merry X-Mas!