Mercurial > hg > orthanc
comparison OrthancServer/Resources/Samples/Python/DownloadAnonymized.py @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | Resources/Samples/Python/DownloadAnonymized.py@94f4a18a79cc |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Orthanc - A Lightweight, RESTful DICOM Store | |
5 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
6 # Department, University Hospital of Liege, Belgium | |
7 # Copyright (C) 2017-2020 Osimis S.A., Belgium | |
8 # | |
9 # This program is free software: you can redistribute it and/or | |
10 # modify it under the terms of the GNU General Public License as | |
11 # published by the Free Software Foundation, either version 3 of the | |
12 # License, or (at your option) any later version. | |
13 # | |
14 # This program is distributed in the hope that it will be useful, but | |
15 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 # General Public License for more details. | |
18 # | |
19 # You should have received a copy of the GNU General Public License | |
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 | |
23 | |
24 URL = 'http://127.0.0.1:8042' | |
25 | |
26 # | |
27 # This sample code will download a ZIP file for each patient that has | |
28 # been anonymized in Orthanc. | |
29 # | |
30 | |
31 import os | |
32 import os.path | |
33 import sys | |
34 import RestToolbox | |
35 | |
36 # Loop over the patients | |
37 for patient in RestToolbox.DoGet('%s/patients' % URL): | |
38 | |
39 # Ignore patients whose name starts with "Anonymized", as it is | |
40 # the result of a previous anonymization | |
41 infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient)) | |
42 name = infos['MainDicomTags']['PatientName'].lower() | |
43 if name.startswith('anonymized'): | |
44 | |
45 # Trigger the download | |
46 print('Downloading %s' % name) | |
47 zipContent = RestToolbox.DoGet('%s/patients/%s/archive' % (URL, patient)) | |
48 with open(os.path.join('/tmp', name + '.zip'), 'wb') as f: | |
49 f.write(zipContent) |