Mercurial > hg > orthanc-tests
annotate Tests/Tests.py @ 11:c660a64ce2dd
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Jun 2015 14:18:49 +0200 |
parents | 5f73008bb873 |
children | 15c166240dfb |
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 | |
382 def test_private_tags(self): | |
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 | |
397 def test_sop_instance_uid(self): | |
398 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') | |
399 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
400 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
401 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
402 | |
403 for i in DoGet(_REMOTE, '/instances'): | |
404 aid = DoGet(_REMOTE, '/instances/%s' % i)['MainDicomTags']['SOPInstanceUID'] | |
405 self.assertEqual(aid, DoGet(_REMOTE, '/instances/%s/content/0008-0018' % i).replace(chr(0), '')) | |
406 | |
407 | |
408 def test_raw_tags_mdn(self): | |
409 # Bug reported by Cyril Paulus | |
410 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
411 self.assertAlmostEqual(0.000027, DoGet(_REMOTE, '/instances/%s/content/7053-1000' % i)) | |
412 | |
413 | |
414 def test_modify_instance(self): | |
415 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] | |
416 modified = DoPost(_REMOTE, '/instances/%s/modify' % i, | |
417 json.dumps({ | |
418 "Replace" : { | |
419 "PatientName" : "hello", | |
420 #"PatientID" : "world" | |
421 }, | |
422 "Remove" : [ "StationName" ], | |
423 "RemovePrivateTags" : None | |
424 }), | |
425 'application/json') | |
426 j = DoPost(_REMOTE, '/instances', modified, 'application/dicom')['ID'] | |
427 | |
428 self.assertNotEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
429 #self.assertNotEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % i).strip()) | |
430 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i).strip()) | |
431 DoGet(_REMOTE, '/instances/%s/content/6003-1010' % i) # Some private tag | |
432 | |
433 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
434 #self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % j).strip()) | |
435 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j)) | |
436 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/6003-1010' % j)) | |
437 | |
438 | |
439 def test_modify_series(self): | |
440 # Upload 4 images from the same series | |
441 for i in range(4): | |
442 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
443 | |
444 origSeries = DoGet(_REMOTE, '/series')[0] | |
445 newSeries = DoPost(_REMOTE, '/series/%s/modify' % origSeries, | |
446 '{"Replace":{"PatientName":"Jodogne"}}', | |
447 'application/json')['ID'] | |
448 | |
449 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['ModifiedFrom']) | |
450 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
451 self.assertEqual(4, len(instances)) | |
452 for i in instances: | |
453 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
454 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
455 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
456 | |
457 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
458 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
459 | |
460 | |
461 def test_modify_study(self): | |
462 # Upload 4 images from the 2 series of the same study | |
463 for i in range(4): | |
464 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
465 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
466 | |
467 origStudy = DoGet(_REMOTE, '/studies')[0] | |
468 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
469 '{"Replace":{"PatientName":"Jodogne"}}', | |
470 'application/json')['ID'] | |
471 | |
472 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['ModifiedFrom']) | |
473 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
474 self.assertEqual(2, len(series)) | |
475 for s in series: | |
476 ss = DoGet(_REMOTE, '/series/%s' % s)['ModifiedFrom'] | |
477 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
478 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
479 | |
480 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
481 for i in instances: | |
482 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
483 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
484 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
485 | |
486 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
487 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
488 | |
489 | |
490 def test_anonymize_series(self): | |
491 # Upload 4 images from the same series | |
492 for i in range(4): | |
493 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
494 | |
495 origSeries = DoGet(_REMOTE, '/series')[0] | |
496 newSeries = DoPost(_REMOTE, '/series/%s/anonymize' % origSeries, | |
497 '{}', | |
498 'application/json')['ID'] | |
499 | |
500 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['AnonymizedFrom']) | |
501 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
502 self.assertEqual(4, len(instances)) | |
503 for i in instances: | |
504 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
505 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
506 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
507 | |
508 DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j) | |
509 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i)) | |
510 | |
511 | |
512 def test_anonymize_study(self): | |
513 # Upload 4 images from the 2 series of the same study | |
514 for i in range(4): | |
515 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
516 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
517 | |
518 origStudy = DoGet(_REMOTE, '/studies')[0] | |
519 newStudy = DoPost(_REMOTE,'/studies/%s/anonymize' % origStudy, | |
520 '{"Replace":{"PatientName":"Jodogne"}}', | |
521 'application/json')['ID'] | |
522 | |
523 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['AnonymizedFrom']) | |
524 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
525 self.assertEqual(2, len(series)) | |
526 for s in series: | |
527 ss = DoGet(_REMOTE, '/series/%s' % s)['AnonymizedFrom'] | |
528 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
529 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
530 | |
531 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
532 for i in instances: | |
533 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
534 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
535 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
536 | |
537 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
538 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
11 | 539 |
540 | |
541 | |
542 def test_storescu(self): | |
543 # Check emptiness | |
544 e = DoGet(_REMOTE, '/exports') | |
545 self.assertEqual(0, len(e['Exports'])) | |
546 self.assertEqual(0, e['Last']) | |
547 self.assertTrue(e['Done']) | |
548 e = DoGet(_REMOTE, '/exports?last') | |
549 self.assertEqual(0, len(e['Exports'])) | |
550 self.assertEqual(0, e['Last']) | |
551 self.assertTrue(e['Done']) | |
552 | |
553 # Add 1 instance | |
554 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
555 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
556 | |
557 # Export the instance | |
558 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') # instance | |
559 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
560 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
561 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
562 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
563 | |
564 e = DoGet(_REMOTE, '/exports') | |
565 self.assertEqual(1, len(e['Exports'])) | |
566 self.assertTrue(e['Done']) | |
567 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
568 e = DoGet(_REMOTE, '/exports?limit=1') | |
569 self.assertEqual(1, len(e['Exports'])) | |
570 self.assertTrue(e['Done']) | |
571 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
572 e = DoGet(_REMOTE, '/exports?last') | |
573 self.assertEqual(1, len(e['Exports'])) | |
574 self.assertTrue(e['Done']) | |
575 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
576 seqInstance = e['Last'] | |
577 | |
578 # Export the series | |
579 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', 'text/plain') | |
580 | |
581 e = DoGet(_REMOTE, '/exports') | |
582 self.assertEqual(2, len(e['Exports'])) | |
583 self.assertTrue(e['Done']) | |
584 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
585 seqSeries = e['Last'] | |
586 self.assertNotEqual(seqInstance, seqSeries) | |
587 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
588 self.assertEqual(1, len(e['Exports'])) | |
589 self.assertFalse(e['Done']) | |
590 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
591 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
592 self.assertEqual(1, len(e['Exports'])) | |
593 self.assertTrue(e['Done']) | |
594 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
595 e = DoGet(_REMOTE, '/exports?last') | |
596 self.assertEqual(1, len(e['Exports'])) | |
597 self.assertTrue(e['Done']) | |
598 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
599 | |
600 # Export the study | |
601 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', 'text/plain') | |
602 seqStudy = DoGet(_REMOTE, '/exports')['Last'] | |
603 | |
604 # Export the patient | |
605 j = DoPost(_REMOTE, '/modalities/orthanctest/store', '6816cb19-844d5aee-85245eba-28e841e6-2414fae2', 'text/plain') | |
606 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
607 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
608 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
609 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
610 | |
611 e = DoGet(_REMOTE, '/exports') | |
612 self.assertEqual(4, len(e['Exports'])) | |
613 self.assertTrue(e['Done']) | |
614 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
615 seqPatient = e['Last'] | |
616 self.assertNotEqual(seqInstance, seqSeries) | |
617 self.assertNotEqual(seqSeries, seqStudy) | |
618 self.assertNotEqual(seqStudy, seqPatient) | |
619 self.assertTrue(seqInstance < seqSeries) | |
620 self.assertTrue(seqSeries < seqStudy) | |
621 self.assertTrue(seqStudy < seqPatient) | |
622 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
623 self.assertEqual(1, len(e['Exports'])) | |
624 self.assertFalse(e['Done']) | |
625 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
626 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
627 self.assertEqual(1, len(e['Exports'])) | |
628 self.assertFalse(e['Done']) | |
629 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
630 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqSeries)) | |
631 self.assertEqual(1, len(e['Exports'])) | |
632 self.assertFalse(e['Done']) | |
633 self.assertEqual(e['Exports'][-1]['Seq'], seqStudy) | |
634 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqStudy)) | |
635 self.assertEqual(1, len(e['Exports'])) | |
636 self.assertTrue(e['Done']) | |
637 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
638 e = DoGet(_REMOTE, '/exports?last') | |
639 self.assertEqual(1, len(e['Exports'])) | |
640 self.assertTrue(e['Done']) | |
641 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
642 | |
643 | |
644 # Check the content of the logged information | |
645 e = DoGet(_REMOTE, '/exports')['Exports'] | |
646 | |
647 if 'PatientID' in e[0]: | |
648 # Since Orthanc 0.8.6 | |
649 patient = 'PatientID' | |
650 study = 'StudyInstanceUID' | |
651 series = 'SeriesInstanceUID' | |
652 instance = 'SOPInstanceUID' | |
653 else: | |
654 # Up to Orthanc 0.8.5 | |
655 patient = 'PatientId' | |
656 study = 'StudyInstanceUid' | |
657 series = 'SeriesInstanceUid' | |
658 instance = 'SopInstanceUid' | |
659 | |
660 for k in range(4): | |
661 self.assertTrue('Date' in e[k]) | |
662 self.assertTrue('Seq' in e[k]) | |
663 self.assertEqual('orthanctest', e[k]['RemoteModality']) | |
664 | |
665 self.assertEqual(10, len(e[0])) | |
666 self.assertEqual('Instance', e[0]['ResourceType']) | |
667 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['ID']) | |
668 self.assertEqual('/instances/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['Path']) | |
669 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', e[0][instance]) | |
670 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[0][series]) | |
671 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[0][study]) | |
672 self.assertEqual('ozp00SjY2xG', e[0][patient]) | |
673 | |
674 self.assertEqual(9, len(e[1])) | |
675 self.assertEqual('Series', e[1]['ResourceType']) | |
676 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['ID']) | |
677 self.assertEqual('/series/f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['Path']) | |
678 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[1][series]) | |
679 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[1][study]) | |
680 self.assertEqual('ozp00SjY2xG', e[1][patient]) | |
681 | |
682 self.assertEqual(8, len(e[2])) | |
683 self.assertEqual('Study', e[2]['ResourceType']) | |
684 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['ID']) | |
685 self.assertEqual('/studies/b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['Path']) | |
686 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[2][study]) | |
687 self.assertEqual('ozp00SjY2xG', e[2][patient]) | |
688 | |
689 self.assertEqual(7, len(e[3])) | |
690 self.assertEqual('Patient', e[3]['ResourceType']) | |
691 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['ID']) | |
692 self.assertEqual('/patients/6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['Path']) | |
693 self.assertEqual('ozp00SjY2xG', e[3][patient]) | |
694 | |
695 DropOrthanc(_REMOTE) | |
696 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
697 | |
698 | |
699 def test_store_peer(self): | |
700 self.assertEqual(0, len(DoGet(_LOCAL, '/exports')['Exports'])) | |
701 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
702 | |
703 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
704 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
705 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
706 | |
707 j = DoPost(_REMOTE, '/peers/peer/store', str(i), 'text/plain') | |
708 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
709 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
710 | |
711 self.assertEqual(1, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
712 | |
713 DropOrthanc(_REMOTE) | |
714 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
715 | |
716 | |
717 def test_bulk_storescu(self): | |
718 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
719 | |
720 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
721 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
722 | |
723 j = DoPost(_REMOTE, '/modalities/orthanctest/store', [ a['ID'], b['ID'] ], 'application/json') | |
724 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
725 | |
726 DropOrthanc(_LOCAL) | |
727 | |
728 # Send using patient's UUID | |
729 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
730 j = DoPost(_REMOTE, '/modalities/orthanctest/store', | |
731 [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ], 'application/json') | |
732 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
733 | |
734 | |
735 def test_color(self): | |
736 i = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID'] | |
737 im = GetImage(_REMOTE, '/instances/%s/preview' % i) | |
738 self.assertEqual("RGB", im.mode) | |
739 self.assertEqual(41, im.size[0]) | |
740 self.assertEqual(41, im.size[1]) | |
741 | |
742 # http://effbot.org/zone/pil-comparing-images.htm | |
743 truth = Image.open(os.path.join(os.path.dirname(__file__), '..', 'Database', 'ColorTestMalaterre.png')) | |
744 self.assertTrue(ImageChops.difference(im, truth).getbbox() is None) | |
745 | |
746 |