changeset 341:b51c67f28b33

documentation of the sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Jan 2013 16:01:58 +0100
parents 61f6a3d66b85
children a58a8be26aff
files Resources/Samples/Python/ChangesLoop.py Resources/Samples/Python/RestToolbox.py
diffstat 2 files changed, 28 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/Python/ChangesLoop.py	Thu Jan 17 15:54:02 2013 +0100
+++ b/Resources/Samples/Python/ChangesLoop.py	Thu Jan 17 16:01:58 2013 +0100
@@ -4,6 +4,11 @@
 import sys
 import RestToolbox
 
+
+##
+## Print help message
+##
+
 if len(sys.argv) != 3:
     print("""
 Sample script that continuously monitors the arrival of new DICOM
@@ -17,22 +22,42 @@
 URL = 'http://%s:%d' % (sys.argv[1], int(sys.argv[2]))
 
 
+
+##
+## The following function is called each time a new instance is
+## received.
+##
+
 def NewInstanceReceived(path):
-    print 'New instance received: "%s"' % path
+    global URL
+    patientName = RestToolbox.DoGet(URL + path + '/content/PatientName')
+    
+    # Remove the possible trailing characters due to DICOM padding
+    patientName = patientName.strip()
+
+    print 'New instance received for patient "%s": "%s"' % (patientName, path)
 
 
-URL = 'http://localhost:8042'
+
+##
+## Main loop that listens to the changes API.
+## 
+
 current = 0
 while True:
     r = RestToolbox.DoGet(URL + '/changes', {
             'since' : current,
-            'limit' : 4 
+            'limit' : 4   # Retrieve at most 4 changes at once
             })
 
     for change in r['Changes']:
+        # We are only interested interested in the arrival of new instances
         if change['ChangeType'] == 'NewInstance':
+            # Call the callback function
             path = change['Path']
             NewInstanceReceived(path)
+
+            # Delete the instance once it has been discovered
             RestToolbox.DoDelete(URL + path)
 
     current = r['Last']
--- a/Resources/Samples/Python/RestToolbox.py	Thu Jan 17 15:54:02 2013 +0100
+++ b/Resources/Samples/Python/RestToolbox.py	Thu Jan 17 16:01:58 2013 +0100
@@ -1,9 +1,5 @@
-import hashlib
 import httplib2
 import json
-import os.path
-import Image
-import zipfile
 from urllib import urlencode
 
 def DoGet(uri, data = {}):