Mercurial > hg > orthanc-tests
annotate Tests/Tests.py @ 18:16c37933384d
test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Jun 2015 09:11:29 +0200 |
parents | 7c8500991a12 |
children | 2a29bcff60a7 |
rev | line source |
---|---|
3 | 1 # Orthanc - A Lightweight, RESTful DICOM Store |
2 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
3 # Department, University Hospital of Liege, Belgium | |
4 # | |
5 # This program is free software: you can redistribute it and/or | |
6 # modify it under the terms of the GNU General Public License as | |
7 # published by the Free Software Foundation, either version 3 of the | |
8 # License, or (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, but | |
11 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 # General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 | |
14 | 19 import tempfile |
3 | 20 import unittest |
21 | |
11 | 22 from PIL import ImageChops |
3 | 23 from Toolbox import * |
13 | 24 from xml.dom import minidom |
3 | 25 |
26 _LOCAL = None | |
27 _REMOTE = None | |
28 | |
29 | |
30 def SetOrthancParameters(local, remote): | |
31 global _LOCAL, _REMOTE | |
32 _LOCAL = local | |
33 _REMOTE = remote | |
34 | |
35 | |
14 | 36 def ExtractDicomTags(rawDicom, tags): |
37 with tempfile.NamedTemporaryFile(delete = True) as f: | |
38 f.write(rawDicom) | |
39 f.flush() | |
40 data = subprocess.check_output([ 'dcm2xml', f.name ]) | |
41 | |
42 result = [] | |
43 for tag in tags: | |
44 match = re.search('<element[^>]+name="%s">([^>]*)</element>' % tag, data) | |
45 if match == None: | |
46 result.append('') | |
47 else: | |
48 result.append(match.group(1)) | |
49 | |
50 return result | |
51 | |
52 | |
15 | 53 def InstallLuaScript(path): |
54 with open(GetDatabasePath(path), 'r') as f: | |
55 DoPost(_REMOTE, '/tools/execute-script', f.read(), 'application/lua') | |
56 | |
57 | |
58 def UninstallLuaCallbacks(): | |
59 DoPost(_REMOTE, '/tools/execute-script', 'function OnStoredInstance() end', 'application/lua') | |
60 | |
61 | |
62 | |
3 | 63 class Orthanc(unittest.TestCase): |
64 def setUp(self): | |
65 DropOrthanc(_LOCAL) | |
66 DropOrthanc(_REMOTE) | |
67 | |
68 def test_system(self): | |
69 self.assertTrue('Version' in DoGet(_REMOTE, '/system')) | |
70 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
71 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
72 | |
73 def test_upload(self): | |
74 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
75 self.assertEqual('Success', u['Status']) | |
76 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
77 self.assertEqual('AlreadyStored', u['Status']) | |
78 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
79 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
80 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
81 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
82 | |
83 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID']) | |
84 self.assertEqual('20070101', i['StudyDate']) | |
85 | |
86 | |
5 | 87 def test_upload_2(self): |
3 | 88 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] |
89 instance = DoGet(_REMOTE, '/instances/%s' % i) | |
90 self.assertEqual(i, instance['ID']) | |
91 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', | |
92 instance['MainDicomTags']['SOPInstanceUID']) | |
93 | |
94 series = DoGet(_REMOTE, '/series/%s' % instance['ParentSeries']) | |
95 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
96 series['MainDicomTags']['SeriesInstanceUID']) | |
97 | |
98 study = DoGet(_REMOTE, '/studies/%s' % series['ParentStudy']) | |
99 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
100 study['MainDicomTags']['StudyInstanceUID']) | |
101 | |
102 patient = DoGet(_REMOTE, '/patients/%s' % study['ParentPatient']) | |
103 self.assertEqual('ozp00SjY2xG', | |
104 patient['MainDicomTags']['PatientID']) | |
105 | |
106 dicom = DoGet(_REMOTE, '/instances/%s/file' % instance['ID']) | |
107 self.assertEqual(2472, len(dicom)) | |
108 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom)) | |
109 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
110 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/simplified-tags' % i)['StationName']) | |
111 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value']) | |
112 | |
113 | |
5 | 114 def test_images(self): |
115 i = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID'] | |
116 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
3 | 117 |
5 | 118 im = GetImage(_REMOTE, '/instances/%s/preview' % i) |
119 self.assertEqual("L", im.mode) | |
120 self.assertEqual(512, im.size[0]) | |
121 self.assertEqual(358, im.size[1]) | |
122 | |
123 im = GetImage(_REMOTE, '/instances/%s/image-uint8' % i) | |
124 self.assertEqual("L", im.mode) | |
125 self.assertEqual(512, im.size[0]) | |
126 self.assertEqual(358, im.size[1]) | |
127 | |
128 im = GetImage(_REMOTE, '/instances/%s/image-uint16' % i) | |
129 self.assertEqual(512, im.size[0]) | |
130 self.assertEqual(358, im.size[1]) | |
131 | |
132 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
133 self.assertEqual("L", im.mode) | |
134 self.assertEqual(512, im.size[0]) | |
135 self.assertEqual(358, im.size[1]) | |
136 | |
137 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
138 self.assertEqual("L", im.mode) | |
139 self.assertEqual(512, im.size[0]) | |
140 self.assertEqual(358, im.size[1]) | |
141 | |
142 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
143 self.assertEqual(512, im.size[0]) | |
144 self.assertEqual(358, im.size[1]) | |
145 | |
6 | 146 |
147 def test_hierarchy(self): | |
148 UploadFolder(_REMOTE, 'Brainix/Epi') | |
149 UploadFolder(_REMOTE, 'Brainix/Flair') | |
150 UploadFolder(_REMOTE, 'Knee/T1') | |
151 UploadFolder(_REMOTE, 'Knee/T2') | |
152 | |
153 p = DoGet(_REMOTE, '/patients') | |
154 s = DoGet(_REMOTE, '/studies') | |
155 t = DoGet(_REMOTE, '/series') | |
156 self.assertEqual(2, len(p)) | |
157 self.assertEqual(2, len(s)) | |
158 self.assertEqual(4, len(t)) | |
159 self.assertEqual(94, len(DoGet(_REMOTE, '/instances'))) | |
160 | |
161 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0' | |
162 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' | |
163 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8' | |
164 brainixFlair = '1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0' | |
165 | |
166 kneePatient = 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' | |
167 kneeStudy = '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918' | |
168 kneeT1 = '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285' | |
169 kneeT2 = 'bbf7a453-0d34251a-03663b55-46bb31b9-ffd74c59' | |
170 | |
171 self.assertTrue(brainixPatient in p) | |
172 self.assertTrue(kneePatient in p) | |
173 self.assertTrue(brainixStudy in s) | |
174 self.assertTrue(kneeStudy in s) | |
175 self.assertTrue(brainixEpi in t) | |
176 self.assertTrue(brainixFlair in t) | |
177 self.assertTrue(kneeT1 in t) | |
178 self.assertTrue(kneeT2 in t) | |
179 | |
180 self.assertEqual(44, len(DoGet(_REMOTE, '/patients/%s/instances' % brainixPatient))) | |
181 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % brainixPatient))) | |
182 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % brainixPatient))) | |
183 | |
184 self.assertEqual(50, len(DoGet(_REMOTE, '/patients/%s/instances' % kneePatient))) | |
185 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % kneePatient))) | |
186 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % kneePatient))) | |
187 | |
188 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % brainixStudy))) | |
189 self.assertEqual(44, len(DoGet(_REMOTE, '/studies/%s/instances' % brainixStudy))) | |
190 | |
191 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % kneeStudy))) | |
192 self.assertEqual(50, len(DoGet(_REMOTE, '/studies/%s/instances' % kneeStudy))) | |
193 | |
194 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixEpi))) | |
195 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixFlair))) | |
196 self.assertEqual(24, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT1))) | |
197 self.assertEqual(26, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT2))) | |
198 | |
199 for patient in p: | |
200 for study in DoGet(_REMOTE, '/patients/%s/studies' % patient): | |
201 self.assertEqual(patient, study['ParentPatient']) | |
202 for series in DoGet(_REMOTE, '/studies/%s/series' % study['ID']): | |
203 self.assertEqual(study['ID'], series['ParentStudy']) | |
204 for instance in DoGet(_REMOTE, '/series/%s/instances' % series['ID']): | |
205 self.assertEqual(series['ID'], instance['ParentSeries']) | |
206 | |
207 self.assertEqual(json.dumps(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance['ID'])), | |
208 json.dumps(DoGet(_REMOTE, '/instances/%s/tags' % instance['ID']))) | |
209 | |
210 | |
211 r = DoDelete(_REMOTE, "/studies/%s" % brainixStudy)['RemainingAncestor'] | |
212 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
213 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
214 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
215 self.assertEqual(50, len(DoGet(_REMOTE, '/instances'))) | |
216 self.assertEqual(None, r) | |
217 | |
218 r = DoDelete(_REMOTE, "/series/%s" % kneeT2)['RemainingAncestor'] | |
219 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
220 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
221 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
222 self.assertEqual(24, len(DoGet(_REMOTE, '/instances'))) | |
223 self.assertEqual('Study', r['Type']) | |
224 self.assertEqual(kneeStudy, r['ID']) | |
225 | |
226 r = DoDelete(_REMOTE, "/instances/%s" % DoGet(_REMOTE, '/instances')[0])['RemainingAncestor'] | |
227 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
228 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
229 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
230 self.assertEqual(23, len(DoGet(_REMOTE, '/instances'))) | |
231 self.assertEqual('Series', r['Type']) | |
232 self.assertEqual(kneeT1, r['ID']) | |
233 | |
234 r = DoDelete(_REMOTE, "/patients/%s" % kneePatient)['RemainingAncestor'] | |
235 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
236 self.assertEqual(0, len(DoGet(_REMOTE, '/studies'))) | |
237 self.assertEqual(0, len(DoGet(_REMOTE, '/series'))) | |
238 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
239 self.assertEqual(None, r) | |
240 | |
241 DropOrthanc(_REMOTE) | |
242 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize']) | |
243 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize']) | |
7 | 244 |
245 | |
246 def test_multi_frame(self): | |
247 i = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID'] | |
248 self.assertEqual(76, len(DoGet(_REMOTE, '/instances/%s/frames' % i))) | |
249 | |
250 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i) | |
251 self.assertEqual("L", im.mode) | |
252 self.assertEqual(512, im.size[0]) | |
253 self.assertEqual(512, im.size[1]) | |
254 | |
255 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint8' % i) | |
256 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint16' % i) | |
257 DoGet(_REMOTE, '/instances/%s/frames/75/preview' % i) | |
258 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/aaa/preview' % i)) | |
259 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/76/preview' % i)) | |
260 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
261 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
262 def test_changes(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
263 # Check emptiness |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
264 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
265 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
266 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
267 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
268 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
269 self.assertEqual(0, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
270 self.assertEqual(0, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
271 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
272 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
273 # Add 1 instance |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
274 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
|
275 c = DoGet(_REMOTE, '/changes') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
276 begin = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
277 self.assertEqual(4, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
278 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
279 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
|
280 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
281 c = DoGet(_REMOTE, '/changes?last') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
282 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
283 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
284 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
285 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
|
286 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
287 self.assertEqual(begin, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
288 self.assertTrue(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
289 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
|
290 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
291 self.assertEqual(begin - 1, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
292 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
293 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
|
294 self.assertEqual(1, len(c['Changes'])) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
295 self.assertEqual(begin - 2, c['Last']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
296 self.assertFalse(c['Done']) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
297 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
298 UploadFolder(_REMOTE, 'Knee/T1') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
299 UploadFolder(_REMOTE, 'Knee/T2') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
300 since = begin |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
301 countPatients = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
302 countStudies = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
303 countSeries = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
304 countInstances = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
305 completed = 0 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
306 while True: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
307 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
|
308 since = c['Last'] |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
309 for i in c['Changes']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
310 if i['ResourceType'] == 'Instance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
311 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
312 if i['ResourceType'] == 'Patient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
313 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
314 if i['ResourceType'] == 'Study': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
315 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
316 if i['ResourceType'] == 'Series': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
317 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
318 if i['ChangeType'] == 'NewInstance': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
319 countInstances += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
320 if i['ChangeType'] == 'NewPatient': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
321 countPatients += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
322 if i['ChangeType'] == 'NewStudy': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
323 countStudies += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
324 if i['ChangeType'] == 'NewSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
325 countSeries += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
326 if i['ChangeType'] == 'CompletedSeries': |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
327 completed += 1 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
328 self.assertTrue('ID' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
329 self.assertTrue('Path' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
330 self.assertTrue('Seq' in i) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
331 if c['Done']: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
332 break |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
333 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
334 self.assertEqual(2 * 50, countInstances) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
335 self.assertEqual(2 * 1, countPatients) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
336 self.assertEqual(2 * 1, countStudies) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
337 self.assertEqual(2 * 2, countSeries) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
338 self.assertEqual(0, completed) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
339 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
340 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
341 def test_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
342 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
|
343 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
|
344 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
345 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
|
346 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
347 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
348 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
|
349 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
350 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
351 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
|
352 self.assertEqual(1, len(z.namelist())) |
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 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
|
355 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
356 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
|
357 self.assertEqual(2, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
358 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
359 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
360 def test_media_archive(self): |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
361 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
|
362 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
|
363 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
364 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
|
365 self.assertEqual(3, len(z.namelist())) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
366 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
|
367 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
|
368 self.assertTrue('DICOMDIR' in z.namelist()) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
369 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
370 try: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
371 os.remove('/tmp/DICOMDIR') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
372 except: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
373 # The file does not exist |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
374 pass |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
375 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
376 z.extract('DICOMDIR', '/tmp') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
377 a = subprocess.check_output([ 'dciodvfy', '/tmp/DICOMDIR' ], |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
378 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
379 self.assertEqual(3, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
380 self.assertTrue(a[0].startswith('Warning')) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
381 self.assertEqual('BasicDirectory', a[1]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
382 self.assertEqual('', a[2]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
383 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
384 a = subprocess.check_output([ 'dcentvfy', '/tmp/DICOMDIR' ], |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
385 stderr = subprocess.STDOUT).split('\n') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
386 self.assertEqual(1, len(a)) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
387 self.assertEqual('', a[0]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
388 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
389 a = subprocess.check_output([ 'dcm2xml', '/tmp/DICOMDIR' ]) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
390 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
|
391 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
|
392 |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
7
diff
changeset
|
393 os.remove('/tmp/DICOMDIR') |
10 | 394 |
395 | |
396 def test_protection(self): | |
397 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
398 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
399 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
400 a = DoGet(_REMOTE, '/patients')[0] | |
401 b = DoGet(_REMOTE, '/patients')[1] | |
402 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
403 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
404 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
405 DoPut(_REMOTE, '/patients/%s/protected' % a, '1', 'text/plain') | |
406 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
407 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain') | |
408 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
409 | |
410 | |
12 | 411 def test_raw_tags(self): |
10 | 412 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] |
413 | |
414 dicom = DoGet(_REMOTE, '/instances/%s/file' % i) | |
415 self.assertEqual('1a7c56cb02d6e742cc9c856a8ac182e3', ComputeMD5(dicom)) | |
416 | |
417 s = '/instances/%s/content/' % i | |
418 | |
419 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, s + '0008-1010').strip()) | |
420 self.assertRaises(Exception, lambda: DoGet(_REMOTE, s + '0008-1011')) | |
421 | |
422 self.assertEqual('Abdomen', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/0/7fe1-1057').strip()) | |
423 self.assertEqual('cla_3c', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/8/7fe1-1057').strip()) | |
424 | |
425 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm') | |
426 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
427 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
428 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
429 | |
430 for i in DoGet(_REMOTE, '/instances'): | |
431 aid = DoGet(_REMOTE, '/instances/%s' % i)['MainDicomTags']['SOPInstanceUID'] | |
432 self.assertEqual(aid, DoGet(_REMOTE, '/instances/%s/content/0008-0018' % i).replace(chr(0), '')) | |
433 | |
434 | |
435 def test_raw_tags_mdn(self): | |
436 # Bug reported by Cyril Paulus | |
437 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
438 self.assertAlmostEqual(0.000027, DoGet(_REMOTE, '/instances/%s/content/7053-1000' % i)) | |
439 | |
440 | |
441 def test_modify_instance(self): | |
442 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID'] | |
443 modified = DoPost(_REMOTE, '/instances/%s/modify' % i, | |
444 json.dumps({ | |
445 "Replace" : { | |
446 "PatientName" : "hello", | |
447 #"PatientID" : "world" | |
448 }, | |
449 "Remove" : [ "StationName" ], | |
450 "RemovePrivateTags" : None | |
451 }), | |
452 'application/json') | |
453 j = DoPost(_REMOTE, '/instances', modified, 'application/dicom')['ID'] | |
454 | |
455 self.assertNotEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
456 #self.assertNotEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % i).strip()) | |
457 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i).strip()) | |
458 DoGet(_REMOTE, '/instances/%s/content/6003-1010' % i) # Some private tag | |
459 | |
460 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
461 #self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % j).strip()) | |
462 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j)) | |
463 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/6003-1010' % j)) | |
464 | |
465 | |
466 def test_modify_series(self): | |
467 # Upload 4 images from the same series | |
468 for i in range(4): | |
469 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
470 | |
471 origSeries = DoGet(_REMOTE, '/series')[0] | |
472 newSeries = DoPost(_REMOTE, '/series/%s/modify' % origSeries, | |
473 '{"Replace":{"PatientName":"Jodogne"}}', | |
474 'application/json')['ID'] | |
475 | |
476 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['ModifiedFrom']) | |
477 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
478 self.assertEqual(4, len(instances)) | |
479 for i in instances: | |
480 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
481 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
482 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
483 | |
484 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
485 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
486 | |
487 | |
488 def test_modify_study(self): | |
489 # Upload 4 images from the 2 series of the same study | |
490 for i in range(4): | |
491 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
492 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
493 | |
494 origStudy = DoGet(_REMOTE, '/studies')[0] | |
495 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
496 '{"Replace":{"PatientName":"Jodogne"}}', | |
497 'application/json')['ID'] | |
498 | |
499 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['ModifiedFrom']) | |
500 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
501 self.assertEqual(2, len(series)) | |
502 for s in series: | |
503 ss = DoGet(_REMOTE, '/series/%s' % s)['ModifiedFrom'] | |
504 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
505 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
506 | |
507 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
508 for i in instances: | |
509 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom'] | |
510 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
511 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
512 | |
513 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
514 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
515 | |
516 | |
517 def test_anonymize_series(self): | |
518 # Upload 4 images from the same series | |
519 for i in range(4): | |
520 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
521 | |
522 origSeries = DoGet(_REMOTE, '/series')[0] | |
523 newSeries = DoPost(_REMOTE, '/series/%s/anonymize' % origSeries, | |
524 '{}', | |
525 'application/json')['ID'] | |
526 | |
527 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['AnonymizedFrom']) | |
528 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances'] | |
529 self.assertEqual(4, len(instances)) | |
530 for i in instances: | |
531 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
532 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
533 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
534 | |
535 DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j) | |
536 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i)) | |
537 | |
538 | |
539 def test_anonymize_study(self): | |
540 # Upload 4 images from the 2 series of the same study | |
541 for i in range(4): | |
542 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
543 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
544 | |
545 origStudy = DoGet(_REMOTE, '/studies')[0] | |
546 newStudy = DoPost(_REMOTE,'/studies/%s/anonymize' % origStudy, | |
547 '{"Replace":{"PatientName":"Jodogne"}}', | |
548 'application/json')['ID'] | |
549 | |
550 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['AnonymizedFrom']) | |
551 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series'] | |
552 self.assertEqual(2, len(series)) | |
553 for s in series: | |
554 ss = DoGet(_REMOTE, '/series/%s' % s)['AnonymizedFrom'] | |
555 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy']) | |
556 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy']) | |
557 | |
558 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances'] | |
559 for i in instances: | |
560 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom'] | |
561 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries']) | |
562 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries']) | |
563 | |
564 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip()) | |
565 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip()) | |
11 | 566 |
567 | |
568 | |
569 def test_storescu(self): | |
570 # Check emptiness | |
571 e = DoGet(_REMOTE, '/exports') | |
572 self.assertEqual(0, len(e['Exports'])) | |
573 self.assertEqual(0, e['Last']) | |
574 self.assertTrue(e['Done']) | |
575 e = DoGet(_REMOTE, '/exports?last') | |
576 self.assertEqual(0, len(e['Exports'])) | |
577 self.assertEqual(0, e['Last']) | |
578 self.assertTrue(e['Done']) | |
579 | |
580 # Add 1 instance | |
581 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
582 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
583 | |
584 # Export the instance | |
585 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') # instance | |
586 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
587 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
588 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
589 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
590 | |
591 e = DoGet(_REMOTE, '/exports') | |
592 self.assertEqual(1, len(e['Exports'])) | |
593 self.assertTrue(e['Done']) | |
594 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
595 e = DoGet(_REMOTE, '/exports?limit=1') | |
596 self.assertEqual(1, len(e['Exports'])) | |
597 self.assertTrue(e['Done']) | |
598 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
599 e = DoGet(_REMOTE, '/exports?last') | |
600 self.assertEqual(1, len(e['Exports'])) | |
601 self.assertTrue(e['Done']) | |
602 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
603 seqInstance = e['Last'] | |
604 | |
605 # Export the series | |
606 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', 'text/plain') | |
607 | |
608 e = DoGet(_REMOTE, '/exports') | |
609 self.assertEqual(2, len(e['Exports'])) | |
610 self.assertTrue(e['Done']) | |
611 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
612 seqSeries = e['Last'] | |
613 self.assertNotEqual(seqInstance, seqSeries) | |
614 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
615 self.assertEqual(1, len(e['Exports'])) | |
616 self.assertFalse(e['Done']) | |
617 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
618 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
619 self.assertEqual(1, len(e['Exports'])) | |
620 self.assertTrue(e['Done']) | |
621 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
622 e = DoGet(_REMOTE, '/exports?last') | |
623 self.assertEqual(1, len(e['Exports'])) | |
624 self.assertTrue(e['Done']) | |
625 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
626 | |
627 # Export the study | |
628 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', 'text/plain') | |
629 seqStudy = DoGet(_REMOTE, '/exports')['Last'] | |
630 | |
631 # Export the patient | |
632 j = DoPost(_REMOTE, '/modalities/orthanctest/store', '6816cb19-844d5aee-85245eba-28e841e6-2414fae2', 'text/plain') | |
633 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
634 self.assertEqual(1, len(DoGet(_LOCAL, '/studies'))) | |
635 self.assertEqual(1, len(DoGet(_LOCAL, '/series'))) | |
636 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
637 | |
638 e = DoGet(_REMOTE, '/exports') | |
639 self.assertEqual(4, len(e['Exports'])) | |
640 self.assertTrue(e['Done']) | |
641 self.assertEqual(e['Exports'][-1]['Seq'], e['Last']) | |
642 seqPatient = e['Last'] | |
643 self.assertNotEqual(seqInstance, seqSeries) | |
644 self.assertNotEqual(seqSeries, seqStudy) | |
645 self.assertNotEqual(seqStudy, seqPatient) | |
646 self.assertTrue(seqInstance < seqSeries) | |
647 self.assertTrue(seqSeries < seqStudy) | |
648 self.assertTrue(seqStudy < seqPatient) | |
649 e = DoGet(_REMOTE, '/exports?limit=1&since=0') | |
650 self.assertEqual(1, len(e['Exports'])) | |
651 self.assertFalse(e['Done']) | |
652 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance) | |
653 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance)) | |
654 self.assertEqual(1, len(e['Exports'])) | |
655 self.assertFalse(e['Done']) | |
656 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries) | |
657 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqSeries)) | |
658 self.assertEqual(1, len(e['Exports'])) | |
659 self.assertFalse(e['Done']) | |
660 self.assertEqual(e['Exports'][-1]['Seq'], seqStudy) | |
661 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqStudy)) | |
662 self.assertEqual(1, len(e['Exports'])) | |
663 self.assertTrue(e['Done']) | |
664 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
665 e = DoGet(_REMOTE, '/exports?last') | |
666 self.assertEqual(1, len(e['Exports'])) | |
667 self.assertTrue(e['Done']) | |
668 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient) | |
669 | |
670 | |
671 # Check the content of the logged information | |
672 e = DoGet(_REMOTE, '/exports')['Exports'] | |
673 | |
674 if 'PatientID' in e[0]: | |
675 # Since Orthanc 0.8.6 | |
676 patient = 'PatientID' | |
677 study = 'StudyInstanceUID' | |
678 series = 'SeriesInstanceUID' | |
679 instance = 'SOPInstanceUID' | |
680 else: | |
681 # Up to Orthanc 0.8.5 | |
682 patient = 'PatientId' | |
683 study = 'StudyInstanceUid' | |
684 series = 'SeriesInstanceUid' | |
685 instance = 'SopInstanceUid' | |
686 | |
687 for k in range(4): | |
688 self.assertTrue('Date' in e[k]) | |
689 self.assertTrue('Seq' in e[k]) | |
690 self.assertEqual('orthanctest', e[k]['RemoteModality']) | |
691 | |
692 self.assertEqual(10, len(e[0])) | |
693 self.assertEqual('Instance', e[0]['ResourceType']) | |
694 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['ID']) | |
695 self.assertEqual('/instances/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['Path']) | |
696 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', e[0][instance]) | |
697 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[0][series]) | |
698 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[0][study]) | |
699 self.assertEqual('ozp00SjY2xG', e[0][patient]) | |
700 | |
701 self.assertEqual(9, len(e[1])) | |
702 self.assertEqual('Series', e[1]['ResourceType']) | |
703 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['ID']) | |
704 self.assertEqual('/series/f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['Path']) | |
705 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[1][series]) | |
706 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[1][study]) | |
707 self.assertEqual('ozp00SjY2xG', e[1][patient]) | |
708 | |
709 self.assertEqual(8, len(e[2])) | |
710 self.assertEqual('Study', e[2]['ResourceType']) | |
711 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['ID']) | |
712 self.assertEqual('/studies/b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['Path']) | |
713 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[2][study]) | |
714 self.assertEqual('ozp00SjY2xG', e[2][patient]) | |
715 | |
716 self.assertEqual(7, len(e[3])) | |
717 self.assertEqual('Patient', e[3]['ResourceType']) | |
718 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['ID']) | |
719 self.assertEqual('/patients/6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['Path']) | |
720 self.assertEqual('ozp00SjY2xG', e[3][patient]) | |
721 | |
722 DropOrthanc(_REMOTE) | |
723 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
724 | |
725 | |
726 def test_store_peer(self): | |
727 self.assertEqual(0, len(DoGet(_LOCAL, '/exports')['Exports'])) | |
728 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
729 | |
730 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
731 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
732 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
733 | |
734 j = DoPost(_REMOTE, '/peers/peer/store', str(i), 'text/plain') | |
735 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
736 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
737 | |
738 self.assertEqual(1, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
739 | |
740 DropOrthanc(_REMOTE) | |
741 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports'])) | |
742 | |
743 | |
744 def test_bulk_storescu(self): | |
745 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
746 | |
747 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
748 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm') | |
749 | |
750 j = DoPost(_REMOTE, '/modalities/orthanctest/store', [ a['ID'], b['ID'] ], 'application/json') | |
751 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
752 | |
753 DropOrthanc(_LOCAL) | |
754 | |
755 # Send using patient's UUID | |
756 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
757 j = DoPost(_REMOTE, '/modalities/orthanctest/store', | |
758 [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ], 'application/json') | |
759 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
760 | |
761 | |
762 def test_color(self): | |
763 i = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID'] | |
764 im = GetImage(_REMOTE, '/instances/%s/preview' % i) | |
765 self.assertEqual("RGB", im.mode) | |
766 self.assertEqual(41, im.size[0]) | |
767 self.assertEqual(41, im.size[1]) | |
768 | |
769 # http://effbot.org/zone/pil-comparing-images.htm | |
13 | 770 truth = Image.open(GetDatabasePath('ColorTestMalaterre.png')) |
11 | 771 self.assertTrue(ImageChops.difference(im, truth).getbbox() is None) |
772 | |
773 | |
12 | 774 def test_faking_ruby_put(self): |
775 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
776 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
777 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
778 a = DoGet(_REMOTE, '/patients')[0] | |
779 b = DoGet(_REMOTE, '/patients')[1] | |
780 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
781 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
782 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
783 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '1') | |
784 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
785 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0') | |
786 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
787 | |
788 | |
789 def test_faking_ruby_delete(self): | |
790 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
791 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
792 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
793 a = DoGet(_REMOTE, '/patients')[0] | |
794 b = DoGet(_REMOTE, '/patients')[1] | |
795 DoGet(_REMOTE, '/patients/%s' % a, data = { '_method' : 'DELETE' }) | |
796 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
797 DoGet(_REMOTE, '/patients/%s' % b, data = { '_method' : 'DELETE' }) | |
798 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
799 | |
800 | |
801 def test_faking_google_put(self): | |
802 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
803 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
804 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
805 a = DoGet(_REMOTE, '/patients')[0] | |
806 b = DoGet(_REMOTE, '/patients')[1] | |
807 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
808 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
809 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
810 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '1') | |
811 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
812 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0') | |
813 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a)) | |
814 | |
815 | |
816 def test_faking_google_delete(self): | |
817 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
818 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
819 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
820 a = DoGet(_REMOTE, '/patients')[0] | |
821 b = DoGet(_REMOTE, '/patients')[1] | |
822 DoPost(_REMOTE, '/patients/%s' % a, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
823 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
824 DoPost(_REMOTE, '/patients/%s' % b, headers = { 'X-HTTP-Method-Override' : 'DELETE' }) | |
825 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
826 | |
827 | |
828 def test_lua(self): | |
829 self.assertEqual(42, DoPost(_REMOTE, '/tools/execute-script', 'print(42)')) | |
830 self.assertTrue(IsDefinedInLua(_REMOTE, 'PrintRecursive')) | |
831 self.assertFalse(IsDefinedInLua(_REMOTE, 'HelloWorld')) | |
832 | |
833 | |
834 def test_metadata(self): | |
835 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm') | |
836 p = DoGet(_REMOTE, '/patients')[0] | |
837 i = DoGet(_REMOTE, '/instances')[0] | |
838 | |
839 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
840 self.assertEqual(1, len(m)) | |
841 self.assertEqual('LastUpdate', m[0]) | |
842 | |
843 m = DoGet(_REMOTE, '/instances/%s/metadata' % i) | |
844 self.assertEqual(3, len(m)) | |
845 self.assertTrue('IndexInSeries' in m) | |
846 self.assertTrue('ReceptionDate' in m) | |
847 self.assertTrue('RemoteAET' in m) | |
848 | |
849 # Play with custom metadata | |
850 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'coucou') | |
851 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
852 self.assertEqual(2, len(m)) | |
853 self.assertTrue('LastUpdate' in m) | |
854 self.assertTrue('5555' in m) | |
855 self.assertEqual('coucou', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
856 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'hello') | |
857 self.assertEqual('hello', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p)) | |
858 DoDelete(_REMOTE, '/patients/%s/metadata/5555' % p) | |
859 m = DoGet(_REMOTE, '/patients/%s/metadata' % p) | |
860 self.assertEqual(1, len(m)) | |
861 self.assertTrue('LastUpdate' in m) | |
13 | 862 |
863 | |
864 def test_statistics(self): | |
865 # Upload 16 instances | |
866 for i in range(4): | |
867 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
868 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
869 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
870 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
871 | |
872 s = DoGet(_REMOTE, '/statistics') | |
873 self.assertEqual(16, s['CountInstances']) | |
874 self.assertEqual(2, s['CountPatients']) | |
875 self.assertEqual(2, s['CountStudies']) | |
876 self.assertEqual(4, s['CountSeries']) | |
877 d = int(s['TotalUncompressedSize']) | |
878 | |
879 e = 0 | |
880 for patient in DoGet(_REMOTE, '/patients'): | |
881 s = DoGet(_REMOTE, '/patients/%s/statistics' % patient) | |
882 self.assertEqual(8, s['CountInstances']) | |
883 self.assertEqual(1, s['CountStudies']) | |
884 self.assertEqual(2, s['CountSeries']) | |
885 e += int(s['UncompressedSize']) | |
886 | |
887 for study in DoGet(_REMOTE, '/studies'): | |
888 s = DoGet(_REMOTE, '/studies/%s/statistics' % study) | |
889 self.assertEqual(8, s['CountInstances']) | |
890 self.assertEqual(2, s['CountSeries']) | |
891 e += int(s['UncompressedSize']) | |
892 | |
893 for series in DoGet(_REMOTE, '/series'): | |
894 s = DoGet(_REMOTE, '/series/%s/statistics' % series) | |
895 self.assertEqual(4, s['CountInstances']) | |
896 e += int(s['UncompressedSize']) | |
897 | |
898 self.assertEqual(3 * d, e) | |
899 | |
900 | |
901 def test_custom_attachment(self): | |
902 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm') | |
903 patient = DoGet(_REMOTE, '/patients')[0] | |
904 instance = DoGet(_REMOTE, '/instances')[0] | |
905 size = int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']) | |
906 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
907 | |
908 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
909 self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % instance))) | |
910 self.assertTrue('dicom' in DoGet(_REMOTE, '/instances/%s/attachments' % instance)) | |
911 self.assertTrue('dicom-as-json' in DoGet(_REMOTE, '/instances/%s/attachments' % instance)) | |
912 | |
913 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/patients/%s/attachments/22' % patient, 'hello')) | |
914 hello = 'hellohellohellohellohellohellohellohellohello' | |
915 DoPut(_REMOTE, '/patients/%s/attachments/1025' % patient, hello) | |
916 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
917 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
918 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
919 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1025/compressed-size' % patient))) | |
920 | |
921 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world') | |
922 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
923 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
924 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
925 size + | |
926 int(DoGet(_REMOTE, '/patients/%s/attachments/1025/compressed-size' % patient)) + | |
927 int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient))) | |
928 | |
929 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
930 self.assertEqual(hello, DoGet(_REMOTE, '/patients/%s/attachments/1025/data' % patient)) | |
931 self.assertEqual('world', DoGet(_REMOTE, '/patients/%s/attachments/1026/data' % patient)) | |
932 DoPost(_REMOTE, '/patients/%s/attachments/1025/verify-md5' % patient) | |
933 DoPost(_REMOTE, '/patients/%s/attachments/1026/verify-md5' % patient) | |
934 DoPut(_REMOTE, '/patients/%s/attachments/1026' % patient, 'world2') | |
935 self.assertEqual('world2', DoGet(_REMOTE, '/patients/%s/attachments/1026/data' % patient)) | |
936 | |
937 self.assertRaises(Exception, lambda: DoDelete(_REMOTE, '/instances/%s/attachments/dicom' % instance)) | |
938 DoDelete(_REMOTE, '/patients/%s/attachments/1025' % patient) | |
939 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
940 int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
941 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), | |
942 size + int(DoGet(_REMOTE, '/patients/%s/attachments/1026/compressed-size' % patient))) | |
943 | |
944 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
945 DoDelete(_REMOTE, '/patients/%s/attachments/1026' % patient) | |
946 self.assertEqual(0, len(DoGet(_REMOTE, '/patients/%s/attachments' % patient))) | |
947 | |
948 self.assertEqual(int(DoGet(_REMOTE, '/patients/%s/statistics' % patient)['DiskSize']), size) | |
949 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) | |
950 | |
951 | |
952 def test_incoming_storescu(self): | |
953 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
954 subprocess.check_call([ 'storescu', _REMOTE['Server'], str(_REMOTE['DicomPort']), | |
955 GetDatabasePath('ColorTestImageJ.dcm') ]) | |
956 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
957 | |
958 | |
959 def test_incoming_findscu(self): | |
960 def CallFindScu(args): | |
961 p = subprocess.Popen([ 'findscu', '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'], | |
962 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, | |
963 stderr=subprocess.PIPE) | |
964 return p.communicate()[1] | |
965 | |
966 UploadInstance(_REMOTE, 'Multiframe.dcm') | |
967 UploadInstance(_REMOTE, 'ColorTestImageJ.dcm') | |
968 | |
969 i = CallFindScu([ '-k', '0008,0052=PATIENT', '-k', '0010,0010' ]) | |
970 patientNames = re.findall('\(0010,0010\).*?\[(.*?)\]', i) | |
971 self.assertEqual(2, len(patientNames)) | |
972 self.assertTrue('Test Patient BG ' in patientNames) | |
973 self.assertTrue('Anonymized' in patientNames) | |
974 | |
975 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', '0008,0021' ]) | |
976 series = re.findall('\(0008,0021\).*?\[\s*(.*?)\s*\]', i) | |
977 self.assertEqual(2, len(series)) | |
978 self.assertTrue('20070208' in series) | |
979 self.assertTrue('19980312' in series) | |
980 | |
981 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', 'PatientName=Anonymized' ]) | |
982 series = re.findall('\(0010,0010\).*?\[\s*(.*?)\s*\]', i) | |
983 self.assertEqual(1, len(series)) | |
984 | |
985 # Test the "CaseSentitivePN" flag (false by default) | |
986 i = CallFindScu([ '-k', '0008,0052=SERIES', '-k', 'PatientName=anonymized' ]) | |
987 series = re.findall('\(0010,0010\).*?\[\s*(.*?)\s*\]', i) | |
988 self.assertEqual(1, len(series)) | |
989 | |
990 | |
991 def test_incoming_movescu(self): | |
992 def CallMoveScu(args): | |
993 subprocess.check_call([ 'movescu', | |
17 | 994 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp) |
995 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc) | |
996 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp) | |
13 | 997 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, |
998 stderr=subprocess.PIPE) | |
999 | |
1000 UploadInstance(_REMOTE, 'Multiframe.dcm') | |
1001 | |
1002 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
17 | 1003 CallMoveScu([ '--patient', '-k', '0008,0052=PATIENT', '-k', 'PatientID=none' ]) |
13 | 1004 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) |
1005 CallMoveScu([ '--patient', '-k', '0008,0052=PATIENT', '-k', 'PatientID=12345678' ]) | |
1006 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
1007 | |
1008 | |
1009 def test_findscu(self): | |
1010 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1011 j = UploadInstance(_REMOTE, 'Issue22.dcm')['ID'] | |
1012 k = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID'] | |
1013 DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1014 | |
1015 # Test the "find-patient" level | |
1016 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }) | |
1017 self.assertEqual(1, len(p)) | |
1018 self.assertEqual('ozp00SjY2xG', p[0]['PatientID']) | |
1019 | |
1020 # Test wildcards constraints. The "LO" value representation | |
1021 # for PatientID is always case-sensitive, but the "PN" for | |
1022 # PatientName might depend on the implementation: | |
1023 # "GenerateConfigurationForTests.py" will force it to be case | |
1024 # insensitive (which was the default until Orthanc 0.8.6). | |
1025 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'K*' }) | |
1026 self.assertEqual(1, len(p)) | |
1027 | |
1028 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'k*' }) | |
1029 self.assertEqual(1, len(p)) | |
1030 | |
1031 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : 'ozp*' }) | |
1032 self.assertEqual(1, len(p)) | |
1033 | |
1034 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : 'o?p*' }) | |
1035 self.assertEqual(1, len(p)) | |
1036 | |
1037 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientID' : '0?q*' }) | |
1038 self.assertEqual(0, len(p)) | |
1039 | |
1040 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'B*' }) | |
1041 self.assertEqual(0, len(p)) | |
1042 | |
1043 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'b*' }) | |
1044 self.assertEqual(0, len(p)) | |
1045 | |
1046 DoPost(_REMOTE, '/modalities/orthanctest/store', str(j), 'text/plain') | |
1047 DoPost(_REMOTE, '/modalities/orthanctest/store', str(k), 'text/plain') | |
1048 DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }) | |
1049 self.assertEqual(3, len(DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { }))) | |
1050 | |
1051 p = DoPost(_REMOTE, '/modalities/orthanctest/find-patient', { 'PatientName' : 'A*' }) | |
1052 self.assertEqual(2, len(p)) | |
1053 | |
1054 # Test the "find-study" level. This is the instance "ColorTestImageJ.dcm" | |
1055 s = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ' }) | |
1056 self.assertEqual(1, len(s)) | |
1057 self.assertEqual('20070208', s[0]['StudyDate']) | |
1058 | |
1059 # Test range searches | |
1060 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1061 'StudyDate' : '-20070101' }) | |
1062 self.assertEqual(0, len(t)) | |
1063 | |
1064 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1065 'StudyDate' : '20090101-' }) | |
1066 self.assertEqual(0, len(t)) | |
1067 | |
1068 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1069 'StudyDate' : '20070101-' }) | |
1070 self.assertEqual(1, len(t)) | |
1071 | |
1072 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1073 'StudyDate' : '-20090101' }) | |
1074 self.assertEqual(1, len(t)) | |
1075 | |
1076 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1077 'StudyDate' : '20070207-20070207' }) | |
1078 self.assertEqual(0, len(t)) | |
1079 | |
1080 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1081 'StudyDate' : '20070208-20070208' }) | |
1082 self.assertEqual(1, len(t)) | |
1083 | |
1084 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { 'PatientID' : 'B9uTHKOZ', | |
1085 'StudyDate' : '20070209-20070209' }) | |
1086 self.assertEqual(0, len(t)) | |
1087 | |
1088 # Test the ModalitiesInStudy tag | |
1089 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1090 'PatientID' : 'B9uTHKOZ', | |
1091 'ModalitiesInStudy' : 'US' }) | |
1092 self.assertEqual(0, len(t)) | |
1093 | |
1094 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1095 'PatientID' : 'B9uTHKOZ', | |
1096 'ModalitiesInStudy' : 'CT' }) | |
1097 self.assertEqual(1, len(t)) | |
1098 | |
1099 t = DoPost(_REMOTE, '/modalities/orthanctest/find-study', { | |
1100 'PatientID' : 'B9uTHKOZ', | |
1101 'ModalitiesInStudy' : 'US\\CT' }) | |
1102 self.assertEqual(1, len(t)) | |
1103 | |
1104 # Test the "find-series" level | |
1105 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1106 'PatientID' : 'B9uTHKOZ', | |
1107 'StudyInstanceUID' : s[0]['StudyInstanceUID'] }) | |
1108 self.assertEqual(1, len(t)) | |
1109 | |
1110 # Test "\" separator | |
1111 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1112 'PatientID' : 'B9uTHKOZ', | |
1113 'StudyInstanceUID' : s[0]['StudyInstanceUID'], | |
1114 'Modality' : 'MR\\CT\\US' }) | |
1115 self.assertEqual(1, len(t)) | |
1116 | |
1117 t = DoPost(_REMOTE, '/modalities/orthanctest/find-series', { | |
1118 'PatientID' : 'B9uTHKOZ', | |
1119 'StudyInstanceUID' : s[0]['StudyInstanceUID'], | |
1120 'Modality' : 'MR\\US' }) | |
1121 self.assertEqual(0, len(t)) | |
1122 | |
1123 | |
1124 def test_update_modalities(self): | |
1125 try: | |
1126 DoDelete(_REMOTE, '/modalities/toto') | |
1127 except: | |
1128 pass | |
1129 try: | |
1130 DoDelete(_REMOTE, '/modalities/tata') | |
1131 except: | |
1132 pass | |
1133 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/toto')) | |
1134 DoPut(_REMOTE, '/modalities/toto', [ "STORESCP", "localhost", 2000 ]) | |
1135 DoPut(_REMOTE, '/modalities/tata', [ "STORESCP", "localhost", 2000, 'MedInria' ]) | |
1136 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/modalities/toto', [ "STORESCP", "localhost", 2000, 'MedInriaaa' ])) | |
1137 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/toto')) | |
1138 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/tata')) | |
1139 DoDelete(_REMOTE, '/modalities/toto') | |
1140 DoDelete(_REMOTE, '/modalities/tata') | |
1141 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/toto')) | |
1142 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/modalities/tata')) | |
1143 | |
1144 | |
1145 def test_update_peers(self): | |
1146 # curl -X PUT http://localhost:8042/peers/toto -d '["http://localhost:8042/"]' -v | |
1147 try: | |
1148 DoDelete(_REMOTE, '/peers/toto') | |
1149 except: | |
1150 pass | |
1151 try: | |
1152 DoDelete(_REMOTE, '/peers/tata') | |
1153 except: | |
1154 pass | |
1155 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/toto')) | |
1156 DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/' ]) | |
1157 DoPut(_REMOTE, '/peers/tata', [ 'http://localhost:8042/', 'user', 'pass' ]) | |
1158 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/', 'a' ])) | |
1159 self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/peers/toto', [ 'http://localhost:8042/', 'a', 'b', 'c' ])) | |
1160 self.assertTrue('store' in DoGet(_REMOTE, '/peers/toto')) | |
1161 self.assertTrue('store' in DoGet(_REMOTE, '/peers/tata')) | |
1162 DoDelete(_REMOTE, '/peers/toto') | |
1163 DoDelete(_REMOTE, '/peers/tata') | |
1164 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/toto')) | |
1165 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/peers/tata')) | |
1166 | |
1167 | |
1168 def test_mesterhazy_modification(self): | |
1169 # When I modify a series ( eg. curl | |
1170 # http://localhost:8042/series/uidhere/modify -X POST -d | |
1171 # '{"Replace":{"SeriesDate":"19990101"}}' ) the modified | |
1172 # series is added to a new Study, instead of the existing | |
1173 # Study. Fixed in Orthanc 0.7.5 | |
1174 | |
1175 u = UploadInstance(_REMOTE, 'DummyCT.dcm') | |
1176 study = 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0' | |
1177 series = 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe' | |
1178 | |
1179 modified = DoPost(_REMOTE, '/series/%s/modify' % series, | |
1180 json.dumps({ "Replace" : { "SeriesDate" : "19990101" }})) | |
1181 | |
1182 self.assertEqual(study, DoGet(_REMOTE, '/series/%s' % modified['ID']) ['ParentStudy']) | |
1183 | |
1184 | |
1185 def test_create(self): | |
1186 i = DoPost(_REMOTE, '/tools/create-dicom', | |
1187 json.dumps({ | |
1188 'PatientName' : 'Jodogne', | |
1189 'Modality' : 'CT', | |
1190 'PixelData' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' # red dot in RGBA | |
1191 })) | |
1192 | |
1193 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i['ID']).strip()) | |
1194 self.assertEqual('CT', DoGet(_REMOTE, '/instances/%s/content/Modality' % i['ID']).strip()) | |
1195 | |
1196 png = GetImage(_REMOTE, '/instances/%s/preview' % i['ID']) | |
1197 self.assertEqual((5, 5), png.size) | |
1198 | |
1199 | |
1200 def test_pilates(self): | |
1201 # "SCU failed error when accessing orthanc with osirix" by | |
1202 # Pilates Agentur (Mar 10, 2014 at 9:33 PM) | |
1203 i = UploadInstance(_REMOTE, 'PilatesArgenturGEUltrasoundOsiriX.dcm')['ID'] | |
1204 self.assertEqual(0, len(DoGet(_LOCAL, '/patients'))) | |
1205 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1206 self.assertEqual(1, len(DoGet(_LOCAL, '/patients'))) | |
1207 | |
1208 | |
1209 def test_shared_tags(self): | |
1210 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1211 b = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0002.dcm')['ID'] | |
1212 p = DoGet(_REMOTE, '/patients')[0] | |
1213 | |
1214 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1215 self.assertTrue('PatientName' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1216 self.assertTrue('0008,1030' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1217 self.assertTrue('StudyDescription' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1218 self.assertTrue('0008,103e' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1219 self.assertTrue('SeriesDescription' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1220 self.assertFalse('0008,0018' in DoGet(_REMOTE, '/patients/%s/shared-tags' % p)) | |
1221 self.assertFalse('SOPInstanceUID' in DoGet(_REMOTE, '/patients/%s/shared-tags?simplify' % p)) | |
1222 | |
1223 self.assertTrue('0008,0018' in DoGet(_REMOTE, '/instances/%s/tags' % a)) | |
1224 self.assertTrue('SOPInstanceUID' in DoGet(_REMOTE, '/instances/%s/tags?simplify' % a)) | |
1225 | |
1226 | |
1227 def test_modules(self): | |
1228 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1229 p = DoGet(_REMOTE, '/patients')[0] | |
1230 s = DoGet(_REMOTE, '/studies')[0] | |
1231 t = DoGet(_REMOTE, '/series')[0] | |
1232 | |
1233 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/patients/%s/module' % p)) | |
1234 self.assertTrue('PatientName' in DoGet(_REMOTE, '/patients/%s/module?simplify' % p)) | |
1235 self.assertTrue('0010,0010' in DoGet(_REMOTE, '/studies/%s/module-patient' % p)) | |
1236 self.assertTrue('PatientName' in DoGet(_REMOTE, '/studies/%s/module-patient?simplify' % p)) | |
1237 self.assertTrue('0008,1030' in DoGet(_REMOTE, '/studies/%s/module' % s)) | |
1238 self.assertTrue('StudyDescription' in DoGet(_REMOTE, '/studies/%s/module?simplify' % s)) | |
1239 self.assertTrue('0008,103e' in DoGet(_REMOTE, '/series/%s/module' % p)) | |
1240 self.assertTrue('SeriesDescription' in DoGet(_REMOTE, '/series/%s/module?simplify' % p)) | |
1241 self.assertTrue('0008,0018' in DoGet(_REMOTE, '/instances/%s/module' % a)) | |
1242 self.assertTrue('SOPInstanceUID' in DoGet(_REMOTE, '/instances/%s/module?simplify' % a)) | |
1243 | |
1244 | |
1245 def test_auto_directory(self): | |
1246 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1247 self.assertTrue('now' in DoGet(_REMOTE, '/tools')) | |
1248 self.assertTrue('dicom-conformance' in DoGet(_REMOTE, '/tools')) | |
1249 self.assertTrue(len(DoGet(_REMOTE, '/tools/dicom-conformance')) > 1000) | |
1250 self.assertTrue('orthanctest' in DoGet(_REMOTE, '/modalities')) | |
1251 self.assertTrue('echo' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1252 self.assertTrue('find' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1253 self.assertTrue('find-instance' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1254 self.assertTrue('find-patient' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1255 self.assertTrue('find-series' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1256 self.assertTrue('find-study' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1257 self.assertTrue('store' in DoGet(_REMOTE, '/modalities/orthanctest')) | |
1258 self.assertTrue('store' in DoGet(_REMOTE, '/peers/peer')) | |
1259 self.assertTrue('matlab' in DoGet(_REMOTE, '/instances/%s/frames/0' % a)) | |
1260 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/tools/nope')) | |
1261 | |
1262 | |
1263 def test_echo(self): | |
1264 DoPost(_REMOTE, '/modalities/orthanctest/echo') | |
1265 | |
1266 | |
1267 def test_xml(self): | |
1268 json = DoGet(_REMOTE, '/tools', headers = { 'accept' : 'application/json' }) | |
1269 xml = minidom.parseString(DoGet(_REMOTE, '/tools', headers = { 'accept' : 'application/xml' })) | |
1270 items = xml.getElementsByTagName('root')[0].getElementsByTagName('item') | |
1271 self.assertEqual(len(items), len(json)) | |
1272 | |
1273 self.assertTrue('dicom-conformance' in json) | |
1274 | |
1275 ok = False | |
1276 for i in items: | |
1277 if i.childNodes[0].data == 'dicom-conformance': | |
1278 ok = True | |
1279 self.assertTrue(ok) | |
1280 | |
1281 | |
1282 def test_issue_16(self): | |
1283 i = UploadInstance(_REMOTE, 'Issue16.dcm')['ID'] | |
1284 t = DoGet(_REMOTE, '/instances/%s/tags?simplify' % i)['FrameIncrementPointer'] | |
1285 self.assertEqual('0018,1063', t) | |
1286 | |
1287 | |
1288 def test_issue_22(self): | |
1289 s = UploadInstance(_REMOTE, 'Issue22.dcm')['ID'] | |
1290 a = [ | |
1291 "f804691f62197040438f4627c6b994f1", # Frame 0 | |
1292 "c69eee9a51eea3e8611e82e578897254", | |
1293 "315666be83e2d0111c77bc0996d84901", | |
1294 "3e27aa959d911172c48a1436443c72b1", | |
1295 "958642c9e7e9d232d3869faff546058c", | |
1296 "5e7ea8e3e4230cae707d143481355c59", | |
1297 "eda37f83558d858a596175aed8b2ad47", | |
1298 "486713bd2895c4ecbe0e97715ac7f80a", | |
1299 "091ef729eb169e67da8a0faa9631f9a8", | |
1300 "5aa2b8c7ffe0a483efaa8e12417686ca", | |
1301 "e2f39e85896fe58876654b94cd0b5013", | |
1302 "6fd2129e4950abbe1be053bc814d5da8", | |
1303 "c3331a8ba7a757f3d423735ab7fa81f9", | |
1304 "746f808582156734dd6b6fdfd3a0b72c", | |
1305 "8075ea2b227a70c60ea6b7b75a6bb190", | |
1306 "806b8b3e300c615099c11a5ec23465aa", | |
1307 "7c836aa298ba6eef96434579af631a11", | |
1308 "a0357dc9f4f72d73a885c33d7c287446", | |
1309 "f25ba3be1cc7d7fad95706adc199ea7d", | |
1310 "8b114c526b8cbed6cad8a3248b7b480c", | |
1311 "44e6670f127e612a2b4aa60a0d207698", | |
1312 "b8945f90fe02facf2ace24ca1ecbe0a5", | |
1313 "95c796c2fa8f59018b15cf2987b1f79b", | |
1314 "ce0a51ab30224205b44920221dc27351", # Frame 23 | |
1315 ] | |
1316 | |
1317 self.assertEqual(24, len(DoGet(_REMOTE, '/instances/%s/frames' % s))) | |
1318 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/24/preview' % s)) | |
1319 | |
1320 for i in range(len(a)): | |
1321 self.assertEqual(a[i], ComputeMD5(DoGet(_REMOTE, '/instances/%s/frames/%d/preview' % (s, i)))) | |
1322 | |
1323 | |
1324 def test_issue_19(self): | |
1325 # This is an image with "YBR_FULL" photometric interpretation | |
1326 # gdcmconv -i /home/jodogne/DICOM/GdcmDatabase/US_DataSet/HDI5000_US/3EAF5E01 -w -o Issue19.dcm | |
1327 | |
1328 a = UploadInstance(_REMOTE, 'Issue19.dcm')['ID'] | |
1329 i = DoGet(_REMOTE, '/instances/941ad3c8-05d05b88-560459f9-0eae0e20-6cddd533/preview') | |
1330 | |
1331 # eb5d156c3594497f589158a6c6f3ca51 <=> Unsupported.png | |
1332 self.assertEqual('eb5d156c3594497f589158a6c6f3ca51', ComputeMD5(i)) | |
1333 | |
1334 | |
1335 def test_issue_37(self): | |
1336 # Same test for issues 35 and 37. Fixed in Orthanc 0.9.1 | |
1337 u = UploadInstance(_REMOTE, 'Beaufix/IM-0001-0001.dcm')['ID'] | |
1338 | |
1339 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', | |
1340 'CaseSensitive' : True, | |
1341 'Query' : { 'StationName' : 'SMR4-MP3' }}) | |
1342 self.assertEqual(1, len(a)) | |
14 | 1343 |
1344 | |
1345 def test_rest_find(self): | |
1346 # Upload 8 instances | |
1347 for i in range(2): | |
1348 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
1349 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
1350 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
1351 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
1352 | |
1353 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1354 'CaseSensitive' : False, | |
1355 'Query' : { 'PatientName' : '*n*' }}) | |
1356 self.assertEqual(2, len(a)) | |
1357 | |
1358 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1359 'CaseSensitive' : True, | |
1360 'Query' : { 'PatientName' : '*n*' }}) | |
1361 self.assertEqual(0, len(a)) | |
1362 | |
1363 a = DoPost(_REMOTE, '/tools/find', { 'Expand' : True, | |
1364 'Level' : 'Patient', | |
1365 'CaseSensitive' : False, | |
1366 'Query' : { 'PatientName' : '*ne*' }}) | |
1367 self.assertEqual(1, len(a)) | |
1368 self.assertEqual('20080822', a[0]['MainDicomTags']['PatientBirthDate']) | |
1369 | |
1370 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', | |
1371 'CaseSensitive' : True, | |
1372 'Query' : { 'PatientName' : '*ne*' }}) | |
1373 self.assertEqual(0, len(a)) | |
1374 | |
1375 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', | |
1376 'CaseSensitive' : True, | |
1377 'Query' : { 'PatientName' : '*NE*' }}) | |
1378 self.assertEqual(1, len(a)) | |
1379 | |
1380 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', | |
1381 'CaseSensitive' : True, | |
1382 'Query' : { 'PatientName' : '*NE*' }}) | |
1383 self.assertEqual(2, len(a)) | |
1384 | |
1385 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
1386 'CaseSensitive' : True, | |
1387 'Query' : { 'PatientName' : '*NE*' }}) | |
1388 self.assertEqual(4, len(a)) | |
1389 | |
1390 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Patient', 'Query' : { }}) | |
1391 self.assertEqual(2, len(a)) | |
1392 | |
1393 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Study', 'Query' : { }}) | |
1394 self.assertEqual(2, len(a)) | |
1395 | |
1396 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 'Query' : { }}) | |
1397 self.assertEqual(4, len(a)) | |
1398 | |
1399 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', 'Query' : { }}) | |
1400 self.assertEqual(8, len(a)) | |
1401 | |
1402 | |
1403 def test_rest_query_retrieve(self): | |
1404 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1405 | |
1406 # Upload 8 instances | |
1407 for i in range(2): | |
1408 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) | |
1409 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) | |
1410 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) | |
1411 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-000%d.dcm' % (i + 1)) | |
1412 | |
1413 self.assertEqual(2, len(DoGet(_REMOTE, '/patients'))) | |
1414 for p in DoGet(_REMOTE, '/patients'): | |
1415 DoPost(_REMOTE, '/modalities/orthanctest/store', p) | |
1416 DoDelete(_REMOTE, '/patients/%s' % p) | |
1417 | |
1418 for q in DoGet(_REMOTE, '/queries'): | |
1419 DoDelete(_REMOTE, '/queries/%s' % q) | |
1420 | |
1421 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1422 self.assertEqual(0, len(DoGet(_REMOTE, '/queries'))) | |
1423 a = DoPost(_REMOTE, '/modalities/orthanctest/query', { 'Level' : 'Series', | |
1424 'Query' : { 'PatientName' : '*NE*' }})['ID'] | |
1425 self.assertEqual(1, len(DoGet(_REMOTE, '/queries'))) | |
1426 | |
1427 b = DoGet(_REMOTE, '/queries/%s' % a) | |
1428 self.assertTrue('answers' in b) | |
1429 self.assertTrue('level' in b) | |
1430 self.assertTrue('modality' in b) | |
1431 self.assertTrue('query' in b) | |
1432 self.assertTrue('retrieve' in b) | |
1433 self.assertEqual('Series', DoGet(_REMOTE, '/queries/%s/level' % a)) | |
1434 self.assertEqual('orthanctest', DoGet(_REMOTE, '/queries/%s/modality' % a)) | |
1435 | |
1436 q = DoGet(_REMOTE, '/queries/%s/query?simplify' % a) | |
1437 self.assertEqual(1, len(q)) | |
1438 self.assertTrue('PatientName' in q) | |
1439 self.assertEqual('*NE*', q['PatientName']) | |
1440 | |
1441 self.assertEqual(2, len(DoGet(_REMOTE, '/queries/%s/answers' % a))) | |
1442 | |
1443 s = DoGet(_REMOTE, '/queries/%s/answers/0' % a) | |
1444 self.assertTrue('content' in s) | |
1445 self.assertTrue('retrieve' in s) | |
1446 | |
1447 s = DoGet(_REMOTE, '/queries/%s/answers/0/content?simplify' % a) | |
1448 self.assertEqual('887', s['PatientID']) | |
1449 self.assertEqual('2.16.840.1.113669.632.20.121711.10000160881', s['StudyInstanceUID']) | |
1450 | |
1451 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) | |
1452 DoPost(_REMOTE, '/queries/%s/answers/0/retrieve' % a, 'ORTHANC') | |
1453 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
1454 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
1455 self.assertEqual(1, len(DoGet(_REMOTE, '/series'))) | |
1456 self.assertEqual(2, len(DoGet(_REMOTE, '/instances'))) | |
1457 | |
1458 DoPost(_REMOTE, '/queries/%s/answers/1/retrieve' % a, 'ORTHANC') | |
1459 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) | |
1460 self.assertEqual(1, len(DoGet(_REMOTE, '/studies'))) | |
1461 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
1462 self.assertEqual(4, len(DoGet(_REMOTE, '/instances'))) | |
1463 | |
1464 DoDelete(_REMOTE, '/queries/%s' % a) | |
1465 self.assertEqual(0, len(DoGet(_REMOTE, '/queries'))) | |
1466 | |
1467 | |
1468 def test_parent(self): | |
1469 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1470 patient = '6816cb19-844d5aee-85245eba-28e841e6-2414fae2' | |
1471 study = 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0' | |
1472 series = 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe' | |
1473 instance = '66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d' | |
1474 self.assertEqual(instance, u); | |
1475 | |
1476 a = DoGet(_REMOTE, '/studies/%s/patient' % study) | |
1477 self.assertEqual('Patient', a['Type']) | |
1478 self.assertEqual(patient, a['ID']) | |
1479 | |
1480 a = DoGet(_REMOTE, '/series/%s/patient' % series) | |
1481 self.assertEqual('Patient', a['Type']) | |
1482 self.assertEqual(patient, a['ID']) | |
1483 | |
1484 a = DoGet(_REMOTE, '/series/%s/study' % series) | |
1485 self.assertEqual('Study', a['Type']) | |
1486 self.assertEqual(study, a['ID']) | |
1487 | |
1488 a = DoGet(_REMOTE, '/instances/%s/patient' % instance) | |
1489 self.assertEqual('Patient', a['Type']) | |
1490 self.assertEqual(patient, a['ID']) | |
1491 | |
1492 a = DoGet(_REMOTE, '/instances/%s/study' % instance) | |
1493 self.assertEqual('Study', a['Type']) | |
1494 self.assertEqual(study, a['ID']) | |
1495 | |
1496 a = DoGet(_REMOTE, '/instances/%s/series' % instance) | |
1497 self.assertEqual('Series', a['Type']) | |
1498 self.assertEqual(series, a['ID']) | |
1499 | |
1500 | |
1501 def test_shanon(self): | |
1502 def Anonymize(instance, replacements = {}): | |
1503 return DoPost(_REMOTE, '/instances/%s/anonymize' % instance, { 'Replace' : replacements }, 'application/json') | |
1504 | |
1505 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
1506 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1507 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1508 | |
1509 tags = [ 'PatientID', 'StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID', 'DeidentificationMethod' ] | |
1510 ids = [ 'ozp00SjY2xG', | |
1511 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
1512 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
1513 '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109' ] | |
1514 | |
1515 a = ExtractDicomTags(Anonymize(u), tags) | |
1516 for i in range(4): | |
1517 self.assertNotEqual(ids[i], a[i]) | |
1518 self.assertTrue(a[4].startswith('Orthanc')) | |
1519 | |
1520 a = ExtractDicomTags(Anonymize(u, { 'PatientName' : 'toto' }), tags) | |
1521 for i in range(4): | |
1522 self.assertNotEqual(ids[i], a[i]) | |
1523 self.assertFalse(a[4].startswith('Orthanc')) | |
1524 | |
1525 a = ExtractDicomTags(Anonymize(u, { 'SOPInstanceUID' : 'instance' }), tags) | |
1526 self.assertEqual('instance', a[3]) | |
1527 self.assertFalse(a[4].startswith('Orthanc')) | |
1528 | |
1529 a = ExtractDicomTags(Anonymize(u, { 'SeriesInstanceUID' : 'series' }), tags) | |
1530 self.assertEqual('series', a[2]) | |
1531 self.assertFalse(a[4].startswith('Orthanc')) | |
1532 | |
1533 a = ExtractDicomTags(Anonymize(u, { 'StudyInstanceUID' : 'study' }), tags) | |
1534 self.assertEqual('study', a[1]) | |
1535 self.assertFalse(a[4].startswith('Orthanc')) | |
1536 | |
1537 a = ExtractDicomTags(Anonymize(u, { 'PatientID' : 'patient' }), tags) | |
1538 self.assertEqual('patient', a[0]) | |
1539 self.assertFalse(a[4].startswith('Orthanc')) | |
1540 | |
1541 a = ExtractDicomTags(Anonymize(u, { 'PatientID' : 'patient', | |
1542 'StudyInstanceUID' : 'study', | |
1543 'SeriesInstanceUID' : 'series', | |
1544 'SOPInstanceUID' : 'instance' }), tags) | |
1545 self.assertEqual('patient', a[0]) | |
1546 self.assertFalse(a[4].startswith('Orthanc')) | |
1547 | |
1548 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1549 | |
1550 | |
1551 def test_shanon_2(self): | |
1552 def Modify(instance, replacements = {}): | |
1553 return DoPost(_REMOTE, '/instances/%s/modify' % instance, { 'Replace' : replacements }, 'application/json') | |
1554 | |
1555 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) | |
1556 u = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID'] | |
1557 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1558 | |
1559 tags = [ 'PatientID', 'StudyInstanceUID', 'SeriesInstanceUID', 'SOPInstanceUID', 'DeidentificationMethod' ] | |
1560 ids = [ 'ozp00SjY2xG', | |
1561 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', | |
1562 '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', | |
1563 '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109' ] | |
1564 | |
1565 a = ExtractDicomTags(Modify(u), tags) | |
1566 self.assertEqual(ids[0], a[0]) | |
1567 self.assertEqual(ids[1], a[1]) | |
1568 self.assertEqual(ids[2], a[2]) | |
1569 self.assertNotEqual(ids[3], a[3]) | |
1570 self.assertEqual(0, len(a[4])) | |
1571 | |
1572 a = ExtractDicomTags(Modify(u, { 'SOPInstanceUID' : 'instance' }), tags) | |
1573 self.assertEqual(ids[0], a[0]) | |
1574 self.assertEqual(ids[1], a[1]) | |
1575 self.assertEqual(ids[2], a[2]) | |
1576 self.assertEqual('instance', a[3]) | |
1577 | |
1578 a = ExtractDicomTags(Modify(u, { 'SeriesInstanceUID' : 'series' }), tags) | |
1579 self.assertEqual(ids[0], a[0]) | |
1580 self.assertEqual(ids[1], a[1]) | |
1581 self.assertEqual('series', a[2]) | |
1582 self.assertNotEqual(ids[3], a[3]) | |
1583 | |
1584 a = ExtractDicomTags(Modify(u, { 'StudyInstanceUID' : 'study' }), tags) | |
1585 self.assertEqual(ids[0], a[0]) | |
1586 self.assertEqual('study', a[1]) | |
1587 self.assertNotEqual(ids[2], a[2]) | |
1588 self.assertNotEqual(ids[3], a[3]) | |
1589 | |
1590 a = ExtractDicomTags(Modify(u, { 'PatientID' : 'patient' }), tags) | |
1591 self.assertEqual('patient', a[0]) | |
1592 self.assertNotEqual(ids[1], a[1]) | |
1593 self.assertNotEqual(ids[2], a[2]) | |
1594 self.assertNotEqual(ids[3], a[3]) | |
1595 | |
1596 a = ExtractDicomTags(Modify(u, { 'PatientID' : 'patient', | |
1597 'StudyInstanceUID' : 'study', | |
1598 'SeriesInstanceUID' : 'series', | |
1599 'SOPInstanceUID' : 'instance' }), tags) | |
1600 self.assertEqual('patient', a[0]) | |
1601 self.assertEqual('study', a[1]) | |
1602 self.assertEqual('series', a[2]) | |
1603 self.assertEqual('instance', a[3]) | |
1604 | |
1605 self.assertEqual(1, len(DoGet(_REMOTE, '/instances'))) | |
1606 | |
1607 | |
1608 def test_instances_tags(self): | |
1609 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID'] | |
1610 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')['ID'] | |
1611 #a = UploadInstance(_REMOTE, 'Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386937.676343')['ID'] | |
1612 #b = UploadInstance(_REMOTE, 'Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386925.676329')['ID'] | |
1613 | |
1614 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/patients')[0]) | |
1615 self.assertEqual(2, len(i)) | |
1616 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1617 self.assertEqual('887', i[i.keys()[1]]['PatientID']) | |
1618 | |
1619 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/studies')[0]) | |
1620 self.assertEqual(2, len(i)) | |
1621 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1622 self.assertEqual('887', i[i.keys()[1]]['PatientID']) | |
1623 | |
1624 self.assertEqual(2, len(DoGet(_REMOTE, '/series'))) | |
1625 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/series')[0]) | |
1626 self.assertEqual(1, len(i)) | |
1627 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1628 | |
1629 i = DoGet(_REMOTE, '/patients/%s/instances-tags?simplify' % DoGet(_REMOTE, '/series')[1]) | |
1630 self.assertEqual(1, len(i)) | |
1631 self.assertEqual('887', i[i.keys()[0]]['PatientID']) | |
1632 | |
1633 | |
1634 def test_lookup(self): | |
1635 a = DoPost(_REMOTE, '/tools/lookup', 'ozp00SjY2xG') | |
1636 self.assertEqual(0, len(a)) | |
1637 | |
1638 UploadInstance(_REMOTE, 'DummyCT.dcm') | |
1639 | |
1640 a = DoPost(_REMOTE, '/tools/lookup', 'ozp00SjY2xG') | |
1641 self.assertEqual(1, len(a)) | |
1642 self.assertEqual('Patient', a[0]['Type']) | |
1643 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', a[0]['ID']) | |
1644 self.assertEqual('/patients/%s' % a[0]['ID'], a[0]['Path']) | |
1645 | |
1646 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7391.1171285944.390') | |
1647 self.assertEqual(1, len(a)) | |
1648 self.assertEqual('Study', a[0]['Type']) | |
1649 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', a[0]['ID']) | |
1650 self.assertEqual('/studies/%s' % a[0]['ID'], a[0]['Path']) | |
1651 | |
1652 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7391.1171285944.394') | |
1653 self.assertEqual(1, len(a)) | |
1654 self.assertEqual('Series', a[0]['Type']) | |
1655 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', a[0]['ID']) | |
1656 self.assertEqual('/series/%s' % a[0]['ID'], a[0]['Path']) | |
1657 | |
1658 a = DoPost(_REMOTE, '/tools/lookup', '1.2.840.113619.2.176.2025.1499492.7040.1171286242.109') | |
1659 self.assertEqual(1, len(a)) | |
1660 self.assertEqual('Instance', a[0]['Type']) | |
1661 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', a[0]['ID']) | |
1662 self.assertEqual('/instances/%s' % a[0]['ID'], a[0]['Path']) | |
1663 | |
1664 DropOrthanc(_REMOTE) | |
1665 a = DoPost(_REMOTE, '/tools/lookup', '3113719P') | |
1666 self.assertEqual(0, len(a)) | |
1667 | |
15 | 1668 |
1669 def test_autorouting(self): | |
1670 knee1 = 'Knee/T1/IM-0001-0001.dcm' | |
1671 knee2 = 'Knee/T2/IM-0001-0002.dcm' | |
1672 other = 'Brainix/Flair/IM-0001-0001.dcm' | |
1673 | |
1674 # Check that this version is >= 0.8.0 | |
1675 self.assertTrue(IsDefinedInLua(_REMOTE, '_InitializeJob')) | |
1676 self.assertTrue('orthanctest' in DoGet(_REMOTE, '/modalities')) | |
1677 | |
1678 UploadInstance(_REMOTE, knee1) | |
1679 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
1680 | |
1681 DropOrthanc(_REMOTE) | |
1682 DropOrthanc(_LOCAL) | |
1683 InstallLuaScript('Lua/Autorouting.lua') | |
1684 UploadInstance(_REMOTE, knee1) | |
1685 UploadInstance(_REMOTE, knee2) | |
1686 UploadInstance(_REMOTE, other) | |
1687 WaitEmpty(_REMOTE) | |
1688 UninstallLuaCallbacks() | |
1689 self.assertEqual(3, len(DoGet(_LOCAL, '/instances'))) | |
1690 | |
1691 DropOrthanc(_REMOTE) | |
1692 DropOrthanc(_LOCAL) | |
1693 InstallLuaScript('Lua/AutoroutingConditional.lua') | |
1694 UploadInstance(_REMOTE, knee1) | |
1695 UploadInstance(_REMOTE, knee2) | |
1696 UploadInstance(_REMOTE, other) | |
1697 WaitEmpty(_REMOTE) | |
1698 UninstallLuaCallbacks() | |
1699 self.assertEqual(2, len(DoGet(_LOCAL, '/instances'))) | |
1700 | |
1701 DropOrthanc(_REMOTE) | |
1702 DropOrthanc(_LOCAL) | |
1703 InstallLuaScript('Lua/AutoroutingModification.lua') | |
1704 UploadInstance(_REMOTE, knee1) | |
1705 WaitEmpty(_REMOTE) | |
1706 UninstallLuaCallbacks() | |
1707 i = DoGet(_LOCAL, '/instances') | |
1708 self.assertEqual(1, len(i)) | |
1709 | |
1710 with tempfile.NamedTemporaryFile(delete = True) as f: | |
1711 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0])) | |
1712 f.flush() | |
1713 routed = subprocess.check_output([ 'dcm2xml', f.name ]) | |
1714 self.assertEqual('My Medical Device', re.search('"StationName">(.*?)<', routed).group(1).strip()) | |
1715 self.assertEqual(None, re.search('"MilitaryRank"', routed)) | |
1716 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag | |
17 | 1717 |
1718 | |
1719 def test_storescu_rf(self): | |
1720 i = UploadInstance(_REMOTE, 'KarstenHilbertRF.dcm')['ID'] | |
1721 self.assertEqual(0, len(DoGet(_LOCAL, '/instances'))) | |
1722 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') | |
1723 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) | |
18 | 1724 |
1725 | |
1726 def test_anonymize_instance(self): | |
1727 def AnonymizeAndUpload(instanceId, parameters): | |
1728 return DoPost(_REMOTE, '/instances', DoPost(_REMOTE, '/instances/%s/anonymize' % instanceId, parameters, | |
1729 'application/json'), 'application/dicom')['ID'] | |
1730 | |
1731 def ModifyAndUpload(instanceId, parameters): | |
1732 return DoPost(_REMOTE, '/instances', DoPost(_REMOTE, '/instances/%s/modify' % instanceId, parameters, | |
1733 'application/json'), 'application/dicom')['ID'] | |
1734 | |
1735 a = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID'] | |
1736 s1 = DoGet(_REMOTE, '/instances/%s/content/PatientName' % a) | |
1737 s2 = DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % a) # Some private tag | |
1738 s3 = DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % a) | |
1739 s4 = DoGet(_REMOTE, '/instances/%s/content/SeriesDescription' % a) | |
1740 s5 = DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % a) | |
1741 | |
1742 b = AnonymizeAndUpload(a, '{}') | |
1743 self.assertNotEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1744 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1745 | |
1746 # Keep private tag (only OK since Orthanc 0.8.0) | |
1747 b = AnonymizeAndUpload(a, '{"Keep":["00e1-10c2"]}') | |
1748 self.assertNotEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1749 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1750 | |
1751 b = AnonymizeAndUpload(a, '{"Keep":["00e1,10c2","PatientName"]}') | |
1752 self.assertEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1753 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1754 | |
1755 b = AnonymizeAndUpload(a, '{"Keep":["PatientName"],"Replace":{"00e1,10c2":"Hello"}}') | |
1756 self.assertEqual(s1, DoGet(_REMOTE, '/instances/%s/content/PatientName' % b)) | |
1757 self.assertTrue(DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b).startswith('Hello')) | |
1758 | |
1759 # Examples from the Wiki | |
1760 b = AnonymizeAndUpload(a, '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": null}') | |
1761 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1762 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1763 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1764 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008,103e' % b)) | |
1765 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008-103E' % b)) | |
1766 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1767 DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % a) | |
1768 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1769 | |
1770 b = ModifyAndUpload(a, '{"Replace":{"PatientName":"hello","PatientID":"world"},"Remove":["InstitutionName"],"RemovePrivateTags": null}') | |
1771 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1772 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1773 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1774 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008,103e' % b)) | |
1775 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/00e1-10c2' % b)) | |
1776 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1777 | |
1778 b = ModifyAndUpload(a, '{"Replace":{"PatientName":"hello","PatientID":"world"}}') | |
1779 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % b).strip()) | |
1780 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/PatientID' % b).strip()) | |
1781 self.assertEqual(s2, DoGet(_REMOTE, '/instances/%s/content/00e1,10c2' % b)) | |
1782 self.assertEqual(s3, DoGet(_REMOTE, '/instances/%s/content/0008,1030' % b)) | |
1783 self.assertEqual(s4, DoGet(_REMOTE, '/instances/%s/content/0008-103E' % b)) | |
1784 self.assertEqual(s5, DoGet(_REMOTE, '/instances/%s/content/InstitutionName' % b)) | |
1785 | |
1786 | |
1787 # Test modify non-existing | |
1788 i = DoPost(_REMOTE, '/tools/create-dicom', | |
1789 json.dumps({ | |
1790 'PatientName' : 'Jodogne', | |
1791 'Modality' : 'CT', | |
1792 }))['ID'] | |
1793 | |
1794 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % i).strip()) | |
1795 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % i)) | |
1796 self.assertEqual('CT', DoGet(_REMOTE, '/instances/%s/content/Modality' % i).strip()) | |
1797 | |
1798 b = ModifyAndUpload(i, '{"Replace":{"StudyDescription":"hello","Modality":"world"}}') | |
1799 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/PatientName' % b).strip()) | |
1800 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/StudyDescription' % b).strip()) | |
1801 self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/Modality' % b).strip()) | |
1802 |