Mercurial > hg > orthanc-tests
annotate Tests/Tests.py @ 55:a395fd51cc4f
test_dicom_to_json
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 21 Oct 2015 16:11:43 +0200 |
parents | c5f8a6b0d85e |
children | 1059b8de42de |
rev | line source |
---|---|
22 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 | |
3 | 5 # Orthanc - A Lightweight, RESTful DICOM Store |
6 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
7 # Department, University Hospital of Liege, Belgium | |
8 # | |
9 # This program is free software: you can redistribute it and/or | |
10 # modify it under the terms of the GNU General Public License as | |
11 # published by the Free Software Foundation, either version 3 of the | |
12 # License, or (at your option) any later version. | |
13 # | |
14 # This program is distributed in the hope that it will be useful, but | |
15 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 # General Public License for more details. | |
18 # | |
19 # You should have received a copy of the GNU General Public License | |
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 | |
14 | 23 import tempfile |
3 | 24 import unittest |
36 | 25 import base64 |
3 | 26 |
11 | 27 from PIL import ImageChops |
3 | 28 from Toolbox import * |
13 | 29 from xml.dom import minidom |
3 | 30 |
31 _LOCAL = None | |
32 _REMOTE = None | |
33 | |
34 | |
35 def SetOrthancParameters(local, remote): | |
36 global _LOCAL, _REMOTE | |
37 _LOCAL = local | |
38 _REMOTE = remote | |
39 | |
40 | |
14 | 41 def ExtractDicomTags(rawDicom, tags): |
42 with tempfile.NamedTemporaryFile(delete = True) as f: | |
43 f.write(rawDicom) | |
44 f.flush() | |
45 | 45 data = subprocess.check_output([ FindExecutable('dcm2xml'), f.name ]) |
14 | 46 |
47 result = [] | |
48 for tag in tags: | |
49 match = re.search('<element[^>]+name="%s">([^>]*)</element>' % tag, data) | |
50 if match == None: | |
51 result.append('') | |
52 else: | |
53 result.append(match.group(1)) | |
54 | |
55 return result | |
56 | |
57 | |
15 | 58 def InstallLuaScript(path): |
59 with open(GetDatabasePath(path), 'r') as f: | |
60 DoPost(_REMOTE, '/tools/execute-script', f.read(), 'application/lua') | |
61 | |
62 | |
63 def UninstallLuaCallbacks(): | |
64 DoPost(_REMOTE, '/tools/execute-script', 'function OnStoredInstance() end', 'application/lua') | |
43 | 65 InstallLuaScript('Lua/TransferSyntaxEnable.lua') |
15 | 66 |
67 | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
68 def CompareLists(a, b): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
69 if len(a) != len(b): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
70 return False |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
71 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
72 for i in range(len(a)): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
73 d = a[i] - b[i] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
74 if abs(d) >= 0.51: # Add some tolerance for rounding errors |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
75 return False |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
76 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
77 return True |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
78 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
79 |
54
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
80 def CallMoveScu(args): |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
81 subprocess.check_call([ FindExecutable('movescu'), |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
82 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
83 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
84 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
85 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
86 stderr=subprocess.PIPE) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
87 |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
88 |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
89 |
51
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
90 def GenerateTestSequence(): |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
91 return [ |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
92 { |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
93 'StudyDescription': 'Hello^', |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
94 'ReferencedStudySequence' : [ |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
95 { |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
96 'StudyDescription': 'Toto', |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
97 }, |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
98 { |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
99 'StudyDescription': 'Tata', |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
100 }, |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
101 ] |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
102 }, |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
103 { |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
104 'StudyDescription': 'Sébastien^', |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
105 'StudyDate' : '19700202', |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
106 } |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
107 ] |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
108 |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
109 |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
110 |
15 | 111 |
3 | 112 class Orthanc(unittest.TestCase): |
113 def setUp(self): | |
114 DropOrthanc(_LOCAL) | |
115 DropOrthanc(_REMOTE) | |
26
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
116 UninstallLuaCallbacks() |
45 | 117 #print "In test", self._testMethodName |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
118 |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
119 def AssertSameImages(self, truth, url): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
120 im = GetImage(_REMOTE, url) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
121 self.assertTrue(CompareLists(truth, im.getdata())) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
122 |
3 | 123 |
124 def test_system(self): | |
125 self.assertTrue('Version' in DoGet(_REMOTE, '/system')) | |
126 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
127 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
128 | |
129 def test_upload(self): | |
130 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
131 self.assertEqual('Success', u['Status']) | |
132 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
133 self.assertEqual('AlreadyStored', u['Status']) | |
134 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
135 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
136 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
137 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
138 | |
139 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID']) | |
140 self.assertEqual('20070101', i['StudyDate']) | |
141 | |
142 | |
5 | 143 def test_upload_2(self): |
3 | 144 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] |
145 instance = DoGet(_REMOTE, '/instances/%s' % i) | |
146 self.assertEqual(i, instance['ID']) | |
147 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', | |
148 instance['MainDicomTags']['SOPInstanceUID']) | |
149 | |
150 series = DoGet(_REMOTE, '/series/%s' % instance['ParentSeries']) | |
151 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
152 series['MainDicomTags']['SeriesInstanceUID']) | |
153 | |
154 study = DoGet(_REMOTE, '/studies/%s' % series['ParentStudy']) | |
155 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
156 study['MainDicomTags']['StudyInstanceUID']) | |
157 | |
158 patient = DoGet(_REMOTE, '/patients/%s' % study['ParentPatient']) | |
159 self.assertEqual('ozp00SjY2xG', | |
160 patient['MainDicomTags']['PatientID']) | |
161 | |
162 dicom = DoGet(_REMOTE, '/instances/%s/file' % instance['ID']) | |
163 self.assertEqual(2472, len(dicom)) | |
164 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom)) | |
165 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
166 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/simplified-tags' % i)['StationName']) | |
167 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value']) | |
168 | |
169 | |
5 | 170 def test_images(self): |
171 i = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID'] | |
172 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
3 | 173 |
5 | 174 im = GetImage(_REMOTE, '/instances/%s/preview' % i) |
175 self.assertEqual("L", im.mode) | |
176 self.assertEqual(512, im.size[0]) | |
177 self.assertEqual(358, im.size[1]) | |
178 | |
179 im = GetImage(_REMOTE, '/instances/%s/image-uint8' % i) | |
180 self.assertEqual("L", im.mode) | |
181 self.assertEqual(512, im.size[0]) | |
182 self.assertEqual(358, im.size[1]) | |
183 | |
184 im = GetImage(_REMOTE, '/instances/%s/image-uint16' % i) | |
185 self.assertEqual(512, im.size[0]) | |
186 self.assertEqual(358, im.size[1]) | |
187 | |
188 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
189 self.assertEqual("L", im.mode) | |
190 self.assertEqual(512, im.size[0]) | |
191 self.assertEqual(358, im.size[1]) | |
192 | |
193 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
194 self.assertEqual("L", im.mode) | |
195 self.assertEqual(512, im.size[0]) | |
196 self.assertEqual(358, im.size[1]) | |
197 | |
198 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
199 self.assertEqual(512, im.size[0]) | |
200 self.assertEqual(358, im.size[1]) | |
201 | |
6 | 202 |
203 def test_hierarchy(self): | |
204 UploadFolder(_REMOTE, 'Brainix/Epi') | |
205 UploadFolder(_REMOTE, 'Brainix/Flair') | |
206 UploadFolder(_REMOTE, 'Knee/T1') | |
207 UploadFolder(_REMOTE, 'Knee/T2') | |
208 | |
209 p = DoGet(_REMOTE, '/patients') | |
210 s = DoGet(_REMOTE, '/studies') | |
211 t = DoGet(_REMOTE, '/series') | |
212 self.assertEqual(2, len(p)) | |
213 self.assertEqual(2, len(s)) | |
214 self.assertEqual(4, len(t)) | |
215 self.assertEqual(94, len(DoGet(_REMOTE, '/instances'))) | |
216 | |
217 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0' | |
218 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' | |
219 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8' | |
220 brainixFlair = '1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0' | |
221 | |
222 kneePatient = 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' | |
223 kneeStudy = '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918' | |
224 kneeT1 = '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285' | |
225 kneeT2 = 'bbf7a453-0d34251a-03663b55-46bb31b9-ffd74c59' | |
226 | |
227 self.assertTrue(brainixPatient in p) | |
228 self.assertTrue(kneePatient in p) | |
229 self.assertTrue(brainixStudy in s) | |
230 self.assertTrue(kneeStudy in s) | |
231 self.assertTrue(brainixEpi in t) | |
232 self.assertTrue(brainixFlair in t) | |
233 self.assertTrue(kneeT1 in t) | |
234 self.assertTrue(kneeT2 in t) | |
235 | |
236 self.assertEqual(44, len(DoGet(_REMOTE, '/patients/%s/instances' % brainixPatient))) | |
237 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % brainixPatient))) | |
238 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % brainixPatient))) | |
239 | |
240 self.assertEqual(50, len(DoGet(_REMOTE, '/patients/%s/instances' % kneePatient))) | |
241 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % kneePatient))) | |
242 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % kneePatient))) | |
243 | |
244 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % brainixStudy))) | |
245 self.assertEqual(44, len(DoGet(_REMOTE, '/studies/%s/instances' % brainixStudy))) | |
246 | |
247 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % kneeStudy))) | |
248 self.assertEqual(50, len(DoGet(_REMOTE, '/studies/%s/instances' % kneeStudy))) | |
249 | |
250 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixEpi))) | |
251 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixFlair))) | |
252 self.assertEqual(24, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT1))) | |
253 self.assertEqual(26, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT2))) | |
254 | |
255 for patient in p: | |
256 for study in DoGet(_REMOTE, '/patients/%s/studies' % patient): | |
257 self.assertEqual(patient, study['ParentPatient']) | |
258 for series in DoGet(_REMOTE, '/studies/%s/series' % study['ID']): | |
259 self.assertEqual(study['ID'], series['ParentStudy']) | |
260 for instance in DoGet(_REMOTE, '/series/%s/instances' % series['ID']): | |
261 self.assertEqual(series['ID'], instance['ParentSeries']) | |
262 | |
263 self.assertEqual(json.dumps(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance['ID'])), | |
264 json.dumps(DoGet(_REMOTE, '/instances/%s/tags' % instance['ID']))) | |
265 | |
266 | |
267 r = DoDelete(_REMOTE, "/studies/%s" % brainixStudy)['RemainingAncestor'] | |
268 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
269 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
270 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
271 self.assertEqual(50, len(DoGet(_REMOTE, '/instances'))) | |
272 self.assertEqual(None, r) | |
273 | |
274 r = DoDelete(_REMOTE, "/series/%s" % kneeT2)['RemainingAncestor'] | |
275 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
276 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
277 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
278 self.assertEqual(24, len(DoGet(_REMOTE, '/instances'))) | |
279 self.assertEqual('Study', r['Type']) | |
280 self.assertEqual(kneeStudy, r['ID']) | |
281 | |
282 r = DoDelete(_REMOTE, "/instances/%s" % DoGet(_REMOTE, '/instances')[0])['RemainingAncestor'] | |
283 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
284 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
285 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
286 self.assertEqual(23, len(DoGet(_REMOTE, '/instances'))) | |
287 self.assertEqual('Series', r['Type']) | |
288 self.assertEqual(kneeT1, r['ID']) | |
289 | |
290 r = DoDelete(_REMOTE, "/patients/%s" % kneePatient)['RemainingAncestor'] | |
291 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
292 self.assertEqual(0, len(DoGet(_REMOTE, '/studies'))) | |
293 self.assertEqual(0, len(DoGet(_REMOTE, '/series'))) | |
294 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
295 self.assertEqual(None, r) | |
296 | |
297 DropOrthanc(_REMOTE) | |
298 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
299 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
7 | 300 |
301 | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
302 def test_multiframe(self): |
7 | 303 i = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID'] |
304 self.assertEqual(76, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
305 | |
306 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
307 self.assertEqual("L", im.mode) | |
308 self.assertEqual(512, im.size[0]) | |
309 self.assertEqual(512, im.size[1]) | |
310 | |
311 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
312 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
313 DoGet(_REMOTE, '/instances/%s/frames/75/preview' % i) | |
314 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/aaa/preview' % i)) | |
315 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/76/preview' % i)) | |
316 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
317 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
318 def test_changes(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
319 # Check emptiness |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
320 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
321 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
322 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
323 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
324 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
325 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
326 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
327 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
328 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
329 # Add 1 instance |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
330 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
|
331 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
332 begin = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
333 self.assertEqual(4, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
334 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
335 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
|
336 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
337 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
338 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
339 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
340 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
341 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
|
342 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
343 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
344 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
345 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
|
346 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
347 self.assertEqual(begin - 1, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
348 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
349 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
|
350 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
351 self.assertEqual(begin - 2, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
352 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
353 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
354 UploadFolder(_REMOTE, 'Knee/T1') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
355 UploadFolder(_REMOTE, 'Knee/T2') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
356 since = begin |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
357 countPatients = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
358 countStudies = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
359 countSeries = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
360 countInstances = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
361 completed = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
362 while True: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
363 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
|
364 since = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
365 for i in c['Changes']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
366 if i['ResourceType'] == 'Instance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
367 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
368 if i['ResourceType'] == 'Patient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
369 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
370 if i['ResourceType'] == 'Study': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
371 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
372 if i['ResourceType'] == 'Series': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
373 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
374 if i['ChangeType'] == 'NewInstance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
375 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
376 if i['ChangeType'] == 'NewPatient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
377 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
378 if i['ChangeType'] == 'NewStudy': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
379 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
380 if i['ChangeType'] == 'NewSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
381 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
382 if i['ChangeType'] == 'CompletedSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
383 completed += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
384 self.assertTrue('ID' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
385 self.assertTrue('Path' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
386 self.assertTrue('Seq' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
387 if c['Done']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
388 break |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
389 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
390 self.assertEqual(2 * 50, countInstances) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
391 self.assertEqual(2 * 1, countPatients) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
392 self.assertEqual(2 * 1, countStudies) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
393 self.assertEqual(2 * 2, countSeries) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
394 self.assertEqual(0, completed) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
395 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
396 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
397 def test_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
398 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
|
399 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
|
400 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
401 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
|
402 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
403 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
404 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
|
405 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
406 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
407 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
|
408 self.assertEqual(1, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
409 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
410 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
|
411 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
412 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
|
413 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
414 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
415 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
416 def test_media_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
417 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
|
418 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
|
419 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
420 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
|
421 self.assertEqual(3, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
422 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
|
423 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
|
424 self.assertTrue('DICOMDIR' in z.namelist()) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
425 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
426 try: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
427 os.remove('/tmp/DICOMDIR') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
428 except: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
429 # The file does not exist |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
430 pass |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
431 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
432 z.extract('DICOMDIR', '/tmp') |
45 | 433 a = subprocess.check_output([ FindExecutable('dciodvfy'), '/tmp/DICOMDIR' ], |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
434 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
435 self.assertEqual(3, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
436 self.assertTrue(a[0].startswith('Warning')) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
437 self.assertEqual('BasicDirectory', a[1]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
438 self.assertEqual('', a[2]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
439 |
45 | 440 a = subprocess.check_output([ FindExecutable('dcentvfy'), '/tmp/DICOMDIR' ], |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
441 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
442 self.assertEqual(1, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
443 self.assertEqual('', a[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
444 |
45 | 445 a = subprocess.check_output([ FindExecutable('dcm2xml'), '/tmp/DICOMDIR' ]) |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
446 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
|
447 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
|
448 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
449 os.remove('/tmp/DICOMDIR') |
10 | 450 |
451 | |
452 def test_protection(self): | |
453 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
454 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
455 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
456 a = DoGet(_REMOTE, '/patients')[0] | |
457 b = DoGet(_REMOTE, '/patients')[1] | |
458 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
459 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
460 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
461 DoPut(_REMOTE, '/patients/%s/protected' % a, '1', 'text/plain') | |
462 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
463 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
464 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
465 | |
466 | |
12 | 467 def test_raw_tags(self): |
10 | 468 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] |
469 | |
470 dicom = DoGet(_REMOTE, '/instances/%s/file' % i) | |
471 self.assertEqual('1a7c56cb02d6e742cc9c856a8ac182e3', ComputeMD5(dicom)) | |
472 | |
473 s = '/instances/%s/content/' % i | |
474 | |
475 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, s + '0008-1010').strip()) | |
476 self.assertRaises(Exception, lambda: DoGet(_REMOTE, s + '0008-1011')) | |
477 | |
478 self.assertEqual('Abdomen', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/0/7fe1-1057').strip()) | |
479 self.assertEqual('cla_3c', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/8/7fe1-1057').strip()) | |
480 | |
481 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') | |
482 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
483 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
484 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
485 | |
486 for i in DoGet(_REMOTE, '/instances'): | |
487 aid = DoGet(_REMOTE, '/instances/%s' % i)['MainDicomTags']['SOPInstanceUID'] | |
488 self.assertEqual(aid, DoGet(_REMOTE, '/instances/%s/content/0008-0018' % i).replace(chr(0), '')) | |
489 | |
490 | |
491 def test_raw_tags_mdn(self): | |
492 # Bug reported by Cyril Paulus | |
493 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
494 self.assertAlmostEqual(0.000027, DoGet(_REMOTE, '/instances/%s/content/7053-1000' % i)) | |
495 | |
496 | |
497 def test_modify_instance(self): | |
498 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] | |
499 modified = DoPost(_REMOTE, '/instances/%s/modify' % i, | |
500 json.dumps({ | |
501 "Replace" : { | |
502 "PatientName" : "hello", | |
503 #"PatientID" : "world" | |
504 }, | |
505 "Remove" : [ "StationName" ], | |
506 "RemovePrivateTags" : None | |
507 }), | |
508 'application/json') | |
509 j = DoPost(_REMOTE, '/instances', modified, 'application/dicom')['ID'] | |
510 | |
511 self.assertNotEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
512 #self.assertNotEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % i).strip()) | |
513 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i).strip()) | |
514 DoGet(_REMOTE, '/instances/%s/content/6003-1010' % i) # Some private tag | |
515 | |
516 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
517 #self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % j).strip()) | |
518 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j)) | |
519 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/6003-1010' % j)) | |
520 | |
521 | |
522 def test_modify_series(self): | |
523 # Upload 4 images from the same series | |
524 for i in range(4): | |
525 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
526 | |
527 origSeries = DoGet(_REMOTE, '/series')[0] | |
528 newSeries = DoPost(_REMOTE, '/series/%s/modify' % origSeries, | |
529 '{"Replace":{"PatientName":"Jodogne"}}', | |
530 'application/json')['ID'] | |
531 | |
532 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['ModifiedFrom']) | |
533 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
534 self.assertEqual(4, len(instances)) | |
535 for i in instances: | |
536 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
537 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
538 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
539 | |
540 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
541 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
542 | |
543 | |
544 def test_modify_study(self): | |
545 # Upload 4 images from the 2 series of the same study | |
546 for i in range(4): | |
547 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
548 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
549 | |
550 origStudy = DoGet(_REMOTE, '/studies')[0] | |
551 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
552 '{"Replace":{"PatientName":"Jodogne"}}', | |
553 'application/json')['ID'] | |
554 | |
555 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['ModifiedFrom']) | |
556 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
557 self.assertEqual(2, len(series)) | |
558 for s in series: | |
559 ss = DoGet(_REMOTE, '/series/%s' % s)['ModifiedFrom'] | |
560 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
561 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
562 | |
563 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
564 for i in instances: | |
565 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
566 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
567 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
568 | |
569 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
570 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
571 | |
572 | |
573 def test_anonymize_series(self): | |
574 # Upload 4 images from the same series | |
575 for i in range(4): | |
576 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
577 | |
578 origSeries = DoGet(_REMOTE, '/series')[0] | |
579 newSeries = DoPost(_REMOTE, '/series/%s/anonymize' % origSeries, | |
580 '{}', | |
581 'application/json')['ID'] | |
582 | |
583 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['AnonymizedFrom']) | |
584 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
585 self.assertEqual(4, len(instances)) | |
586 for i in instances: | |
587 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
588 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
589 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
590 | |
591 DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j) | |
592 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i)) | |
593 | |
594 | |
595 def test_anonymize_study(self): | |
596 # Upload 4 images from the 2 series of the same study | |
597 for i in range(4): | |
598 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
599 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
600 | |
601 origStudy = DoGet(_REMOTE, '/studies')[0] | |
602 newStudy = DoPost(_REMOTE,'/studies/%s/anonymize' % origStudy, | |
603 '{"Replace":{"PatientName":"Jodogne"}}', | |
604 'application/json')['ID'] | |
605 | |
606 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['AnonymizedFrom']) | |
607 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
608 self.assertEqual(2, len(series)) | |
609 for s in series: | |
610 ss = DoGet(_REMOTE, '/series/%s' % s)['AnonymizedFrom'] | |
611 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
612 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
613 | |
614 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
615 for i in instances: | |
616 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
617 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
618 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
619 | |
620 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
621 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
11 | 622 |
623 | |
624 | |
625 def test_storescu(self): | |
626 # Check emptiness | |
627 e = DoGet(_REMOTE, '/exports') | |
628 self.assertEqual(0, len(e['Exports'])) | |
629 self.assertEqual(0, e['Last']) | |
630 self.assertTrue(e['Done']) | |
631 e = DoGet(_REMOTE, '/exports?last') | |
632 self.assertEqual(0, len(e['Exports'])) | |
633 self.assertEqual(0, e['Last']) | |
634 self.assertTrue(e['Done']) | |
635 | |
636 # Add 1 instance | |
637 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
638 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
639 | |
640 # Export the instance | |
641 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') # instance | |
642 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
643 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
644 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
645 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
646 | |
647 e = DoGet(_REMOTE, '/exports') | |
648 self.assertEqual(1, len(e['Exports'])) | |
649 self.assertTrue(e['Done']) | |
650 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
651 e = DoGet(_REMOTE, '/exports?limit=1') | |
652 self.assertEqual(1, len(e['Exports'])) | |
653 self.assertTrue(e['Done']) | |
654 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
655 e = DoGet(_REMOTE, '/exports?last') | |
656 self.assertEqual(1, len(e['Exports'])) | |
657 self.assertTrue(e['Done']) | |
658 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
659 seqInstance = e['Last'] | |
660 | |
661 # Export the series | |
662 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', 'text/plain') | |
663 | |
664 e = DoGet(_REMOTE, '/exports') | |
665 self.assertEqual(2, len(e['Exports'])) | |
666 self.assertTrue(e['Done']) | |
667 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
668 seqSeries = e['Last'] | |
669 self.assertNotEqual(seqInstance, seqSeries) | |
670 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
671 self.assertEqual(1, len(e['Exports'])) | |
672 self.assertFalse(e['Done']) | |
673 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
674 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
675 self.assertEqual(1, len(e['Exports'])) | |
676 self.assertTrue(e['Done']) | |
677 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
678 e = DoGet(_REMOTE, '/exports?last') | |
679 self.assertEqual(1, len(e['Exports'])) | |
680 self.assertTrue(e['Done']) | |
681 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
682 | |
683 # Export the study | |
684 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', 'text/plain') | |
685 seqStudy = DoGet(_REMOTE, '/exports')['Last'] | |
686 | |
687 # Export the patient | |
688 j = DoPost(_REMOTE, '/modalities/orthanctest/store', '6816cb19-844d5aee-85245eba-28e841e6-2414fae2', 'text/plain') | |
689 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
690 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
691 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
692 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
693 | |
694 e = DoGet(_REMOTE, '/exports') | |
695 self.assertEqual(4, len(e['Exports'])) | |
696 self.assertTrue(e['Done']) | |
697 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
698 seqPatient = e['Last'] | |
699 self.assertNotEqual(seqInstance, seqSeries) | |
700 self.assertNotEqual(seqSeries, seqStudy) | |
701 self.assertNotEqual(seqStudy, seqPatient) | |
702 self.assertTrue(seqInstance < seqSeries) | |
703 self.assertTrue(seqSeries < seqStudy) | |
704 self.assertTrue(seqStudy < seqPatient) | |
705 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
706 self.assertEqual(1, len(e['Exports'])) | |
707 self.assertFalse(e['Done']) | |
708 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
709 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
710 self.assertEqual(1, len(e['Exports'])) | |
711 self.assertFalse(e['Done']) | |
712 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
713 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqSeries)) | |
714 self.assertEqual(1, len(e['Exports'])) | |
715 self.assertFalse(e['Done']) | |
716 self.assertEqual(e['Exports'][-1]['Seq'], seqStudy) | |
717 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqStudy)) | |
718 self.assertEqual(1, len(e['Exports'])) | |
719 self.assertTrue(e['Done']) | |
720 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
721 e = DoGet(_REMOTE, '/exports?last') | |
722 self.assertEqual(1, len(e['Exports'])) | |
723 self.assertTrue(e['Done']) | |
724 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
725 | |
726 | |
727 # Check the content of the logged information | |
728 e = DoGet(_REMOTE, '/exports')['Exports'] | |
729 | |
730 if 'PatientID' in e[0]: | |
731 # Since Orthanc 0.8.6 | |
732 patient = 'PatientID' | |
733 study = 'StudyInstanceUID' | |
734 series = 'SeriesInstanceUID' | |
735 instance = 'SOPInstanceUID' | |
736 else: | |
737 # Up to Orthanc 0.8.5 | |
738 patient = 'PatientId' | |
739 study = 'StudyInstanceUid' | |
740 series = 'SeriesInstanceUid' | |
741 instance = 'SopInstanceUid' | |
742 | |
743 for k in range(4): | |
744 self.assertTrue('Date' in e[k]) | |
745 self.assertTrue('Seq' in e[k]) | |
746 self.assertEqual('orthanctest', e[k]['RemoteModality']) | |
747 | |
748 self.assertEqual(10, len(e[0])) | |
749 self.assertEqual('Instance', e[0]['ResourceType']) | |
750 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['ID']) | |
751 self.assertEqual('/instances/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['Path']) | |
752 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', e[0][instance]) | |
753 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[0][series]) | |
754 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[0][study]) | |
755 self.assertEqual('ozp00SjY2xG', e[0][patient]) | |
756 | |
757 self.assertEqual(9, len(e[1])) | |
758 self.assertEqual('Series', e[1]['ResourceType']) | |
759 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['ID']) | |
760 self.assertEqual('/series/f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['Path']) | |
761 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[1][series]) | |
762 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[1][study]) | |
763 self.assertEqual('ozp00SjY2xG', e[1][patient]) | |
764 | |
765 self.assertEqual(8, len(e[2])) | |
766 self.assertEqual('Study', e[2]['ResourceType']) | |
767 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['ID']) | |
768 self.assertEqual('/studies/b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['Path']) | |
769 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[2][study]) | |
770 self.assertEqual('ozp00SjY2xG', e[2][patient]) | |
771 | |
772 self.assertEqual(7, len(e[3])) | |
773 self.assertEqual('Patient', e[3]['ResourceType']) | |
774 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['ID']) | |
775 self.assertEqual('/patients/6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['Path']) | |
776 self.assertEqual('ozp00SjY2xG', e[3][patient]) | |
777 | |
778 DropOrthanc(_REMOTE) | |
779 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
780 | |
781 | |
782 def test_store_peer(self): | |
783 self.assertEqual(0, len(DoGet(_LOCAL, '/exports')['Exports'])) | |
784 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
785 | |
786 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
787 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
788 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
789 | |
790 j = DoPost(_REMOTE, '/peers/peer/store', str(i), 'text/plain') | |
791 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
792 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
793 | |
794 self.assertEqual(1, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
795 | |
796 DropOrthanc(_REMOTE) | |
797 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
798 | |
799 | |
800 def test_bulk_storescu(self): | |
801 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
802 | |
803 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
804 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
805 | |
806 j = DoPost(_REMOTE, '/modalities/orthanctest/store', [ a['ID'], b['ID'] ], 'application/json') | |
807 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
808 | |
809 DropOrthanc(_LOCAL) | |
810 | |
811 # Send using patient's UUID | |
812 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
813 j = DoPost(_REMOTE, '/modalities/orthanctest/store', | |
814 [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ], 'application/json') | |
815 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
816 | |
817 | |
818 def test_color(self): | |
819 i = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID'] | |
820 im = GetImage(_REMOTE, '/instances/%s/preview' % i) | |
821 self.assertEqual("RGB", im.mode) | |
822 self.assertEqual(41, im.size[0]) | |
823 self.assertEqual(41, im.size[1]) | |
824 | |
825 # http://effbot.org/zone/pil-comparing-images.htm | |
13 | 826 truth = Image.open(GetDatabasePath('ColorTestMalaterre.png')) |
11 | 827 self.assertTrue(ImageChops.difference(im, truth).getbbox() is None) |
828 | |
829 | |
12 | 830 def test_faking_ruby_put(self): |
831 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
832 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
833 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
834 a = DoGet(_REMOTE, '/patients')[0] | |
835 b = DoGet(_REMOTE, '/patients')[1] | |
836 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
837 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
838 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
839 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '1') | |
840 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
841 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
842 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
843 | |
844 | |
845 def test_faking_ruby_delete(self): | |
846 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
847 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
848 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
849 a = DoGet(_REMOTE, '/patients')[0] | |
850 b = DoGet(_REMOTE, '/patients')[1] | |
851 DoGet(_REMOTE, '/patients/%s' % a, data = { '_method' : 'DELETE' }) | |
852 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
853 DoGet(_REMOTE, '/patients/%s' % b, data = { '_method' : 'DELETE' }) | |
854 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
855 | |
856 | |
857 def test_faking_google_put(self): | |
858 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
859 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
860 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
861 a = DoGet(_REMOTE, '/patients')[0] | |
862 b = DoGet(_REMOTE, '/patients')[1] | |
863 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
864 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
865 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
866 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '1') | |
867 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
868 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
869 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
870 | |
871 | |
872 def test_faking_google_delete(self): | |
873 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
874 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
875 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
876 a = DoGet(_REMOTE, '/patients')[0] | |
877 b = DoGet(_REMOTE, '/patients')[1] | |
878 DoPost(_REMOTE, '/patients/%s' % a, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
879 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
880 DoPost(_REMOTE, '/patients/%s' % b, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
881 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
882 | |
883 | |
884 def test_lua(self): | |
885 self.assertEqual(42, DoPost(_REMOTE, '/tools/execute-script', 'print(42)')) | |
886 self.assertTrue(IsDefinedInLua(_REMOTE, 'PrintRecursive')) | |
887 self.assertFalse(IsDefinedInLua(_REMOTE, 'HelloWorld')) | |
888 | |
889 | |
890 def test_metadata(self): | |
891 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
892 p = DoGet(_REMOTE, '/patients')[0] | |
893 i = DoGet(_REMOTE, '/instances')[0] | |
894 | |
895 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
896 self.assertEqual(1, len(m)) | |
897 self.assertEqual('LastUpdate', m[0]) | |
898 | |
899 m = DoGet(_REMOTE, '/instances/%s/metadata' % i) | |
900 self.assertEqual(3, len(m)) | |
901 self.assertTrue('IndexInSeries' in m) | |
902 self.assertTrue('ReceptionDate' in m) | |
903 self.assertTrue('RemoteAET' in m) | |
904 | |
905 # Play with custom metadata | |
906 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'coucou') | |
907 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
908 self.assertEqual(2, len(m)) | |
909 self.assertTrue('LastUpdate' in m) | |
910 self.assertTrue('5555' in m) | |
911 self.assertEqual('coucou', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
912 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'hello') | |
913 self.assertEqual('hello', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
914 DoDelete(_REMOTE, '/patients/%s/metadata/5555' % p) | |
915 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
916 self.assertEqual(1, len(m)) | |
917 self.assertTrue('LastUpdate' in m) | |
13 | 918 |
919 | |
920 def test_statistics(self): | |
921 # Upload 16 instances | |
922 for i in range(4): | |
923 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
924 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
925 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
926 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
927 | |
928 s = DoGet(_REMOTE, '/statistics') | |
929 self.assertEqual(16, s['CountInstances']) | |
930 self.assertEqual(2, s['CountPatients']) | |
931 self.assertEqual(2, s['CountStudies']) | |
932 self.assertEqual(4, s['CountSeries']) | |
933 d = int(s['TotalUncompressedSize']) | |
934 | |
935 e = 0 | |
936 for patient in DoGet(_REMOTE, '/patients'): | |
937 s = DoGet(_REMOTE, '/patients/%s/statistics' % patient) | |
938 self.assertEqual(8, s['CountInstances']) | |
939 self.assertEqual(1, s['CountStudies']) | |
940 self.assertEqual(2, s['CountSeries']) | |
941 e += int(s['UncompressedSize']) | |
942 | |
943 for study in DoGet(_REMOTE, '/studies'): | |
944 s = DoGet(_REMOTE, '/studies/%s/statistics' % study) | |
945 self.assertEqual(8, s['CountInstances']) | |
946 self.assertEqual(2, s['CountSeries']) | |
947 e += int(s['UncompressedSize']) | |
948 | |
949 for series in DoGet(_REMOTE, '/series'): | |
950 s = DoGet(_REMOTE, '/series/%s/statistics' % series) | |
951 self.assertEqual(4, s['CountInstances']) | |
952 e += int(s['UncompressedSize']) | |
953 | |
954 self.assertEqual(3 * d, e) | |
955 | |
956 | |
957 def test_custom_attachment(self): | |
958 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
959 patient = DoGet(_REMOTE, '/patients')[0] | |
960 instance = DoGet(_REMOTE, '/instances')[0] | |
961 size = int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']) | |
962 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
963 | |
964 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
965 self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % instance))) | |
966 self.assertTrue('dicom' in DoGet(_REMOTE, '/instances/%s/attachments' % instance)) | |
967 self.assertTrue('dicom-as-json' in DoGet(_REMOTE, '/instances/%s/attachments' % instance)) | |
968 | |
969 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/patients/%s/attachments/22' % patient, 'hello')) | |
970 hello = 'hellohellohellohellohellohellohellohellohello' | |
971 DoPut(_REMOTE, '/patients/%s/attachments/1025' % patient, hello) | |
972 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
973 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
974 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
975 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1025/compressed-size' % patient))) | |
976 | |
977 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world') | |
978 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
979 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
980 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
981 size + | |
982 int(DoGet(_REMOTE, '/patients/%s/attachments/1025/compressed-size' % patient)) + | |
983 int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient))) | |
984 | |
985 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
986 self.assertEqual(hello, DoGet(_REMOTE, '/patients/%s/attachments/1025/data' % patient)) | |
987 self.assertEqual('world', DoGet(_REMOTE, '/patients/%s/attachments/1026/data' % patient)) | |
988 DoPost(_REMOTE, '/patients/%s/attachments/1025/verify-md5' % patient) | |
989 DoPost(_REMOTE, '/patients/%s/attachments/1026/verify-md5' % patient) | |
990 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world2') | |
991 self.assertEqual('world2', DoGet(_REMOTE, '/patients/%s/attachments/1026/data' % patient)) | |
992 | |
993 self.assertRaises(Exception, lambda: DoDelete(_REMOTE, '/instances/%s/attachments/dicom' % instance)) | |
994 DoDelete(_REMOTE, '/patients/%s/attachments/1025' % patient) | |
995 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
996 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
997 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
998 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient))) | |
999 | |
1000 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
1001 DoDelete(_REMOTE, '/patients/%s/attachments/1026' % patient) | |
1002 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
1003 | |
1004 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), size) | |
1005 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
1006 | |
1007 | |
1008 def test_incoming_storescu(self): | |
1009 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
45 | 1010 subprocess.check_call([ FindExecutable('storescu'), |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
1011 _REMOTE['Server'], str(_REMOTE['DicomPort']), |
13 | 1012 GetDatabasePath('ColorTestImageJ.dcm') ]) |
1013 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
1014 | |
1015 | |
1016 def test_incoming_findscu(self): | |
1017 def CallFindScu(args): | |
45 | 1018 p = subprocess.Popen([ FindExecutable('findscu'), |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
1019 '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'], |
13 | 1020 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, |
1021 stderr=subprocess.PIPE) | |
1022 return p.communicate()[1] | |
1023 | |
1024 UploadInstance(_REMOTE, 'Multiframe.dcm') | |
1025 UploadInstance(_REMOTE, 'ColorTestImageJ.dcm') | |
1026 | |
1027 i = CallFindScu([ '-k', '0008,0052=PATIENT', '-k', '0010,0010' ]) | |
1028 patientNames = re.findall('\(0010,0010\).*?\[(.*?)\]', i) | |
1029 self.assertEqual(2, len(patientNames)) | |
1030 self.assertTrue('Test Patient BG ' in patientNames) | |
1031 self.assertTrue('Anonymized' in patientNames) | |
1032 | |
1033 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', '0008,0021' ]) | |
1034 series = re.findall('\(0008,0021\).*?\[\s*(.*?)\s*\]', i) | |
1035 self.assertEqual(2, len(series)) | |
1036 self.assertTrue('20070208' in series) | |
1037 self.assertTrue('19980312' in series) | |
1038 | |
1039 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', 'PatientName=Anonymized' ]) | |
1040 series = re.findall('\(0010,0010\).*?\[\s*(.*?)\s*\]', i) | |
1041 self.assertEqual(1, len(series)) | |
1042 | |
1043 # Test the "CaseSentitivePN" flag (false by default) | |
1044 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', 'PatientName=anonymized' ]) | |
1045 series = re.findall('\(0010,0010\).*?\[\s*(.*?)\s*\]', i) | |
1046 self.assertEqual(1, len(series)) | |
1047 | |
1048 | |
1049 def test_incoming_movescu(self): | |
1050 UploadInstance(_REMOTE, 'Multiframe.dcm') | |
1051 | |
1052 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
17 | 1053 CallMoveScu([ '--patient', '-k', '0008,0052=PATIENT', '-k', 'PatientID=none' ]) |
13 | 1054 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
1055 CallMoveScu([ '--patient', '-k', '0008,0052=PATIENT', '-k', 'PatientID=12345678' ]) | |
1056 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
1057 | |
1058 | |
1059 def test_findscu(self): | |
1060 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1061 j = UploadInstance(_REMOTE, 'Issue22.dcm')['ID'] | |
1062 k = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID'] | |
1063 DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1064 | |
1065 # Test the "find-patient" level | |
1066 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }) | |
1067 self.assertEqual(1, len(p)) | |
1068 self.assertEqual('ozp00SjY2xG', p[0]['PatientID']) | |
1069 | |
1070 # Test wildcards constraints. The "LO" value representation | |
1071 # for PatientID is always case-sensitive, but the "PN" for | |
1072 # PatientName might depend on the implementation: | |
1073 # "GenerateConfigurationForTests.py" will force it to be case | |
1074 # insensitive (which was the default until Orthanc 0.8.6). | |
1075 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'K*' }) | |
1076 self.assertEqual(1, len(p)) | |
1077 | |
1078 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'k*' }) | |
1079 self.assertEqual(1, len(p)) | |
1080 | |
1081 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : 'ozp*' }) | |
1082 self.assertEqual(1, len(p)) | |
1083 | |
1084 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : 'o?p*' }) | |
1085 self.assertEqual(1, len(p)) | |
1086 | |
1087 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : '0?q*' }) | |
1088 self.assertEqual(0, len(p)) | |
1089 | |
1090 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'B*' }) | |
1091 self.assertEqual(0, len(p)) | |
1092 | |
1093 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'b*' }) | |
1094 self.assertEqual(0, len(p)) | |
1095 | |
1096 DoPost(_REMOTE, '/modalities/orthanctest/store', str(j), 'text/plain') | |
1097 DoPost(_REMOTE, '/modalities/orthanctest/store', str(k), 'text/plain') | |
1098 DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }) | |
1099 self.assertEqual(3, len(DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }))) | |
1100 | |
1101 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'A*' }) | |
1102 self.assertEqual(2, len(p)) | |
1103 | |
1104 # Test the "find-study" level. This is the instance "ColorTestImageJ.dcm" | |
1105 s = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ' }) | |
1106 self.assertEqual(1, len(s)) | |
1107 self.assertEqual('20070208', s[0]['StudyDate']) | |
1108 | |
1109 # Test range searches | |
1110 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1111 'StudyDate' : '-20070101' }) | |
1112 self.assertEqual(0, len(t)) | |
1113 | |
1114 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1115 'StudyDate' : '20090101-' }) | |
1116 self.assertEqual(0, len(t)) | |
1117 | |
1118 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1119 'StudyDate' : '20070101-' }) | |
1120 self.assertEqual(1, len(t)) | |
1121 | |
1122 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1123 'StudyDate' : '-20090101' }) | |
1124 self.assertEqual(1, len(t)) | |
1125 | |
1126 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1127 'StudyDate' : '20070207-20070207' }) | |
1128 self.assertEqual(0, len(t)) | |
1129 | |
1130 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1131 'StudyDate' : '20070208-20070208' }) | |
1132 self.assertEqual(1, len(t)) | |
1133 | |
1134 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1135 'StudyDate' : '20070209-20070209' }) | |
1136 self.assertEqual(0, len(t)) | |
1137 | |
1138 # Test the ModalitiesInStudy tag | |
1139 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1140 'PatientID' : 'B9uTHKOZ', | |
1141 'ModalitiesInStudy' : 'US' }) | |
1142 self.assertEqual(0, len(t)) | |
1143 | |
1144 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1145 'PatientID' : 'B9uTHKOZ', | |
1146 'ModalitiesInStudy' : 'CT' }) | |
1147 self.assertEqual(1, len(t)) | |
1148 | |
1149 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1150 'PatientID' : 'B9uTHKOZ', | |
1151 'ModalitiesInStudy' : 'US\\CT' }) | |
1152 self.assertEqual(1, len(t)) | |
1153 | |
1154 # Test the "find-series" level | |
1155 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1156 'PatientID' : 'B9uTHKOZ', | |
1157 'StudyInstanceUID' : s[0]['StudyInstanceUID'] }) | |
1158 self.assertEqual(1, len(t)) | |
1159 | |
1160 # Test "\" separator | |
1161 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1162 'PatientID' : 'B9uTHKOZ', | |
1163 'StudyInstanceUID' : s[0]['StudyInstanceUID'], | |
1164 'Modality' : 'MR\\CT\\US' }) | |
1165 self.assertEqual(1, len(t)) | |
1166 | |
1167 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1168 'PatientID' : 'B9uTHKOZ', | |
1169 'StudyInstanceUID' : s[0]['StudyInstanceUID'], | |
1170 'Modality' : 'MR\\US' }) | |
1171 self.assertEqual(0, len(t)) | |
1172 | |
1173 | |
1174 def test_update_modalities(self): | |
1175 try: | |
1176 DoDelete(_REMOTE, '/modalities/toto') | |
1177 except: | |
1178 pass | |
1179 try: | |
1180 DoDelete(_REMOTE, '/modalities/tata') | |
1181 except: | |
1182 pass | |
1183 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/toto')) | |
1184 DoPut(_REMOTE, '/modalities/toto', [ "STORESCP", "localhost", 2000 ]) | |
1185 DoPut(_REMOTE, '/modalities/tata', [ "STORESCP", "localhost", 2000, 'MedInria' ]) | |
1186 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/modalities/toto', [ "STORESCP", "localhost", 2000, 'MedInriaaa' ])) | |
1187 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/toto')) | |
1188 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/tata')) | |
1189 DoDelete(_REMOTE, '/modalities/toto') | |
1190 DoDelete(_REMOTE, '/modalities/tata') | |
1191 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/toto')) | |
1192 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/tata')) | |
1193 | |
1194 | |
1195 def test_update_peers(self): | |
1196 # curl -X PUT http://localhost:8042/peers/toto -d '["http://localhost:8042/"]' -v | |
1197 try: | |
1198 DoDelete(_REMOTE, '/peers/toto') | |
1199 except: | |
1200 pass | |
1201 try: | |
1202 DoDelete(_REMOTE, '/peers/tata') | |
1203 except: | |
1204 pass | |
1205 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/toto')) | |
1206 DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/' ]) | |
1207 DoPut(_REMOTE, '/peers/tata', [ 'http://localhost:8042/', 'user', 'pass' ]) | |
1208 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/', 'a' ])) | |
1209 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/', 'a', 'b', 'c' ])) | |
1210 self.assertTrue('store' in DoGet(_REMOTE, '/peers/toto')) | |
1211 self.assertTrue('store' in DoGet(_REMOTE, '/peers/tata')) | |
1212 DoDelete(_REMOTE, '/peers/toto') | |
1213 DoDelete(_REMOTE, '/peers/tata') | |
1214 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/toto')) | |
1215 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/tata')) | |
1216 | |
1217 | |
1218 def test_mesterhazy_modification(self): | |
1219 # When I modify a series ( eg. curl | |
1220 # http://localhost:8042/series/uidhere/modify -X POST -d | |
1221 # '{"Replace":{"SeriesDate":"19990101"}}' ) the modified | |
1222 # series is added to a new Study, instead of the existing | |
1223 # Study. Fixed in Orthanc 0.7.5 | |
1224 | |
1225 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
1226 study = 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0' | |
1227 series = 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe' | |
1228 | |
1229 modified = DoPost(_REMOTE, '/series/%s/modify' % series, | |
1230 json.dumps({ "Replace" : { "SeriesDate" : "19990101" }})) | |
1231 | |
1232 self.assertEqual(study, DoGet(_REMOTE, '/series/%s' % modified['ID']) ['ParentStudy']) | |
1233 | |
1234 | |
1235 def test_create(self): | |
1236 i = DoPost(_REMOTE, '/tools/create-dicom', | |
1237 json.dumps({ | |
1238 'PatientName' : 'Jodogne', | |
1239 'Modality' : 'CT', | |
1240 'PixelData' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' # red dot in RGBA | |
1241 })) | |
1242 | |
1243 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i['ID']).strip()) | |
1244 self.assertEqual('CT', DoGet(_REMOTE, '/instances/%s/content/Modality' % i['ID']).strip()) | |
1245 | |
1246 png = GetImage(_REMOTE, '/instances/%s/preview' % i['ID']) | |
1247 self.assertEqual((5, 5), png.size) | |
1248 | |
38 | 1249 j = DoGet(_REMOTE, i['Path']) |
1250 self.assertEqual('Instance', j['Type']) | |
1251 self.assertEqual(j['ID'], i['ID']) | |
1252 | |
13 | 1253 |
1254 def test_pilates(self): | |
1255 # "SCU failed error when accessing orthanc with osirix" by | |
1256 # Pilates Agentur (Mar 10, 2014 at 9:33 PM) | |
1257 i = UploadInstance(_REMOTE, 'PilatesArgenturGEUltrasoundOsiriX.dcm')['ID'] | |
1258 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
1259 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1260 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
1261 | |
1262 | |
1263 def test_shared_tags(self): | |
1264 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1265 b = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0002.dcm')['ID'] | |
1266 p = DoGet(_REMOTE, '/patients')[0] | |
1267 | |
1268 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1269 self.assertTrue('PatientName' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1270 self.assertTrue('0008,1030' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1271 self.assertTrue('StudyDescription' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1272 self.assertTrue('0008,103e' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1273 self.assertTrue('SeriesDescription' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1274 self.assertFalse('0008,0018' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1275 self.assertFalse('SOPInstanceUID' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1276 | |
1277 self.assertTrue('0008,0018' in DoGet(_REMOTE, '/instances/%s/tags' % a)) | |
1278 self.assertTrue('SOPInstanceUID' in DoGet(_REMOTE, '/instances/%s/tags?simplify' % a)) | |
1279 | |
1280 | |
1281 def test_modules(self): | |
1282 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1283 p = DoGet(_REMOTE, '/patients')[0] | |
1284 s = DoGet(_REMOTE, '/studies')[0] | |
1285 t = DoGet(_REMOTE, '/series')[0] | |
1286 | |
1287 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/patients/%s/module' % p)) | |
1288 self.assertTrue('PatientName' in DoGet(_REMOTE, '/patients/%s/module?simplify' % p)) | |
1289 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/studies/%s/module-patient' % p)) | |
1290 self.assertTrue('PatientName' in DoGet(_REMOTE, '/studies/%s/module-patient?simplify' % p)) | |
1291 self.assertTrue('0008,1030' in DoGet(_REMOTE, '/studies/%s/module' % s)) | |
1292 self.assertTrue('StudyDescription' in DoGet(_REMOTE, '/studies/%s/module?simplify' % s)) | |
1293 self.assertTrue('0008,103e' in DoGet(_REMOTE, '/series/%s/module' % p)) | |
1294 self.assertTrue('SeriesDescription' in DoGet(_REMOTE, '/series/%s/module?simplify' % p)) | |
1295 self.assertTrue('0008,0018' in DoGet(_REMOTE, '/instances/%s/module' % a)) | |
1296 self.assertTrue('SOPInstanceUID' in DoGet(_REMOTE, '/instances/%s/module?simplify' % a)) | |
1297 | |
1298 | |
1299 def test_auto_directory(self): | |
1300 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1301 self.assertTrue('now' in DoGet(_REMOTE, '/tools')) | |
1302 self.assertTrue('dicom-conformance' in DoGet(_REMOTE, '/tools')) | |
1303 self.assertTrue(len(DoGet(_REMOTE, '/tools/dicom-conformance')) > 1000) | |
1304 self.assertTrue('orthanctest' in DoGet(_REMOTE, '/modalities')) | |
1305 self.assertTrue('echo' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1306 self.assertTrue('find' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1307 self.assertTrue('find-instance' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1308 self.assertTrue('find-patient' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1309 self.assertTrue('find-series' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1310 self.assertTrue('find-study' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1311 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1312 self.assertTrue('store' in DoGet(_REMOTE, '/peers/peer')) | |
1313 self.assertTrue('matlab' in DoGet(_REMOTE, '/instances/%s/frames/0' % a)) | |
1314 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/tools/nope')) | |
28 | 1315 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/nope')) |
1316 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/nope/nope.html')) | |
1317 self.assertEqual(404, DoGetRaw(_REMOTE, '/nope')[0].status) | |
1318 self.assertEqual(404, DoGetRaw(_REMOTE, '/nope/nope.html')[0].status) | |
13 | 1319 |
1320 | |
1321 def test_echo(self): | |
1322 DoPost(_REMOTE, '/modalities/orthanctest/echo') | |
1323 | |
1324 | |
1325 def test_xml(self): | |
1326 json = DoGet(_REMOTE, '/tools', headers = { 'accept' : 'application/json' }) | |
1327 xml = minidom.parseString(DoGet(_REMOTE, '/tools', headers = { 'accept' : 'application/xml' })) | |
1328 items = xml.getElementsByTagName('root')[0].getElementsByTagName('item') | |
1329 self.assertEqual(len(items), len(json)) | |
1330 | |
1331 self.assertTrue('dicom-conformance' in json) | |
1332 | |
1333 ok = False | |
1334 for i in items: | |
1335 if i.childNodes[0].data == 'dicom-conformance': | |
1336 ok = True | |
1337 self.assertTrue(ok) | |
1338 | |
1339 | |
46
85b2e36ed392
explicit GoogleCode source
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
1340 def test_googlecode_issue_16(self): |
13 | 1341 i = UploadInstance(_REMOTE, 'Issue16.dcm')['ID'] |
1342 t = DoGet(_REMOTE, '/instances/%s/tags?simplify' % i)['FrameIncrementPointer'] | |
1343 self.assertEqual('0018,1063', t) | |
1344 | |
1345 | |
46
85b2e36ed392
explicit GoogleCode source
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
1346 def test_googlecode_issue_22(self): |
13 | 1347 s = UploadInstance(_REMOTE, 'Issue22.dcm')['ID'] |
1348 a = [ | |
1349 "f804691f62197040438f4627c6b994f1", # Frame 0 | |
1350 "c69eee9a51eea3e8611e82e578897254", | |
1351 "315666be83e2d0111c77bc0996d84901", | |
1352 "3e27aa959d911172c48a1436443c72b1", | |
1353 "958642c9e7e9d232d3869faff546058c", | |
1354 "5e7ea8e3e4230cae707d143481355c59", | |
1355 "eda37f83558d858a596175aed8b2ad47", | |
1356 "486713bd2895c4ecbe0e97715ac7f80a", | |
1357 "091ef729eb169e67da8a0faa9631f9a8", | |
1358 "5aa2b8c7ffe0a483efaa8e12417686ca", | |
1359 "e2f39e85896fe58876654b94cd0b5013", | |
1360 "6fd2129e4950abbe1be053bc814d5da8", | |
1361 "c3331a8ba7a757f3d423735ab7fa81f9", | |
1362 "746f808582156734dd6b6fdfd3a0b72c", | |
1363 "8075ea2b227a70c60ea6b7b75a6bb190", | |
1364 "806b8b3e300c615099c11a5ec23465aa", | |
1365 "7c836aa298ba6eef96434579af631a11", | |
1366 "a0357dc9f4f72d73a885c33d7c287446", | |
1367 "f25ba3be1cc7d7fad95706adc199ea7d", | |
1368 "8b114c526b8cbed6cad8a3248b7b480c", | |
1369 "44e6670f127e612a2b4aa60a0d207698", | |
1370 "b8945f90fe02facf2ace24ca1ecbe0a5", | |
1371 "95c796c2fa8f59018b15cf2987b1f79b", | |
1372 "ce0a51ab30224205b44920221dc27351", # Frame 23 | |
1373 ] | |
1374 | |
1375 self.assertEqual(24, len(DoGet(_REMOTE, '/instances/%s/frames' % s))) | |
1376 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/24/preview' % s)) | |
1377 | |
1378 for i in range(len(a)): | |
1379 self.assertEqual(a[i], ComputeMD5(DoGet(_REMOTE, '/instances/%s/frames/%d/preview' % (s, i)))) | |
1380 | |
1381 | |
46
85b2e36ed392
explicit GoogleCode source
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
1382 def test_googlecode_issue_19(self): |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1383 # This is an image with "YBR_FULL" photometric interpretation, it is not supported by Orthanc |
13 | 1384 # gdcmconv -i /home/jodogne/DICOM/GdcmDatabase/US_DataSet/HDI5000_US/3EAF5E01 -w -o Issue19.dcm |
1385 | |
1386 a = UploadInstance(_REMOTE, 'Issue19.dcm')['ID'] | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1387 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/941ad3c8-05d05b88-560459f9-0eae0e20-6cddd533/preview')) |
13 | 1388 |
1389 | |
46
85b2e36ed392
explicit GoogleCode source
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
1390 def test_googlecode_issue_37(self): |
13 | 1391 # Same test for issues 35 and 37. Fixed in Orthanc 0.9.1 |
1392 u = UploadInstance(_REMOTE, 'Beaufix/IM-0001-0001.dcm')['ID'] | |
1393 | |
1394 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', | |
1395 'CaseSensitive' : True, | |
1396 'Query' : { 'StationName' : 'SMR4-MP3' }}) | |
1397 self.assertEqual(1, len(a)) | |
14 | 1398 |
1399 | |
1400 def test_rest_find(self): | |
1401 # Upload 8 instances | |
1402 for i in range(2): | |
1403 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
1404 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
1405 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
1406 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
1407 | |
1408 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1409 'CaseSensitive' : False, | |
1410 'Query' : { 'PatientName' : '*n*' }}) | |
1411 self.assertEqual(2, len(a)) | |
1412 | |
1413 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1414 'CaseSensitive' : True, | |
1415 'Query' : { 'PatientName' : '*n*' }}) | |
1416 self.assertEqual(0, len(a)) | |
1417 | |
1418 a = DoPost(_REMOTE, '/tools/find', { 'Expand' : True, | |
1419 'Level' : 'Patient', | |
1420 'CaseSensitive' : False, | |
1421 'Query' : { 'PatientName' : '*ne*' }}) | |
1422 self.assertEqual(1, len(a)) | |
1423 self.assertEqual('20080822', a[0]['MainDicomTags']['PatientBirthDate']) | |
1424 | |
1425 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1426 'CaseSensitive' : True, | |
1427 'Query' : { 'PatientName' : '*ne*' }}) | |
1428 self.assertEqual(0, len(a)) | |
1429 | |
1430 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', | |
1431 'CaseSensitive' : True, | |
1432 'Query' : { 'PatientName' : '*NE*' }}) | |
1433 self.assertEqual(1, len(a)) | |
1434 | |
1435 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', | |
1436 'CaseSensitive' : True, | |
1437 'Query' : { 'PatientName' : '*NE*' }}) | |
1438 self.assertEqual(2, len(a)) | |
1439 | |
1440 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
1441 'CaseSensitive' : True, | |
1442 'Query' : { 'PatientName' : '*NE*' }}) | |
1443 self.assertEqual(4, len(a)) | |
1444 | |
1445 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', 'Query' : { }}) | |
1446 self.assertEqual(2, len(a)) | |
1447 | |
1448 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', 'Query' : { }}) | |
1449 self.assertEqual(2, len(a)) | |
1450 | |
1451 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 'Query' : { }}) | |
1452 self.assertEqual(4, len(a)) | |
1453 | |
1454 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', 'Query' : { }}) | |
1455 self.assertEqual(8, len(a)) | |
1456 | |
1457 | |
1458 def test_rest_query_retrieve(self): | |
1459 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1460 | |
1461 # Upload 8 instances | |
1462 for i in range(2): | |
1463 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
1464 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
1465 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
1466 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
1467 | |
1468 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
1469 for p in DoGet(_REMOTE, '/patients'): | |
1470 DoPost(_REMOTE, '/modalities/orthanctest/store', p) | |
1471 DoDelete(_REMOTE, '/patients/%s' % p) | |
1472 | |
1473 for q in DoGet(_REMOTE, '/queries'): | |
1474 DoDelete(_REMOTE, '/queries/%s' % q) | |
1475 | |
1476 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1477 self.assertEqual(0, len(DoGet(_REMOTE, '/queries'))) | |
1478 a = DoPost(_REMOTE, '/modalities/orthanctest/query', { 'Level' : 'Series', | |
27 | 1479 'Query' : { |
1480 'PatientName' : '*NE*', | |
1481 'StudyDate' : '*', | |
1482 }})['ID'] | |
14 | 1483 self.assertEqual(1, len(DoGet(_REMOTE, '/queries'))) |
1484 | |
1485 b = DoGet(_REMOTE, '/queries/%s' % a) | |
1486 self.assertTrue('answers' in b) | |
1487 self.assertTrue('level' in b) | |
1488 self.assertTrue('modality' in b) | |
1489 self.assertTrue('query' in b) | |
1490 self.assertTrue('retrieve' in b) | |
1491 self.assertEqual('Series', DoGet(_REMOTE, '/queries/%s/level' % a)) | |
1492 self.assertEqual('orthanctest', DoGet(_REMOTE, '/queries/%s/modality' % a)) | |
1493 | |
1494 q = DoGet(_REMOTE, '/queries/%s/query?simplify' % a) | |
27 | 1495 self.assertEqual(2, len(q)) |
14 | 1496 self.assertTrue('PatientName' in q) |
27 | 1497 self.assertTrue('StudyDate' in q) |
14 | 1498 self.assertEqual('*NE*', q['PatientName']) |
27 | 1499 self.assertEqual('*', q['StudyDate']) |
14 | 1500 |
1501 self.assertEqual(2, len(DoGet(_REMOTE, '/queries/%s/answers' % a))) | |
1502 | |
1503 s = DoGet(_REMOTE, '/queries/%s/answers/0' % a) | |
1504 self.assertTrue('content' in s) | |
1505 self.assertTrue('retrieve' in s) | |
1506 | |
1507 s = DoGet(_REMOTE, '/queries/%s/answers/0/content?simplify' % a) | |
1508 self.assertEqual('887', s['PatientID']) | |
1509 self.assertEqual('2.16.840.1.113669.632.20.121711.10000160881', s['StudyInstanceUID']) | |
1510 | |
1511 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1512 DoPost(_REMOTE, '/queries/%s/answers/0/retrieve' % a, 'ORTHANC') | |
1513 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
1514 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
1515 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
1516 self.assertEqual(2, len(DoGet(_REMOTE, '/instances'))) | |
1517 | |
1518 DoPost(_REMOTE, '/queries/%s/answers/1/retrieve' % a, 'ORTHANC') | |
1519 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
1520 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
1521 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
1522 self.assertEqual(4, len(DoGet(_REMOTE, '/instances'))) | |
1523 | |
1524 DoDelete(_REMOTE, '/queries/%s' % a) | |
1525 self.assertEqual(0, len(DoGet(_REMOTE, '/queries'))) | |
1526 | |
1527 | |
1528 def test_parent(self): | |
1529 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1530 patient = '6816cb19-844d5aee-85245eba-28e841e6-2414fae2' | |
1531 study = 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0' | |
1532 series = 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe' | |
1533 instance = '66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d' | |
1534 self.assertEqual(instance, u); | |
1535 | |
1536 a = DoGet(_REMOTE, '/studies/%s/patient' % study) | |
1537 self.assertEqual('Patient', a['Type']) | |
1538 self.assertEqual(patient, a['ID']) | |
1539 | |
1540 a = DoGet(_REMOTE, '/series/%s/patient' % series) | |
1541 self.assertEqual('Patient', a['Type']) | |
1542 self.assertEqual(patient, a['ID']) | |
1543 | |
1544 a = DoGet(_REMOTE, '/series/%s/study' % series) | |
1545 self.assertEqual('Study', a['Type']) | |
1546 self.assertEqual(study, a['ID']) | |
1547 | |
1548 a = DoGet(_REMOTE, '/instances/%s/patient' % instance) | |
1549 self.assertEqual('Patient', a['Type']) | |
1550 self.assertEqual(patient, a['ID']) | |
1551 | |
1552 a = DoGet(_REMOTE, '/instances/%s/study' % instance) | |
1553 self.assertEqual('Study', a['Type']) | |
1554 self.assertEqual(study, a['ID']) | |
1555 | |
1556 a = DoGet(_REMOTE, '/instances/%s/series' % instance) | |
1557 self.assertEqual('Series', a['Type']) | |
1558 self.assertEqual(series, a['ID']) | |
1559 | |
1560 | |
1561 def test_shanon(self): | |
1562 def Anonymize(instance, replacements = {}): | |
1563 return DoPost(_REMOTE, '/instances/%s/anonymize' % instance, { 'Replace' : replacements }, 'application/json') | |
1564 | |
1565 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
1566 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1567 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1568 | |
1569 tags = [ 'PatientID', 'StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID', 'DeidentificationMethod' ] | |
1570 ids = [ 'ozp00SjY2xG', | |
1571 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
1572 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
1573 '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109' ] | |
1574 | |
1575 a = ExtractDicomTags(Anonymize(u), tags) | |
1576 for i in range(4): | |
1577 self.assertNotEqual(ids[i], a[i]) | |
1578 self.assertTrue(a[4].startswith('Orthanc')) | |
1579 | |
1580 a = ExtractDicomTags(Anonymize(u, { 'PatientName' : 'toto' }), tags) | |
1581 for i in range(4): | |
1582 self.assertNotEqual(ids[i], a[i]) | |
1583 self.assertFalse(a[4].startswith('Orthanc')) | |
1584 | |
1585 a = ExtractDicomTags(Anonymize(u, { 'SOPInstanceUID' : 'instance' }), tags) | |
1586 self.assertEqual('instance', a[3]) | |
1587 self.assertFalse(a[4].startswith('Orthanc')) | |
1588 | |
1589 a = ExtractDicomTags(Anonymize(u, { 'SeriesInstanceUID' : 'series' }), tags) | |
1590 self.assertEqual('series', a[2]) | |
1591 self.assertFalse(a[4].startswith('Orthanc')) | |
1592 | |
1593 a = ExtractDicomTags(Anonymize(u, { 'StudyInstanceUID' : 'study' }), tags) | |
1594 self.assertEqual('study', a[1]) | |
1595 self.assertFalse(a[4].startswith('Orthanc')) | |
1596 | |
1597 a = ExtractDicomTags(Anonymize(u, { 'PatientID' : 'patient' }), tags) | |
1598 self.assertEqual('patient', a[0]) | |
1599 self.assertFalse(a[4].startswith('Orthanc')) | |
1600 | |
1601 a = ExtractDicomTags(Anonymize(u, { 'PatientID' : 'patient', | |
1602 'StudyInstanceUID' : 'study', | |
1603 'SeriesInstanceUID' : 'series', | |
1604 'SOPInstanceUID' : 'instance' }), tags) | |
1605 self.assertEqual('patient', a[0]) | |
1606 self.assertFalse(a[4].startswith('Orthanc')) | |
1607 | |
1608 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1609 | |
1610 | |
1611 def test_shanon_2(self): | |
1612 def Modify(instance, replacements = {}): | |
1613 return DoPost(_REMOTE, '/instances/%s/modify' % instance, { 'Replace' : replacements }, 'application/json') | |
1614 | |
1615 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
1616 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1617 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1618 | |
1619 tags = [ 'PatientID', 'StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID', 'DeidentificationMethod' ] | |
1620 ids = [ 'ozp00SjY2xG', | |
1621 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
1622 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
1623 '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109' ] | |
1624 | |
1625 a = ExtractDicomTags(Modify(u), tags) | |
1626 self.assertEqual(ids[0], a[0]) | |
1627 self.assertEqual(ids[1], a[1]) | |
1628 self.assertEqual(ids[2], a[2]) | |
1629 self.assertNotEqual(ids[3], a[3]) | |
1630 self.assertEqual(0, len(a[4])) | |
1631 | |
1632 a = ExtractDicomTags(Modify(u, { 'SOPInstanceUID' : 'instance' }), tags) | |
1633 self.assertEqual(ids[0], a[0]) | |
1634 self.assertEqual(ids[1], a[1]) | |
1635 self.assertEqual(ids[2], a[2]) | |
1636 self.assertEqual('instance', a[3]) | |
1637 | |
1638 a = ExtractDicomTags(Modify(u, { 'SeriesInstanceUID' : 'series' }), tags) | |
1639 self.assertEqual(ids[0], a[0]) | |
1640 self.assertEqual(ids[1], a[1]) | |
1641 self.assertEqual('series', a[2]) | |
1642 self.assertNotEqual(ids[3], a[3]) | |
1643 | |
1644 a = ExtractDicomTags(Modify(u, { 'StudyInstanceUID' : 'study' }), tags) | |
1645 self.assertEqual(ids[0], a[0]) | |
1646 self.assertEqual('study', a[1]) | |
1647 self.assertNotEqual(ids[2], a[2]) | |
1648 self.assertNotEqual(ids[3], a[3]) | |
1649 | |
1650 a = ExtractDicomTags(Modify(u, { 'PatientID' : 'patient' }), tags) | |
1651 self.assertEqual('patient', a[0]) | |
1652 self.assertNotEqual(ids[1], a[1]) | |
1653 self.assertNotEqual(ids[2], a[2]) | |
1654 self.assertNotEqual(ids[3], a[3]) | |
1655 | |
1656 a = ExtractDicomTags(Modify(u, { 'PatientID' : 'patient', | |
1657 'StudyInstanceUID' : 'study', | |
1658 'SeriesInstanceUID' : 'series', | |
1659 'SOPInstanceUID' : 'instance' }), tags) | |
1660 self.assertEqual('patient', a[0]) | |
1661 self.assertEqual('study', a[1]) | |
1662 self.assertEqual('series', a[2]) | |
1663 self.assertEqual('instance', a[3]) | |
1664 | |
1665 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1666 | |
1667 | |
1668 def test_instances_tags(self): | |
1669 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1670 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')['ID'] | |
1671 #a = UploadInstance(_REMOTE, 'Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386937.676343')['ID'] | |
1672 #b = UploadInstance(_REMOTE, 'Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386925.676329')['ID'] | |
1673 | |
1674 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/patients')[0]) | |
1675 self.assertEqual(2, len(i)) | |
1676 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1677 self.assertEqual('887', i[i.keys()[1]]['PatientID']) | |
1678 | |
1679 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/studies')[0]) | |
1680 self.assertEqual(2, len(i)) | |
1681 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1682 self.assertEqual('887', i[i.keys()[1]]['PatientID']) | |
1683 | |
1684 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
1685 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/series')[0]) | |
1686 self.assertEqual(1, len(i)) | |
1687 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1688 | |
1689 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/series')[1]) | |
1690 self.assertEqual(1, len(i)) | |
1691 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1692 | |
1693 | |
1694 def test_lookup(self): | |
1695 a = DoPost(_REMOTE, '/tools/lookup', 'ozp00SjY2xG') | |
1696 self.assertEqual(0, len(a)) | |
1697 | |
1698 UploadInstance(_REMOTE, 'DummyCT.dcm') | |
1699 | |
1700 a = DoPost(_REMOTE, '/tools/lookup', 'ozp00SjY2xG') | |
1701 self.assertEqual(1, len(a)) | |
1702 self.assertEqual('Patient', a[0]['Type']) | |
1703 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', a[0]['ID']) | |
1704 self.assertEqual('/patients/%s' % a[0]['ID'], a[0]['Path']) | |
1705 | |
1706 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390') | |
1707 self.assertEqual(1, len(a)) | |
1708 self.assertEqual('Study', a[0]['Type']) | |
1709 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', a[0]['ID']) | |
1710 self.assertEqual('/studies/%s' % a[0]['ID'], a[0]['Path']) | |
1711 | |
1712 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394') | |
1713 self.assertEqual(1, len(a)) | |
1714 self.assertEqual('Series', a[0]['Type']) | |
1715 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', a[0]['ID']) | |
1716 self.assertEqual('/series/%s' % a[0]['ID'], a[0]['Path']) | |
1717 | |
1718 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109') | |
1719 self.assertEqual(1, len(a)) | |
1720 self.assertEqual('Instance', a[0]['Type']) | |
1721 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', a[0]['ID']) | |
1722 self.assertEqual('/instances/%s' % a[0]['ID'], a[0]['Path']) | |
1723 | |
1724 DropOrthanc(_REMOTE) | |
1725 a = DoPost(_REMOTE, '/tools/lookup', '3113719P') | |
1726 self.assertEqual(0, len(a)) | |
1727 | |
15 | 1728 |
1729 def test_autorouting(self): | |
1730 knee1 = 'Knee/T1/IM-0001-0001.dcm' | |
1731 knee2 = 'Knee/T2/IM-0001-0002.dcm' | |
1732 other = 'Brainix/Flair/IM-0001-0001.dcm' | |
1733 | |
1734 # Check that this version is >= 0.8.0 | |
1735 self.assertTrue(IsDefinedInLua(_REMOTE, '_InitializeJob')) | |
1736 self.assertTrue('orthanctest' in DoGet(_REMOTE, '/modalities')) | |
1737 | |
1738 UploadInstance(_REMOTE, knee1) | |
1739 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
1740 | |
1741 DropOrthanc(_REMOTE) | |
1742 DropOrthanc(_LOCAL) | |
1743 InstallLuaScript('Lua/Autorouting.lua') | |
1744 UploadInstance(_REMOTE, knee1) | |
1745 UploadInstance(_REMOTE, knee2) | |
1746 UploadInstance(_REMOTE, other) | |
1747 WaitEmpty(_REMOTE) | |
1748 UninstallLuaCallbacks() | |
1749 self.assertEqual(3, len(DoGet(_LOCAL, '/instances'))) | |
1750 | |
1751 DropOrthanc(_REMOTE) | |
1752 DropOrthanc(_LOCAL) | |
1753 InstallLuaScript('Lua/AutoroutingConditional.lua') | |
1754 UploadInstance(_REMOTE, knee1) | |
1755 UploadInstance(_REMOTE, knee2) | |
1756 UploadInstance(_REMOTE, other) | |
1757 WaitEmpty(_REMOTE) | |
1758 UninstallLuaCallbacks() | |
1759 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
1760 | |
1761 DropOrthanc(_REMOTE) | |
1762 DropOrthanc(_LOCAL) | |
1763 InstallLuaScript('Lua/AutoroutingModification.lua') | |
1764 UploadInstance(_REMOTE, knee1) | |
1765 WaitEmpty(_REMOTE) | |
1766 UninstallLuaCallbacks() | |
1767 i = DoGet(_LOCAL, '/instances') | |
1768 self.assertEqual(1, len(i)) | |
1769 | |
1770 with tempfile.NamedTemporaryFile(delete = True) as f: | |
1771 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0])) | |
1772 f.flush() | |
45 | 1773 routed = subprocess.check_output([ FindExecutable('dcm2xml'), f.name ]) |
15 | 1774 self.assertEqual('My Medical Device', re.search('"StationName">(.*?)<', routed).group(1).strip()) |
1775 self.assertEqual(None, re.search('"MilitaryRank"', routed)) | |
1776 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag | |
17 | 1777 |
1778 | |
1779 def test_storescu_rf(self): | |
1780 i = UploadInstance(_REMOTE, 'KarstenHilbertRF.dcm')['ID'] | |
1781 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
1782 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1783 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
18 | 1784 |
1785 | |
1786 def test_anonymize_instance(self): | |
1787 def AnonymizeAndUpload(instanceId, parameters): | |
1788 return DoPost(_REMOTE, '/instances', DoPost(_REMOTE, '/instances/%s/anonymize' % instanceId, parameters, | |
1789 'application/json'), 'application/dicom')['ID'] | |
1790 | |
1791 def ModifyAndUpload(instanceId, parameters): | |
1792 return DoPost(_REMOTE, '/instances', DoPost(_REMOTE, '/instances/%s/modify' % instanceId, parameters, | |
1793 'application/json'), 'application/dicom')['ID'] | |
1794 | |
1795 a = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
1796 s1 = DoGet(_REMOTE, '/instances/%s/content/PatientName' % a) | |
1797 s2 = DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % a) # Some private tag | |
1798 s3 = DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % a) | |
1799 s4 = DoGet(_REMOTE, '/instances/%s/content/SeriesDescription' % a) | |
1800 s5 = DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % a) | |
1801 | |
1802 b = AnonymizeAndUpload(a, '{}') | |
1803 self.assertNotEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1804 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1805 | |
1806 # Keep private tag (only OK since Orthanc 0.8.0) | |
1807 b = AnonymizeAndUpload(a, '{"Keep":["00e1-10c2"]}') | |
1808 self.assertNotEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1809 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1810 | |
1811 b = AnonymizeAndUpload(a, '{"Keep":["00e1,10c2","PatientName"]}') | |
1812 self.assertEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1813 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1814 | |
1815 b = AnonymizeAndUpload(a, '{"Keep":["PatientName"],"Replace":{"00e1,10c2":"Hello"}}') | |
1816 self.assertEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1817 self.assertTrue(DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b).startswith('Hello')) | |
1818 | |
1819 # Examples from the Wiki | |
1820 b = AnonymizeAndUpload(a, '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": null}') | |
1821 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1822 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1823 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1824 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008,103e' % b)) | |
1825 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008-103E' % b)) | |
1826 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1827 DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % a) | |
1828 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1829 | |
1830 b = ModifyAndUpload(a, '{"Replace":{"PatientName":"hello","PatientID":"world"},"Remove":["InstitutionName"],"RemovePrivateTags": null}') | |
1831 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1832 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1833 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1834 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008,103e' % b)) | |
1835 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1836 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1837 | |
1838 b = ModifyAndUpload(a, '{"Replace":{"PatientName":"hello","PatientID":"world"}}') | |
1839 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1840 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1841 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1,10c2' % b)) | |
1842 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1843 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008-103E' % b)) | |
1844 self.assertEqual(s5, DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1845 | |
1846 | |
1847 # Test modify non-existing | |
1848 i = DoPost(_REMOTE, '/tools/create-dicom', | |
1849 json.dumps({ | |
1850 'PatientName' : 'Jodogne', | |
1851 'Modality' : 'CT', | |
1852 }))['ID'] | |
1853 | |
1854 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i).strip()) | |
1855 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % i)) | |
1856 self.assertEqual('CT', DoGet(_REMOTE, '/instances/%s/content/Modality' % i).strip()) | |
1857 | |
1858 b = ModifyAndUpload(i, '{"Replace":{"StudyDescription":"hello","Modality":"world"}}') | |
1859 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % b).strip()) | |
1860 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % b).strip()) | |
1861 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/Modality' % b).strip()) | |
1862 | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1863 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1864 def test_incoming_jpeg(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1865 def storescu(): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1866 with open(os.devnull, 'w') as FNULL: |
45 | 1867 subprocess.check_call([ FindExecutable('storescu'), '-xs', |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1868 _REMOTE['Server'], str(_REMOTE['DicomPort']), |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1869 GetDatabasePath('Knix/Loc/IM-0001-0001.dcm') ], |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1870 stderr = FNULL) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1871 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1872 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1873 InstallLuaScript('Lua/TransferSyntaxDisable.lua') |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1874 self.assertRaises(Exception, storescu) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1875 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1876 InstallLuaScript('Lua/TransferSyntaxEnable.lua') |
43 | 1877 DoPost(_REMOTE, '/tools/execute-script', "print('All special transfer syntaxes are now accepted')") |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1878 storescu() |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1879 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1880 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1881 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1882 def test_storescu_jpeg(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1883 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1884 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1885 knixStudy = 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0' |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1886 UploadInstance(_REMOTE, 'Knix/Loc/IM-0001-0001.dcm') |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1887 UploadInstance(_REMOTE, 'Knix/Loc/IM-0001-0002.dcm') |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1888 UploadInstance(_REMOTE, 'Knix/Loc/IM-0001-0003.dcm') |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1889 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1890 a = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1891 b = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1892 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1893 DoPost(_REMOTE, '/modalities/orthanctest/store', [ knixStudy, a, b ]) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1894 self.assertEqual(5, len(DoGet(_LOCAL, '/instances'))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1895 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1896 self.assertEqual(3, len(DoGet(_REMOTE, '/exports')['Exports'])) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1897 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1898 DropOrthanc(_REMOTE) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1899 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1900 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1901 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1902 def test_pixel_data(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1903 jpeg = UploadInstance(_REMOTE, 'Knix/Loc/IM-0001-0001.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1904 color = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1905 phenix = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1906 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1907 phenixSize = 358 * 512 * 2 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1908 colorSize = 1000 * 1000 * 3 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1909 jpegSize = 51918 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1910 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1911 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010' % phenix))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1912 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010' % color))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1913 self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010' % jpeg))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1914 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1915 self.assertEqual(0, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010/0' % jpeg))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1916 self.assertEqual(jpegSize, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010/1' % jpeg))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1917 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1918 self.assertEqual(phenixSize, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010/0' % phenix))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1919 self.assertEqual(colorSize, len(DoGet(_REMOTE, '/instances/%s/content/7fe0-0010/0' % color))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1920 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1921 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1922 def test_decode_brainix(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1923 brainix = [ |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1924 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')['ID'], # (*) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1925 UploadInstance(_REMOTE, 'Formats/JpegLossless.dcm')['ID'], # JPEG-LS, same as (*) (since Orthanc 0.7.6) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1926 UploadInstance(_REMOTE, 'Formats/Jpeg.dcm')['ID'], # JPEG, same as (*) (since Orthanc 0.7.6) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1927 ] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1928 h = '6fb11b932d535c2be04beabd99793ff8' |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1929 maxValue = 426.0 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1930 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1931 truth = Image.open(GetDatabasePath('Formats/Brainix.png')) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1932 for i in brainix: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1933 self.AssertSameImages(truth.getdata(), '/instances/%s/image-int16' % i) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1934 self.AssertSameImages(truth.getdata(), '/instances/%s/image-uint16' % i) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1935 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1936 truth2 = map(lambda x: min(255, x), truth.getdata()) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1937 for i in brainix: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1938 self.AssertSameImages(truth2, '/instances/%s/image-uint8' % i) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1939 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1940 truth2 = map(lambda x: x * 255.0 / maxValue, truth.getdata()) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1941 for i in brainix: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1942 self.AssertSameImages(truth2, '/instances/%s/preview' % i) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1943 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1944 for i in brainix: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1945 self.assertEqual(h, ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % i))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1946 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1947 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1948 def test_decode_color(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1949 imagej = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1950 color = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1951 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1952 for i in [ imagej, color ]: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1953 for j in [ 'image-uint8', 'image-uint16', 'image-int16' ]: |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1954 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/%s' % (i, j))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1955 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1956 self.assertEqual('c14c687f7a1ea9fe022479fc87c67274', ComputeMD5(DoGet(_REMOTE, '/instances/%s/preview' % imagej))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1957 self.assertEqual('a87d122918a56f803bcfe9d2586b9125', ComputeMD5(DoGet(_REMOTE, '/instances/%s/preview' % color))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1958 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1959 self.assertEqual('30cc46bfa7aba77a40e4178f6184c25a', ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % imagej))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1960 self.assertEqual('ff195005cef06b59666fd220a9b4cd9a', ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % color))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1961 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1962 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1963 def test_decode_rf(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1964 rf = UploadInstance(_REMOTE, 'KarstenHilbertRF.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1965 truth = Image.open(GetDatabasePath('Formats/KarstenHilbertRF.png')) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1966 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1967 self.AssertSameImages(truth.getdata(), '/instances/%s/image-uint8' % rf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1968 self.AssertSameImages(truth.getdata(), '/instances/%s/image-uint16' % rf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1969 self.AssertSameImages(truth.getdata(), '/instances/%s/image-int16' % rf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1970 self.AssertSameImages(truth.getdata(), '/instances/%s/preview' % rf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1971 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1972 self.assertEqual('42254d70efd2f4a1b8f3455909689f0e', ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % rf))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1973 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1974 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1975 def test_decode_multiframe(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1976 mf = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1977 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1978 # Test the first frame |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1979 truth = Image.open(GetDatabasePath('Formats/Multiframe0.png')) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1980 self.AssertSameImages(truth.getdata(), '/instances/%s/image-uint8' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1981 self.AssertSameImages(truth.getdata(), '/instances/%s/image-uint16' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1982 self.AssertSameImages(truth.getdata(), '/instances/%s/image-int16' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1983 self.AssertSameImages(truth.getdata(), '/instances/%s/preview' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1984 self.assertEqual('9812b99d93bbcd4e7684ded089b5dfb3', ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % mf))) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1985 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1986 self.AssertSameImages(truth.getdata(), '/instances/%s/frames/0/image-uint16' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1987 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1988 # Test the last frame |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1989 truth = Image.open(GetDatabasePath('Formats/Multiframe75.png')) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1990 self.AssertSameImages(truth.getdata(), '/instances/%s/frames/75/image-uint16' % mf) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1991 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1992 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1993 def test_decode_signed(self): |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1994 signed = UploadInstance(_REMOTE, 'SignedCT.dcm')['ID'] |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1995 minValue = -2000 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1996 maxValue = 4042 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1997 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1998 truth = Image.open(GetDatabasePath('Formats/SignedCT.png')) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
1999 self.AssertSameImages(truth.getdata(), '/instances/%s/image-int16' % signed) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2000 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2001 truth2 = map(lambda x: 0 if x >= 32768 else x, truth.getdata()) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2002 self.AssertSameImages(truth2, '/instances/%s/image-uint16' % signed) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2003 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2004 truth3 = map(lambda x: 255 if x >= 256 else x, truth2) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2005 self.AssertSameImages(truth3, '/instances/%s/image-uint8' % signed) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2006 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2007 tmp = map(lambda x: x - 65536 if x >= 32768 else x, truth.getdata()) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2008 tmp = map(lambda x: (255.0 * (x - minValue)) / (maxValue - minValue), tmp) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2009 self.AssertSameImages(tmp, '/instances/%s/preview' % signed) |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2010 |
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
2011 self.assertEqual('b57e6c872a3da50877c7da689b03a444', ComputeMD5(DoGet(_REMOTE, '/instances/%s/matlab' % signed))) |
22 | 2012 |
2013 | |
46
85b2e36ed392
explicit GoogleCode source
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
45
diff
changeset
|
2014 def test_googlecode_issue_32(self): |
22 | 2015 f = UploadInstance(_REMOTE, 'Issue32.dcm')['ID'] |
2016 tags = DoGet(_REMOTE, '/instances/%s/tags?simplify' % f) | |
2017 self.assertEqual(u'Рентгенография', tags['SeriesDescription']) | |
2018 self.assertEqual(u'Таз', tags['BodyPartExamined']) | |
2019 self.assertEqual(u'Прямая', tags['ViewPosition']) | |
2020 | |
2021 | |
2022 def test_encodings(self): | |
23 | 2023 # Latin-1 (ISO_IR 100) |
22 | 2024 brainix = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')['ID'] |
2025 tags = DoGet(_REMOTE, '/instances/%s/tags?simplify' % brainix) | |
2026 self.assertEqual(u'IRM cérébrale, neuro-crâne', tags['StudyDescription']) | |
23 | 2027 |
2028 # Latin-2 (ISO_IR 101) | |
2029 a = UploadInstance(_REMOTE, 'MarekLatin2.dcm')['ID'] | |
2030 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % a) | |
2031 # dcm2xml MarekLatin2.dcm | iconv -f latin2 -t utf-8 | xmllint --format - | |
2032 self.assertEqual('Imię i Nazwisko osoby opisującej', | |
2033 i['ContentSequence'][4]['ConceptNameCodeSequence'][0]['CodeMeaning'].encode('utf-8')) | |
2034 | |
26
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2035 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2036 def test_storescu_custom_aet(self): |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2037 # This tests a feature introduced in Orthanc 0.9.1: "Custom |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2038 # setting of the local AET during C-Store SCU (both in Lua and |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2039 # in the REST API)." |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2040 # https://groups.google.com/forum/#!msg/orthanc-users/o5qMULformU/wZjW2iSaMcAJ |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2041 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2042 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2043 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2044 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2045 b = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0002.dcm') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2046 c = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0003.dcm') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2047 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2048 j = DoPost(_REMOTE, '/modalities/orthanctest/store', { |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2049 'LocalAet' : 'YOP', |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2050 'Resources' : [ a['ID'], b['ID'] ] |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2051 }) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2052 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2053 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2054 self.assertEqual('YOP', DoGet(_LOCAL, '/instances/%s/metadata/RemoteAET' % a['ID'])) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2055 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2056 DropOrthanc(_LOCAL) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2057 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2058 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2059 j = DoPost(_REMOTE, '/modalities/orthanctest/store', { |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2060 'Resources' : [ c['ID'] ] |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2061 }) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2062 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2063 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2064 self.assertEqual('ORTHANC', DoGet(_LOCAL, '/instances/%s/metadata/RemoteAET' % c['ID'])) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2065 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2066 DropOrthanc(_REMOTE) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2067 DropOrthanc(_LOCAL) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2068 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2069 InstallLuaScript('Lua/AutoroutingChangeAet.lua') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2070 DoPost(_REMOTE, '/tools/execute-script', 'aet = "HELLO"', 'application/lua') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2071 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2072 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2073 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2074 WaitEmpty(_REMOTE) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2075 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2076 self.assertEqual('HELLO', DoGet(_LOCAL, '/instances/%s/metadata/RemoteAET' % a['ID'])) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2077 |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2078 DoPost(_REMOTE, '/tools/execute-script', 'aet = nill', 'application/lua') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2079 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0002.dcm') |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2080 WaitEmpty(_REMOTE) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2081 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) |
040f6ef1394a
test_storescu_custom_aet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
2082 self.assertEqual('ORTHANC', DoGet(_LOCAL, '/instances/%s/metadata/RemoteAET' % b['ID'])) |
34
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2083 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2084 def test_resources_since_limit(self): |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2085 # Upload 16 instances |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2086 for i in range(4): |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2087 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2088 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2089 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2090 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2091 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2092 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2093 self.assertEqual(2, len(DoGet(_REMOTE, '/studies'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2094 self.assertEqual(4, len(DoGet(_REMOTE, '/series'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2095 self.assertEqual(16, len(DoGet(_REMOTE, '/instances'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2096 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2097 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/patients&since=10' % i)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2098 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/patients&limit=10' % i)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2099 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2100 self.assertEqual(0, len(DoGet(_REMOTE, '/patients?since=0&limit=0'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2101 self.assertEqual(2, len(DoGet(_REMOTE, '/patients?since=0&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2102 self.assertEqual(2, len(DoGet(_REMOTE, '/studies?since=0&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2103 self.assertEqual(4, len(DoGet(_REMOTE, '/series?since=0&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2104 self.assertEqual(16, len(DoGet(_REMOTE, '/instances?since=0&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2105 self.assertEqual(1, len(DoGet(_REMOTE, '/patients?since=1&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2106 self.assertEqual(0, len(DoGet(_REMOTE, '/patients?since=2&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2107 self.assertEqual(0, len(DoGet(_REMOTE, '/patients?since=3&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2108 self.assertEqual(1, len(DoGet(_REMOTE, '/studies?since=1&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2109 self.assertEqual(3, len(DoGet(_REMOTE, '/series?since=1&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2110 self.assertEqual(2, len(DoGet(_REMOTE, '/series?since=2&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2111 self.assertEqual(1, len(DoGet(_REMOTE, '/series?since=3&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2112 self.assertEqual(0, len(DoGet(_REMOTE, '/series?since=4&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2113 self.assertEqual(0, len(DoGet(_REMOTE, '/series?since=100&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2114 self.assertEqual(15, len(DoGet(_REMOTE, '/instances?since=1&limit=100'))) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2115 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2116 for limit in [ 1, 2, 3, 7, 16, 17 ]: |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2117 s = {} |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2118 since = 0 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2119 while True: |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2120 t = DoGet(_REMOTE, '/instances?since=%d&limit=%d' % (since, limit)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2121 if len(t) == 0: |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2122 break |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2123 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2124 since += len(t) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2125 for i in t: |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2126 s[i] = None |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2127 |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2128 self.assertEqual(16, len(s)) |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2129 for instance in DoGet(_REMOTE, '/instances'): |
1047d7bc5210
test limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2130 self.assertTrue(instance in s) |
36 | 2131 |
2132 | |
2133 def test_create_pdf(self): | |
2134 # Upload 4 instances | |
2135 brainixInstance = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID'] | |
2136 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') | |
2137 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
2138 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
2139 | |
2140 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0' | |
2141 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' | |
2142 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8' | |
2143 | |
2144 with open(GetDatabasePath('HelloWorld.pdf'), 'rb') as f: | |
2145 pdf = f.read() | |
2146 | |
2147 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2148 json.dumps({ | |
2149 'Tags' : { | |
2150 'PatientName' : 'Jodogne', | |
2151 'Modality' : 'CT', | |
2152 }, | |
2153 'Content' : 'data:application/pdf;base64,' + base64.b64encode(pdf) | |
2154 })) | |
2155 | |
2156 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i['ID']).strip()) | |
2157 self.assertEqual('OT', DoGet(_REMOTE, '/instances/%s/content/Modality' % i['ID']).strip()) | |
2158 | |
2159 b = DoGet(_REMOTE, '/instances/%s/content/0042-0011' % i['ID']) | |
2160 self.assertEqual(len(b), len(pdf) + 1) | |
2161 self.assertEqual(ComputeMD5(b), ComputeMD5(pdf + '\0')) | |
2162 | |
2163 self.assertRaises(Exception, lambda: DoPost(_REMOTE, '/tools/create-dicom', | |
2164 json.dumps({ | |
2165 'Parent' : brainixPatient, | |
2166 'Tags' : { | |
2167 'PatientName' : 'Jodogne', | |
2168 } | |
2169 }))) | |
2170 | |
2171 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2172 json.dumps({ | |
2173 'Parent' : brainixPatient, | |
2174 'Tags' : { 'StudyDescription' : 'PDF^Patient' }, | |
2175 'Content' : 'data:application/pdf;base64,' + base64.b64encode(pdf) | |
2176 })) | |
2177 | |
2178 self.assertEqual(brainixPatient, DoGet(_REMOTE, '/instances/%s/patient' % i['ID'])['ID']) | |
2179 | |
2180 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2181 json.dumps({ | |
2182 'Parent' : brainixStudy, | |
2183 'Tags' : { 'SeriesDescription' : 'PDF^Study' }, | |
2184 'Content' : 'data:application/pdf;base64,' + base64.b64encode(pdf) | |
2185 })) | |
2186 | |
2187 self.assertEqual(brainixStudy, DoGet(_REMOTE, '/instances/%s/study' % i['ID'])['ID']) | |
2188 | |
2189 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2190 json.dumps({ | |
2191 'Parent' : brainixEpi, | |
37 | 2192 'Tags' : { 'SpecificCharacterSet' : 'ISO_IR 13' }, |
36 | 2193 'Content' : 'data:application/pdf;base64,' + base64.b64encode(pdf) |
2194 })) | |
2195 | |
2196 self.assertEqual(brainixEpi, DoGet(_REMOTE, '/instances/%s/series' % i['ID'])['ID']) | |
2197 | |
2198 b = DoGet(_REMOTE, '/instances/%s/pdf' % i['ID']) | |
2199 self.assertEqual(len(b), len(pdf)) | |
2200 self.assertEqual(ComputeMD5(b), ComputeMD5(pdf)) | |
2201 | |
2202 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/pdf' % brainixInstance)) | |
38 | 2203 |
2204 | |
2205 def test_create_series(self): | |
2206 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2207 json.dumps({ | |
2208 'Tags' : { | |
40 | 2209 'SpecificCharacterSet' : 'ISO_IR 100', |
2210 'PatientName' : 'Sébastien Jodogne', | |
38 | 2211 'Modality' : 'CT', |
2212 }, | |
2213 'Content' : [ | |
40 | 2214 { |
2215 'Content': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', # red dot in RGBA | |
2216 'Tags' : { 'ImageComments' : 'Tutu' } | |
2217 }, | |
38 | 2218 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAoUlEQVQ4jZ2SWw3EIBREjwUsYAELa2EtoAULFUCyXAtroRZqoRbox254BdLC/DZnZjoXWJFgCDg8egW2CBEhEnDzyRk+Ecxz2KP/0AL8S99T+jQccAVs22qKwAuPuq0uyNg9cPLh3am+pe/dkHLZtqJHj6vXJrZ7nvzvxxgemXgUwnGfXqpee09mUwp8m022OYP6bLF7mVuVe0y/umxinsAXRd9z0k1ubWsAAAAASUVORK5CYII=', |
2219 ] | |
2220 })) | |
2221 | |
2222 s = DoGet(_REMOTE, i['Path']) | |
2223 self.assertEqual('Series', s['Type']) | |
2224 self.assertEqual(s['ID'], i['ID']) | |
2225 self.assertEqual(2, len(s['Instances'])) | |
39 | 2226 self.assertEqual(2, s['ExpectedNumberOfInstances']) |
2227 self.assertEqual('Complete', s['Status']) | |
40 | 2228 |
2229 a = DoGet(_REMOTE, '/instances/%s/tags?simplify' % s['Instances'][0]) | |
2230 b = DoGet(_REMOTE, '/instances/%s/tags?simplify' % s['Instances'][1]) | |
2231 self.assertTrue('ImageComments' in a or 'ImageComments' in b) | |
2232 if 'ImageComments' in a: | |
2233 self.assertEqual('Tutu', a['ImageComments']) | |
2234 else: | |
2235 self.assertEqual('Tutu', b['ImageComments']) | |
2236 | |
2237 patient = DoGet(_REMOTE, '/instances/%s/patient' % s['Instances'][0]) | |
2238 self.assertEqual(patient['MainDicomTags']['PatientName'].encode('utf-8'), | |
2239 'Sébastien Jodogne') | |
47 | 2240 |
2241 | |
2242 def test_create_binary(self): | |
2243 binary = ''.join(map(chr, range(256))) | |
2244 encoded = 'data:application/octet-stream;base64,' + base64.b64encode(binary) | |
2245 tags = { | |
2246 'PatientName' : 'Jodogne', | |
2247 '8899-8899' : encoded | |
2248 } | |
2249 | |
2250 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2251 json.dumps({ | |
2252 'Tags' : tags | |
2253 })) | |
2254 | |
2255 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i['ID']).strip()) | |
2256 self.assertEqual(binary, DoGet(_REMOTE, '/instances/%s/content/8899-8899' % i['ID']).strip()) | |
2257 | |
2258 i = DoPost(_REMOTE, '/tools/create-dicom', | |
2259 json.dumps({ | |
2260 'InterpretBinaryTags' : False, | |
2261 'Tags' : tags | |
2262 })) | |
2263 | |
2264 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i['ID']).strip()) | |
2265 self.assertEqual(encoded, DoGet(_REMOTE, '/instances/%s/content/8899-8899' % i['ID'])[0:-1]) | |
48
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2266 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2267 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2268 def test_patient_ids_collision(self): |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2269 # Upload 3 instances from 3 different studies, but with the |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2270 # same PatientID |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2271 for i in range(3): |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2272 UploadInstance(_REMOTE, 'PatientIdsCollision/Image%d.dcm' % (i + 1)) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2273 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2274 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2275 'Query' : { 'PatientName' : '*' }}) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2276 self.assertEqual(1, len(a)) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2277 self.assertEqual('COMMON', DoGet(_REMOTE, '/patients/%s' % a[0]) ['MainDicomTags']['PatientID']) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2278 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2279 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2280 'CaseSensitive' : True, |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2281 'Query' : { 'PatientName' : 'FOO\\HELLO' }}) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2282 self.assertEqual(2, len(a)) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2283 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2284 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2285 'CaseSensitive' : False, |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2286 'Query' : { 'PatientName' : 'Foo' }}) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2287 self.assertEqual(1, len(a)) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2288 self.assertEqual('FOO^SERIES', DoGet(_REMOTE, '/series/%s/study' % a[0]) ['MainDicomTags']['StudyDescription']) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2289 self.assertEqual('FOO', DoGet(_REMOTE, '/series/%s/study' % a[0]) ['PatientMainDicomTags']['PatientName']) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2290 self.assertEqual('COMMON', DoGet(_REMOTE, '/series/%s/study' % a[0]) ['PatientMainDicomTags']['PatientID']) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2291 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2292 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2293 'Query' : { 'PatientName' : '*' }}) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2294 self.assertEqual(3, len(a)) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2295 d = map(lambda x: DoGet(_REMOTE, '/studies/%s' % x) ['MainDicomTags']['StudyDescription'], a) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2296 self.assertTrue('FOO^SERIES' in d) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2297 self.assertTrue('HELLO^SERIES' in d) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2298 self.assertTrue('WORLD^SERIES' in d) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2299 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2300 d = map(lambda x: DoGet(_REMOTE, '/studies/%s' % x) ['PatientMainDicomTags']['PatientID'], a) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2301 self.assertEqual(1, len(set(d))) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2302 self.assertEqual('COMMON', d[0]) |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2303 |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2304 for i in a: |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2305 d = DoGet(_REMOTE, '/studies/%s' % i) ['MainDicomTags']['StudyDescription'] |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2306 p = DoGet(_REMOTE, '/studies/%s' % i) ['PatientMainDicomTags']['PatientName'] |
e4352463ff74
test_patient_ids_collision
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
2307 self.assertEqual('%s^SERIES' % p, d) |
49
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2308 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2309 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2310 def test_bitbucket_issue_4(self): |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2311 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2312 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0002.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2313 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0003.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2314 UploadInstance(_REMOTE, 'Formats/Jpeg.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2315 UploadInstance(_REMOTE, 'Formats/JpegLossless.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2316 UploadInstance(_REMOTE, 'Formats/Rle.dcm') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2317 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2318 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2319 self.assertEqual(6, len(DoGet(_REMOTE, '/instances'))) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2320 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2321 p = DoGet(_REMOTE, '/patients') |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2322 self.assertEqual(2, len(p)) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2323 i1 = map(lambda x: x['ID'], DoGet(_REMOTE, '/patients/%s/instances' % p[0])) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2324 i2 = map(lambda x: x['ID'], DoGet(_REMOTE, '/patients/%s/instances' % p[1])) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2325 self.assertEqual(3, len(i1)) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2326 self.assertEqual(3, len(i2)) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2327 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2328 j = DoPost(_REMOTE, '/modalities/orthanctest/store', i2[0:1] + i1 + i2[1:3]) |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2329 |
e7f9b8199545
test_bitbucket_issue_4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
2330 self.assertEqual(6, len(DoGet(_LOCAL, '/instances'))) |
50
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2331 |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2332 |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2333 def test_create_sequence(self): |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2334 i = DoPost(_REMOTE, '/tools/create-dicom', |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2335 json.dumps({ |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2336 'Tags' : { |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2337 'SpecificCharacterSet': 'ISO_IR 100', # Encode using Latin1 |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2338 'PatientName': 'Jodogne^', |
51
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2339 'ReferencedStudySequence': GenerateTestSequence(), |
50
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2340 } |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2341 }))['ID'] |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2342 |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2343 self.assertEqual('Jodogne^', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i)) |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2344 self.assertEqual('Hello^', DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence/0/StudyDescription' % i)) |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2345 self.assertEqual('Toto', DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence/0/ReferencedStudySequence/0/StudyDescription' % i)) |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2346 self.assertEqual('Tata', DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence/0/ReferencedStudySequence/1/StudyDescription' % i)) |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2347 self.assertEqual(u'Sébastien^'.encode('latin-1'), |
8de63d56cf11
test_create_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
49
diff
changeset
|
2348 DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence/1/StudyDescription' % i)) |
51
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2349 |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2350 |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2351 def test_modify_sequence(self): |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2352 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2353 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence' % i)) |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2354 |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2355 j = DoPost(_REMOTE, '/instances/%s/modify' % i, |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2356 json.dumps({ |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2357 "Replace" : { |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2358 "PatientName" : "hello", |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2359 'ReferencedStudySequence': GenerateTestSequence(), |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2360 }, |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2361 }), |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2362 'application/json') |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2363 j = DoPost(_REMOTE, '/instances', j, 'application/dicom')['ID'] |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2364 DoDelete(_REMOTE, '/instances/%s' % i) |
264a20a0276d
test_modify_sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
2365 |
52 | 2366 self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/content/ReferencedStudySequence' % j))) |
2367 | |
2368 | |
2369 def test_compression(self): | |
2370 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
2371 | |
2372 data = DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % i)[1] | |
2373 | |
2374 # "StorageCompression" is enabled in the Orthanc to be tested, | |
2375 # uncompress the data before running the test | |
2376 if DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/is-compressed' % i) != 0: | |
2377 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/uncompress' % i) | |
2378 | |
2379 cs = DoGet(_REMOTE, '/statistics')['TotalDiskSize'] | |
2380 us = DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'] | |
2381 size = DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/size' % i) | |
2382 md5 = DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/md5' % i) | |
2383 self.assertEqual(data, DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-data' % i)[1]) | |
2384 self.assertEqual(md5, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-md5' % i)) | |
2385 self.assertEqual(size, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-size' % i)) | |
2386 | |
2387 ops = DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json' % i) | |
2388 self.assertTrue('compress' in ops) | |
2389 self.assertTrue('uncompress' in ops) | |
2390 self.assertTrue('is-compressed' in ops) | |
2391 self.assertEqual(0, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/is-compressed' % i)) | |
2392 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/verify-md5' % i) | |
2393 | |
2394 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/compress' % i) | |
2395 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/verify-md5' % i) | |
2396 self.assertEqual(1, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/is-compressed' % i)) | |
2397 self.assertLess(cs, DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
2398 self.assertEqual(us, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
2399 self.assertGreater(len(data), len(DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-data' % i)[1])) | |
2400 self.assertGreater(size, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-size' % i)) | |
2401 self.assertEqual(size, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/size' % i)) | |
2402 self.assertEqual(md5, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/md5' % i)) | |
2403 self.assertNotEqual(md5, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-md5' % i)) | |
2404 | |
2405 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/uncompress' % i) | |
2406 DoPost(_REMOTE, '/instances/%s/attachments/dicom-as-json/verify-md5' % i) | |
2407 self.assertEqual(0, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/is-compressed' % i)) | |
2408 self.assertEqual(data, DoGetRaw(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-data' % i)[1]) | |
2409 self.assertEqual(size, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-size' % i)) | |
2410 self.assertEqual(size, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/size' % i)) | |
2411 self.assertEqual(md5, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/md5' % i)) | |
2412 self.assertEqual(md5, DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/compressed-md5' % i)) | |
2413 self.assertEqual(cs, DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
2414 self.assertEqual(us, DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
53 | 2415 |
2416 | |
2417 def test_ordered_slices(self): | |
2418 i = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID'] | |
2419 s = DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'] | |
2420 o = DoGet(_REMOTE, '/series/%s/ordered-slices' % s) | |
2421 self.assertEqual('Sequence', o['Type']) | |
2422 self.assertEqual(1, len(o['Dicom'])) | |
2423 self.assertEqual('/instances/9e05eb0a-18b6268c-e0d36085-8ddab517-3b5aec02/file', o['Dicom'][0]) | |
2424 self.assertEqual(76, len(o['Slices'])) | |
2425 for j in range(76): | |
2426 self.assertEqual('/instances/9e05eb0a-18b6268c-e0d36085-8ddab517-3b5aec02/frames/%d' % j, o['Slices'][j]) | |
2427 | |
2428 i = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')['ID'] | |
2429 j = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0002.dcm')['ID'] | |
2430 k = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0003.dcm')['ID'] | |
2431 s = DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'] | |
2432 o = DoGet(_REMOTE, '/series/%s/ordered-slices' % s) | |
2433 | |
2434 self.assertEqual('Volume', o['Type']) | |
2435 self.assertEqual(3, len(o['Dicom'])) | |
2436 self.assertEqual(3, len(o['Slices'])) | |
2437 self.assertEqual('/instances/%s/file' % i, o['Dicom'][2]) | |
2438 self.assertEqual('/instances/%s/file' % j, o['Dicom'][1]) | |
2439 self.assertEqual('/instances/%s/file' % k, o['Dicom'][0]) | |
2440 self.assertEqual('/instances/%s/frames/0' % i, o['Slices'][2]) | |
2441 self.assertEqual('/instances/%s/frames/0' % j, o['Slices'][1]) | |
2442 self.assertEqual('/instances/%s/frames/0' % k, o['Slices'][0]) | |
2443 | |
2444 i = UploadInstance(_REMOTE, 'Beaufix/IM-0001-0001.dcm')['ID'] | |
2445 j = UploadInstance(_REMOTE, 'Beaufix/IM-0001-0002.dcm')['ID'] | |
2446 s = DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'] | |
2447 o = DoGet(_REMOTE, '/series/%s/ordered-slices' % s) | |
2448 | |
2449 self.assertEqual('Sequence', o['Type']) | |
2450 self.assertEqual(2, len(o['Dicom'])) | |
2451 self.assertEqual(2, len(o['Slices'])) | |
2452 self.assertEqual('/instances/%s/file' % i, o['Dicom'][0]) | |
2453 self.assertEqual('/instances/%s/file' % j, o['Dicom'][1]) | |
2454 self.assertEqual('/instances/%s/frames/0' % i, o['Slices'][0]) | |
2455 self.assertEqual('/instances/%s/frames/0' % j, o['Slices'][1]) | |
54
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2456 |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2457 |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2458 def test_incoming_movescu_accession(self): |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2459 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2460 |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2461 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2462 CallMoveScu([ '--study', '-k', '0008,0052=STUDY', '-k', 'AccessionNumber=nope' ]) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2463 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2464 CallMoveScu([ '--study', '-k', '0008,0052=PATIENT', '-k', 'AccessionNumber=A10003245599' ]) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2465 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2466 CallMoveScu([ '--study', '-k', '0008,0052=STUDY', '-k', 'AccessionNumber=A10003245599' ]) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2467 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) |
c5f8a6b0d85e
test_incoming_movescu_accession
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
2468 |
55 | 2469 |
2470 def test_dicom_to_json(self): | |
2471 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
2472 | |
2473 t = DoGet(_REMOTE, '/instances/%s/tags' % i) | |
2474 with open(GetDatabasePath('PrivateMDNTagsFull.json'), 'r') as f: | |
2475 self.assertEqual(json.loads(f.read()), t) | |
2476 | |
2477 t = DoGet(_REMOTE, '/instances/%s/tags?simplify' % i) | |
2478 with open(GetDatabasePath('PrivateMDNTagsSimplify.json'), 'r') as f: | |
2479 self.assertEqual(json.loads(f.read()), t) |