comparison Plugins/DicomWeb/Run.py @ 249:24e5c8ca9440 Orthanc-1.5.7

DICOMweb: test_rendered
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Jun 2019 15:35:41 +0200
parents 26c3a1ed935a
children 298f80c6ccc4
comparison
equal deleted inserted replaced
248:26c3a1ed935a 249:24e5c8ca9440
102 102
103 ## 103 ##
104 ## The tests 104 ## The tests
105 ## 105 ##
106 106
107
108 def UploadAndGetWadoPath(dicom):
109 i = UploadInstance(ORTHANC, dicom) ['ID']
110 study = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['StudyInstanceUID']
111 series = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['SeriesInstanceUID']
112 instance = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['SOPInstanceUID']
113 return '/studies/%s/series/%s/instances/%s' % (study, series, instance)
114
115
116
107 class Orthanc(unittest.TestCase): 117 class Orthanc(unittest.TestCase):
108 def setUp(self): 118 def setUp(self):
109 if (sys.version_info >= (3, 0)): 119 if (sys.version_info >= (3, 0)):
110 # Remove annoying warnings about unclosed socket in Python 3 120 # Remove annoying warnings about unclosed socket in Python 3
111 import warnings 121 import warnings
685 'Hello' : 'World' 695 'Hello' : 'World'
686 }, 696 },
687 'Username' : 'bob', 697 'Username' : 'bob',
688 'Password' : 'password', 698 'Password' : 'password',
689 'UserProperty' : 'Test', 699 'UserProperty' : 'Test',
700 'HasDelete' : True,
690 }) 701 })
691 702
692 l = DoGet(ORTHANC, '/dicom-web/servers') 703 l = DoGet(ORTHANC, '/dicom-web/servers')
693 self.assertEqual(2, len(l)) 704 self.assertEqual(2, len(l))
694 self.assertTrue('sample' in l) 705 self.assertTrue('sample' in l)
695 self.assertTrue('hello' in l) 706 self.assertTrue('hello' in l)
696 707
708 o = DoGet(ORTHANC, '/dicom-web/servers/sample')
709 self.assertEqual(5, len(o))
710 self.assertTrue('stow' in o)
711 self.assertTrue('retrieve' in o)
712 self.assertTrue('get' in o)
713 self.assertTrue('wado' in o) # New in 0.7
714 self.assertTrue('qido' in o) # New in 0.7
715
716 o = DoGet(ORTHANC, '/dicom-web/servers/hello')
717 self.assertEqual(6, len(o))
718 self.assertTrue('stow' in o)
719 self.assertTrue('retrieve' in o)
720 self.assertTrue('get' in o)
721 self.assertTrue('wado' in o) # New in 0.7
722 self.assertTrue('qido' in o) # New in 0.7
723 self.assertTrue('delete' in o) # New in 0.7
724
697 s = DoGet(ORTHANC, '/dicom-web/servers?expand') 725 s = DoGet(ORTHANC, '/dicom-web/servers?expand')
698 self.assertEqual(6, len(s['hello'])) 726 self.assertEqual(7, len(s['hello']))
699 self.assertEqual(url, s['hello']['Url']) 727 self.assertEqual(url, s['hello']['Url'])
700 self.assertEqual('bob', s['hello']['Username']) 728 self.assertEqual('bob', s['hello']['Username'])
701 self.assertEqual(None, s['hello']['Password']) 729 self.assertEqual(None, s['hello']['Password'])
702 self.assertFalse(s['hello']['Pkcs11']) 730 self.assertFalse(s['hello']['Pkcs11'])
703 self.assertEqual(1, len(s['hello']['HttpHeaders'])) 731 self.assertEqual(1, len(s['hello']['HttpHeaders']))
704 self.assertTrue('Hello' in s['hello']['HttpHeaders']) 732 self.assertTrue('Hello' in s['hello']['HttpHeaders'])
705 self.assertEqual('Test', s['hello']['UserProperty']) 733 self.assertEqual('Test', s['hello']['UserProperty'])
734 self.assertEqual('1', s['hello']['HasDelete'])
706 735
707 DoDelete(ORTHANC, '/dicom-web/servers/hello') 736 DoDelete(ORTHANC, '/dicom-web/servers/hello')
708 737
709 738
710 def test_bitbucket_issue_143(self): 739 def test_bitbucket_issue_143(self):
778 self.assertEqual(u'Yamada^Tarou', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Alphabetic']) 807 self.assertEqual(u'Yamada^Tarou', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Alphabetic'])
779 self.assertEqual(u'山田^太郎', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Ideographic']) 808 self.assertEqual(u'山田^太郎', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Ideographic'])
780 self.assertEqual(u'やまだ^たろう', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Phonetic']) 809 self.assertEqual(u'やまだ^たろう', GetPatientName('Encodings/DavidClunie/SCSH31', False)['Phonetic'])
781 self.assertEqual(u'ヤマダ^タロウ', GetPatientName('Encodings/DavidClunie/SCSH32', False)['Alphabetic']) 810 self.assertEqual(u'ヤマダ^タロウ', GetPatientName('Encodings/DavidClunie/SCSH32', False)['Alphabetic'])
782 811
783 # TODO - Not supported yet by the Orthanc core 812 # TODO - Not supported yet by the Orthanc core as of 1.5.7
784 #self.assertEqual(u'山田^太郎', GetPatientName('Encodings/DavidClunie/SCSH32')['Ideographic']) 813 #self.assertEqual(u'山田^太郎', GetPatientName('Encodings/DavidClunie/SCSH32')['Ideographic'])
785 #self.assertEqual(u'やまだ^たろう', GetPatientName('Encodings/DavidClunie/SCSH32')['Phonetic']) 814 #self.assertEqual(u'やまだ^たろう', GetPatientName('Encodings/DavidClunie/SCSH32')['Phonetic'])
786 815
787 816
788 def test_encodings_wado_metadata(self): 817 def test_encodings_wado_metadata(self):
789 # If querying the instance metadata, the "DefaultEncoding" 818 # If querying the instance metadata, the "DefaultEncoding"
790 # configuration is not used, but the actual encoding 819 # configuration is not used, but the actual encoding
791 def GetEncoding(dicom, length): 820 def GetEncoding(dicom, length):
792 i = UploadInstance(ORTHANC, dicom) ['ID'] 821 qido = DoGet(ORTHANC, '/dicom-web/%s/metadata' % UploadAndGetWadoPath(dicom))
793 study = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['StudyInstanceUID']
794 series = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['SeriesInstanceUID']
795 instance = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) ['SOPInstanceUID']
796 qido = DoGet(ORTHANC, '/dicom-web/studies/%s/series/%s/instances/%s/metadata' % (study, series, instance))
797 self.assertEqual(1, len(qido)) 822 self.assertEqual(1, len(qido))
798 self.assertEqual(length, len(qido[0]['00080005']['Value'])) 823 self.assertEqual(length, len(qido[0]['00080005']['Value']))
799 self.assertEqual('CS', qido[0]['00080005']['vr']) 824 self.assertEqual('CS', qido[0]['00080005']['vr'])
800 return qido[0]['00080005']['Value'] 825 return qido[0]['00080005']['Value']
801 826
810 self.assertEqual('ISO_IR 192', GetEncoding('Encodings/DavidClunie/SCSX1', 1)[0]) 835 self.assertEqual('ISO_IR 192', GetEncoding('Encodings/DavidClunie/SCSX1', 1)[0])
811 self.assertEqual('ISO 2022 IR 87', GetEncoding('Encodings/DavidClunie/SCSH31', 1)[0]) 836 self.assertEqual('ISO 2022 IR 87', GetEncoding('Encodings/DavidClunie/SCSH31', 1)[0])
812 self.assertEqual('ISO 2022 IR 13', GetEncoding('Encodings/DavidClunie/SCSH32', 2)[0]) 837 self.assertEqual('ISO 2022 IR 13', GetEncoding('Encodings/DavidClunie/SCSH32', 2)[0])
813 self.assertEqual('ISO 2022 IR 87', GetEncoding('Encodings/DavidClunie/SCSH32', 2)[1]) 838 self.assertEqual('ISO 2022 IR 87', GetEncoding('Encodings/DavidClunie/SCSH32', 2)[1])
814 839
840
841 def test_rendered(self):
842 def RenderFrame(path, i):
843 return DoPost(ORTHANC, '/dicom-web/servers/sample/get', {
844 'Uri' : '%s/frames/%d/rendered' % (path, i)
845 })
846
847 # This image has 76 frames
848 path = UploadAndGetWadoPath('Multiframe.dcm')
849
850 self.assertRaises(Exception, lambda: RenderFrame(path, 0))
851
852 frame1 = RenderFrame(path, 1)
853 im = UncompressImage(frame1)
854 self.assertEqual("L", im.mode)
855 self.assertEqual(512, im.size[0])
856 self.assertEqual(512, im.size[1])
857
858 im = UncompressImage(RenderFrame(path, 76))
859 self.assertEqual("L", im.mode)
860 self.assertEqual(512, im.size[0])
861 self.assertEqual(512, im.size[1])
862
863 self.assertRaises(Exception, lambda: RenderFrame(path, 77))
864
865 defaultFrame = DoPost(ORTHANC, '/dicom-web/servers/sample/get', {
866 'Uri' : '%s/rendered' % path
867 })
868
869 self.assertEqual(len(frame1), len(defaultFrame))
870 self.assertEqual(frame1, defaultFrame)
871
872
873 # This image has 1 frame
874 path = UploadAndGetWadoPath('Phenix/IM-0001-0001.dcm')
875
876 self.assertRaises(Exception, lambda: RenderFrame(path, 0))
877 self.assertRaises(Exception, lambda: RenderFrame(path, 2))
878
879 frame1 = RenderFrame(path, 1)
880 im = UncompressImage(frame1)
881 self.assertEqual("L", im.mode)
882 self.assertEqual(512, im.size[0])
883 self.assertEqual(358, im.size[1])
884
885 defaultFrame = DoPost(ORTHANC, '/dicom-web/servers/sample/get', {
886 'Uri' : '%s/rendered' % path
887 })
888
889 self.assertEqual(len(frame1), len(defaultFrame))
890 self.assertEqual(frame1, defaultFrame)
891
815 892
816 try: 893 try:
817 print('\nStarting the tests...') 894 print('\nStarting the tests...')
818 unittest.main(argv = [ sys.argv[0] ] + args.options) 895 unittest.main(argv = [ sys.argv[0] ] + args.options)
819 896