comparison OrthancServer/Resources/Samples/Python/ManualModification.py @ 4044:d25f4c0fa160 framework

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