changeset 1011:23590917e83e lua-scripting

lua samples
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Jul 2014 17:51:28 +0200
parents 160dfe770618
children 52e71b25f9ce
files Resources/Samples/Lua/Autorouting.lua Resources/Samples/Lua/AutoroutingConditional.lua Resources/Samples/Lua/AutoroutingModification.lua
diffstat 3 files changed, 34 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/Lua/Autorouting.lua	Wed Jul 09 17:05:00 2014 +0200
+++ b/Resources/Samples/Lua/Autorouting.lua	Wed Jul 09 17:51:28 2014 +0200
@@ -1,23 +1,3 @@
 function OnStoredInstance(instanceId, tags, metadata)
-   --PrintRecursive(tags)
-   --PrintRecursive(metadata)
-   --print(metadata['RemoteAET'])
-
-   if (metadata['ModifiedFrom'] == nil and
-       metadata['AnonymizedFrom'] == nil) then
-      local patientName = string.lower(tags['PatientName'])
-      if string.find(patientName, 'david') ~= nil then
-         --Delete(SendToModality(instanceId, 'sample'))
-         --Delete(SendToPeer(instanceId, 'peer'))
-         local replace = {}
-         replace['StationName'] = 'My Medical Device'
-
-         local remove = { 'MilitaryRank' }
-
-         Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'sample'))
-         Delete(instanceId)
-      else
-         Delete(instanceId)
-      end
-   end
+   Delete(SendToModality(instanceId, 'sample'))
 end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/AutoroutingConditional.lua	Wed Jul 09 17:51:28 2014 +0200
@@ -0,0 +1,13 @@
+function OnStoredInstance(instanceId, tags, metadata)
+   -- Extract the value of the "PatientName" DICOM tag
+   local patientName = string.lower(tags['PatientName'])
+
+   if string.find(patientName, 'david') ~= nil then
+      -- Only send patients whose name contains "David"
+      Delete(SendToModality(instanceId, 'sample'))
+
+   else
+      -- Delete the patients that are not called "David"
+      Delete(instanceId)
+   end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/AutoroutingModification.lua	Wed Jul 09 17:51:28 2014 +0200
@@ -0,0 +1,20 @@
+function OnStoredInstance(instanceId, tags, metadata)
+   -- Ignore the instances that result from a modification to avoid
+   -- infinite loops
+   if (metadata['ModifiedFrom'] == nil and
+       metadata['AnonymizedFrom'] == nil) then
+
+      -- The tags to be replaced
+      local replace = {}
+      replace['StationName'] = 'My Medical Device'
+
+      -- 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), 'sample'))
+
+      -- Delete the original instance
+      Delete(instanceId)
+   end
+end