# HG changeset patch # User Sebastien Jodogne # Date 1466500871 -7200 # Node ID c98317fedf879e32ff46b00b70da6cc16318af03 # Parent dabe6df0267fa008b7386ca290e69c48f3145272 note about autorouting diff -r dabe6df0267f -r c98317fedf87 Sphinx/source/users/lua.rst --- a/Sphinx/source/users/lua.rst Tue Jun 21 09:36:54 2016 +0200 +++ b/Sphinx/source/users/lua.rst Tue Jun 21 11:21:11 2016 +0200 @@ -356,12 +356,55 @@ end -**Important remark:** The ``SendToModality()``, ``SendToPeer()``, -``ModifyInstance()`` and ``Delete()`` functions are for the most -common cases of auto-routing (implying a single DICOM instance, and -possibly a basic modification of this instance). For more evolved -auto-routing scenarios, remember that Lua scripts :ref:`have full to -the REST API of Orthanc `, and that :ref:`other callbacks -are available ` to react to other events than the -reception of a single instance (notably ``OnStablePatient()``, -``OnStableStudy()`` and ``OnStableSeries()``). +Important Remarks about Auto-Routing +------------------------------------ + +The ``SendToModality()``, ``SendToPeer()``, ``ModifyInstance()`` and +``Delete()`` functions are for the most basic cases of auto-routing +(implying a single DICOM instance, and possibly a basic modification +of this instance). The ``ModifyInstance()`` function `could also lead +to problems +`__ +if it deals with tags wrongly interpreted as numbers by Lua. + +For more evolved auto-routing scenarios, remember that Lua scripts +:ref:`have full to the REST API of Orthanc `. This is +illustrated by the ``AutoroutingModification.lua`` sample available in +the source distribution of Orthanc:: + + function OnStoredInstance(instanceId, tags, metadata, origin) + -- Ignore the instances that result from the present Lua script to + -- avoid infinite loops + if origin['RequestOrigin'] ~= 'Lua' then + + -- The tags to be replaced + local replace = {} + replace['StationName'] = 'My Medical Device' + replace['0031-1020'] = 'Some private tag' + + -- The tags to be removed + local remove = { 'MilitaryRank' } + + -- Modify the instance + local command = {} + command['Replace'] = replace + command['Remove'] = remove + local modifiedFile = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(command, true)) + + -- Upload the modified instance to the Orthanc database so that + -- it can be sent by Orthanc to other modalities + local modifiedId = ParseJson(RestApiPost('/instances/', modifiedFile)) ['ID'] + + -- Send the modified instance to another modality + RestApiPost('/modalities/sample/store', modifiedId) + + -- Delete the original and the modified instances + RestApiDelete('/instances/' .. instanceId) + RestApiDelete('/instances/' .. modifiedId) + end + end + +Also note that :ref:`other callbacks are available ` +(``OnStablePatient()``, ``OnStableStudy()`` and ``OnStableSeries()``) +to react to other events than the reception of a single instance +with ``OnStoredInstance()``.