Mercurial > hg > orthanc
annotate Resources/Samples/Python/DownloadAnonymized.py @ 635:cd3b60f6e7d4
refactoring cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Oct 2013 10:48:03 +0100 |
parents | 61e4c62b8c35 |
children | 44382c8bcd15 |
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 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 URL = 'http://localhost:8042' |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # 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
|
9 # been anonymized in Orthanc. |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 import os |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 import os.path |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 import sys |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 import RestToolbox |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # Loop over the patients |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 for patient in RestToolbox.DoGet('%s/patients' % URL): |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # Ignore patients whose name starts with "Anonymized", as it is |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 # the result of a previous anonymization |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient)) |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 name = infos['MainDicomTags']['PatientName'].lower() |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 if name.startswith('anonymized'): |
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 # Trigger the download |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 print 'Downloading %s' % name |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 zipContent = RestToolbox.DoGet('%s/patients/%s/archive' % (URL, patient)) |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 f = open(os.path.join('/tmp', name + '.zip'), 'wb') |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 f.write(zipContent) |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 f.close() |