changeset 174:d468cbe1b161

added tests for IncomingWorklistRequestFilter
author am@osimis.io
date Thu, 20 Sep 2018 11:51:34 +0200
parents ed3db6386587
children 09ca519087a1
files Database/Worklists/Sequences/NO_STATION_AET/orig.7705.dump Database/Worklists/Sequences/NO_STATION_AET/orig.7814.other.station.dump Database/Worklists/Working/orig.7814.other.station.dump.wl Plugins/Worklists/Run.py README Tests/Tests.py Tests/Toolbox.py
diffstat 7 files changed, 157 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Database/Worklists/Sequences/NO_STATION_AET/orig.7705.dump	Thu Sep 20 11:51:34 2018 +0200
@@ -0,0 +1,44 @@
+# Dicom-Meta-Information-Header
+# Used TransferSyntax: Little Endian Explicit
+(0002,0000) UL 200                                      #   4, 1 FileMetaInformationGroupLength
+(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
+(0002,0002) UI [1.2.276.0.7230010.3.1.0.1]              #  26, 1 MediaStorageSOPClassUID
+(0002,0003) UI [1.2.276.0.7230010.3.1.4.2173265676.11480.1480155293.189] #  56, 1 MediaStorageSOPInstanceUID
+(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID
+(0002,0012) UI [1.2.276.0.7230010.3.0.3.6.0]            #  28, 1 ImplementationClassUID
+(0002,0013) SH [OFFIS_DCMTK_360]                        #  16, 1 ImplementationVersionName
+
+# Dicom-Data-Set
+# Used TransferSyntax: Little Endian Explicit
+(0008,0005) CS [ISO_IR 100]                             #  10, 1 SpecificCharacterSet
+(0008,0050) SH [AN123456]                               #  14, 1 AccessionNumber
+(0008,0090) PN [ReferringPhysicianName]                 #  12, 1 ReferringPhysicianName
+(0008,1050) PN [PerformingPhysicianName]                #  12, 1 PerformingPhysicianName
+(0010,0010) PN [PatientName]                            #   4, 1 PatientName
+(0010,0020) LO [01234567]                               #  10, 1 PatientID
+(0010,0030) DA [20120201]                               #   8, 1 PatientBirthDate
+(0010,0040) CS [F]                                      #   2, 1 PatientSex
+(0010,2000) LO (no value available)                     #   0, 0 MedicalAlerts
+(0010,2110) LO (no value available)                     #   0, 0 Allergies
+(0010,2201) LO [Dog]                                    #   4, 1 PatientSpeciesDescription
+(0010,2297) PN [ResponsiblePerson]                      #  16, 1 ResponsiblePerson
+(0020,000d) UI [1.2.826.0.1.12345678.8.975.1.11.123456.20161117140053.7705] #  58, 1 StudyInstanceUID
+(0032,1032) PN [RequestingPhysician]                    #  12, 1 RequestingPhysician
+(0032,1060) LO (no value available)                     #   0, 0 RequestedProcedureDescription
+(0040,0100) SQ (Sequence with explicit length #=1)      # 166, 1 ScheduledProcedureStepSequence
+  (fffe,e000) na (Item with explicit length #=11)         # 158, 1 Item
+    (0008,0060) CS [DX]                                     #   2, 1 Modality
+    (0032,1070) LO (no value available)                     #   0, 0 RequestedContrastAgent
+    (0040,0001) AE [STATION_AET]                            #   8, 1 ScheduledStationAETitle
+    (0040,0002) DA [20161117]                               #   8, 1 ScheduledProcedureStepStartDate
+    (0040,0003) TM [140053]                                 #   6, 1 ScheduledProcedureStepStartTime
+    (0040,0006) PN [ScheduledPerformingPhysicianName]                           #  12, 1 ScheduledPerformingPhysicianName
+    (0040,0009) SH (no value available)                     #   0, 0 ScheduledProcedureStepID
+    (0040,0011) SH (no value available)                     #   0, 0 ScheduledProcedureStepLocation
+    (0040,0012) LO (no value available)                     #   0, 0 PreMedication
+    (0040,0400) LT (no value available)                     #   0, 0 CommentsOnTheScheduledProcedureStep
+    (0040,1005) LO [RequestedProcedureLocation]          #  34, 1 RequestedProcedureLocation
+  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
+(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem
+(0040,1001) SH (no value available)                     #   0, 0 RequestedProcedureID
+(0040,1003) SH (no value available)                     #   0, 0 RequestedProcedurePriority
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Database/Worklists/Sequences/NO_STATION_AET/orig.7814.other.station.dump	Thu Sep 20 11:51:34 2018 +0200
@@ -0,0 +1,45 @@
+(0008,0050) SH [AN123457]                               #  14, 1 AccessionNumber
+(0008,0090) PN [ReferringPhysiciansName]                #  12, 1 ReferringPhysiciansName
+(0008,1080) LO (no value available)                     #   0, 0 AdmittingDiagnosesDescription
+(0008,1110) SQ (Sequence with explicit length #=0)      #  36, 1 ReferencedStudySequence
+(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem
+(0008,1120) SQ (Sequence with explicit length #=0)      #  36, 1 ReferencedPatientSequence
+(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem
+(0010,0010) PN [nn]                                     #   2, 1 PatientsName
+(0010,0020) LO [01234568]                               #  10, 1 PatientID
+(0010,0030) DA (no value available)                     #   0, 0 PatientsBirthDate
+(0010,0040) CS [F ]                                     #   2, 1 PatientsSex
+(0010,1000) LO (no value available)                     #   0, 0 OtherPatientIDs
+(0010,1030) DS (no value available)                     #   0, 0 PatientsWeight
+(0010,1040) LO (no value available)                     #   0, 0 PatientsAddress
+(0010,2000) LO (no value available)                     #   0, 0 MedicalAlerts
+(0010,2110) LO (no value available)                     #   0, 0 ContrastAllergies
+(0010,21c0) US 4                                        #   2, 1 PregnancyStatus
+(0020,000d) UI [1.2.826.0.1.12345678.8.975.1.11.123456.20161117140053.7814] #  58, 1 StudyInstanceUID
+(0032,1032) PN [RequestingPhysician]                           #  12, 1 RequestingPhysician
+(0032,1060) LO (no value available)                     #   0, 0 RequestedProcedureDescription
+(0038,0010) LO (no value available)                     #   0, 0 AdmissionID
+(0038,0050) LO (no value available)                     #   0, 0 SpecialNeeds
+(0038,0300) LO (no value available)                     #   0, 0 CurrentPatientLocation
+(0038,0500) LO (no value available)                     #   0, 0 PatientState
+(0040,0100) SQ (Sequence with explicit length #=1)      # 176, 1 ScheduledProcedureStepSequence
+  (fffe,e000) na (Item with explicit length #=13)         # 168, 1 Item
+    (0008,0060) CS [CR]                                     #   2, 1 Modality
+    (0032,1070) LO (no value available)                     #   0, 0 RequestedContrastAgent
+    (0040,0001) AE [ORTHANCTEST]                      #   8, 1 ScheduledStationAETitle
+    (0040,0002) DA [20161116]                               #   8, 1 ScheduledProcedureStepStartDate
+    (0040,0003) TM [110253]                                 #   6, 1 ScheduledProcedureStepStartTime
+    (0040,0004) DA (no value available)                     #   0, 0 ScheduledProcedureStepEndDate
+    (0040,0005) TM (no value available)                     #   0, 0 ScheduledProcedureStepEndTime
+    (0040,0006) PN [ScheduledPerformingPhysicianName]                           #  12, 1 ScheduledPerformingPhysiciansName
+    (0040,0007) LO (no value available)                     #   0, 0 ScheduledProcedureStepDescription
+    (0040,0009) SH (no value available)                     #   0, 0 ScheduledProcedureStepID
+    (0040,0010) SH (no value available)                     #   0, 0 ScheduledStationName
+    (0040,0011) SH (no value available)                     #   0, 0 ScheduledProcedureStepLocation
+    (0040,0020) CS (no value available)                     #   0, 0 ScheduledProcedureStepStatus
+  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
+(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem
+(0040,1001) SH (no value available)                     #   0, 0 RequestedProcedureID
+(0040,1003) SH (no value available)                     #   0, 0 RequestedProcedurePriority
+(0040,1004) LO (no value available)                     #   0, 0 PatientTransportArrangements
+(0040,3001) LO (no value available)                     #   0, 0 ConfidentialityConstraintOnPatientDataDescription
Binary file Database/Worklists/Working/orig.7814.other.station.dump.wl has changed
--- a/Plugins/Worklists/Run.py	Wed Sep 19 15:26:17 2018 +0200
+++ b/Plugins/Worklists/Run.py	Thu Sep 20 11:51:34 2018 +0200
@@ -185,6 +185,7 @@
             warnings.simplefilter("ignore", ResourceWarning)
 
         ClearDatabase()
+        DoPost(ORTHANC, '/tools/execute-script', 'function IncomingWorklistRequestFilter(query, origin) return query end', 'application/lua')
 
 
     def test_single(self):
@@ -241,6 +242,30 @@
 
         self.assertEqual(1, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', [])))
 
+    def test_filter_issuer_aet_from_lua(self):
+        AddToDatabase('Sequences/STATION_AET/orig.7814.dump')  # targeted at STATION_AET
+        AddToDatabase('Sequences/STATION_AET/orig.7814.other.station.dump') # targeted at ORTHANC_TEST
+
+        self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', []))) # query is not targeting any station -> match all
+        InstallLuaScript(ORTHANC, "\
+            function IncomingWorklistRequestFilter(query, origin)\
+                query['0040,0100'][1]['0040,0001'] = origin['RemoteAet']\
+                return query\
+            end");
+
+        self.assertEqual(1, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', []))) # now, query is targeting ORTHANCTEST -> match one
+
+
+    def test_remove_aet_from_query(self):
+        AddToDatabase('Sequences/NO_STATION_AET/orig.7814.other.station.dump')  # targeted at ORTHANCTEST
+
+        self.assertEqual(0, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) # query is targeting STATION_AET -> will not match
+        InstallLuaScript(ORTHANC, "\
+            function IncomingWorklistRequestFilter(query, origin)\
+                query['0040,0100'][1]['0040,0001'] = nil\
+                return query\
+            end");
+        self.assertEqual(1, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) # query is targeting STATION_AET but, since we have removed this field, we should get 2 queries
 
     def test_encodings(self):
         # Check out ../../Database/Worklists/Encodings/database.dump
--- a/README	Wed Sep 19 15:26:17 2018 +0200
+++ b/README	Thu Sep 20 11:51:34 2018 +0200
@@ -14,6 +14,14 @@
 General information about Orthanc can be found on its official
 Website: http://www.orthanc-server.com/
 
+Prerequisites:
+=============
+
+You need Python2.7 installed with the following package
+# pip2 install httplib2 Pillow
+
+You also need DCMTK and Dicom3Tools
+# sudo apt-get install -y dicom3tools DCMTK
 
 Quick-start: Running tests on the localhost 
 ===========================================
@@ -31,6 +39,18 @@
 
 # python ./Tests/Run.py
 
+To test the worklist plugin
+---------------------------
+
+1. In the first command shell:
+
+# python ./GenerateConfigurationForTests.py --force --plugins /home/.../libModalityWorklists.so
+# Orthanc IntegrationTestsConfiguration.json
+
+2. In the second command shell:
+
+# python ./Tests/Run.py
+
 
 
 Running the tests
--- a/Tests/Tests.py	Wed Sep 19 15:26:17 2018 +0200
+++ b/Tests/Tests.py	Thu Sep 20 11:51:34 2018 +0200
@@ -56,16 +56,6 @@
     return result
 
 
-def InstallLuaScript(path):
-    with open(GetDatabasePath(path), 'r') as f:
-        DoPost(_REMOTE, '/tools/execute-script', f.read(), 'application/lua')
-    
-
-def UninstallLuaCallbacks():
-    DoPost(_REMOTE, '/tools/execute-script', 'function OnStoredInstance() end', 'application/lua')
-    InstallLuaScript('Lua/TransferSyntaxEnable.lua')
-
-
 def CompareLists(a, b):
     if len(a) != len(b):
         return False
@@ -147,7 +137,7 @@
 
         DropOrthanc(_LOCAL)
         DropOrthanc(_REMOTE)
-        UninstallLuaCallbacks()
+        UninstallLuaCallbacks(_REMOTE)
         #print "In test", self._testMethodName
         
     def AssertSameImages(self, truth, url):
@@ -1913,30 +1903,30 @@
 
         DropOrthanc(_REMOTE)
         DropOrthanc(_LOCAL)
-        InstallLuaScript('Lua/Autorouting.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/Autorouting.lua')
         UploadInstance(_REMOTE, knee1)
         UploadInstance(_REMOTE, knee2)
         UploadInstance(_REMOTE, other)
         WaitEmpty(_REMOTE)
-        UninstallLuaCallbacks()
+        UninstallLuaCallbacks(_REMOTE)
         self.assertEqual(3, len(DoGet(_LOCAL, '/instances')))
 
         DropOrthanc(_REMOTE)
         DropOrthanc(_LOCAL)
-        InstallLuaScript('Lua/AutoroutingConditional.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/AutoroutingConditional.lua')
         UploadInstance(_REMOTE, knee1)
         UploadInstance(_REMOTE, knee2)
         UploadInstance(_REMOTE, other)
         WaitEmpty(_REMOTE)
-        UninstallLuaCallbacks()
+        UninstallLuaCallbacks(_REMOTE)
         self.assertEqual(2, len(DoGet(_LOCAL, '/instances')))
         
         DropOrthanc(_REMOTE)
         DropOrthanc(_LOCAL)
-        InstallLuaScript('Lua/AutoroutingModification.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/AutoroutingModification.lua')
         UploadInstance(_REMOTE, knee1)
         WaitEmpty(_REMOTE)
-        UninstallLuaCallbacks()
+        UninstallLuaCallbacks(_REMOTE)
         i = DoGet(_LOCAL, '/instances')
         self.assertEqual(1, len(i))
         
@@ -2048,11 +2038,11 @@
                                       stderr = FNULL)
 
         self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
-        InstallLuaScript('Lua/TransferSyntaxDisable.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/TransferSyntaxDisable.lua')
         self.assertRaises(Exception, lambda: storescu('Knix/Loc/IM-0001-0001.dcm', False))
         self.assertRaises(Exception, lambda: storescu('UnknownSopClassUid.dcm', True))
         self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
-        InstallLuaScript('Lua/TransferSyntaxEnable.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/TransferSyntaxEnable.lua')
         DoPost(_REMOTE, '/tools/execute-script', "print('All special transfer syntaxes are now accepted')")
         storescu('Knix/Loc/IM-0001-0001.dcm', False)
         storescu('UnknownSopClassUid.dcm', True)
@@ -2264,7 +2254,7 @@
         DropOrthanc(_REMOTE)        
         DropOrthanc(_LOCAL)        
 
-        InstallLuaScript('Lua/AutoroutingChangeAet.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/AutoroutingChangeAet.lua')
         DoPost(_REMOTE, '/tools/execute-script', 'aet = "HELLO"', 'application/lua')
 
         self.assertEqual(0, len(DoGet(_LOCAL, '/instances')))
@@ -3826,7 +3816,7 @@
         # instance appears to be stored and then everything just
         # halts, ie Orthanc wont respond to anything after that."
         # https://groups.google.com/d/msg/orthanc-users/Rc-Beb42xc8/JUgdzrmCAgAJ
-        InstallLuaScript('Lua/Jpeg2000Conversion.lua')
+        InstallLuaScriptFromPath(_REMOTE, 'Lua/Jpeg2000Conversion.lua')
 
         subprocess.check_call([ FindExecutable('storescu'),
                                 _REMOTE['Server'], str(_REMOTE['DicomPort']),
--- a/Tests/Toolbox.py	Wed Sep 19 15:26:17 2018 +0200
+++ b/Tests/Toolbox.py	Thu Sep 20 11:51:34 2018 +0200
@@ -180,6 +180,18 @@
     for s in DoGet(orthanc, '/patients'):
         DoDelete(orthanc, '/patients/%s' % s)
 
+def InstallLuaScriptFromPath(orthanc, path):
+    with open(GetDatabasePath(path), 'r') as f:
+        InstallLuaScript(orthanc, f.read())
+    
+def InstallLuaScript(orthanc, script):
+    DoPost(orthanc, '/tools/execute-script', script, 'application/lua')
+
+def UninstallLuaCallbacks(orthanc):
+    DoPost(orthanc, '/tools/execute-script', 'function OnStoredInstance() end', 'application/lua')
+    InstallLuaScriptFromPath(orthanc, 'Lua/TransferSyntaxEnable.lua')
+
+
 def ComputeMD5(data):
     m = hashlib.md5()
     m.update(data)