changeset 87:4b24faec842b

test_reconstruct_json2 + test_private_tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Nov 2016 17:42:39 +0100
parents 0401ef51f5c1
children 47a3d6c08413
files Database/PrivateMDNTags.dic GenerateConfigurationForTests.py Tests/Tests.py
diffstat 3 files changed, 76 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Database/PrivateMDNTags.dic	Mon Nov 07 17:42:39 2016 +0100
@@ -0,0 +1,8 @@
+# DCMDICTPATH=PrivateMDNTags.dic:/usr/share/libdcmtk2/dicom.dic dcm2xml ./PrivateMDNTags.dcm
+
+# Private tags taken from DICOM conformance statement of
+# Philips "GEMINI PET/CT Systems with v3.5 or 3.6" (page 141/168)
+
+(7053,"Philips PET Private Group",03)	ST	OriginalImageFileName	1
+(00e1,"ELSCINT1", c2)	UI	PET-CT-MultiModalityName	1
+
--- a/GenerateConfigurationForTests.py	Mon Nov 07 15:17:19 2016 +0100
+++ b/GenerateConfigurationForTests.py	Mon Nov 07 17:42:39 2016 +0100
@@ -24,6 +24,7 @@
 import socket
 import subprocess
 import sys
+import json
 
 ##
 ## Parse the command-line arguments
@@ -77,31 +78,36 @@
 subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ])
 
 with open(args.target, 'r') as f:
-    config = f.read()
+    # Remove the C++-style comments
+    nocomment = re.sub('//.*$', '', f.read(), 0, re.MULTILINE)
+
+    # Remove the C-style comments
+    nocomment = re.sub('/\*.*?\*/', '', nocomment, 0, re.DOTALL | re.MULTILINE)
+
+    config = json.loads(nocomment)
 
-config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANC"', config)
-config = re.sub(r'("DicomPort"\s*:)\s*.*?,', r'\1 %d,' % args.dicom, config)
-config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
-config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
-config = re.sub(r'("DicomAssociationCloseDelay"\s*:)\s*[0-9]*', r'\1 0', config)
-config = re.sub(r'("DefaultEncoding"\s*:)\s*".*?"', r'\1 "Windows1251"', config)  # For test_issue_32
-config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : "orthanctest"', config)
-config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanctest" : [ "%s", "%s", %d ]' % 
-                ('ORTHANCTEST', ip, 5001), config)
-config = re.sub(r'("OrthancPeers"\s*:)\s*{', r'\1 { "peer" : [ "http://%s:%d/", "%s", "%s" ]' % 
-                (ip, 5000, 'alice', 'orthanctest'), config)
-config = re.sub(r'("HttpCompressionEnabled"\s*:)\s*true', r'\1 false', config)
+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 ] }
+config['DicomPort'] = args.dicom
+config['HttpCompressionEnabled'] = False
+config['OrthancPeers'] = { 'peer' : [ 'http://%s:%d/' % (ip, 5000), 'alice', 'orthanctest' ] }
+config['RegisteredUsers'] = { 'alice' : 'orthanctest' }
+config['RemoteAccessAllowed'] = True
+config['Dictionary'] = {
+    "00e1,10c2" : [ "UI", "PET-CT Multi Modality Name", 1, 1, "ELSCINT1" ],
+    "7053,1003" : [ "ST", "Original Image Filename", 1, 1, "Philips PET Private Group" ]
+}
 
 # Enable case-insensitive PN (the default on versions <= 0.8.6)
-config = re.sub(r'("CaseSensitivePN"\s*:)\s*true', r'\1 false', config) 
-
-config = re.sub(r'("AllowFindSopClassesInStudy"\s*:)\s*false', r'\1 true', config)
-
+config['CaseSensitivePN'] = False
 
 if args.plugins != None:
-    config = re.sub(r'("Plugins"\s*:\s*\[)', r'\1 "%s"' % args.plugins, config)
-   
+    config['Plugins'] = [ args.plugins ]
 
 with open(args.target, 'wt') as f:
-    f.write(config)
-
+    f.write(json.dumps(config, indent = True, sort_keys = True))
+    f.write('\n')
--- a/Tests/Tests.py	Mon Nov 07 15:17:19 2016 +0100
+++ b/Tests/Tests.py	Mon Nov 07 17:42:39 2016 +0100
@@ -1361,6 +1361,7 @@
         a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')['ID']
         self.assertTrue('now' in DoGet(_REMOTE, '/tools'))
         self.assertTrue('dicom-conformance' in DoGet(_REMOTE, '/tools'))
+        self.assertTrue('invalidate-tags' in DoGet(_REMOTE, '/tools'))
         self.assertTrue(len(DoGet(_REMOTE, '/tools/dicom-conformance')) > 1000)
         self.assertTrue('orthanctest' in DoGet(_REMOTE, '/modalities'))
         self.assertTrue('echo' in DoGet(_REMOTE, '/modalities/orthanctest'))
@@ -2573,12 +2574,18 @@
         with open(GetDatabasePath('PrivateMDNTagsSimplify.json'), 'r') as f:
             self.assertTrue(CompareTags(t, json.loads(f.read()), [
                 'ACR_NEMA_2C_VariablePixelDataGroupLength', 
-                'GenericGroupLength'
+                'GenericGroupLength',
+                'Original Image Filename',
+                'PET-CT Multi Modality Name'
             ]))
 
         t = DoGet(_REMOTE, '/instances/%s/tags' % i)
         with open(GetDatabasePath('PrivateMDNTagsFull.json'), 'r') as f:
-            self.assertTrue(CompareTags(t, json.loads(f.read()), [ '7fe0,0000' ]))
+            self.assertTrue(CompareTags(t, json.loads(f.read()), [ 
+                '7fe0,0000',
+                '00e1,10c2',
+                '7053,1003'
+            ]))
 
         t = DoGet(_REMOTE, '/instances/%s/tags?simplify' % j)
         with open(GetDatabasePath('PrivateTagsSimplify.json'), 'r') as f:
@@ -2942,3 +2949,35 @@
         third = DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance)
         self.assertEqual(str(first), str(second))
         self.assertEqual(str(first), str(third))
+
+
+    def test_reconstruct_json2(self):
+        self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
+
+        a = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID']
+        b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')['ID']
+
+        self.assertEqual('BRAINIX', DoGet(_REMOTE, '/instances/%s/tags?simplify' % a)['PatientName'])
+        self.assertEqual('KNEE', DoGet(_REMOTE, '/instances/%s/tags?simplify' % b)['PatientName'])
+
+        self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % a)))
+        self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % b)))
+
+        DoPost(_REMOTE, '/tools/invalidate-tags', '', 'text/plain')
+
+        self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/attachments' % a)))
+        self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/attachments' % b)))
+
+        self.assertEqual('BRAINIX', DoGet(_REMOTE, '/instances/%s/tags?simplify' % a)['PatientName'])
+        self.assertEqual('KNEE', DoGet(_REMOTE, '/instances/%s/tags?simplify' % b)['PatientName'])
+
+        self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % a)))
+        self.assertEqual(2, len(DoGet(_REMOTE, '/instances/%s/attachments' % b)))
+
+
+    def test_private_tags(self):
+        i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID']
+        t = DoGet(_REMOTE, '/instances/%s/tags?simplify' % i)
+        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'])
+