changeset 2249:38c7bf2e10f6

updated samples to set keepStrings=ture when calling DumpJson() to access the Orthanc API
author Alain Mazy <alain@mazy.be>
date Mon, 16 Jan 2017 13:55:54 +0100
parents 69b0f4e8a49b
children b5c8c0590f7f
files Resources/Samples/Lua/ModifyInstanceWithSequence.lua Resources/Samples/Lua/ModifyInstanceWithSequence.lua.orig Resources/Samples/Lua/OnStableStudy.lua Resources/Samples/Lua/OnStableStudy.lua.orig
diffstat 4 files changed, 76 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/Lua/ModifyInstanceWithSequence.lua	Mon Jan 16 13:07:11 2017 +0100
+++ b/Resources/Samples/Lua/ModifyInstanceWithSequence.lua	Mon Jan 16 13:55:54 2017 +0100
@@ -17,7 +17,7 @@
 
       -- Create the modified instance
       local modified = RestApiPost('/instances/' .. instanceId .. '/modify',
-                                   DumpJson(request))
+                                   DumpJson(request, true))
 
       -- Upload the modified instance to the Orthanc store
       RestApiPost('/instances/', modified)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/ModifyInstanceWithSequence.lua.orig	Mon Jan 16 13:55:54 2017 +0100
@@ -0,0 +1,28 @@
+-- Answer to:
+-- https://groups.google.com/d/msg/orthanc-users/0ymHe1cDBCQ/YfD0NoOTn0wJ
+-- Applicable starting with Orthanc 0.9.5
+
+function OnStoredInstance(instanceId, tags, metadata, origin)
+   -- Do not modify twice the same file
+   if origin['RequestOrigin'] ~= 'Lua' then
+      local replace = {}
+      replace['0010,1002'] = {}
+      replace['0010,1002'][1] = {}
+      replace['0010,1002'][1]['PatientID'] = 'Hello'
+      replace['0010,1002'][2] = {}
+      replace['0010,1002'][2]['PatientID'] = 'World'
+
+      local request = {}
+      request['Replace'] = replace
+
+      -- Create the modified instance
+      local modified = RestApiPost('/instances/' .. instanceId .. '/modify',
+                                   DumpJson(request, true))
+
+      -- Upload the modified instance to the Orthanc store
+      RestApiPost('/instances/', modified)
+
+      -- Delete the original instance
+      RestApiDelete('/instances/' .. instanceId)
+   end
+end
--- a/Resources/Samples/Lua/OnStableStudy.lua	Mon Jan 16 13:07:11 2017 +0100
+++ b/Resources/Samples/Lua/OnStableStudy.lua	Mon Jan 16 13:55:54 2017 +0100
@@ -40,7 +40,7 @@
 
       -- Modify the entire study in one single call
       local m = RestApiPost('/studies/' .. studyId .. '/modify',
-                            DumpJson(command))
+                            DumpJson(command, true))
       print('Modified study: ' .. m)
    end
 end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/OnStableStudy.lua.orig	Mon Jan 16 13:55:54 2017 +0100
@@ -0,0 +1,46 @@
+function Initialize()
+   print('Number of stored studies at initialization: ' ..
+            table.getn(ParseJson(RestApiGet('/studies'))))
+end
+
+
+function Finalize()
+   print('Number of stored studies at finalization: ' ..
+            table.getn(ParseJson(RestApiGet('/studies'))))
+end
+
+
+function OnStoredInstance(instanceId, tags, metadata)
+   patient = ParseJson(RestApiGet('/instances/' .. instanceId .. '/patient'))
+   print('Received an instance for patient: ' .. 
+            patient['MainDicomTags']['PatientID'] .. ' - ' .. 
+            patient['MainDicomTags']['PatientName'])
+end
+
+
+function OnStableStudy(studyId, tags, metadata)
+   if (metadata['ModifiedFrom'] == nil and
+       metadata['AnonymizedFrom'] == nil) then
+
+      print('This study is now stable: ' .. studyId)
+      
+      -- The tags to be replaced
+      local replace = {}
+      replace['StudyDescription'] = 'Modified study'
+      replace['StationName'] = 'My Medical Device'
+      replace['0031-1020'] = 'Some private tag'
+
+      -- The tags to be removed
+      local remove = { 'MilitaryRank' }
+
+      -- The modification command
+      local command = {}
+      command['Remove'] = remove
+      command['Replace'] = replace
+
+      -- Modify the entire study in one single call
+      local m = RestApiPost('/studies/' .. studyId .. '/modify',
+                            DumpJson(command, true))
+      print('Modified study: ' .. m)
+   end
+end