Mercurial > hg > orthanc
comparison OrthancServer/Resources/GenerateAnonymizationProfile.py @ 4675:7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Jun 2021 19:41:11 +0200 |
parents | d9473bd5ed43 |
children | caf963ee3de9 |
comparison
equal
deleted
inserted
replaced
4674:cdab941fe17d | 4675:7e4d1f2b3a8f |
---|---|
30 # You should have received a copy of the GNU General Public License | 30 # You should have received a copy of the GNU General Public License |
31 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 31 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
32 | 32 |
33 | 33 |
34 import re | 34 import re |
35 import requests | |
35 import sys | 36 import sys |
36 import xml.etree.ElementTree as ET | 37 import xml.etree.ElementTree as ET |
37 | 38 |
38 # Usage: | 39 # Usage: |
39 # ./GenerateAnonymizationProfile.py ~/Subversion/dicom-specification/2017c/part15.xml | 40 # ./GenerateAnonymizationProfile.py https://raw.githubusercontent.com/jodogne/dicom-specification/master/2021b/part15.xml |
40 | 41 |
41 if len(sys.argv) != 2: | 42 if len(sys.argv) != 2: |
42 raise Exception('Please provide the path to the part15.xml file from the DICOM standard') | 43 raise Exception('Please provide the path or the URL to the part15.xml file from the DICOM standard') |
43 | 44 |
44 with open(sys.argv[1], 'r') as f: | 45 source = sys.argv[1] |
45 root = ET.fromstring(f.read()) | 46 |
47 if (source.startswith('http://') or | |
48 source.startswith('https://')): | |
49 part15 = requests.get(source).content | |
50 else: | |
51 with open(source, 'r') as f: | |
52 part15 = f.read() | |
53 | |
54 root = ET.fromstring(part15) | |
46 | 55 |
47 br = '{http://docbook.org/ns/docbook}' # Shorthand variable | 56 br = '{http://docbook.org/ns/docbook}' # Shorthand variable |
48 | 57 |
49 | 58 |
50 LINES = [] | 59 LINES = [] |
113 FormatLine('removals_.insert(DicomTag(%s)); /* TODO UID */' % (tag), name) | 122 FormatLine('removals_.insert(DicomTag(%s)); /* TODO UID */' % (tag), name) |
114 else: | 123 else: |
115 FormatUnknown(rawTag, name, profile) | 124 FormatUnknown(rawTag, name, profile) |
116 | 125 |
117 for line in sorted(LINES): | 126 for line in sorted(LINES): |
118 print line | 127 print(line.encode('ascii', 'ignore').decode('ascii')) |
119 | 128 |
120 | 129 |
121 # D - replace with a non-zero length value that may be a dummy value and consistent with the VR | 130 # D - replace with a non-zero length value that may be a dummy value and consistent with the VR |
122 # Z - replace with a zero length value, or a non-zero length value that may be a dummy value and consistent with the VR | 131 # Z - replace with a zero length value, or a non-zero length value that may be a dummy value and consistent with the VR |
123 # X - remove | 132 # X - remove |