# HG changeset patch # User Sebastien Jodogne # Date 1359388687 -3600 # Node ID 61e4c62b8c35f512713182bde2179bb226388698 # Parent cc9eddbf07d37c635c4bc7db0a52ddba4e9c302e samples of anonymization diff -r cc9eddbf07d3 -r 61e4c62b8c35 Resources/Samples/Python/AnonymizeAllPatients.py --- a/Resources/Samples/Python/AnonymizeAllPatients.py Mon Jan 28 16:43:49 2013 +0100 +++ b/Resources/Samples/Python/AnonymizeAllPatients.py Mon Jan 28 16:58:07 2013 +0100 @@ -22,4 +22,6 @@ if not name.startswith('anonymized'): # Trigger the anonymization - RestToolbox.DoPost('%s/patients/%s/anonymize' % (URL, patient)) + RestToolbox.DoPost('%s/patients/%s/anonymize' % (URL, patient), + { 'Keep' : [ 'SeriesDescription', + 'StudyDescription' ] }) diff -r cc9eddbf07d3 -r 61e4c62b8c35 Resources/Samples/Python/DownloadAnonymized.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Samples/Python/DownloadAnonymized.py Mon Jan 28 16:58:07 2013 +0100 @@ -0,0 +1,31 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + + +URL = 'http://localhost:8042' + +# +# This sample code will download a ZIP file for each patient that has +# been anonymized in Orthanc. +# + +import os +import os.path +import sys +import RestToolbox + +# Loop over the patients +for patient in RestToolbox.DoGet('%s/patients' % URL): + + # Ignore patients whose name starts with "Anonymized", as it is + # the result of a previous anonymization + infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient)) + name = infos['MainDicomTags']['PatientName'].lower() + if name.startswith('anonymized'): + + # Trigger the download + print 'Downloading %s' % name + zipContent = RestToolbox.DoGet('%s/patients/%s/archive' % (URL, patient)) + f = open(os.path.join('/tmp', name + '.zip'), 'wb') + f.write(zipContent) + f.close()