Mercurial > hg > orthanc-tests
annotate Tests/Tests.py @ 12:15c166240dfb
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Jun 2015 14:33:01 +0200 |
parents | c660a64ce2dd |
children | 7b69a561f4d3 |
rev | line source |
---|---|
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 | |
11 | 21 from PIL import ImageChops |
3 | 22 from Toolbox import * |
23 | |
24 _LOCAL = None | |
25 _REMOTE = None | |
26 | |
27 | |
28 def SetOrthancParameters(local, remote): | |
29 global _LOCAL, _REMOTE | |
30 _LOCAL = local | |
31 _REMOTE = remote | |
32 | |
33 | |
34 class Orthanc(unittest.TestCase): | |
35 def setUp(self): | |
36 DropOrthanc(_LOCAL) | |
37 DropOrthanc(_REMOTE) | |
38 | |
39 def test_system(self): | |
40 self.assertTrue('Version' in DoGet(_REMOTE, '/system')) | |
41 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
42 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
43 | |
44 def test_upload(self): | |
45 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
46 self.assertEqual('Success', u['Status']) | |
47 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
48 self.assertEqual('AlreadyStored', u['Status']) | |
49 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
50 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
51 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
52 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
53 | |
54 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID']) | |
55 self.assertEqual('20070101', i['StudyDate']) | |
56 | |
57 | |
5 | 58 def test_upload_2(self): |
3 | 59 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] |
60 instance = DoGet(_REMOTE, '/instances/%s' % i) | |
61 self.assertEqual(i, instance['ID']) | |
62 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', | |
63 instance['MainDicomTags']['SOPInstanceUID']) | |
64 | |
65 series = DoGet(_REMOTE, '/series/%s' % instance['ParentSeries']) | |
66 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
67 series['MainDicomTags']['SeriesInstanceUID']) | |
68 | |
69 study = DoGet(_REMOTE, '/studies/%s' % series['ParentStudy']) | |
70 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
71 study['MainDicomTags']['StudyInstanceUID']) | |
72 | |
73 patient = DoGet(_REMOTE, '/patients/%s' % study['ParentPatient']) | |
74 self.assertEqual('ozp00SjY2xG', | |
75 patient['MainDicomTags']['PatientID']) | |
76 | |
77 dicom = DoGet(_REMOTE, '/instances/%s/file' % instance['ID']) | |
78 self.assertEqual(2472, len(dicom)) | |
79 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom)) | |
80 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
81 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/simplified-tags' % i)['StationName']) | |
82 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value']) | |
83 | |
84 | |
5 | 85 def test_images(self): |
86 i = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID'] | |
87 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
3 | 88 |
5 | 89 im = GetImage(_REMOTE, '/instances/%s/preview' % i) |
90 self.assertEqual("L", im.mode) | |
91 self.assertEqual(512, im.size[0]) | |
92 self.assertEqual(358, im.size[1]) | |
93 | |
94 im = GetImage(_REMOTE, '/instances/%s/image-uint8' % i) | |
95 self.assertEqual("L", im.mode) | |
96 self.assertEqual(512, im.size[0]) | |
97 self.assertEqual(358, im.size[1]) | |
98 | |
99 im = GetImage(_REMOTE, '/instances/%s/image-uint16' % i) | |
100 self.assertEqual(512, im.size[0]) | |
101 self.assertEqual(358, im.size[1]) | |
102 | |
103 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
104 self.assertEqual("L", im.mode) | |
105 self.assertEqual(512, im.size[0]) | |
106 self.assertEqual(358, im.size[1]) | |
107 | |
108 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
109 self.assertEqual("L", im.mode) | |
110 self.assertEqual(512, im.size[0]) | |
111 self.assertEqual(358, im.size[1]) | |
112 | |
113 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
114 self.assertEqual(512, im.size[0]) | |
115 self.assertEqual(358, im.size[1]) | |
116 | |
6 | 117 |
118 def test_hierarchy(self): | |
119 UploadFolder(_REMOTE, 'Brainix/Epi') | |
120 UploadFolder(_REMOTE, 'Brainix/Flair') | |
121 UploadFolder(_REMOTE, 'Knee/T1') | |
122 UploadFolder(_REMOTE, 'Knee/T2') | |
123 | |
124 p = DoGet(_REMOTE, '/patients') | |
125 s = DoGet(_REMOTE, '/studies') | |
126 t = DoGet(_REMOTE, '/series') | |
127 self.assertEqual(2, len(p)) | |
128 self.assertEqual(2, len(s)) | |
129 self.assertEqual(4, len(t)) | |
130 self.assertEqual(94, len(DoGet(_REMOTE, '/instances'))) | |
131 | |
132 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0' | |
133 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' | |
134 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8' | |
135 brainixFlair = '1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0' | |
136 | |
137 kneePatient = 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' | |
138 kneeStudy = '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918' | |
139 kneeT1 = '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285' | |
140 kneeT2 = 'bbf7a453-0d34251a-03663b55-46bb31b9-ffd74c59' | |
141 | |
142 self.assertTrue(brainixPatient in p) | |
143 self.assertTrue(kneePatient in p) | |
144 self.assertTrue(brainixStudy in s) | |
145 self.assertTrue(kneeStudy in s) | |
146 self.assertTrue(brainixEpi in t) | |
147 self.assertTrue(brainixFlair in t) | |
148 self.assertTrue(kneeT1 in t) | |
149 self.assertTrue(kneeT2 in t) | |
150 | |
151 self.assertEqual(44, len(DoGet(_REMOTE, '/patients/%s/instances' % brainixPatient))) | |
152 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % brainixPatient))) | |
153 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % brainixPatient))) | |
154 | |
155 self.assertEqual(50, len(DoGet(_REMOTE, '/patients/%s/instances' % kneePatient))) | |
156 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % kneePatient))) | |
157 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % kneePatient))) | |
158 | |
159 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % brainixStudy))) | |
160 self.assertEqual(44, len(DoGet(_REMOTE, '/studies/%s/instances' % brainixStudy))) | |
161 | |
162 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % kneeStudy))) | |
163 self.assertEqual(50, len(DoGet(_REMOTE, '/studies/%s/instances' % kneeStudy))) | |
164 | |
165 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixEpi))) | |
166 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixFlair))) | |
167 self.assertEqual(24, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT1))) | |
168 self.assertEqual(26, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT2))) | |
169 | |
170 for patient in p: | |
171 for study in DoGet(_REMOTE, '/patients/%s/studies' % patient): | |
172 self.assertEqual(patient, study['ParentPatient']) | |
173 for series in DoGet(_REMOTE, '/studies/%s/series' % study['ID']): | |
174 self.assertEqual(study['ID'], series['ParentStudy']) | |
175 for instance in DoGet(_REMOTE, '/series/%s/instances' % series['ID']): | |
176 self.assertEqual(series['ID'], instance['ParentSeries']) | |
177 | |
178 self.assertEqual(json.dumps(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance['ID'])), | |
179 json.dumps(DoGet(_REMOTE, '/instances/%s/tags' % instance['ID']))) | |
180 | |
181 | |
182 r = DoDelete(_REMOTE, "/studies/%s" % brainixStudy)['RemainingAncestor'] | |
183 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
184 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
185 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
186 self.assertEqual(50, len(DoGet(_REMOTE, '/instances'))) | |
187 self.assertEqual(None, r) | |
188 | |
189 r = DoDelete(_REMOTE, "/series/%s" % kneeT2)['RemainingAncestor'] | |
190 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
191 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
192 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
193 self.assertEqual(24, len(DoGet(_REMOTE, '/instances'))) | |
194 self.assertEqual('Study', r['Type']) | |
195 self.assertEqual(kneeStudy, r['ID']) | |
196 | |
197 r = DoDelete(_REMOTE, "/instances/%s" % DoGet(_REMOTE, '/instances')[0])['RemainingAncestor'] | |
198 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
199 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
200 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
201 self.assertEqual(23, len(DoGet(_REMOTE, '/instances'))) | |
202 self.assertEqual('Series', r['Type']) | |
203 self.assertEqual(kneeT1, r['ID']) | |
204 | |
205 r = DoDelete(_REMOTE, "/patients/%s" % kneePatient)['RemainingAncestor'] | |
206 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
207 self.assertEqual(0, len(DoGet(_REMOTE, '/studies'))) | |
208 self.assertEqual(0, len(DoGet(_REMOTE, '/series'))) | |
209 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
210 self.assertEqual(None, r) | |
211 | |
212 DropOrthanc(_REMOTE) | |
213 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
214 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
7 | 215 |
216 | |
217 def test_multi_frame(self): | |
218 i = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID'] | |
219 self.assertEqual(76, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
220 | |
221 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
222 self.assertEqual("L", im.mode) | |
223 self.assertEqual(512, im.size[0]) | |
224 self.assertEqual(512, im.size[1]) | |
225 | |
226 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
227 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
228 DoGet(_REMOTE, '/instances/%s/frames/75/preview' % i) | |
229 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/aaa/preview' % i)) | |
230 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/76/preview' % i)) | |
231 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
232 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
233 def test_changes(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
234 # Check emptiness |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
235 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
236 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
237 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
238 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
239 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
240 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
241 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
242 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
243 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
244 # Add 1 instance |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
245 i = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
246 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
247 begin = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
248 self.assertEqual(4, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
249 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
250 self.assertEqual(c['Changes'][-1]['Seq'], c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
251 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
252 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
253 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
254 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
255 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
256 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 1)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
257 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
258 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
259 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
260 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 2)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
261 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
262 self.assertEqual(begin - 1, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
263 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
264 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 3)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
265 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
266 self.assertEqual(begin - 2, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
267 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
268 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
269 UploadFolder(_REMOTE, 'Knee/T1') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
270 UploadFolder(_REMOTE, 'Knee/T2') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
271 since = begin |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
272 countPatients = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
273 countStudies = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
274 countSeries = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
275 countInstances = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
276 completed = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
277 while True: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
278 c = DoGet(_REMOTE, '/changes', { 'since' : since, 'limit' : 3 }) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
279 since = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
280 for i in c['Changes']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
281 if i['ResourceType'] == 'Instance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
282 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
283 if i['ResourceType'] == 'Patient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
284 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
285 if i['ResourceType'] == 'Study': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
286 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
287 if i['ResourceType'] == 'Series': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
288 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
289 if i['ChangeType'] == 'NewInstance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
290 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
291 if i['ChangeType'] == 'NewPatient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
292 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
293 if i['ChangeType'] == 'NewStudy': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
294 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
295 if i['ChangeType'] == 'NewSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
296 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
297 if i['ChangeType'] == 'CompletedSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
298 completed += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
299 self.assertTrue('ID' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
300 self.assertTrue('Path' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
301 self.assertTrue('Seq' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
302 if c['Done']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
303 break |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
304 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
305 self.assertEqual(2 * 50, countInstances) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
306 self.assertEqual(2 * 1, countPatients) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
307 self.assertEqual(2 * 1, countStudies) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
308 self.assertEqual(2 * 2, countSeries) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
309 self.assertEqual(0, completed) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
310 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
311 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
312 def test_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
313 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
314 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
315 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
316 z = GetArchive(_REMOTE, '/patients/%s/archive' % DoGet(_REMOTE, '/patients')[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
317 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
318 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
319 z = GetArchive(_REMOTE, '/studies/%s/archive' % DoGet(_REMOTE, '/studies')[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
320 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
321 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
322 z = GetArchive(_REMOTE, '/series/%s/archive' % DoGet(_REMOTE, '/series')[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
323 self.assertEqual(1, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
324 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
325 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
326 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
327 z = GetArchive(_REMOTE, '/patients/%s/archive' % DoGet(_REMOTE, '/patients')[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
328 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
329 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
330 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
331 def test_media_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
332 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
333 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
334 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
335 z = GetArchive(_REMOTE, '/patients/%s/media' % DoGet(_REMOTE, '/patients')[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
336 self.assertEqual(3, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
337 self.assertTrue('IMAGES/IM0' in z.namelist()) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
338 self.assertTrue('IMAGES/IM1' in z.namelist()) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
339 self.assertTrue('DICOMDIR' in z.namelist()) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
340 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
341 try: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
342 os.remove('/tmp/DICOMDIR') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
343 except: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
344 # The file does not exist |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
345 pass |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
346 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
347 z.extract('DICOMDIR', '/tmp') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
348 a = subprocess.check_output([ 'dciodvfy', '/tmp/DICOMDIR' ], |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
349 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
350 self.assertEqual(3, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
351 self.assertTrue(a[0].startswith('Warning')) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
352 self.assertEqual('BasicDirectory', a[1]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
353 self.assertEqual('', a[2]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
354 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
355 a = subprocess.check_output([ 'dcentvfy', '/tmp/DICOMDIR' ], |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
356 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
357 self.assertEqual(1, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
358 self.assertEqual('', a[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
359 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
360 a = subprocess.check_output([ 'dcm2xml', '/tmp/DICOMDIR' ]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
361 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081908590448738', a) != None) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
362 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081909113806560', a) != None) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
363 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
364 os.remove('/tmp/DICOMDIR') |
10 | 365 |
366 | |
367 def test_protection(self): | |
368 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
369 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
370 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
371 a = DoGet(_REMOTE, '/patients')[0] | |
372 b = DoGet(_REMOTE, '/patients')[1] | |
373 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
374 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
375 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
376 DoPut(_REMOTE, '/patients/%s/protected' % a, '1', 'text/plain') | |
377 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
378 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
379 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
380 | |
381 | |
12 | 382 def test_raw_tags(self): |
10 | 383 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] |
384 | |
385 dicom = DoGet(_REMOTE, '/instances/%s/file' % i) | |
386 self.assertEqual('1a7c56cb02d6e742cc9c856a8ac182e3', ComputeMD5(dicom)) | |
387 | |
388 s = '/instances/%s/content/' % i | |
389 | |
390 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, s + '0008-1010').strip()) | |
391 self.assertRaises(Exception, lambda: DoGet(_REMOTE, s + '0008-1011')) | |
392 | |
393 self.assertEqual('Abdomen', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/0/7fe1-1057').strip()) | |
394 self.assertEqual('cla_3c', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/8/7fe1-1057').strip()) | |
395 | |
396 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') | |
397 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
398 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
399 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
400 | |
401 for i in DoGet(_REMOTE, '/instances'): | |
402 aid = DoGet(_REMOTE, '/instances/%s' % i)['MainDicomTags']['SOPInstanceUID'] | |
403 self.assertEqual(aid, DoGet(_REMOTE, '/instances/%s/content/0008-0018' % i).replace(chr(0), '')) | |
404 | |
405 | |
406 def test_raw_tags_mdn(self): | |
407 # Bug reported by Cyril Paulus | |
408 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
409 self.assertAlmostEqual(0.000027, DoGet(_REMOTE, '/instances/%s/content/7053-1000' % i)) | |
410 | |
411 | |
412 def test_modify_instance(self): | |
413 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] | |
414 modified = DoPost(_REMOTE, '/instances/%s/modify' % i, | |
415 json.dumps({ | |
416 "Replace" : { | |
417 "PatientName" : "hello", | |
418 #"PatientID" : "world" | |
419 }, | |
420 "Remove" : [ "StationName" ], | |
421 "RemovePrivateTags" : None | |
422 }), | |
423 'application/json') | |
424 j = DoPost(_REMOTE, '/instances', modified, 'application/dicom')['ID'] | |
425 | |
426 self.assertNotEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
427 #self.assertNotEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % i).strip()) | |
428 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i).strip()) | |
429 DoGet(_REMOTE, '/instances/%s/content/6003-1010' % i) # Some private tag | |
430 | |
431 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
432 #self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % j).strip()) | |
433 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j)) | |
434 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/6003-1010' % j)) | |
435 | |
436 | |
437 def test_modify_series(self): | |
438 # Upload 4 images from the same series | |
439 for i in range(4): | |
440 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
441 | |
442 origSeries = DoGet(_REMOTE, '/series')[0] | |
443 newSeries = DoPost(_REMOTE, '/series/%s/modify' % origSeries, | |
444 '{"Replace":{"PatientName":"Jodogne"}}', | |
445 'application/json')['ID'] | |
446 | |
447 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['ModifiedFrom']) | |
448 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
449 self.assertEqual(4, len(instances)) | |
450 for i in instances: | |
451 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
452 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
453 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
454 | |
455 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
456 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
457 | |
458 | |
459 def test_modify_study(self): | |
460 # Upload 4 images from the 2 series of the same study | |
461 for i in range(4): | |
462 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
463 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
464 | |
465 origStudy = DoGet(_REMOTE, '/studies')[0] | |
466 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
467 '{"Replace":{"PatientName":"Jodogne"}}', | |
468 'application/json')['ID'] | |
469 | |
470 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['ModifiedFrom']) | |
471 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
472 self.assertEqual(2, len(series)) | |
473 for s in series: | |
474 ss = DoGet(_REMOTE, '/series/%s' % s)['ModifiedFrom'] | |
475 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
476 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
477 | |
478 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
479 for i in instances: | |
480 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
481 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
482 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
483 | |
484 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
485 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
486 | |
487 | |
488 def test_anonymize_series(self): | |
489 # Upload 4 images from the same series | |
490 for i in range(4): | |
491 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
492 | |
493 origSeries = DoGet(_REMOTE, '/series')[0] | |
494 newSeries = DoPost(_REMOTE, '/series/%s/anonymize' % origSeries, | |
495 '{}', | |
496 'application/json')['ID'] | |
497 | |
498 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['AnonymizedFrom']) | |
499 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
500 self.assertEqual(4, len(instances)) | |
501 for i in instances: | |
502 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
503 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
504 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
505 | |
506 DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j) | |
507 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i)) | |
508 | |
509 | |
510 def test_anonymize_study(self): | |
511 # Upload 4 images from the 2 series of the same study | |
512 for i in range(4): | |
513 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
514 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
515 | |
516 origStudy = DoGet(_REMOTE, '/studies')[0] | |
517 newStudy = DoPost(_REMOTE,'/studies/%s/anonymize' % origStudy, | |
518 '{"Replace":{"PatientName":"Jodogne"}}', | |
519 'application/json')['ID'] | |
520 | |
521 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['AnonymizedFrom']) | |
522 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
523 self.assertEqual(2, len(series)) | |
524 for s in series: | |
525 ss = DoGet(_REMOTE, '/series/%s' % s)['AnonymizedFrom'] | |
526 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
527 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
528 | |
529 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
530 for i in instances: | |
531 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
532 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
533 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
534 | |
535 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
536 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
11 | 537 |
538 | |
539 | |
540 def test_storescu(self): | |
541 # Check emptiness | |
542 e = DoGet(_REMOTE, '/exports') | |
543 self.assertEqual(0, len(e['Exports'])) | |
544 self.assertEqual(0, e['Last']) | |
545 self.assertTrue(e['Done']) | |
546 e = DoGet(_REMOTE, '/exports?last') | |
547 self.assertEqual(0, len(e['Exports'])) | |
548 self.assertEqual(0, e['Last']) | |
549 self.assertTrue(e['Done']) | |
550 | |
551 # Add 1 instance | |
552 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
553 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
554 | |
555 # Export the instance | |
556 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') # instance | |
557 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
558 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
559 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
560 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
561 | |
562 e = DoGet(_REMOTE, '/exports') | |
563 self.assertEqual(1, len(e['Exports'])) | |
564 self.assertTrue(e['Done']) | |
565 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
566 e = DoGet(_REMOTE, '/exports?limit=1') | |
567 self.assertEqual(1, len(e['Exports'])) | |
568 self.assertTrue(e['Done']) | |
569 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
570 e = DoGet(_REMOTE, '/exports?last') | |
571 self.assertEqual(1, len(e['Exports'])) | |
572 self.assertTrue(e['Done']) | |
573 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
574 seqInstance = e['Last'] | |
575 | |
576 # Export the series | |
577 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', 'text/plain') | |
578 | |
579 e = DoGet(_REMOTE, '/exports') | |
580 self.assertEqual(2, len(e['Exports'])) | |
581 self.assertTrue(e['Done']) | |
582 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
583 seqSeries = e['Last'] | |
584 self.assertNotEqual(seqInstance, seqSeries) | |
585 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
586 self.assertEqual(1, len(e['Exports'])) | |
587 self.assertFalse(e['Done']) | |
588 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
589 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
590 self.assertEqual(1, len(e['Exports'])) | |
591 self.assertTrue(e['Done']) | |
592 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
593 e = DoGet(_REMOTE, '/exports?last') | |
594 self.assertEqual(1, len(e['Exports'])) | |
595 self.assertTrue(e['Done']) | |
596 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
597 | |
598 # Export the study | |
599 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', 'text/plain') | |
600 seqStudy = DoGet(_REMOTE, '/exports')['Last'] | |
601 | |
602 # Export the patient | |
603 j = DoPost(_REMOTE, '/modalities/orthanctest/store', '6816cb19-844d5aee-85245eba-28e841e6-2414fae2', 'text/plain') | |
604 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
605 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
606 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
607 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
608 | |
609 e = DoGet(_REMOTE, '/exports') | |
610 self.assertEqual(4, len(e['Exports'])) | |
611 self.assertTrue(e['Done']) | |
612 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
613 seqPatient = e['Last'] | |
614 self.assertNotEqual(seqInstance, seqSeries) | |
615 self.assertNotEqual(seqSeries, seqStudy) | |
616 self.assertNotEqual(seqStudy, seqPatient) | |
617 self.assertTrue(seqInstance < seqSeries) | |
618 self.assertTrue(seqSeries < seqStudy) | |
619 self.assertTrue(seqStudy < seqPatient) | |
620 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
621 self.assertEqual(1, len(e['Exports'])) | |
622 self.assertFalse(e['Done']) | |
623 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
624 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
625 self.assertEqual(1, len(e['Exports'])) | |
626 self.assertFalse(e['Done']) | |
627 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
628 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqSeries)) | |
629 self.assertEqual(1, len(e['Exports'])) | |
630 self.assertFalse(e['Done']) | |
631 self.assertEqual(e['Exports'][-1]['Seq'], seqStudy) | |
632 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqStudy)) | |
633 self.assertEqual(1, len(e['Exports'])) | |
634 self.assertTrue(e['Done']) | |
635 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
636 e = DoGet(_REMOTE, '/exports?last') | |
637 self.assertEqual(1, len(e['Exports'])) | |
638 self.assertTrue(e['Done']) | |
639 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
640 | |
641 | |
642 # Check the content of the logged information | |
643 e = DoGet(_REMOTE, '/exports')['Exports'] | |
644 | |
645 if 'PatientID' in e[0]: | |
646 # Since Orthanc 0.8.6 | |
647 patient = 'PatientID' | |
648 study = 'StudyInstanceUID' | |
649 series = 'SeriesInstanceUID' | |
650 instance = 'SOPInstanceUID' | |
651 else: | |
652 # Up to Orthanc 0.8.5 | |
653 patient = 'PatientId' | |
654 study = 'StudyInstanceUid' | |
655 series = 'SeriesInstanceUid' | |
656 instance = 'SopInstanceUid' | |
657 | |
658 for k in range(4): | |
659 self.assertTrue('Date' in e[k]) | |
660 self.assertTrue('Seq' in e[k]) | |
661 self.assertEqual('orthanctest', e[k]['RemoteModality']) | |
662 | |
663 self.assertEqual(10, len(e[0])) | |
664 self.assertEqual('Instance', e[0]['ResourceType']) | |
665 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['ID']) | |
666 self.assertEqual('/instances/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['Path']) | |
667 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', e[0][instance]) | |
668 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[0][series]) | |
669 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[0][study]) | |
670 self.assertEqual('ozp00SjY2xG', e[0][patient]) | |
671 | |
672 self.assertEqual(9, len(e[1])) | |
673 self.assertEqual('Series', e[1]['ResourceType']) | |
674 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['ID']) | |
675 self.assertEqual('/series/f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['Path']) | |
676 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[1][series]) | |
677 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[1][study]) | |
678 self.assertEqual('ozp00SjY2xG', e[1][patient]) | |
679 | |
680 self.assertEqual(8, len(e[2])) | |
681 self.assertEqual('Study', e[2]['ResourceType']) | |
682 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['ID']) | |
683 self.assertEqual('/studies/b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['Path']) | |
684 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[2][study]) | |
685 self.assertEqual('ozp00SjY2xG', e[2][patient]) | |
686 | |
687 self.assertEqual(7, len(e[3])) | |
688 self.assertEqual('Patient', e[3]['ResourceType']) | |
689 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['ID']) | |
690 self.assertEqual('/patients/6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['Path']) | |
691 self.assertEqual('ozp00SjY2xG', e[3][patient]) | |
692 | |
693 DropOrthanc(_REMOTE) | |
694 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
695 | |
696 | |
697 def test_store_peer(self): | |
698 self.assertEqual(0, len(DoGet(_LOCAL, '/exports')['Exports'])) | |
699 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
700 | |
701 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
702 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
703 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
704 | |
705 j = DoPost(_REMOTE, '/peers/peer/store', str(i), 'text/plain') | |
706 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
707 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
708 | |
709 self.assertEqual(1, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
710 | |
711 DropOrthanc(_REMOTE) | |
712 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
713 | |
714 | |
715 def test_bulk_storescu(self): | |
716 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
717 | |
718 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
719 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
720 | |
721 j = DoPost(_REMOTE, '/modalities/orthanctest/store', [ a['ID'], b['ID'] ], 'application/json') | |
722 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
723 | |
724 DropOrthanc(_LOCAL) | |
725 | |
726 # Send using patient's UUID | |
727 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
728 j = DoPost(_REMOTE, '/modalities/orthanctest/store', | |
729 [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ], 'application/json') | |
730 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
731 | |
732 | |
733 def test_color(self): | |
734 i = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID'] | |
735 im = GetImage(_REMOTE, '/instances/%s/preview' % i) | |
736 self.assertEqual("RGB", im.mode) | |
737 self.assertEqual(41, im.size[0]) | |
738 self.assertEqual(41, im.size[1]) | |
739 | |
740 # http://effbot.org/zone/pil-comparing-images.htm | |
741 truth = Image.open(os.path.join(os.path.dirname(__file__), '..', 'Database', 'ColorTestMalaterre.png')) | |
742 self.assertTrue(ImageChops.difference(im, truth).getbbox() is None) | |
743 | |
744 | |
12 | 745 def test_faking_ruby_put(self): |
746 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
747 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
748 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
749 a = DoGet(_REMOTE, '/patients')[0] | |
750 b = DoGet(_REMOTE, '/patients')[1] | |
751 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
752 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
753 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
754 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '1') | |
755 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
756 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
757 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
758 | |
759 | |
760 def test_faking_ruby_delete(self): | |
761 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
762 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
763 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
764 a = DoGet(_REMOTE, '/patients')[0] | |
765 b = DoGet(_REMOTE, '/patients')[1] | |
766 DoGet(_REMOTE, '/patients/%s' % a, data = { '_method' : 'DELETE' }) | |
767 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
768 DoGet(_REMOTE, '/patients/%s' % b, data = { '_method' : 'DELETE' }) | |
769 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
770 | |
771 | |
772 def test_faking_google_put(self): | |
773 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
774 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
775 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
776 a = DoGet(_REMOTE, '/patients')[0] | |
777 b = DoGet(_REMOTE, '/patients')[1] | |
778 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
779 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
780 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
781 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '1') | |
782 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
783 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
784 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
785 | |
786 | |
787 def test_faking_google_delete(self): | |
788 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
789 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
790 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
791 a = DoGet(_REMOTE, '/patients')[0] | |
792 b = DoGet(_REMOTE, '/patients')[1] | |
793 DoPost(_REMOTE, '/patients/%s' % a, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
794 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
795 DoPost(_REMOTE, '/patients/%s' % b, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
796 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
797 | |
798 | |
799 def test_lua(self): | |
800 self.assertEqual(42, DoPost(_REMOTE, '/tools/execute-script', 'print(42)')) | |
801 self.assertTrue(IsDefinedInLua(_REMOTE, 'PrintRecursive')) | |
802 self.assertFalse(IsDefinedInLua(_REMOTE, 'HelloWorld')) | |
803 | |
804 | |
805 def test_metadata(self): | |
806 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
807 p = DoGet(_REMOTE, '/patients')[0] | |
808 i = DoGet(_REMOTE, '/instances')[0] | |
809 | |
810 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
811 self.assertEqual(1, len(m)) | |
812 self.assertEqual('LastUpdate', m[0]) | |
813 | |
814 m = DoGet(_REMOTE, '/instances/%s/metadata' % i) | |
815 self.assertEqual(3, len(m)) | |
816 self.assertTrue('IndexInSeries' in m) | |
817 self.assertTrue('ReceptionDate' in m) | |
818 self.assertTrue('RemoteAET' in m) | |
819 | |
820 # Play with custom metadata | |
821 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'coucou') | |
822 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
823 self.assertEqual(2, len(m)) | |
824 self.assertTrue('LastUpdate' in m) | |
825 self.assertTrue('5555' in m) | |
826 self.assertEqual('coucou', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
827 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'hello') | |
828 self.assertEqual('hello', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
829 DoDelete(_REMOTE, '/patients/%s/metadata/5555' % p) | |
830 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
831 self.assertEqual(1, len(m)) | |
832 self.assertTrue('LastUpdate' in m) |