comparison Sphinx/source/users/lua.rst @ 19:c98317fedf87

note about autorouting
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 Jun 2016 11:21:11 +0200
parents 901e8961f46e
children 669ea65ba7fb
comparison
equal deleted inserted replaced
18:dabe6df0267f 19:c98317fedf87
354 Delete(instanceId) 354 Delete(instanceId)
355 end 355 end
356 end 356 end
357 357
358 358
359 **Important remark:** The ``SendToModality()``, ``SendToPeer()``, 359 Important Remarks about Auto-Routing
360 ``ModifyInstance()`` and ``Delete()`` functions are for the most 360 ------------------------------------
361 common cases of auto-routing (implying a single DICOM instance, and 361
362 possibly a basic modification of this instance). For more evolved 362 The ``SendToModality()``, ``SendToPeer()``, ``ModifyInstance()`` and
363 auto-routing scenarios, remember that Lua scripts :ref:`have full to 363 ``Delete()`` functions are for the most basic cases of auto-routing
364 the REST API of Orthanc <lua-rest>`, and that :ref:`other callbacks 364 (implying a single DICOM instance, and possibly a basic modification
365 are available <lua-callbacks>` to react to other events than the 365 of this instance). The ``ModifyInstance()`` function `could also lead
366 reception of a single instance (notably ``OnStablePatient()``, 366 to problems
367 ``OnStableStudy()`` and ``OnStableSeries()``). 367 <https://groups.google.com/d/msg/orthanc-users/hmv2y-LgKm8/oMAuGJWMBgAJ>`__
368 if it deals with tags wrongly interpreted as numbers by Lua.
369
370 For more evolved auto-routing scenarios, remember that Lua scripts
371 :ref:`have full to the REST API of Orthanc <lua-rest>`. This is
372 illustrated by the ``AutoroutingModification.lua`` sample available in
373 the source distribution of Orthanc::
374
375 function OnStoredInstance(instanceId, tags, metadata, origin)
376 -- Ignore the instances that result from the present Lua script to
377 -- avoid infinite loops
378 if origin['RequestOrigin'] ~= 'Lua' then
379
380 -- The tags to be replaced
381 local replace = {}
382 replace['StationName'] = 'My Medical Device'
383 replace['0031-1020'] = 'Some private tag'
384
385 -- The tags to be removed
386 local remove = { 'MilitaryRank' }
387
388 -- Modify the instance
389 local command = {}
390 command['Replace'] = replace
391 command['Remove'] = remove
392 local modifiedFile = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true))
393
394 -- Upload the modified instance to the Orthanc database so that
395 -- it can be sent by Orthanc to other modalities
396 local modifiedId = ParseJson(RestApiPost('/instances/', modifiedFile)) ['ID']
397
398 -- Send the modified instance to another modality
399 RestApiPost('/modalities/sample/store', modifiedId)
400
401 -- Delete the original and the modified instances
402 RestApiDelete('/instances/' .. instanceId)
403 RestApiDelete('/instances/' .. modifiedId)
404 end
405 end
406
407 Also note that :ref:`other callbacks are available <lua-callbacks>`
408 (``OnStablePatient()``, ``OnStableStudy()`` and ``OnStableSeries()``)
409 to react to other events than the reception of a single instance
410 with ``OnStoredInstance()``.