Mercurial > hg > orthanc
annotate Resources/Samples/Python/ArchiveAllPatients.py @ 3244:6f35279215c4
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 16 Feb 2019 10:27:07 +0100 |
parents | 4e43e67f8ecf |
children | 94f4a18a79cc |
rev | line source |
---|---|
1899
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 5 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1899
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # Department, University Hospital of Liege, Belgium |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
7 # Copyright (C) 2017-2019 Osimis S.A., Belgium |
1899
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # This program is free software: you can redistribute it and/or |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # modify it under the terms of the GNU General Public License as |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # published by the Free Software Foundation, either version 3 of the |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # License, or (at your option) any later version. |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # This program is distributed in the hope that it will be useful, but |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # WITHOUT ANY WARRANTY; without even the implied warranty of |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # General Public License for more details. |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # You should have received a copy of the GNU General Public License |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import os |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import os.path |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import sys |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import RestToolbox |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 def PrintHelp(): |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 print('Download one ZIP archive for all the patients stored in Orthanc\n') |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 print('Usage: %s <URL> <Target>\n' % sys.argv[0]) |
2032
65b1ce7cb84f
Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
32 print('Example: %s http://127.0.0.1:8042/ /tmp/Archive.zip\n' % sys.argv[0]) |
1899
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 exit(-1) |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 if len(sys.argv) != 3: |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 PrintHelp() |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 URL = sys.argv[1] |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 TARGET = sys.argv[2] |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 patients = RestToolbox.DoGet('%s/patients' % URL) |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 print('Downloading ZIP...') |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 zipContent = RestToolbox.DoPost('%s/tools/create-archive' % URL, patients) |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 # Write the ZIP archive at the proper location |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 with open(TARGET, 'wb') as f: |
6615133a996c
new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 f.write(zipContent) |