comparison Resources/Samples/Lua/ParseDoseReport.lua @ 1559:1e6fbb2dcc6f

ParseDoseReport.lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Aug 2015 10:12:56 +0200
parents
children
comparison
equal deleted inserted replaced
1558:124de28b32ed 1559:1e6fbb2dcc6f
1 -- Sample Lua script that demonstrates how to extract DICOM tags
2 -- related to dose reports. In this example, the value of the DLP
3 -- (Dose Length Product), the value of the mean CTDI volume (Computed
4 -- Tomography Dose Index), and the number of "IntervalsRejected" are
5 -- extracted and printed. Furthermore, these values are saved as
6 -- metadata that is attached to their parent DICOM instance for
7 -- further processing by external software.
8
9
10 function ExploreContentSequence(instanceId, tags)
11 if tags then
12 for key, value in pairs(tags) do
13 -- Recursive exploration
14 ExploreContentSequence(instanceId, value['ContentSequence'])
15
16 local concept = value['ConceptNameCodeSequence']
17 local measure = value['MeasuredValueSequence']
18 if concept and measure then
19
20 local value = measure[1]['NumericValue']
21 local code = concept[1]['CodeValue']
22
23 if type(value) == 'string' and type(code) == 'string' then
24 -- If the field contains the DLP, stores it as a metadata.
25 -- "DLP" is associated with CodeValue 113838.
26 -- ftp://medical.nema.org/medical/dicom/final/sup127_ft.pdf
27 if code == '113838' then
28 print('DLP = ' .. value)
29 RestApiPut('/instances/' .. instanceId .. '/metadata/2001', value)
30 end
31
32 -- Extract the mean CTDI volume
33 if code == '113830' then
34 print('CTDI = ' .. value)
35 RestApiPut('/instances/' .. instanceId .. '/metadata/2002', value)
36 end
37
38 -- Other values can be extracted here
39 end
40 end
41 end
42 end
43 end
44
45
46 function StoreTagToMetadata(instanceId, tags, name, metadata)
47 if tags then
48 for key, value in pairs(tags) do
49 if type(value) ~= 'string' then
50 -- Recursive exploration
51 StoreTagToMetadata(instanceId, value, name, metadata)
52 elseif key == name then
53 print(name .. ' = ' .. value)
54 if metadata then
55 RestApiPut('/instances/' .. instanceId .. '/metadata/' .. metadata, value)
56 end
57 end
58 end
59 end
60 end
61
62
63 function OnStoredInstance(instanceId, tags)
64 StoreTagToMetadata(instanceId, tags, 'IntervalsRejected', 2000)
65 ExploreContentSequence(instanceId, tags['ContentSequence'])
66 end