How to remove dicom tag using lua script?

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.

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.

You can get some inspiration from this script to use the RestAPI to modify the instance: https://bitbucket.org/osimis/orthanc-setup-samples/src/871e611bd1307c057da0b7886578f4d55492974b/docker/modify-instances/orthanc-pacs/modify.lua

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

function OnStoredInstance(instanceId, tags, metadata, origin)
– 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.