How to remove dicom tag using lua script?

386 views
Skip to first unread message

Marius S

unread,
Sep 30, 2021, 8:50:19 AM9/30/21
to Orthanc Users
Hello,

when we try to remove dicom tag using lua script and forward to Pacs, Orthanc changes SOP Instance UID. How to keep the same SOP Instance UID?

function OnStoredInstance(instanceId, tags, metadata, origin)
   print('onStoredInstance function has been called')
   local replace = {}
replace['SourceAE'] = 'ORTHANC'
    local remove = {'0028-3010'}
   Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'Forward'))
   Delete(instanceId)
end


When we put replace empty we get: Error while processing Lua events: Bad request. How can we use only remove command?

function OnStoredInstance(instanceId, tags, metadata, origin)
   print('onStoredInstance function has been called')
   local replace = {}
    local remove = {'0028-3010'}
   Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'Forward'))
   Delete(instanceId)
end

Thanks.

Alain Mazy

unread,
Oct 1, 2021, 10:23:39 AM10/1/21
to Marius S, Orthanc Users
Hi Marius,

Concerning the replace={} issue, it seems that it works if you use replace=nil instead.

However, the ModifyInstance lua function has some limitations: e.g, you can not use the "force" option that is available in the RestAPI and this force option is mandatory if you want to keep the SOPInstanceUID.


If we adapt this script to your use case, that gives something like:

function OnStoredInstance(instanceIdtagsmetadataorigin)
    -- Do not process twice the same file
    if origin['RequestOrigin'] ~= 'Lua' then
 
       local modifyRequest = {}
       
       modifyRequest["Remove"] = {}
       table.insert(modifyRequest["Remove"], "0028-3010")
       
       modifyRequest["Replace"] = {}
       modifyRequest["Replace"]["SOPInstanceUID"] = tags["SOPInstanceUID"]
       modifyRequest["Force"] = true  -- because we want to keep the same SOPInstanceUID
 
       -- download a modified version of the instance
       local modifiedDicom = RestApiPost('/instances/' .. instanceId .. '/modify'DumpJson(modifyRequest))
 
       RestApiPost('/modalities/Forward/store-straight', modifiedDicom)

       RestApiDelete('/instances/' .. instanceId)
    end
 end

HTH

Alain.

--
You received this message because you are subscribed to the Google Groups "Orthanc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orthanc-users/df0e5252-febb-4eb1-99eb-f40d09fc0754n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages