Failed to modify PatientName with curl

347 views
Skip to first unread message

act...@gmail.com

unread,
Jul 8, 2017, 4:35:54 PM7/8/17
to Orthanc Users
I usually receive DICOM files in which the PatientName was encoded in Big5 character set. Since Big5 is not supported in most viewers/server, patients' names are not displayed correctly. Thus, I am trying to replace the Big5 PatientNames with UTF-8 ones based on a list of PatientName/PatientID pairs. Initially, I tried to do this with EXCEL VBA, the tool I am more familiar with. With EXCEL VBA, I can "GET" patients information successfully, but failed to modify the PatientName tag with HTTP POST. Then, I tried curl. with which, I can get patients information as well, but failed to modify either. The picture attached are my VBA code and the command line I used with curl. Can some please help me out of this? Thanks a lot!

Environment:
Windows 10 pro 64bit
ORTHANC V1.2
Curl 7.54.1 64bit

Fail to modify PatientName.jpg
Fail to modify PatientName (EXCEL VBA).jpg

act...@gmail.com

unread,
Jul 9, 2017, 10:45:16 AM7/9/17
to Orthanc Users, act...@gmail.com
Just solved the problem myself after googling more about curl and POST.
I replaced "" with \" and removed the outer ' in the JSON text. Based on the info from -v, the use of -X seemed unnecessary.
Successful method.jpg

act...@gmail.com

unread,
Jul 9, 2017, 12:18:07 PM7/9/17
to Orthanc Users, act...@gmail.com
In the session MODIFICATION of PATIENTS, the instruction says "Please note that, in this case, you have to set the value of the PatientID (0010,0020) tag for Orthanc to accept this modification: This is a security to prevent the merging of patient data before and after anonymization, if the user does not explicitly tell Orthanc to do so."

However, in my case, I simply want to change the PatientName tag. To do so, I have to:
1. create a whole new set of Dicom files with a slightly modified PatientID,
2. delete the old set of Dicom files with the original PatientID,
3. create another new set of Dicom files with target PatientName and original PaitentID.
4. delete the set of Dicome files with the slightly modified PatientID.

Is there any easier way to modify PatientName or other tags without creating a new set of files? Without creating a new set, there is no chance "merging of patient data before and after anonymization".

Of course a more sensible way, I think, is to allow users to assign PatientName and other tags while importing Dicom files.

I don't know if either of these ways is possible.

Alain Mazy

unread,
Jul 10, 2017, 12:08:18 PM7/10/17
to act...@gmail.com, Orthanc Users
Hi,

Well, I think you might have found a bug in the /patients/../modify route.

Indeed, when you follow the book recommendation (as you do), and re-use the same PatientID as the original one, Orthanc will modify all instances of the patient with the new PatientName.  All studies will appear twice in Orthanc, once with the old PatientName and once with the new PatientName.  These 2 studies are attached to a patient that has not been renamed.

I've added an issue in the Orthanc bug tracker and I'll discuss it with Sebastien to decide if we should fix Orthanc or the documentation: https://bitbucket.org/sjodogne/orthanc/issues/55/patients-id-modify-while-keeping-the

Before this is fixed, the process you suggest is the one that will work.






--

Alain Mazy / CTO 
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Rue bois Saint-Jean 15/1BE-4102 Seraing 
www.osimis.io

Twitter LinkedIn


act...@gmail.com

unread,
Jul 10, 2017, 1:17:54 PM7/10/17
to Orthanc Users, act...@gmail.com
Hi,

Yes, the 4-step method works well for me. I also tried the LUA scripts from the ORTHANC book, which are capable of finishing the rename modification when a DICOM image is stored. I love this method. The LUA codes are much simpler. No need to identify the ID in the first place. Less disk space usage. And probably saves time.

However, it works only when a patient's name is coded in ASCII. And in my case, I need utf8. I learned from Google that LUA actually supports utf8 since Ver. 5.3. I am just wondering if there is any chance I can get a utf8 string passed to ORTHANC through LUA. Maybe after a newer version of LUA was adopted by ORTHANC? Or maybe there is another way to do so?

* The picture attached is the LUA script that failed only because a utf8 string was used.

Failed LUA script.jpg

Sébastien Jodogne

unread,
Jul 11, 2017, 2:52:53 PM7/11/17
to Orthanc Users, act...@gmail.com
Hello,

From my point of view, this is not a bug, but a feature. I have just added an explanation in the issue opened by Alain:

Regarding UTF-8 strings inside Lua, this already works with Orthanc 1.2.0. You will find a sample Lua script attached to this post. IMHO, your instance of Notepad++ does not write your file using UTF-8 encoding.

HTH,
Sébastien-
utf8.lua

act...@gmail.com

unread,
Jul 12, 2017, 8:38:31 AM7/12/17
to Orthanc Users, act...@gmail.com

Hello Sébastien,

Thank you for the utf8.lua script. I tried this script. I opened it in Notepad++, made minimal changes, and saved it to utf8_2.lua. Still, the modified script was functional except the Chinese character part (replace['PatientName'] = '姓名'). I have no idea why. Any suggestion?


蔡豪軒 <-- you may try with my name if you want :)
utf8_2.lua

Sébastien Jodogne

unread,
Feb 26, 2020, 9:10:42 AM2/26/20
to Orthanc Users
Hello,

Back to this old thread, I confirm that your Lua script works fine with recent versions of Orthanc. This was most probably resolved by Orthanc 1.5.5, that was precisely focused on Asian encodings.

Here is your sample script:

function OnStoredInstance(instanceId, tags, metadata)
   if (metadata['ModifiedFrom'] == nil and
       metadata['AnonymizedFrom'] == nil) then
      local replace = {}
      replace['PatientName'] = '姓名'
      local remove = {}
      ModifyInstance(instanceId, replace, remove, true)
      Delete(instanceId)
   end
end

Let's upload an UTF-8 encoded DICOM image, such as the "Lena-utf8.dcm" sample image from the integration tests of Orthanc:

$ storescu -xy localhost 4242 Lena-utf8.dcm 

Then, one can see that the DICOM tags have been properly modified:

{
  [...]
  "PatientBirthDate" : "",
  "PatientID" : "utf8",
  "PatientName" : "姓名",
  "SpecificCharacterSet" : "ISO_IR 192",
  [...]
}

Note that Orthanc won't modify the encoding of the file, i.e. the "Specific Character Set" tag (0008,0005) will not change. If the encoding of the source DICOM file doesn't support Chinese characters, the "PatientName" would have been set to the empty string.

HTH,
Sébastien-
Reply all
Reply to author
Forward
0 new messages