changeset 1559:1e6fbb2dcc6f

ParseDoseReport.lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Aug 2015 10:12:56 +0200
parents 124de28b32ed
children 307b9ea6c39b
files Resources/Samples/Lua/ParseDoseReport.lua
diffstat 1 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/ParseDoseReport.lua	Fri Aug 21 10:12:56 2015 +0200
@@ -0,0 +1,66 @@
+-- Sample Lua script that demonstrates how to extract DICOM tags
+-- related to dose reports. In this example, the value of the DLP
+-- (Dose Length Product), the value of the mean CTDI volume (Computed
+-- Tomography Dose Index), and the number of "IntervalsRejected" are
+-- extracted and printed. Furthermore, these values are saved as
+-- metadata that is attached to their parent DICOM instance for
+-- further processing by external software.
+
+
+function ExploreContentSequence(instanceId, tags)
+   if tags then
+      for key, value in pairs(tags) do
+         -- Recursive exploration
+         ExploreContentSequence(instanceId, value['ContentSequence'])
+
+         local concept = value['ConceptNameCodeSequence'] 
+         local measure = value['MeasuredValueSequence']
+         if concept and measure then
+
+            local value = measure[1]['NumericValue']
+            local code = concept[1]['CodeValue']
+
+            if type(value) == 'string' and type(code) == 'string' then
+               -- If the field contains the DLP, stores it as a metadata.
+               -- "DLP" is associated with CodeValue 113838.
+               -- ftp://medical.nema.org/medical/dicom/final/sup127_ft.pdf
+               if code == '113838' then
+                  print('DLP = ' .. value)
+                  RestApiPut('/instances/' .. instanceId .. '/metadata/2001', value)
+               end
+
+               -- Extract the mean CTDI volume
+               if code == '113830' then
+                  print('CTDI = ' .. value)
+                  RestApiPut('/instances/' .. instanceId .. '/metadata/2002', value)
+               end
+
+               -- Other values can be extracted here
+            end
+         end
+      end
+   end
+end
+
+
+function StoreTagToMetadata(instanceId, tags, name, metadata)
+   if tags then
+      for key, value in pairs(tags) do
+         if type(value) ~= 'string' then
+            -- Recursive exploration
+            StoreTagToMetadata(instanceId, value, name, metadata)
+         elseif key == name then
+            print(name .. ' = ' .. value)
+            if metadata then
+               RestApiPut('/instances/' .. instanceId .. '/metadata/' .. metadata, value)
+            end
+         end
+      end
+   end
+end
+
+
+function OnStoredInstance(instanceId, tags)
+   StoreTagToMetadata(instanceId, tags, 'IntervalsRejected', 2000)
+   ExploreContentSequence(instanceId, tags['ContentSequence'])
+end