annotate Resources/Samples/Lua/ParseDoseReport.lua @ 2936:4b3929668358

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