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