3
|
1 # Orthanc - A Lightweight, RESTful DICOM Store
|
|
2 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
|
|
3 # Department, University Hospital of Liege, Belgium
|
|
4 #
|
|
5 # This program is free software: you can redistribute it and/or
|
|
6 # modify it under the terms of the GNU General Public License as
|
|
7 # published by the Free Software Foundation, either version 3 of the
|
|
8 # License, or (at your option) any later version.
|
|
9 #
|
|
10 # This program is distributed in the hope that it will be useful, but
|
|
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 # General Public License for more details.
|
|
14 #
|
|
15 # You should have received a copy of the GNU General Public License
|
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
|
18
|
|
19 import unittest
|
|
20
|
|
21 from Toolbox import *
|
|
22
|
|
23 _LOCAL = None
|
|
24 _REMOTE = None
|
|
25
|
|
26
|
|
27 def SetOrthancParameters(local, remote):
|
|
28 global _LOCAL, _REMOTE
|
|
29 _LOCAL = local
|
|
30 _REMOTE = remote
|
|
31
|
|
32
|
|
33 class Orthanc(unittest.TestCase):
|
|
34 def setUp(self):
|
|
35 DropOrthanc(_LOCAL)
|
|
36 DropOrthanc(_REMOTE)
|
|
37
|
|
38 def test_system(self):
|
|
39 self.assertTrue('Version' in DoGet(_REMOTE, '/system'))
|
|
40 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
|
|
41 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
|
|
42
|
|
43 def test_upload(self):
|
|
44 u = UploadInstance(_REMOTE, 'DummyCT.dcm')
|
|
45 self.assertEqual('Success', u['Status'])
|
|
46 u = UploadInstance(_REMOTE, 'DummyCT.dcm')
|
|
47 self.assertEqual('AlreadyStored', u['Status'])
|
|
48 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
|
|
49 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
|
|
50 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
|
|
51 self.assertEqual(1, len(DoGet(_REMOTE, '/instances')))
|
|
52
|
|
53 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID'])
|
|
54 self.assertEqual('20070101', i['StudyDate'])
|
|
55
|
|
56
|
5
|
57 def test_upload_2(self):
|
3
|
58 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID']
|
|
59 instance = DoGet(_REMOTE, '/instances/%s' % i)
|
|
60 self.assertEqual(i, instance['ID'])
|
|
61 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109',
|
|
62 instance['MainDicomTags']['SOPInstanceUID'])
|
|
63
|
|
64 series = DoGet(_REMOTE, '/series/%s' % instance['ParentSeries'])
|
|
65 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394',
|
|
66 series['MainDicomTags']['SeriesInstanceUID'])
|
|
67
|
|
68 study = DoGet(_REMOTE, '/studies/%s' % series['ParentStudy'])
|
|
69 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390',
|
|
70 study['MainDicomTags']['StudyInstanceUID'])
|
|
71
|
|
72 patient = DoGet(_REMOTE, '/patients/%s' % study['ParentPatient'])
|
|
73 self.assertEqual('ozp00SjY2xG',
|
|
74 patient['MainDicomTags']['PatientID'])
|
|
75
|
|
76 dicom = DoGet(_REMOTE, '/instances/%s/file' % instance['ID'])
|
|
77 self.assertEqual(2472, len(dicom))
|
|
78 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom))
|
|
79 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i)))
|
|
80 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/simplified-tags' % i)['StationName'])
|
|
81 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value'])
|
|
82
|
|
83
|
5
|
84 def test_images(self):
|
|
85 i = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID']
|
|
86 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i)))
|
3
|
87
|
5
|
88 im = GetImage(_REMOTE, '/instances/%s/preview' % i)
|
|
89 self.assertEqual("L", im.mode)
|
|
90 self.assertEqual(512, im.size[0])
|
|
91 self.assertEqual(358, im.size[1])
|
|
92
|
|
93 im = GetImage(_REMOTE, '/instances/%s/image-uint8' % i)
|
|
94 self.assertEqual("L", im.mode)
|
|
95 self.assertEqual(512, im.size[0])
|
|
96 self.assertEqual(358, im.size[1])
|
|
97
|
|
98 im = GetImage(_REMOTE, '/instances/%s/image-uint16' % i)
|
|
99 self.assertEqual(512, im.size[0])
|
|
100 self.assertEqual(358, im.size[1])
|
|
101
|
|
102 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i)
|
|
103 self.assertEqual("L", im.mode)
|
|
104 self.assertEqual(512, im.size[0])
|
|
105 self.assertEqual(358, im.size[1])
|
|
106
|
|
107 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint8' % i)
|
|
108 self.assertEqual("L", im.mode)
|
|
109 self.assertEqual(512, im.size[0])
|
|
110 self.assertEqual(358, im.size[1])
|
|
111
|
|
112 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint16' % i)
|
|
113 self.assertEqual(512, im.size[0])
|
|
114 self.assertEqual(358, im.size[1])
|
|
115
|
6
|
116
|
|
117 def test_hierarchy(self):
|
|
118 UploadFolder(_REMOTE, 'Brainix/Epi')
|
|
119 UploadFolder(_REMOTE, 'Brainix/Flair')
|
|
120 UploadFolder(_REMOTE, 'Knee/T1')
|
|
121 UploadFolder(_REMOTE, 'Knee/T2')
|
|
122
|
|
123 p = DoGet(_REMOTE, '/patients')
|
|
124 s = DoGet(_REMOTE, '/studies')
|
|
125 t = DoGet(_REMOTE, '/series')
|
|
126 self.assertEqual(2, len(p))
|
|
127 self.assertEqual(2, len(s))
|
|
128 self.assertEqual(4, len(t))
|
|
129 self.assertEqual(94, len(DoGet(_REMOTE, '/instances')))
|
|
130
|
|
131 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0'
|
|
132 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988'
|
|
133 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8'
|
|
134 brainixFlair = '1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0'
|
|
135
|
|
136 kneePatient = 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17'
|
|
137 kneeStudy = '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918'
|
|
138 kneeT1 = '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285'
|
|
139 kneeT2 = 'bbf7a453-0d34251a-03663b55-46bb31b9-ffd74c59'
|
|
140
|
|
141 self.assertTrue(brainixPatient in p)
|
|
142 self.assertTrue(kneePatient in p)
|
|
143 self.assertTrue(brainixStudy in s)
|
|
144 self.assertTrue(kneeStudy in s)
|
|
145 self.assertTrue(brainixEpi in t)
|
|
146 self.assertTrue(brainixFlair in t)
|
|
147 self.assertTrue(kneeT1 in t)
|
|
148 self.assertTrue(kneeT2 in t)
|
|
149
|
|
150 self.assertEqual(44, len(DoGet(_REMOTE, '/patients/%s/instances' % brainixPatient)))
|
|
151 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % brainixPatient)))
|
|
152 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % brainixPatient)))
|
|
153
|
|
154 self.assertEqual(50, len(DoGet(_REMOTE, '/patients/%s/instances' % kneePatient)))
|
|
155 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % kneePatient)))
|
|
156 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % kneePatient)))
|
|
157
|
|
158 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % brainixStudy)))
|
|
159 self.assertEqual(44, len(DoGet(_REMOTE, '/studies/%s/instances' % brainixStudy)))
|
|
160
|
|
161 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % kneeStudy)))
|
|
162 self.assertEqual(50, len(DoGet(_REMOTE, '/studies/%s/instances' % kneeStudy)))
|
|
163
|
|
164 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixEpi)))
|
|
165 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixFlair)))
|
|
166 self.assertEqual(24, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT1)))
|
|
167 self.assertEqual(26, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT2)))
|
|
168
|
|
169 for patient in p:
|
|
170 for study in DoGet(_REMOTE, '/patients/%s/studies' % patient):
|
|
171 self.assertEqual(patient, study['ParentPatient'])
|
|
172 for series in DoGet(_REMOTE, '/studies/%s/series' % study['ID']):
|
|
173 self.assertEqual(study['ID'], series['ParentStudy'])
|
|
174 for instance in DoGet(_REMOTE, '/series/%s/instances' % series['ID']):
|
|
175 self.assertEqual(series['ID'], instance['ParentSeries'])
|
|
176
|
|
177 self.assertEqual(json.dumps(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance['ID'])),
|
|
178 json.dumps(DoGet(_REMOTE, '/instances/%s/tags' % instance['ID'])))
|
|
179
|
|
180
|
|
181 r = DoDelete(_REMOTE, "/studies/%s" % brainixStudy)['RemainingAncestor']
|
|
182 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
|
|
183 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
|
|
184 self.assertEqual(2, len(DoGet(_REMOTE, '/series')))
|
|
185 self.assertEqual(50, len(DoGet(_REMOTE, '/instances')))
|
|
186 self.assertEqual(None, r)
|
|
187
|
|
188 r = DoDelete(_REMOTE, "/series/%s" % kneeT2)['RemainingAncestor']
|
|
189 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
|
|
190 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
|
|
191 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
|
|
192 self.assertEqual(24, len(DoGet(_REMOTE, '/instances')))
|
|
193 self.assertEqual('Study', r['Type'])
|
|
194 self.assertEqual(kneeStudy, r['ID'])
|
|
195
|
|
196 r = DoDelete(_REMOTE, "/instances/%s" % DoGet(_REMOTE, '/instances')[0])['RemainingAncestor']
|
|
197 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
|
|
198 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
|
|
199 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
|
|
200 self.assertEqual(23, len(DoGet(_REMOTE, '/instances')))
|
|
201 self.assertEqual('Series', r['Type'])
|
|
202 self.assertEqual(kneeT1, r['ID'])
|
|
203
|
|
204 r = DoDelete(_REMOTE, "/patients/%s" % kneePatient)['RemainingAncestor']
|
|
205 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
|
|
206 self.assertEqual(0, len(DoGet(_REMOTE, '/studies')))
|
|
207 self.assertEqual(0, len(DoGet(_REMOTE, '/series')))
|
|
208 self.assertEqual(0, len(DoGet(_REMOTE, '/instances')))
|
|
209 self.assertEqual(None, r)
|
|
210
|
|
211 DropOrthanc(_REMOTE)
|
|
212 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
|
|
213 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
|