# HG changeset patch # User Sebastien Jodogne # Date 1358434918 -3600 # Node ID b51c67f28b333ee77c3fe9983a7eeab9af5a1112 # Parent 61f6a3d66b85a9b1903258f11c458416ee43e0fd documentation of the sample diff -r 61f6a3d66b85 -r b51c67f28b33 Resources/Samples/Python/ChangesLoop.py --- 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'] diff -r 61f6a3d66b85 -r b51c67f28b33 Resources/Samples/Python/RestToolbox.py --- 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 = {}):