Lua script for anonymisation and send to DICOM node

Hi,

You can clearly get some inspiration from this script: https://book.orthanc-server.com/users/lua.html#important-remarks-about-auto-routing

That would look like this (disclaimer: not tested):

function OnStoredInstance(instanceId, tags, metadata, origin)

– Anonymize the instance
local anonmyizedFile = RestApiPost(‘/instances/’ … instanceId … ‘/anonymize’, {})

– Send the anonymized instance to another modality
RestApiPost(‘/modalities/sample/store-straight’, anonmyizedFile)

– Delete the original instance
RestApiDelete(‘/instances/’ … instanceId)
end

Thank you for your answer.

I succeeded thanks to this script:

function OnStoredInstance(instanceId, tags, metadata)
– Ignore the instances that result from a modification to avoid
– infinite loops
if (metadata[‘ModifiedFrom’] == nil and
metadata[‘AnonymizedFrom’] == nil) then

– The tags to be replaced
local replace = {}
replace[‘PatientName’] = ‘TeleDiag Demo’
replace[‘PatientBirthDate’] = ‘1900/12/24’
replace[‘InstitutionName’] = ‘TELEDIAG’
replace[‘PatientAge’] = ‘045Y’

– The tags to be removed
local remove = { ‘MilitaryRank’ }

– Modify the instance, send it, then delete the modified instance
Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), ‘STOREKQC’))

– Delete the original instance
Delete(instanceId)
end
end

Do you know if it is possible to script the deletion of the dose reports with a condition rejecting the images whose field (0008,103E) LO # Series Description contains “DOSE” so that they are not rerouted?

Is it possible to “generate” a “number” to replace the Patient Name?

All my anonymus study have the same name…

Hi Ludovic,

You actually have access to all built-in lua modules so there’s probably one to generate a uuid that can be used as a unique patient name. You can also install lua modules globally on your system and Orthanc should be able to access them.

Note that, on my side, as soon as the script becomes too complex, I usually switch to python which I’m more familiar with.

HTH,

Alain.