comparison Plugins/DicomWeb/Run.py @ 297:f95cd3af1c7a

DICOMweb: test_transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 12 May 2020 20:58:14 +0200
parents 7fa5c7a03137
children cb56f56c98fb
comparison
equal deleted inserted replaced
293:032722c3e919 297:f95cd3af1c7a
30 # } 30 # }
31 # } 31 # }
32 32
33 33
34 34
35 35 import copy
36 import os 36 import os
37 import pprint 37 import pprint
38 import sys 38 import sys
39 import argparse 39 import argparse
40 import unittest 40 import unittest
587 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 2))) 587 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 2)))
588 588
589 b = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1)) 589 b = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1))
590 self.assertEqual(1, len(b)) 590 self.assertEqual(1, len(b))
591 self.assertEqual(256 * 256 * 2, len(b[0])) 591 self.assertEqual(256 * 256 * 2, len(b[0]))
592 self.assertEqual('ce394eb4d4de4eeef348436108101f3b', ComputeMD5(b[0]))
592 593
593 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1), 594 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1),
594 headers = { 'Accept' : 'multipart/related; type=application/octet-stream' }) 595 headers = { 'Accept' : 'multipart/related; type=application/octet-stream' })
595 self.assertEqual(1, len(c)) 596 self.assertEqual(1, len(c))
596 self.assertEqual(b[0], c[0]) 597 self.assertEqual(b[0], c[0])
598 self.assertEqual('ce394eb4d4de4eeef348436108101f3b', ComputeMD5(c[0]))
597 599
598 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1), 600 c = DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1),
599 headers = { 'Accept' : 'multipart/related; type="application/octet-stream"' }) 601 headers = { 'Accept' : 'multipart/related; type="application/octet-stream"' })
600 self.assertEqual(1, len(c)) 602 self.assertEqual(1, len(c))
601 self.assertEqual(b[0], c[0]) 603 self.assertEqual(b[0], c[0])
604 self.assertEqual('ce394eb4d4de4eeef348436108101f3b', ComputeMD5(c[0]))
602 605
603 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1), 606 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1),
604 headers = { 'Accept' : 'multipart/related; type="nope"' })) 607 headers = { 'Accept' : 'multipart/related; type="nope"' }))
605 608
606 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1), 609 self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s/frames/%d' % (uri, 1),
996 UploadInstance(ORTHANC, 'Issue164.dcm') 999 UploadInstance(ORTHANC, 'Issue164.dcm')
997 1000
998 p = DoGetMultipart(ORTHANC, 'dicom-web/studies/1.2.276.0.26.1.1.1.2.2020.45.52293.1506048/series/1.2.276.0.26.1.1.1.2.2020.45.52293.6384450/instances/1.2.276.0.26.1.1.1.2.2020.45.52366.2551599.179568640/frames/5') 1001 p = DoGetMultipart(ORTHANC, 'dicom-web/studies/1.2.276.0.26.1.1.1.2.2020.45.52293.1506048/series/1.2.276.0.26.1.1.1.2.2020.45.52293.6384450/instances/1.2.276.0.26.1.1.1.2.2020.45.52366.2551599.179568640/frames/5')
999 self.assertEqual(1, len(p)) 1002 self.assertEqual(1, len(p))
1000 self.assertEqual(743 * 975 * 3, len(p[0])) 1003 self.assertEqual(743 * 975 * 3, len(p[0]))
1004 self.assertTrue(ComputeMD5(p[0]) in [
1005 # The actual value depends on the JPEG decompression algorithm
1006 '326acdaa507e01e611d4d152e5526782', # With GDCM
1007 'b3662c4bfa24a0c73abb08548c63319b', # With DCMTK
1008 ])
1001 1009
1002 1010
1003 def test_bitbucket_issue_168(self): 1011 def test_bitbucket_issue_168(self):
1004 # "Plugins can't read private tags from the configuration 1012 # "Plugins can't read private tags from the configuration
1005 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu 1013 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu
1130 }))) 1138 })))
1131 1139
1132 self.assertEqual(1, len(DoGet(ORTHANC, u'/dicom-web/studies?PatientName=Гусева*', 1140 self.assertEqual(1, len(DoGet(ORTHANC, u'/dicom-web/studies?PatientName=Гусева*',
1133 headers = { 'accept' : 'application/json' }))) 1141 headers = { 'accept' : 'application/json' })))
1134 1142
1135 # This line is the isse 1143 # This line is the issue
1136 self.assertEqual(1, len(DoGet(ORTHANC, u'/dicom-web/studies?PatientName=гусева*', 1144 self.assertEqual(1, len(DoGet(ORTHANC, u'/dicom-web/studies?PatientName=гусева*',
1137 headers = { 'accept' : 'application/json' }))) 1145 headers = { 'accept' : 'application/json' })))
1138 1146
1147
1148 def test_transcoding(self):
1149 ACCEPT = {
1150 '1.2.840.10008.1.2' : 'multipart/related; type=application/octet-stream; transfer-syntax=1.2.840.10008.1.2',
1151 '1.2.840.10008.1.2.1' : 'multipart/related; type=application/octet-stream; transfer-syntax=1.2.840.10008.1.2.1',
1152 '1.2.840.10008.1.2.4.50' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.50',
1153 '1.2.840.10008.1.2.4.51' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.51',
1154 '1.2.840.10008.1.2.4.57' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57',
1155 '1.2.840.10008.1.2.4.70' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70',
1156 }
1157
1158 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm')
1159
1160 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1161 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] },
1162 returnHeaders = True)
1163 self.assertEqual(1, len(a))
1164 self.assertEqual(2, len(a[0]))
1165 self.assertEqual('http://localhost:8042%s/frames/1' % uri,
1166 a[0][1]['Content-Location'])
1167 self.assertEqual(ACCEPT['1.2.840.10008.1.2.4.50'],
1168 'multipart/related; type=%s' % a[0][1]['Content-Type'])
1169 self.assertEqual(53476, len(a[0][0]))
1170 self.assertEqual('142fdb8a1dc2aa7e6b8952aa294a6e22', ComputeMD5(a[0][0]))
1171
1172 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri)
1173 self.assertEqual(1, len(a))
1174 self.assertEqual(480 * 640 * 3, len(a[0]))
1175
1176 ACCEPT2 = copy.deepcopy(ACCEPT)
1177 if ComputeMD5(a[0]) == '654fd026c19daf92bf05137233b4f426':
1178 IS_GDCM = True
1179 ACCEPT2['1.2.840.10008.1.2.1'] = 'multipart/related; type=application/octet-stream'
1180 del ACCEPT2['1.2.840.10008.1.2']
1181 else:
1182 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1183 IS_GDCM = False
1184
1185 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1186 headers = { 'Accept' : ACCEPT2['1.2.840.10008.1.2.1'] })
1187 self.assertEqual(1, len(a))
1188 self.assertEqual(480 * 640 * 3, len(a[0]))
1189
1190 if IS_GDCM:
1191 self.assertEqual('654fd026c19daf92bf05137233b4f426', ComputeMD5(a[0]))
1192 else:
1193 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1194
1195
1196 # Test download using the same transfer syntax
1197 RESULTS = {
1198 '1.2.840.10008.1.2' : 'f54c7ea520ab3ec32b6303581ecd262f',
1199 '1.2.840.10008.1.2.1' : '4b350b9353a93c747917c7c3bf9b8f44',
1200 '1.2.840.10008.1.2.4.50' : '142fdb8a1dc2aa7e6b8952aa294a6e22',
1201 '1.2.840.10008.1.2.4.51' : '8b37945d75f9d2899ed868bdba429a0d',
1202 '1.2.840.10008.1.2.4.57' : '75c84823eddb560d127b1d24c9406f30',
1203 '1.2.840.10008.1.2.4.70' : '2c35726328f0200396e583a0038b0269',
1204 }
1205
1206 if IS_GDCM:
1207 # This file was failing with GDCM, as it has 2 fragments,
1208 # and only the first one was returned => the MD5 below is BAD
1209 RESULTS['1.2.840.10008.1.2.4.51'] = '901963a322a817946b074f9ed0afa060'
1210
1211 for syntax in ACCEPT2:
1212 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/%s.dcm' % syntax)
1213 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1214 headers = { 'Accept' : ACCEPT2[syntax] })
1215 self.assertEqual(1, len(a))
1216 self.assertEqual(RESULTS[syntax], ComputeMD5(a[0]))
1217
1218 # Test transcoding to all the possible transfer syntaxes
1219 uri = '/dicom-web%s' % UploadAndGetWadoPath('KarstenHilbertRF.dcm')
1220 for syntax in ACCEPT2:
1221 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1222 headers = { 'Accept' : ACCEPT2[syntax] },
1223 returnHeaders = True)
1224 self.assertEqual(1, len(a))
1225 self.assertEqual(2, len(a[0]))
1226 self.assertEqual('http://localhost:8042%s/frames/1' % uri,
1227 a[0][1]['Content-Location'])
1228 self.assertEqual(ACCEPT[syntax],
1229 'multipart/related; type=%s' % a[0][1]['Content-Type'])
1230 if IS_GDCM:
1231 self.assertEqual({
1232 '1.2.840.10008.1.2' : '1c8cebde0c74450ce4dfb75dd52ddad7',
1233 '1.2.840.10008.1.2.1' : '1c8cebde0c74450ce4dfb75dd52ddad7',
1234 '1.2.840.10008.1.2.4.50' : 'f4d145e5f33fbd39375ce0f91453d6cc',
1235 '1.2.840.10008.1.2.4.51' : 'f4d145e5f33fbd39375ce0f91453d6cc',
1236 '1.2.840.10008.1.2.4.57' : 'dc55800ce1a8ac556c266cdb26d75757',
1237 '1.2.840.10008.1.2.4.70' : 'dc55800ce1a8ac556c266cdb26d75757',
1238 } [syntax], ComputeMD5(a[0][0]))
1239 else:
1240 self.assertEqual({
1241 '1.2.840.10008.1.2' : '1c8cebde0c74450ce4dfb75dd52ddad7',
1242 '1.2.840.10008.1.2.1' : '1c8cebde0c74450ce4dfb75dd52ddad7',
1243 '1.2.840.10008.1.2.4.50' : '0a0ab74fe7c68529bdd416fc9e5e742a',
1244 '1.2.840.10008.1.2.4.51' : '33d1ab2fe169c5b5ba932a9bbc3c6306',
1245 '1.2.840.10008.1.2.4.57' : '3d21c969da846ca41e0498a0dcfad061',
1246 '1.2.840.10008.1.2.4.70' : '49d5353c8673208629847ad45a855557',
1247 } [syntax], ComputeMD5(a[0][0]))
1248
1249
1250 # JPEG image with many fragments for 2 frames
1251 uri = '/dicom-web%s' % UploadAndGetWadoPath('LenaTwiceWithFragments.dcm')
1252
1253 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1254 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] })
1255 self.assertEqual(1, len(a))
1256 self.assertEqual(69214, len(a[0]))
1257 self.assertEqual('0eaf36d4881c513ca70b6684bfaa5b08', ComputeMD5(a[0]))
1258
1259 b = DoGetMultipart(ORTHANC, '%s/frames/2' % uri,
1260 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] })
1261 self.assertEqual(1, len(b))
1262 self.assertEqual(a[0], b[0])
1263
1264 b = DoGetMultipart(ORTHANC, '%s/frames/1,2' % uri,
1265 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] })
1266 self.assertEqual(2, len(b))
1267 self.assertEqual(a[0], b[0])
1268 self.assertEqual(a[0], b[1])
1269
1270
1139 1271
1140 try: 1272 try:
1141 print('\nStarting the tests...') 1273 print('\nStarting the tests...')
1142 unittest.main(argv = [ sys.argv[0] ] + args.options) 1274 unittest.main(argv = [ sys.argv[0] ] + args.options)
1143 1275