Mercurial > hg > orthanc
annotate OrthancServer/Resources/GenerateAnonymizationProfile.py @ 5646:9d27024a431f
fix uninitialized variable minimumTlsVersion_ in DicomServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 31 May 2024 19:10:57 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 # Orthanc - A Lightweight, RESTful DICOM Store |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 # Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
7 # Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5334
diff
changeset
|
8 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # This program is free software: you can redistribute it and/or |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # modify it under the terms of the GNU General Public License as |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # published by the Free Software Foundation, either version 3 of the |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # License, or (at your option) any later version. |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # This program is distributed in the hope that it will be useful, but |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # General Public License for more details. |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # You should have received a copy of the GNU General Public License |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import re |
4675
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
25 import requests |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import sys |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import xml.etree.ElementTree as ET |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 # Usage: |
5334
5b2a5cc64cb1
upgraded anonymization to Basic Profile of PS 3.15-2023b Table E.1-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
30 # ./GenerateAnonymizationProfile.py https://raw.githubusercontent.com/jodogne/dicom-specification/master/2023b/part15.xml > ../../OrthancFramework/Sources/DicomParsing/DicomModification_Anonymization2023b.impl.h |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 if len(sys.argv) != 2: |
4675
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
33 raise Exception('Please provide the path or the URL to the part15.xml file from the DICOM standard') |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
34 |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
35 source = sys.argv[1] |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
4675
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
37 if (source.startswith('http://') or |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
38 source.startswith('https://')): |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
39 part15 = requests.get(source).content |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
40 else: |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
41 with open(source, 'r') as f: |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
42 part15 = f.read() |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
43 |
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
44 root = ET.fromstring(part15) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 br = '{http://docbook.org/ns/docbook}' # Shorthand variable |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 LINES = [] |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 def FormatLine(command, name): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 indentation = 65 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 if len(command) > indentation: |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
55 indentation = len(command) + 2 |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
4676
caf963ee3de9
DicomModification_Anonymization2017c.impl.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4675
diff
changeset
|
57 line = command + (' ' * (indentation - len(command))) + '// ' + name |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 LINES.append(line) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 def FormatUnknown(rawTag, name, profile): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 FormatLine('// TODO: %s with rule %s' % (rawTag, profile), name) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
64 RAW_TAG_RE = re.compile(r'^\(\s*([0-9A-Fx]{4})\s*,\s*([0-9A-Fx]{4})\s*\)$') |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 for table in root.iter('%stable' % br): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 if table.attrib['label'] == 'E.1-1': |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 for row in table.find('%stbody' % br).iter('%str' % br): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 rawTag = row.find('%std[2]/%spara' % (br, br)).text |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 name = row.find('%std[1]/%spara' % (br, br)).text |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 profile = row.find('%std[5]/%spara' % (br, br)).text |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 if len(name.strip()) == 0: |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 continue |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 match = RAW_TAG_RE.match(rawTag) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 if match == None: |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
79 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 else: |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
81 group = match.group(1).lower() |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
82 element = match.group(2).lower() |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
83 tag = '0x%s, 0x%s' % (group, element) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
85 if 'x' in group or 'x' in element: |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
86 if profile == 'X': |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
87 groupFrom = group.replace('x', '0') |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
88 groupTo = group.replace('x', 'f') |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
89 elementFrom = element.replace('x', '0') |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
90 elementTo = element.replace('x', 'f') |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
91 FormatLine('removedRanges_.push_back(DicomTagRange(0x%s, 0x%s, 0x%s, 0x%s));' % ( |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
92 groupFrom, groupTo, elementFrom, elementTo), name) |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
93 else: |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
94 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
95 elif tag in [ |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
96 '0x0008, 0x0018', # SOP Instance UID |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
97 '0x0020, 0x000e', # Series Instance UID |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
98 '0x0020, 0x000d', # Study Instance UID |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 ]: |
2506
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
100 FormatLine('// Tag (%s) is set in Apply() /* %s */' % (tag, profile), name) |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
101 elif tag in [ |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
102 '0x0010, 0x0010', # Patient's Name |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
103 '0x0010, 0x0020', # Patient ID |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 ]: |
2506
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
105 FormatLine('// Tag (%s) is set below (*) /* %s */' % (tag, profile), name) |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
106 elif profile == 'U': |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
107 FormatLine('uids_.insert(DicomTag(%s));' % (tag), name) |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
108 elif profile == 'X/Z/U*': |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
109 FormatLine('// RelationshipsVisitor handles (%s) /* %s */' % (tag, profile), name) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 elif profile == 'X': |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 FormatLine('removals_.insert(DicomTag(%s));' % tag, name) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 elif profile.startswith('X/'): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 FormatLine('removals_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 elif profile == 'Z': |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 FormatLine('clearings_.insert(DicomTag(%s));' % tag, name) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 elif profile == 'D' or profile.startswith('Z/'): |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 FormatLine('clearings_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 else: |
4678
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
119 # FormatUnknown(rawTag, name, profile) |
2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4676
diff
changeset
|
120 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 for line in sorted(LINES): |
4675
7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
123 print(line.encode('ascii', 'ignore').decode('ascii')) |
2312
8700dcaa02e5
GenerateAnonymizationProfile.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 |
2313
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
125 |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
126 # D - replace with a non-zero length value that may be a dummy value and consistent with the VR |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
127 # Z - replace with a zero length value, or a non-zero length value that may be a dummy value and consistent with the VR |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
128 # X - remove |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
129 # K - keep (unchanged for non-sequence attributes, cleaned for sequences) |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
130 # C - clean, that is replace with values of similar meaning known not to contain identifying information and consistent with the VR |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
131 # U - replace with a non-zero length UID that is internally consistent within a set of Instances |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
132 # Z/D - Z unless D is required to maintain IOD conformance (Type 2 versus Type 1) |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
133 # X/Z - X unless Z is required to maintain IOD conformance (Type 3 versus Type 2) |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
134 # X/D - X unless D is required to maintain IOD conformance (Type 3 versus Type 1) |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
135 # X/Z/D - X unless Z or D is required to maintain IOD conformance (Type 3 versus Type 2 versus Type 1) |
d19e716b79fa
switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2312
diff
changeset
|
136 # X/Z/U* - X unless Z or replacement of contained instance UIDs (U) is required to maintain IOD conformance (Type 3 versus Type 2 versus Type 1 sequences containing UID references) |