Anonymizing, server-side scripting, and Python script

Hello again,

I'm really excited about using Orthanc for my local DICOM server. I am now trying to anonymize all incoming instances. My use case is that a hospital will be transferring DICOMs to me using "storescu," but I would like them to be anonymized before saving to my local server. Here is what I have been able to do so far:

Using the example script AnonymizeAllPatients.py, I can anonymize after the DICOMS have been transferred to my server. This is less-than-ideal because they should really be anonymized before storing.

Using the example script AutoroutingModification.lua, with the following in the main body:

if (metadata['ModifiedFrom'] == nil and
       metadata['AnonymizedFrom'] == nil) then

      -- The tags to be replaced
      local replace = {}
      replace['0010-0010'] = 'AnonName'

      -- more tags follow...
                                                                                                          
      -- The tags to be removed
      local remove = { }

      -- Modify the instance, send it, then delete the modified instance
    ModifyInstance(instanceId, replace, remove, true)

      -- Delete the original instance
      Delete(instanceId)

I am able to change attributes of the particular instance, e.g. PatientName, but this only seems to change the particular instance entry and not the actual patient entry. So in the end I get the original PatientName as the patient name entry in Orthanc, with 'AnonName' as the PatientName of the instances. In addition, I am not sure how to use this Lua script to make unique patient names (though I could append a random number, etc.). Should I call the python script within the body of "OnStoredInstance"?

Not sure if my process makes sense. I am very new to PACS/DICOM servers...

Thanks for your help,

Jon

I'm also unable to use ModifyInstance in receive-store-modify scenario. Please give us some explanation of ModifyInstance() usage. Short example will be appreciated. Thanks alot!

Dear Jon,

We have well received your messages, unfortunately I am currently unavailable for support requests requiring an analysis such as yours, because of deadlines and conferences.

Please be patient, I should have more time in about 10 days. In the meantime, if anybody in this mailing list could help Jon…

Sébastien-

Hi!

  • Just looked into this because I’m setting up an anonymization server for my post-grad student for data collection for her thesis *

First of all (correct me if I’m wrong), in DICOM, there are no files allocated to a “Patient”, a “Study” or a “Series”. Only Instances have a file. Therefore, when you query a PACS server, they will return the PatientName from the DICOM file (unless they return it from their SQL database, of course).

Using your script, I encountered the same issues when using Orthanc Explorer. However, when I query Orthanc from somewhere else, it returns “AnonName” to me. Thus, it appears that Orthanc will return the unmodified PatientName from SQL database when you use Orthanc Explorer, but will return the modified PatientName from the modified DICOM instances when you perform a Q/R.

That led me to my quick and dirty solution:

I run another instance of Orthanc (using a different AET and ports) on the same computer whose job is to modify-route-delete (basically using original script in AutoroutingModification.lua) to the Orthanc you want to permanently store your anonymized studies.

Basically, run another instance of Orthanc, lets say with ports 4243 (DICOM) and 8043 (http), and add the info for your Orthanc server, e.g.
“Orthanc” : [ “ORTHANC”, localhost, 4242 ] (or something like that)

Then, in the LUA script, change to Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), ‘Orthanc’))

If all works well, when you use Orthanc Explorer on 8042, it should show AnonName. Orthanc Explorer on 8043 will have no patient data (automatically deleted after routing).

I’m quite sure that LUA scripting can generate random numbers, but Orthanc won’t let you change the PatientID. (This must have a good reason, although I don’t really know why). Because of this, I haven’t quite figured out how to get rid of PatientID without an external script yet.

Hope this helps!

Regards,
Emsy

p.s. Trying to cheat by asking Orthanc to reference itself as the remote modality in SendToModality doesn’t work… heh heh heh :stuck_out_tongue:

Sorry, for clarity’s sake, I need to add that you have to send the study to Orthanc:4243 (the anonymization server) that it will anonymize and route to Orthanc:4242 (permanent storage).

Dear Jon,

Sorry for the delay. So far, the Lua engine can only modify a single instance at once, which makes it not adapted to the batch anonymization of patients.

You will find attached to this message a sample Python script that continuously waits for a patient to get stable (i.e. no new instance received for a certain amount of time), then anonymizes this patient. This script internally uses the “RestToolbox.py” from the standard distribution of Orthanc [1].

This script also shows how to manually replace the PatientName and the PatientID.

HTH,
Sébastien-

[1] https://code.google.com/p/orthanc/source/browse/Resources/Samples/Python/RestToolbox.py