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 :P