comparison Plugins/DicomWeb/Run.py @ 227:875ff7460ae8

test_qido_fields, test_stow_errors
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 27 Feb 2019 12:50:09 +0100
parents 230aede7f8d5
children 84244277413b
comparison
equal deleted inserted replaced
226:230aede7f8d5 227:875ff7460ae8
168 SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm')) 168 SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm'))
169 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) 169 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
170 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm')) 170 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm'))
171 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) 171 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
172 172
173 self.assertEqual(0, len(a['00081198']['Value'])) # No error 173 self.assertEqual(4, len(a))
174
175 # Specific character set
176 self.assertTrue('00080005' in a)
177 self.assertEqual('CS', a['00080005']['vr'])
178
179 self.assertTrue(a['00081190']['Value'][0].endswith('studies/2.16.840.1.113669.632.20.1211.10000098591'))
180 self.assertEqual('UR', a['00081190']['vr'])
181
182 self.assertFalse('Value' in a['00081198']) # No error => empty sequence
183 self.assertEqual('SQ', a['00081198']['vr'])
184
174 self.assertEqual(1, len(a['00081199']['Value'])) # 1 success 185 self.assertEqual(1, len(a['00081199']['Value'])) # 1 success
175 186 self.assertEqual('SQ', a['00081199']['vr'])
176 self.assertTrue(a['00081190']['Value'][0].endswith('studies/2.16.840.1.113669.632.20.1211.10000098591')) 187
177 self.assertTrue(a['00081199']['Value'][0]['00081190']['Value'][0]. 188 b = a['00081199']['Value'][0]
189
190 # Referenced SOP class UID
191 self.assertEqual('UI', b['00081150']['vr'])
192 self.assertEqual(1, len(b['00081150']['Value']))
193 self.assertEqual('1.2.840.10008.5.1.4.1.1.2', b['00081150']['Value'][0])
194
195 # Referenced SOP instance UID
196 self.assertEqual('UI', b['00081155']['vr'])
197 self.assertEqual(1, len(b['00081155']['Value']))
198 self.assertEqual('1.2.840.113704.7.1.1.6632.1127829031.2', b['00081155']['Value'][0])
199
200 # Retrieve URL
201 self.assertEqual('UR', b['00081190']['vr'])
202 self.assertEqual(1, len(b['00081190']['Value']))
203 self.assertTrue(b['00081190']['Value'][0].
178 endswith('series/1.2.840.113704.1.111.5692.1127828999.2/instances/1.2.840.113704.7.1.1.6632.1127829031.2')) 204 endswith('series/1.2.840.113704.1.111.5692.1127828999.2/instances/1.2.840.113704.7.1.1.6632.1127829031.2'))
179 205
180 # Remove the "http://localhost:8042" prefix 206 # Remove the "http://localhost:8042" prefix
181 url = a['00081190']['Value'][0] 207 url = a['00081190']['Value'][0]
182 url = re.sub(r'(http|https)://[^/]+(/.*)', r'\2', url) 208 url = re.sub(r'(http|https)://[^/]+(/.*)', r'\2', url)
185 b = DoGet(ORTHANC, url).decode('utf-8', 'ignore') 211 b = DoGet(ORTHANC, url).decode('utf-8', 'ignore')
186 parts = re.findall(r'^Content-Length:\s*(\d+)\s*', b, re.IGNORECASE | re.MULTILINE) 212 parts = re.findall(r'^Content-Length:\s*(\d+)\s*', b, re.IGNORECASE | re.MULTILINE)
187 self.assertEqual(1, len(parts)) 213 self.assertEqual(1, len(parts))
188 self.assertEqual(os.path.getsize(GetDatabasePath('Phenix/IM-0001-0001.dcm')), int(parts[0])) 214 self.assertEqual(os.path.getsize(GetDatabasePath('Phenix/IM-0001-0001.dcm')), int(parts[0]))
189 215
216
190 def test_server_get(self): 217 def test_server_get(self):
191 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm') 218 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm')
192 219
193 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/servers'))) 220 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/servers')))
194 self.assertTrue('sample' in DoGet(ORTHANC, '/dicom-web/servers')) 221 self.assertTrue('sample' in DoGet(ORTHANC, '/dicom-web/servers'))
522 549
523 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 2), 550 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 2),
524 headers = { 'Accept' : 'multipart/related; type="application/octet-stream"' }) 551 headers = { 'Accept' : 'multipart/related; type="application/octet-stream"' })
525 self.assertEqual(1, len(c)) 552 self.assertEqual(1, len(c))
526 self.assertEqual(b[0], c[0]) 553 self.assertEqual(b[0], c[0])
527 554
555
556 def test_qido_fields(self):
557 UploadInstance(ORTHANC, 'DummyCT.dcm')
558
559 a = DoGet(ORTHANC, '/dicom-web/studies')
560 self.assertEqual(1, len(a))
561 self.assertFalse('00280010' in a[0]) # Rows
562
563 a = DoGet(ORTHANC, '/dicom-web/studies?includefield=Rows')
564 self.assertEqual(1, len(a))
565 self.assertTrue('00280010' in a[0])
566 self.assertEqual(512, a[0]['00280010']['Value'][0])
567
568 a = DoGet(ORTHANC, '/dicom-web/studies?Rows=128')
569 self.assertEqual(0, len(a))
570
571 a = DoGet(ORTHANC, '/dicom-web/studies?Rows=512')
572 self.assertEqual(1, len(a))
573 self.assertTrue('00280010' in a[0])
574 self.assertEqual(512, a[0]['00280010']['Value'][0])
575
576
577 def test_stow_errors(self):
578 # Pushing an instance to a study that is not its parent
579 a = SendStow(ORTHANC, args.dicomweb + '/studies/nope', GetDatabasePath('Phenix/IM-0001-0001.dcm'))
580 self.assertEqual(3, len(a))
581 self.assertTrue('00080005' in a)
582 self.assertEqual('CS', a['00080005']['vr'])
583 self.assertTrue('00081198' in a)
584 self.assertEqual('SQ', a['00081198']['vr'])
585 self.assertEqual(1, len(['00081198']))
586 self.assertTrue('00081199' in a)
587 self.assertEqual('SQ', a['00081199']['vr'])
588 self.assertEqual(1, len(['00081199']))
589
590 # Pushing an instance with missing tags
591 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Issue111.dcm'))
592 self.assertEqual(3, len(a))
593 self.assertTrue('00080005' in a)
594 self.assertEqual('CS', a['00080005']['vr'])
595 self.assertTrue('00081198' in a)
596 self.assertEqual('SQ', a['00081198']['vr'])
597 self.assertEqual(1, len(['00081198']))
598 self.assertTrue('00081199' in a)
599 self.assertEqual('SQ', a['00081199']['vr'])
600 self.assertEqual(1, len(['00081199']))
601
602 # Pushing a file that is not in the DICOM format
603 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Issue111.dump'))
604 self.assertEqual(3, len(a))
605 self.assertTrue('00080005' in a)
606 self.assertEqual('CS', a['00080005']['vr'])
607 self.assertTrue('00081198' in a)
608 self.assertEqual('SQ', a['00081198']['vr'])
609 self.assertEqual(1, len(['00081198']))
610 self.assertTrue('00081199' in a)
611 self.assertEqual('SQ', a['00081199']['vr'])
612 self.assertEqual(1, len(['00081199']))
613
528 614
529 try: 615 try:
530 print('\nStarting the tests...') 616 print('\nStarting the tests...')
531 unittest.main(argv = [ sys.argv[0] ] + args.options) 617 unittest.main(argv = [ sys.argv[0] ] + args.options)
532 618