comparison OrthancServer/Resources/Samples/Lua/ClassifyUsingAet.lua @ 4249:485f9be9ba92

improvement
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Oct 2020 15:41:25 +0200
parents 38b24aa98ed3
children cbf9afa17415
comparison
equal deleted inserted replaced
4248:38b24aa98ed3 4249:485f9be9ba92
26 function OnStoredInstance(instanceId, tags, metadata, origin) 26 function OnStoredInstance(instanceId, tags, metadata, origin)
27 local dicom = RestApiGet('/instances/' .. instanceId .. '/file') 27 local dicom = RestApiGet('/instances/' .. instanceId .. '/file')
28 local tags = ParseJson(RestApiGet('/instances/' .. instanceId .. '/tags?simplify')) 28 local tags = ParseJson(RestApiGet('/instances/' .. instanceId .. '/tags?simplify'))
29 local metadata = ParseJson(RestApiGet('/instances/' .. instanceId .. '/metadata?expand')) 29 local metadata = ParseJson(RestApiGet('/instances/' .. instanceId .. '/metadata?expand'))
30 30
31 local path = ToAscii( 31 local path = ToAscii(TARGET .. '/' ..
32 TARGET .. '/' .. 32 GetFromTable(metadata, 'RemoteAET', 'None') .. '/'..
33 GetFromTable(metadata, 'RemoteAET', 'None') .. '/'.. 33 GetFromTable(tags, 'StudyDate', '') .. '/' ..
34 GetFromTable(tags, 'PatientID', '') .. ' - ' .. GetFromTable(tags, 'PatientName', '') .. '/' .. 34 GetFromTable(tags, 'PatientID', '') .. ' - ' ..
35 GetFromTable(tags, 'StudyDate', '') .. ' - ' .. GetFromTable(tags, 'StudyDescription', '') .. '/' .. 35 GetFromTable(tags, 'PatientName', '') .. ' - ' ..
36 GetFromTable(tags, 'SeriesDescription', '')) 36 GetFromTable(tags, 'StudyDescription', '') .. '/' ..
37 GetFromTable(tags, 'Modality', '') .. ' - ' ..
38 GetFromTable(tags, 'SeriesDescription', ''))
37 39
38 -- Create the subdirectory (CAUTION: For Linux demo only, this is insecure!) 40 -- Create the subdirectory (CAUTION: For Linux demo only, this is insecure!)
39 -- http://stackoverflow.com/a/16029744/881731 41 -- http://stackoverflow.com/a/16029744/881731
40 os.execute('mkdir -p "' .. path .. '"') 42 os.execute('mkdir -p "' .. path .. '"')
41 43
42 -- Write to the file 44 -- Write to the file
43 local target = assert(io.open(path .. '/' .. GetFromTable(tags, 'SOPInstanceUID', 'none') .. '.dcm', 'wb')) 45 local target = assert(io.open(path .. '/' .. GetFromTable(tags, 'SOPInstanceUID', 'none') .. '.dcm', 'wb'))
44 target:write(dicom) 46 target:write(dicom)
45 target:close() 47 target:close()
46 48
47 -- Optional step: Remove the source file 49 -- Optional step: Remove the DICOM instance from Orthanc
48 RestApiDelete('/instances/' .. instanceId) 50 RestApiDelete('/instances/' .. instanceId)
49 end 51 end