annotate OrthancServer/Resources/Samples/Python/ArchiveAllPatients.py @ 5185:0ea402b4d901

upgrade to year 2023
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 25 Mar 2023 12:27:21 +0100
parents 43e613a7756b
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1899
diff changeset
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
7 # Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
8 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1899
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 #
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # 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
11 # 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
12 # 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
13 # License, or (at your option) any later version.
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 #
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # 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
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # General Public License for more details.
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 #
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # 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
21 # 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
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
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import os
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import os.path
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import sys
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import RestToolbox
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 def PrintHelp():
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 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
32 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
33 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
34 exit(-1)
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 if len(sys.argv) != 3:
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 PrintHelp()
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 URL = sys.argv[1]
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 TARGET = sys.argv[2]
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 patients = RestToolbox.DoGet('%s/patients' % URL)
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 print('Downloading ZIP...')
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 zipContent = RestToolbox.DoPost('%s/tools/create-archive' % URL, patients)
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 # Write the ZIP archive at the proper location
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 with open(TARGET, 'wb') as f:
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 f.write(zipContent)