Mercurial > hg > orthanc
comparison OrthancServer/Resources/GenerateAnonymizationProfile.py @ 4678:2e850edf03d6
Full support for the anonymization of subsequences containing tags whose VR is UI
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 04 Jun 2021 17:38:43 +0200 |
parents | caf963ee3de9 |
children | f0038043fb97 7053502fbf97 |
comparison
equal
deleted
inserted
replaced
4677:521e39b3f2c0 | 4678:2e850edf03d6 |
---|---|
60 | 60 |
61 def FormatLine(command, name): | 61 def FormatLine(command, name): |
62 indentation = 65 | 62 indentation = 65 |
63 | 63 |
64 if len(command) > indentation: | 64 if len(command) > indentation: |
65 raise Exception('Too long command') | 65 indentation = len(command) + 2 |
66 | 66 |
67 line = command + (' ' * (indentation - len(command))) + '// ' + name | 67 line = command + (' ' * (indentation - len(command))) + '// ' + name |
68 LINES.append(line) | 68 LINES.append(line) |
69 | 69 |
70 def FormatUnknown(rawTag, name, profile): | 70 def FormatUnknown(rawTag, name, profile): |
71 FormatLine('// TODO: %s with rule %s' % (rawTag, profile), name) | 71 FormatLine('// TODO: %s with rule %s' % (rawTag, profile), name) |
72 | 72 |
73 | 73 |
74 RAW_TAG_RE = re.compile(r'^\(\s*([0-9A-F]{4})\s*,\s*([0-9A-F]{4})\s*\)$') | 74 RAW_TAG_RE = re.compile(r'^\(\s*([0-9A-Fx]{4})\s*,\s*([0-9A-Fx]{4})\s*\)$') |
75 | 75 |
76 | 76 |
77 for table in root.iter('%stable' % br): | 77 for table in root.iter('%stable' % br): |
78 if table.attrib['label'] == 'E.1-1': | 78 if table.attrib['label'] == 'E.1-1': |
79 for row in table.find('%stbody' % br).iter('%str' % br): | 79 for row in table.find('%stbody' % br).iter('%str' % br): |
84 if len(name.strip()) == 0: | 84 if len(name.strip()) == 0: |
85 continue | 85 continue |
86 | 86 |
87 match = RAW_TAG_RE.match(rawTag) | 87 match = RAW_TAG_RE.match(rawTag) |
88 if match == None: | 88 if match == None: |
89 FormatUnknown(rawTag, name, profile) | 89 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) |
90 else: | 90 else: |
91 tag = '0x%s, 0x%s' % (match.group(1).lower(), match.group(2).lower()) | 91 group = match.group(1).lower() |
92 element = match.group(2).lower() | |
93 tag = '0x%s, 0x%s' % (group, element) | |
92 | 94 |
93 if name in [ | 95 if 'x' in group or 'x' in element: |
94 'SOP Instance UID', | 96 if profile == 'X': |
95 'Series Instance UID', | 97 groupFrom = group.replace('x', '0') |
96 'Study Instance UID', | 98 groupTo = group.replace('x', 'f') |
99 elementFrom = element.replace('x', '0') | |
100 elementTo = element.replace('x', 'f') | |
101 FormatLine('removedRanges_.push_back(DicomTagRange(0x%s, 0x%s, 0x%s, 0x%s));' % ( | |
102 groupFrom, groupTo, elementFrom, elementTo), name) | |
103 else: | |
104 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) | |
105 elif tag in [ | |
106 '0x0008, 0x0018', # SOP Instance UID | |
107 '0x0020, 0x000e', # Series Instance UID | |
108 '0x0020, 0x000d', # Study Instance UID | |
97 ]: | 109 ]: |
98 FormatLine('// Tag (%s) is set in Apply() /* %s */' % (tag, profile), name) | 110 FormatLine('// Tag (%s) is set in Apply() /* %s */' % (tag, profile), name) |
99 elif name in [ | 111 elif tag in [ |
100 'Referenced Image Sequence', | 112 '0x0010, 0x0010', # Patient's Name |
101 'Source Image Sequence', | 113 '0x0010, 0x0020', # Patient ID |
102 'Referenced SOP Instance UID', | |
103 'Frame of Reference UID', | |
104 'Referenced Frame of Reference UID', | |
105 'Related Frame of Reference UID', | |
106 ]: | |
107 FormatLine('// Tag (%s) => RelationshipsVisitor /* %s */' % (tag, profile), name) | |
108 elif name in [ | |
109 'Patient\'s Name', | |
110 'Patient ID', | |
111 ]: | 114 ]: |
112 FormatLine('// Tag (%s) is set below (*) /* %s */' % (tag, profile), name) | 115 FormatLine('// Tag (%s) is set below (*) /* %s */' % (tag, profile), name) |
116 elif profile == 'U': | |
117 FormatLine('uids_.insert(DicomTag(%s));' % (tag), name) | |
118 elif profile == 'X/Z/U*': | |
119 FormatLine('// RelationshipsVisitor handles (%s) /* %s */' % (tag, profile), name) | |
113 elif profile == 'X': | 120 elif profile == 'X': |
114 FormatLine('removals_.insert(DicomTag(%s));' % tag, name) | 121 FormatLine('removals_.insert(DicomTag(%s));' % tag, name) |
115 elif profile.startswith('X/'): | 122 elif profile.startswith('X/'): |
116 FormatLine('removals_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) | 123 FormatLine('removals_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) |
117 elif profile == 'Z': | 124 elif profile == 'Z': |
118 FormatLine('clearings_.insert(DicomTag(%s));' % tag, name) | 125 FormatLine('clearings_.insert(DicomTag(%s));' % tag, name) |
119 elif profile == 'D' or profile.startswith('Z/'): | 126 elif profile == 'D' or profile.startswith('Z/'): |
120 FormatLine('clearings_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) | 127 FormatLine('clearings_.insert(DicomTag(%s)); /* %s */' % (tag, profile), name) |
121 elif profile == 'U': | |
122 FormatLine('removals_.insert(DicomTag(%s)); /* TODO UID */' % (tag), name) | |
123 else: | 128 else: |
124 FormatUnknown(rawTag, name, profile) | 129 # FormatUnknown(rawTag, name, profile) |
130 raise Exception('Unsupported rule: %s, %s, %s' % (rawTag, profile, name)) | |
125 | 131 |
126 for line in sorted(LINES): | 132 for line in sorted(LINES): |
127 print(line.encode('ascii', 'ignore').decode('ascii')) | 133 print(line.encode('ascii', 'ignore').decode('ascii')) |
128 | 134 |
129 | 135 |