Orthanc Lua Script to filter and allow only files with a certain dicom tag to be autorouted into the set directory

867 Views Asked by At

My lua script for auto-routing files received in Orthanc is as below:

function OnStoredInstance(instanceId, tags, metadata)
  SendToModality(instanceId, 'sample')
end

How can I filter and allow only files with first and foremost a StudyDescription dicom tag and secondly a certain StudyDescription dicom tag to be received in the directory which I have set in my Orthanc configuration file for auto-routing. Have tried all the methods in the lua script documentation but none has worked to suit my case.

What piece of code should I add into this function:

function OnStoredInstance(instanceId, tags, metadata)
  SendToModality(instanceId, 'sample')
end

(Note: Some of the files I am receiving completely don't have a StudyDescription dicom tag.)

1

There are 1 best solutions below

0
On

Here is an example of conditional routing with Lua taken from the Orthanc docs

function OnStoredInstance(instanceId, tags, metadata)
   -- Extract the value of the "PatientName" DICOM tag
   local patientName = string.lower(tags['PatientName'])

  if string.find(patientName, 'david') ~= nil then
      -- Only route patients whose name contains "David"
      Delete(SendToModality(instanceId, 'sample'))

  else
      -- Delete the patients that are not called "David"
      Delete(instanceId)
   end
end

You can change the PatientName tag to StudyDescription since they belong to the study level.