diff Resources/Samples/Lua/Autorouting.lua @ 1010:160dfe770618 lua-scripting

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Jul 2014 17:05:00 +0200
parents 187ed107a59f
children 23590917e83e
line wrap: on
line diff
--- a/Resources/Samples/Lua/Autorouting.lua	Wed Jul 09 16:11:44 2014 +0200
+++ b/Resources/Samples/Lua/Autorouting.lua	Wed Jul 09 17:05:00 2014 +0200
@@ -1,69 +1,3 @@
-function _InitializeJob()
-   _job = {}
-end
-
-function _AccessJob()
-   return _job
-end
-
-function SendToModality(instanceId, modality)
-   if instanceId == nil then
-      error('Cannot send an nonexistent instance')
-   end
-
-   table.insert(_job, { 
-                   operation = 'store-scu', 
-                   instance = instanceId,
-                   modality = modality 
-                })
-   return instanceId
-end
-
-function SendToPeer(instanceId, peer)
-   if instanceId == nil then
-      error('Cannot send an nonexistent instance')
-   end
-
-   table.insert(_job, { 
-                   operation = 'store-peer', 
-                   instance = instanceId,
-                   peer = peer
-                })
-   return instanceId
-end
-
-function Delete(instanceId)
-   if instanceId == nil then
-      error('Cannot delete an nonexistent instance')
-   end
-
-   table.insert(_job, { 
-                   operation = 'delete', 
-                   instance = instanceId
-                })
-   return nil  -- Forbid chaining
-end
-
-function Modify(instanceId, replacements, removals, removePrivateTags)
-   if instanceId == nil then
-      error('Cannot modify an nonexistent instance')
-   end
-
-   if instanceId == '' then
-      error('Cannot modify twice an instance');
-   end
-
-   table.insert(_job, { 
-                   operation = 'modify', 
-                   instance = instanceId,
-                   replacements = replacements, 
-                   removals = removals,
-                   removePrivateTags = removePrivateTags 
-                })
-   return ''  -- Chain with another operation
-end
-
-
 function OnStoredInstance(instanceId, tags, metadata)
    --PrintRecursive(tags)
    --PrintRecursive(metadata)
@@ -75,7 +9,12 @@
       if string.find(patientName, 'david') ~= nil then
          --Delete(SendToModality(instanceId, 'sample'))
          --Delete(SendToPeer(instanceId, 'peer'))
-         SendToModality(Modify(instanceId, { PatientName = 'Hello^World' }), 'sample')
+         local replace = {}
+         replace['StationName'] = 'My Medical Device'
+
+         local remove = { 'MilitaryRank' }
+
+         Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'sample'))
          Delete(instanceId)
       else
          Delete(instanceId)