comparison Tests/Tests.py @ 296:b55b959647ed c-get

merge default -> c-get
author Alain Mazy <alain@mazy.be>
date Tue, 12 May 2020 14:36:29 +0200
parents 946b2199f481 032722c3e919
children da2be3ff2db5
comparison
equal deleted inserted replaced
295:946b2199f481 296:b55b959647ed
20 # You should have received a copy of the GNU General Public License 20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. 21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 22
23 23
24 import base64 24 import base64
25 import bz2
25 import copy 26 import copy
26 import pprint 27 import pprint
27 import tempfile 28 import tempfile
28 import unittest 29 import unittest
29 import shutil 30 import shutil
134 { 135 {
135 'StudyDescription': 'Sébastien^', 136 'StudyDescription': 'Sébastien^',
136 'StudyDate' : '19700202', 137 'StudyDate' : '19700202',
137 } 138 }
138 ] 139 ]
139
140 140
141 141
142 142
143 class Orthanc(unittest.TestCase): 143 class Orthanc(unittest.TestCase):
144 def setUp(self): 144 def setUp(self):
5449 answer['SOPInstanceUID']) 5449 answer['SOPInstanceUID'])
5450 5450
5451 self.assertEqual(1, len(DoGet(_LOCAL, '/instances'))) 5451 self.assertEqual(1, len(DoGet(_LOCAL, '/instances')))
5452 self.assertEqual(0, len(DoGet(_REMOTE, '/instances'))) 5452 self.assertEqual(0, len(DoGet(_REMOTE, '/instances')))
5453 5453
5454
5455 def test_storescu_transcoding(self): # New in Orthanc 1.7.0
5456 # Add a RLE-encoded DICOM file
5457 i = UploadInstance(_REMOTE, 'TransferSyntaxes/1.2.840.10008.1.2.5.dcm')['ID']
5458 self.assertEqual(0, len(DoGet(_LOCAL, '/instances')))
5459 self.assertEqual(1, len(DoGet(_REMOTE, '/instances')))
5460 rleSize = len(DoGet(_REMOTE, '/instances/%s/file' % i))
5461
5462 # Export the instance, with transcoding: "_REMOTE" is the
5463 # Orthanc server being tested
5464 try:
5465 DoDelete(_REMOTE, '/modalities/toto')
5466 except:
5467 pass
5468
5469 params = DoGet(_REMOTE, '/modalities?expand') ['orthanctest']
5470 DoPut(_REMOTE, '/modalities/toto', params)
5471 DoPost(_REMOTE, '/modalities/toto/store', str(i), 'text/plain')
5472 j = DoGet(_LOCAL, '/instances')
5473 self.assertEqual(1, len(j))
5474 uncompressedSize = len(DoGet(_LOCAL, '/instances/%s/file' % j[0]))
5475 self.assertTrue(uncompressedSize > rleSize / 2)
5476
5477 # Export, with transcoding disabled => this fails
5478 params['AllowTranscoding'] = False
5479 DoPut(_REMOTE, '/modalities/toto', params)
5480 self.assertRaises(Exception, lambda: DoPost(_REMOTE, '/modalities/toto/store', str(i), 'text/plain'))
5481
5482
5483 def test_bitbucket_issue_169(self):
5484 with open(GetDatabasePath('Issue169.dcm.bz2'), 'rb') as f:
5485 dicom = bz2.decompress(f.read())
5486
5487 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(dicom))
5488
5489 self.assertEqual(44350560, len(dicom))
5490 i = DoPost(_REMOTE, '/instances', dicom, 'application/dicom') ['ID']
5491
5492 tags = DoGet(_REMOTE, '/instances/%s/tags' % i)
5493 self.assertEqual('NORMAL', tags['1337,1001']['Value'])
5494
5495 self.assertEqual(0, len(DoGet(_LOCAL, '/instances')))
5496 DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain')
5497 j = DoGet(_LOCAL, '/instances')
5498 self.assertEqual(1, len(j))
5499
5500 # In Orthanc <= 1.6.1, transfer syntax changed from "Explicit
5501 # VR Little Endian" (1.2.840.10008.1.2.1) to "Implicit VR
5502 # Little Endian" (1.2.840.10008.1.2)
5503 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(
5504 DoGet(_LOCAL, '/instances/%s/file' % j[0])))
5505
5506 # In Orthanc <= 1.6.1, the value of the private tags was lost
5507 # because of this transcoding
5508 tags = DoGet(_LOCAL, '/instances/%s/tags' % j[0])
5509 self.assertEqual('NORMAL', tags['1337,1001']['Value'])
5510
5511
5512 def test_modify_transcode(self):
5513 i = UploadInstance(_REMOTE, 'KarstenHilbertRF.dcm')['ID']
5514 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(
5515 DoGet(_REMOTE, '/instances/%s/file' % i)))
5516
5517 for syntax in [
5518 '1.2.840.10008.1.2',
5519 '1.2.840.10008.1.2.1',
5520 #'1.2.840.10008.1.2.1.99', # Deflated Explicit VR Little Endian
5521 '1.2.840.10008.1.2.2',
5522 '1.2.840.10008.1.2.4.50',
5523 '1.2.840.10008.1.2.4.51',
5524 '1.2.840.10008.1.2.4.57',
5525 '1.2.840.10008.1.2.4.70',
5526 #'1.2.840.10008.1.2.4.80', # This makes DCMTK 3.6.2 crash
5527 #'1.2.840.10008.1.2.4.81', # This makes DCMTK 3.6.2 crash
5528 ]:
5529 transcoded = DoPost(_REMOTE, '/instances/%s/modify' % i, {
5530 'Transcode' : syntax,
5531 })
5532
5533 self.assertEqual(syntax, GetTransferSyntax(transcoded))
5534
5535
5536 def test_archive_transcode(self):
5537 info = UploadInstance(_REMOTE, 'KarstenHilbertRF.dcm')
5538
5539 # GET on "/media"
5540 z = GetArchive(_REMOTE, '/patients/%s/media' % info['ParentPatient'])
5541 self.assertEqual(2, len(z.namelist()))
5542 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(z.read('IMAGES/IM0')))
5543
5544 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/patients/%s/media?transcode=nope' % info['ParentPatient']))
5545
5546 z = GetArchive(_REMOTE, '/patients/%s/media?transcode=1.2.840.10008.1.2.4.50' % info['ParentPatient'])
5547 self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(z.read('IMAGES/IM0')))
5548
5549 z = GetArchive(_REMOTE, '/studies/%s/media?transcode=1.2.840.10008.1.2.4.51' % info['ParentStudy'])
5550 self.assertEqual('1.2.840.10008.1.2.4.51', GetTransferSyntax(z.read('IMAGES/IM0')))
5551
5552 z = GetArchive(_REMOTE, '/series/%s/media?transcode=1.2.840.10008.1.2.4.57' % info['ParentSeries'])
5553 self.assertEqual('1.2.840.10008.1.2.4.57', GetTransferSyntax(z.read('IMAGES/IM0')))
5554
5555
5556 # POST on "/media"
5557 self.assertRaises(Exception, lambda: PostArchive(
5558 _REMOTE, '/patients/%s/media' % info['ParentPatient'], { 'Transcode' : 'nope' }))
5559
5560 z = PostArchive(_REMOTE, '/patients/%s/media' % info['ParentPatient'], {
5561 'Transcode' : '1.2.840.10008.1.2.4.50',
5562 })
5563 self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(z.read('IMAGES/IM0')))
5564
5565 z = PostArchive(_REMOTE, '/studies/%s/media' % info['ParentStudy'], {
5566 'Transcode' : '1.2.840.10008.1.2.4.51',
5567 })
5568 self.assertEqual('1.2.840.10008.1.2.4.51', GetTransferSyntax(z.read('IMAGES/IM0')))
5569
5570 z = PostArchive(_REMOTE, '/series/%s/media' % info['ParentSeries'], {
5571 'Transcode' : '1.2.840.10008.1.2.4.57',
5572 })
5573 self.assertEqual('1.2.840.10008.1.2.4.57', GetTransferSyntax(z.read('IMAGES/IM0')))
5574
5575
5576 # GET on "/archive"
5577 z = GetArchive(_REMOTE, '/patients/%s/archive' % info['ParentPatient'])
5578 self.assertEqual(1, len(z.namelist()))
5579 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(z.read(z.namelist()[0])))
5580
5581 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/patients/%s/archive?transcode=nope' % info['ParentPatient']))
5582
5583 z = GetArchive(_REMOTE, '/patients/%s/archive?transcode=1.2.840.10008.1.2' % info['ParentPatient'])
5584 self.assertEqual('1.2.840.10008.1.2', GetTransferSyntax(z.read(z.namelist()[0])))
5585
5586 z = GetArchive(_REMOTE, '/studies/%s/archive?transcode=1.2.840.10008.1.2.2' % info['ParentStudy'])
5587 self.assertEqual('1.2.840.10008.1.2.2', GetTransferSyntax(z.read(z.namelist()[0])))
5588
5589 z = GetArchive(_REMOTE, '/series/%s/archive?transcode=1.2.840.10008.1.2.4.70' % info['ParentSeries'])
5590 self.assertEqual('1.2.840.10008.1.2.4.70', GetTransferSyntax(z.read(z.namelist()[0])))
5591
5592
5593 # POST on "/archive"
5594 self.assertRaises(Exception, lambda: PostArchive(
5595 _REMOTE, '/patients/%s/archive' % info['ParentPatient'], { 'Transcode' : 'nope' }))
5596
5597 z = PostArchive(_REMOTE, '/patients/%s/archive' % info['ParentPatient'], {
5598 'Transcode' : '1.2.840.10008.1.2.4.50',
5599 })
5600 self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(z.read(z.namelist()[0])))
5601
5602 z = PostArchive(_REMOTE, '/studies/%s/archive' % info['ParentStudy'], {
5603 'Transcode' : '1.2.840.10008.1.2.4.51',
5604 })
5605 self.assertEqual('1.2.840.10008.1.2.4.51', GetTransferSyntax(z.read(z.namelist()[0])))
5606
5607 z = PostArchive(_REMOTE, '/series/%s/archive' % info['ParentSeries'], {
5608 'Transcode' : '1.2.840.10008.1.2.4.57',
5609 })
5610 self.assertEqual('1.2.840.10008.1.2.4.57', GetTransferSyntax(z.read(z.namelist()[0])))
5611
5612
5613 # "/tools/create-*"
5614 z = PostArchive(_REMOTE, '/tools/create-archive', {
5615 'Resources' : [ info['ParentStudy'] ],
5616 'Transcode' : '1.2.840.10008.1.2.4.50',
5617 })
5618 self.assertEqual(1, len(z.namelist()))
5619 self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(z.read(z.namelist()[0])))
5620
5621 z = PostArchive(_REMOTE, '/tools/create-media', {
5622 'Resources' : [ info['ParentStudy'] ],
5623 'Transcode' : '1.2.840.10008.1.2.4.51',
5624 })
5625 self.assertEqual(2, len(z.namelist()))
5626 self.assertEqual('1.2.840.10008.1.2.4.51', GetTransferSyntax(z.read('IMAGES/IM0')))
5627
5628 z = PostArchive(_REMOTE, '/tools/create-media-extended', {
5629 'Resources' : [ info['ParentStudy'] ],
5630 'Transcode' : '1.2.840.10008.1.2.4.57',
5631 })
5632 self.assertEqual(2, len(z.namelist()))
5633 self.assertEqual('1.2.840.10008.1.2.4.57', GetTransferSyntax(z.read('IMAGES/IM0')))
5634
5635
5636
5454 def test_getscu(self): 5637 def test_getscu(self):
5455 5638
5456 # no transcoding required 5639 # no transcoding required
5457 UploadInstance(_REMOTE, 'DummyCT.dcm') 5640 UploadInstance(_REMOTE, 'DummyCT.dcm')
5458 5641