Mercurial > hg > orthanc-tests
changeset 92:dbcbffb889da
test_findscu_encoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Dec 2016 12:46:04 +0100 |
parents | ba5619c3941d |
children | fff2b4a24b5f |
files | Database/Encodings/Generate.sh Database/Encodings/Lena-arabic.dcm Database/Encodings/Lena-ascii.dcm Database/Encodings/Lena-cyrillic.dcm Database/Encodings/Lena-greek.dcm Database/Encodings/Lena-hebrew.dcm Database/Encodings/Lena-latin1.dcm Database/Encodings/Lena-latin2.dcm Database/Encodings/Lena-latin3.dcm Database/Encodings/Lena-latin4.dcm Database/Encodings/Lena-latin5.dcm Database/Encodings/Lena-shift-jis.dcm Database/Encodings/Lena-tis-620.dcm Database/Encodings/Lena-utf8.dcm GenerateConfigurationForTests.py Tests/Tests.py |
diffstat | 16 files changed, 138 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Database/Encodings/Generate.sh Thu Dec 08 12:46:04 2016 +0100 @@ -0,0 +1,37 @@ +#!/bin/bash + +# Inspired from Levin Alexander on 2016-11-03 +# https://groups.google.com/d/msg/orthanc-users/kYURTgtgPmI/KeOL8lGFAwAJ + +set -e + +convert -quality 90 -resize 128x128 ../Lena.png /tmp/Lena.jpg + +function Encode { + echo $1 + SOURCE="Test-éüäöòДΘĝדصķћ๛ネİ" + CONVERTED=$(echo "$SOURCE" | iconv -c -t $1) + + img2dcm /tmp/Lena.jpg Lena-$1.dcm \ + -k "(0010,0010)=${CONVERTED}" \ + -k "(0010,0020)=${1}" \ + -k "(0008,0005)=${2}" + + echo -n "${CONVERTED}" | md5sum +} + + +# http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 +Encode 'arabic' 'ISO_IR 127' +Encode 'ascii' 'ISO_IR 6' # More accurately, ISO 646 +Encode 'cyrillic' 'ISO_IR 144' +Encode 'greek' 'ISO_IR 126' +Encode 'hebrew' 'ISO_IR 138' +Encode 'latin1' 'ISO_IR 100' +Encode 'latin2' 'ISO_IR 101' +Encode 'latin3' 'ISO_IR 109' +Encode 'latin4' 'ISO_IR 110' +Encode 'latin5' 'ISO_IR 148' +Encode 'shift-jis' 'ISO_IR 13' # Japanese +Encode 'tis-620' 'ISO_IR 166' # Thai +Encode 'utf8' 'ISO_IR 192'
--- a/GenerateConfigurationForTests.py Tue Dec 06 13:26:51 2016 +0100 +++ b/GenerateConfigurationForTests.py Thu Dec 08 12:46:04 2016 +0100 @@ -86,9 +86,10 @@ config = json.loads(nocomment) +del config['DefaultEncoding'] + config['AllowFindSopClassesInStudy'] = True config['AuthenticationEnabled'] = True -config['DefaultEncoding'] = 'Windows1251' # For test_issue_32 config['DicomAet'] = 'ORTHANC' config['DicomAssociationCloseDelay'] = 0 config['DicomModalities'] = { 'orthanctest' : [ 'ORTHANCTEST', ip, 5001 ] }
--- a/Tests/Tests.py Tue Dec 06 13:26:51 2016 +0100 +++ b/Tests/Tests.py Thu Dec 08 12:46:04 2016 +0100 @@ -2090,13 +2090,25 @@ def test_googlecode_issue_32(self): + self.assertRaises(Exception, lambda: DoPut(_REMOTE, '/tools/default-encoding', 'nope')) + self.assertEqual('Windows1251', DoPut(_REMOTE, '/tools/default-encoding', 'Windows1251')) + self.assertEqual('Windows1251', DoGet(_REMOTE, '/tools/default-encoding')) + f = UploadInstance(_REMOTE, 'Issue32.dcm')['ID'] tags = DoGet(_REMOTE, '/instances/%s/tags?simplify' % f) self.assertEqual(u'Рентгенография', tags['SeriesDescription']) self.assertEqual(u'Таз', tags['BodyPartExamined']) self.assertEqual(u'Прямая', tags['ViewPosition']) - + # Replay the same test using Latin1 as default encoding: This must fail + self.assertEqual('Latin1', DoPut(_REMOTE, '/tools/default-encoding', 'Latin1')) + + DoDelete(_REMOTE, '/instances/%s' % f) + f = UploadInstance(_REMOTE, 'Issue32.dcm')['ID'] + tags = DoGet(_REMOTE, '/instances/%s/tags?simplify' % f) + self.assertNotEqual(u'Рентгенография', tags['SeriesDescription']) + + def test_encodings(self): # Latin-1 (ISO_IR 100) brainix = UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')['ID'] @@ -2989,3 +3001,89 @@ self.assertEqual('1.2.840.113704.1.111.6320.1342451261.21', t['PET-CT Multi Modality Name']) self.assertEqual('p37s0_na_ctac.img', t['Original Image Filename']) + + def test_findscu_encoding(self): + # Check out ../Database/Encodings/Generate.sh + TEST = u'Test-éüäöòДΘĝדصķћ๛ネİ' + ENCODINGS = { + 'Arabic' : [ 'ISO_IR 127' ], + 'Ascii' : [ 'ISO_IR 6' ], # More accurately, ISO 646 + 'Cyrillic' : [ 'ISO_IR 144' ], + 'Greek' : [ 'ISO_IR 126' ], + 'Hebrew' : [ 'ISO_IR 138' ], + 'Japanese' : [ 'ISO_IR 13', 'shift-jis' ], + 'Latin1' : [ 'ISO_IR 100' ], + 'Latin2' : [ 'ISO_IR 101' ], + 'Latin3' : [ 'ISO_IR 109' ], + 'Latin4' : [ 'ISO_IR 110' ], + 'Latin5' : [ 'ISO_IR 148' ], + 'Thai' : [ 'ISO_IR 166', 'tis-620' ], + 'Utf8' : [ 'ISO_IR 192' ], + } + + for name in ENCODINGS.iterkeys(): + if len(ENCODINGS[name]) == 1: + ENCODINGS[name].append(name.lower()) + + UploadInstance(_REMOTE, 'Encodings/Lena-utf8.dcm') + + for name in ENCODINGS.iterkeys(): + self.assertEqual(name, DoPut(_REMOTE, '/tools/default-encoding', name)) + self.assertEqual(name, DoGet(_REMOTE, '/tools/default-encoding')) + + i = CallFindScu([ '-k', '0008,0052=STUDY', + '-k', 'SpecificCharacterSet', + '-k', 'PatientName' ]) + + characterSet = re.findall('\(0008,0005\).*?\[(.*?)\]', i) + self.assertEqual(1, len(characterSet)) + self.assertEqual(ENCODINGS[name][0], characterSet[0].strip()) + + patientName = re.findall('\(0010,0010\).*?\[(.*?)\]', i) + self.assertEqual(1, len(patientName)) + + expected = TEST.encode(ENCODINGS[name][1], 'ignore') + self.assertEqual(expected, patientName[0].strip()) + + + #for master in ENCODINGS: + for master in [ 'Latin1', 'Utf8', 'Cyrillic' ]: # Shortcut to speedup tests + self.assertEqual(master, DoPut(_REMOTE, '/tools/default-encoding', master)) + self.assertEqual(master, DoGet(_REMOTE, '/tools/default-encoding')) + + for name in ENCODINGS: + DropOrthanc(_REMOTE) + UploadInstance(_REMOTE, 'Encodings/Lena-%s.dcm' % ENCODINGS[name][1]) + + i = CallFindScu([ '-k', '0008,0052=STUDY', + '-k', 'PatientID', + '-k', 'SpecificCharacterSet', + '-k', 'PatientName' ]) + i = i.decode(ENCODINGS[master][1]) + + characterSet = re.findall('\(0008,0005\).*?\[(.*?)\]', i) + self.assertEqual(1, len(characterSet)) + self.assertEqual(ENCODINGS[master][0], characterSet[0].strip()) + + patientId = re.findall('\(0010,0020\).*?\[(.*?)\]', i) + self.assertEqual(1, len(patientId)) + self.assertEqual(ENCODINGS[name][1], patientId[0].strip()) + + patientName = re.findall('\(0010,0010\).*?\[(.*?)\]', i) + self.assertEqual(1, len(patientName)) + + tmp = ENCODINGS[name][1] + expected = TEST.encode(tmp, 'ignore').decode(tmp) + tmp = ENCODINGS[master][1] + expected = expected.encode(tmp, 'ignore').decode(tmp) + + self.assertEqual(expected, patientName[0].strip()) + + + a = DoPost(_REMOTE, '/tools/find', { 'Expand' : True, + 'Level' : 'Study', + 'Query' : { }}) + self.assertEqual(1, len(a)) + + tmp = ENCODINGS[name][1] + self.assertEqual(TEST.encode(tmp, 'ignore').decode(tmp), a[0]["PatientMainDicomTags"]["PatientName"])