# HG changeset patch # User Alain Mazy # Date 1484571354 -3600 # Node ID 38c7bf2e10f6a95f8a0d35022ba6ac6b336f35a6 # Parent 69b0f4e8a49b3df9474120c0534770e459a23403 updated samples to set keepStrings=ture when calling DumpJson() to access the Orthanc API diff -r 69b0f4e8a49b -r 38c7bf2e10f6 Resources/Samples/Lua/ModifyInstanceWithSequence.lua --- 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) diff -r 69b0f4e8a49b -r 38c7bf2e10f6 Resources/Samples/Lua/ModifyInstanceWithSequence.lua.orig --- /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 diff -r 69b0f4e8a49b -r 38c7bf2e10f6 Resources/Samples/Lua/OnStableStudy.lua --- 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 diff -r 69b0f4e8a49b -r 38c7bf2e10f6 Resources/Samples/Lua/OnStableStudy.lua.orig --- /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