lua problem

424 views
Skip to first unread message

Robert van Ommen

unread,
Dec 23, 2015, 9:20:24 AM12/23/15
to Orthanc Users
i can't get lua to work when replacing value's with a value from another dicom tag (it's probably because i do not understand LUA)..

function OnStoredInstance(instanceId, tags, metadata, origin)

   if origin['RequestOrigin'] ~= 'Lua' then
  
     -- The tags to be replaced
      local replace = {}
  replace['PatientName'] = tags['PatientID']
  
     -- The tags to be removed
      local remove = { 'MilitaryRank' }

     -- Modify the instance, send it, then delete the modified instance
     -- Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'AZM'))
 ModifyInstance(instanceId, replace, remove, true)

     -- Delete the original instance
     Delete(instanceId)
end
 end
in the trace i see:
ModifyInstanceCommand.cpp:117] Unable to modify instance 59cbbbde-6d43dfe1-92c74d9d-19e5051e-a8a19bb1 in a Lua script: Bad type for a parameter

Is there a simple fix?


Regards,
Robert

Sébastien Jodogne

unread,
Dec 23, 2015, 9:39:47 AM12/23/15
to Orthanc Users
Hello,

This is most likely due to the fact that your "PatientID" is made of digits, which Lua interprets as a number, which in turns breaks the modification command that is sent to the Orthanc core by Lua (as it is assumed to be made of strings). The argument "keepStrings" of function "DumpJson()" is designed to bypass this problem.

I now recommend to directly use the REST API inside Lua for new developments whose intent is to modify DICOM resources. Here is the corresponding Lua script:

function OnStoredInstance(instanceId, tags, metadata, origin)
   if origin['RequestOrigin'] ~= 'Lua' then
      
      -- The tags to be replaced
      local replace = {}
      replace['PatientName'] = tags['PatientID']
      
      -- The tags to be removed
      local remove = { 'Manufacturer' }

      -- Modify the instance
      local command = {}
      command['Replace'] = replace
      command['Remove'] = remove
      local modified = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true))

      -- Delete the original instance
      RestApiDelete('/instances/' .. instanceId)

      -- Upload the modified instance
      RestApiPost('/instances/', modified)
   end
end

HTH,
Sébastien-

Robert van Ommen

unread,
Dec 23, 2015, 4:15:59 PM12/23/15
to Orthanc Users
Thanks!!
Reply all
Reply to author
Forward
0 new messages