# HG changeset patch # User Sebastien Jodogne # Date 1639744587 -3600 # Node ID ffc03a1d60c3f47b419e803e59b7bf75732993e2 # Parent 8bd1f0d9506ef49ff30253f2ffad1f7024ddaa4a fix sample scripts for Python3 diff -r 8bd1f0d9506e -r ffc03a1d60c3 OrthancServer/Resources/Samples/Python/ArchiveStudiesInTimeRange.py --- a/OrthancServer/Resources/Samples/Python/ArchiveStudiesInTimeRange.py Thu Dec 16 16:13:03 2021 +0100 +++ b/OrthancServer/Resources/Samples/Python/ArchiveStudiesInTimeRange.py Fri Dec 17 13:36:27 2021 +0100 @@ -36,7 +36,7 @@ def CheckIsDate(date): if len(date) != 8 or not date.isdigit(): - print '"%s" is not a valid date!\n' % date + print('"%s" is not a valid date!\n' % date) exit(-1) @@ -83,7 +83,9 @@ GetTag(study, 'StudyDescription')) # Remove any non-ASCII character in the filename - filename = filename.encode('ascii', errors = 'replace').translate(None, r"'\/:*?\"<>|!=").strip() + filename = filename.encode('ascii', errors = 'replace') + filename = filename.translate(None, b"'\/:*?\"<>|!=") + filename = filename.decode('ascii').strip() # Download the ZIP archive of the study print('Downloading %s' % filename) diff -r 8bd1f0d9506e -r ffc03a1d60c3 OrthancServer/Resources/Samples/Python/ContinuousPatientAnonymization.py --- a/OrthancServer/Resources/Samples/Python/ContinuousPatientAnonymization.py Thu Dec 16 16:13:03 2021 +0100 +++ b/OrthancServer/Resources/Samples/Python/ContinuousPatientAnonymization.py Fri Dec 17 13:36:27 2021 +0100 @@ -24,7 +24,7 @@ import time import sys import RestToolbox -import md5 +import hashlib ## @@ -66,13 +66,15 @@ # The PatientID after anonymization is taken as the 8 first # characters from the MD5 hash of the original PatientID - anonymizedID = md5.new(patientID).hexdigest()[:8] + h = hashlib.md5(patientID.encode('ascii')) + anonymizedID = h.hexdigest()[:8] anonymizedName = 'Anonymized patient %d' % COUNT COUNT += 1 RestToolbox.DoPost(URL + path + '/anonymize', { 'Replace' : { 'PatientID' : anonymizedID, - 'PatientName' : anonymizedName } }) + 'PatientName' : anonymizedName }, + 'Force' : True }) # Delete the source patient after the anonymization RestToolbox.DoDelete(URL + change['Path'])