Slow forward on Lua Scripting

Hi guys,
I´ve just created my first Lua script, forwarding received DICOM (CT) to two diferent workstations. Althougth it´s working, it´s extremely slow. It took more than 10 minutes to forward 500 images. My script is as follows… Any idea? I´m running on Windows platform. Thanks!

function OnStoredInstance(instanceId, tags, metadata)
   local modality = string.lower(tags['Modality'])

  if string.find(modality, 'ct') ~= nil then
      SendToModality(instanceId, 'Modality1'))   
      SendToModality(instanceId, 'Modality2'))

I would first encourage you to add a few print statements in your script and to comment out each part separately to determine which step is slowing down. It could be:

  • reception of the instance (try to comment out the forwarding code)
  • forwarding to Modality 1
  • forwarding to Modality 2

there are some timestamps in the logs so you should see which part is slow.

Thanks, I tried with only one modality and it is still slow (both were in diferent tests), so maybe the problem is in reception or in our network… Which log do yo refer? Can I set it to a higher level? I can only see what happens at startup in the log at .\logs.… In the other hand, I´ll test isolating the network…
Thanks again!

If you add a statement like print(‘received a ct’),
it should display in the logs as:
W0116 09:58:11.449896 LuaContext.cpp:104] Lua says: received a ct

This log is at warning level so need to start Orthanc with --verbose. And, it’s in the regular Orthanc logs …


I would recommend you to try and replace “SendToModality()” by calls to the REST API using “RestApiPost()”, as explained in the Orthanc Book:


I am also attempting to speed up my image auto-routing. With the lua I am able to use a modality name (defined in the configuration file) as the destination argument for SendToModality(), but I cant figure out how to supply the correct format for the destination argument in RestApiPost".

Thanks for any help!

Jason McDonald

Lua auto-routing examples using “RestApiPost()” instead of “SendToModality()” are available in the Orthanc Book: