annotate OrthancServer/Resources/Samples/Python/ManualModification.py @ 4864:09d06d99745c openssl-3.x

integration mainline->openssl-3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Dec 2021 17:18:06 +0100
parents 7053502fbf97
children 43e613a7756b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1917
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium
4831
7053502fbf97 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
7 # Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1917
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # modify it under the terms of the GNU General Public License as
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # published by the Free Software Foundation, either version 3 of the
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # License, or (at your option) any later version.
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # General Public License for more details.
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 # This sample shows how to carry on a manual modification of DICOM
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # tags spread accross various levels (Patient/Study/Series/Instance)
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 # that would normally forbidden as such by the REST API of Orthanc to
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # avoid breaking the DICOM hierarchy. This sample can be useful for
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 # more complex anonymization/modification scenarios, or for optimizing
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # the disk usage (the original and the modified instances never
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 # coexist).
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 from RestToolbox import *
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2032
65b1ce7cb84f Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1917
diff changeset
34 URL = 'http://127.0.0.1:8042'
1917
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 STUDY = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988'
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 identifiers = {}
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 for instance in DoGet('%s/studies/%s/instances' % (URL, STUDY)):
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 # Setup the parameters of the modification
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 replace = {
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 "PatientID" : "Hello",
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 "PatientName" : "Modified",
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 "StationName" : "TEST",
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 # Get the original UIDs of the instance
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 seriesUID = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, instance['ID']))
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if seriesUID in identifiers:
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 replace['SeriesInstanceUID'] = identifiers[seriesUID]
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 studyUID = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, instance['ID']))
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if studyUID in identifiers:
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 replace['StudyInstanceUID'] = identifiers[studyUID]
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 # Manually modify the instance
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 print('Modifying instance %s' % instance['ID'])
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 modified = DoPost('%s/instances/%s/modify' % (URL, instance['ID']),
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 { "Replace" : replace })
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 # Remove the original instance
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 DoDelete('%s/instances/%s' % (URL, instance['ID']))
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 # Add the modified instance
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 modifiedId = DoPost('%s/instances' % URL, modified)['ID']
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 # Register the modified UIDs
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 identifiers[seriesUID] = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, modifiedId))
7db4b909bec3 ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 identifiers[studyUID] = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, modifiedId))