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