comparison Resources/Samples/Python/DownloadAnonymized.py @ 353:61e4c62b8c35

samples of anonymization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Jan 2013 16:58:07 +0100
parents
children 44382c8bcd15
comparison
equal deleted inserted replaced
352:cc9eddbf07d3 353:61e4c62b8c35
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4
5 URL = 'http://localhost:8042'
6
7 #
8 # This sample code will download a ZIP file for each patient that has
9 # been anonymized in Orthanc.
10 #
11
12 import os
13 import os.path
14 import sys
15 import RestToolbox
16
17 # Loop over the patients
18 for patient in RestToolbox.DoGet('%s/patients' % URL):
19
20 # Ignore patients whose name starts with "Anonymized", as it is
21 # the result of a previous anonymization
22 infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient))
23 name = infos['MainDicomTags']['PatientName'].lower()
24 if name.startswith('anonymized'):
25
26 # Trigger the download
27 print 'Downloading %s' % name
28 zipContent = RestToolbox.DoGet('%s/patients/%s/archive' % (URL, patient))
29 f = open(os.path.join('/tmp', name + '.zip'), 'wb')
30 f.write(zipContent)
31 f.close()