Injecting private DICOM tags into received instances

I’d like the ability to automatically inject private DICOM tags into received instances. The private tags will be pre-defined in the orthanc config files (the private tags will have static values).

As of now, I’m doing this via lua/python plugin by intercepting the OnStoredInstance hook. However, it uses multiple REST calls overwrite the metadata.

Here’s my code:

function OnStoredInstance(instanceId, tags, metadata, origin)
   if origin['RequestOrigin'] ~= 'Lua' then

      local replace = {}
	  replace["00xx,00xx"] = "some data"
	  replace["Private_Tag_Defined_In_Dictionary"] = "more data"
	  replace["SOPInstanceUID"] = tags["SOPInstanceUID"]

      local remove = {}

      local command = {}
      command['Replace'] = replace
      command['Remove'] = remove
	  command["Force"] = true
      local modifiedFile = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true))

      local uploadResponse = ParseJson(RestApiPost('/instances/', modifiedFile)) ['ID']
 
      if (uploadResponse["Status"] == 'AlreadyStored') then
         print("Are you sure you've enabled 'OverwriteInstances' option ?")
      end

      if (uploadResponse["ID"] ~= instanceId) then
         print("modified instance and original instance don't have the same Orthanc IDs !")
      end 

      print('replaced Private Tag in instance ' .. instanceId)
   end
end

I’d like to know if this can be done in the core DICOM server. Ideally, the tags would be injected upon receiving images.

Hi,

The Orthanc core will not allow injecting a tag by configuration - this is not a generic use case so we won’t add this as a feature in the Orthanc core.

However, there is an alternative solution: inject the tag before the instance is even read/interpreted by Orthanc. This can only be done in python with this callback.

Hope this helps,

Alain

1 Like

Thanks for the pointer! The ReceivedInstanceCallback is more efficient and cleaner than my Lua/REST code. Much appreciated.