changeset 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 cdab941fe17d
children caf963ee3de9
files OrthancFramework/Sources/DicomParsing/DicomModification.cpp OrthancServer/Resources/GenerateAnonymizationProfile.py
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Thu Jun 03 17:40:15 2021 +0200
+++ b/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Thu Jun 03 19:41:11 2021 +0200
@@ -579,9 +579,9 @@
     /**
      * This is Table E.1-1 from PS 3.15-2017c (DICOM Part 15: Security
      * and System Management Profiles), "basic profile" column. It was
-     * generated automatically with the
-     * "../Resources/GenerateAnonymizationProfile.py" script.
-     * https://raw.githubusercontent.com/jodogne/dicom-specification/master/2017c/part15.pdf
+     * generated automatically by calling:
+     * "../../../OrthancServer/Resources/GenerateAnonymizationProfile.py
+     * https://raw.githubusercontent.com/jodogne/dicom-specification/master/2017c/part15.xml"
      **/
     
     // TODO: (50xx,xxxx) with rule X                                 // Curve Data
--- a/OrthancServer/Resources/GenerateAnonymizationProfile.py	Thu Jun 03 17:40:15 2021 +0200
+++ b/OrthancServer/Resources/GenerateAnonymizationProfile.py	Thu Jun 03 19:41:11 2021 +0200
@@ -32,17 +32,26 @@
 
 
 import re
+import requests
 import sys
 import xml.etree.ElementTree as ET
 
 # Usage:
-# ./GenerateAnonymizationProfile.py ~/Subversion/dicom-specification/2017c/part15.xml 
+# ./GenerateAnonymizationProfile.py https://raw.githubusercontent.com/jodogne/dicom-specification/master/2021b/part15.xml
 
 if len(sys.argv) != 2:
-    raise Exception('Please provide the path to the part15.xml file from the DICOM standard')
+    raise Exception('Please provide the path or the URL to the part15.xml file from the DICOM standard')
+
+source = sys.argv[1]
 
-with open(sys.argv[1], 'r') as f:
-    root = ET.fromstring(f.read())
+if (source.startswith('http://') or
+    source.startswith('https://')):
+    part15 = requests.get(source).content
+else:
+    with open(source, 'r') as f:
+        part15 = f.read()
+
+root = ET.fromstring(part15)
 
 br = '{http://docbook.org/ns/docbook}' # Shorthand variable
 
@@ -115,7 +124,7 @@
                     FormatUnknown(rawTag, name, profile)
 
 for line in sorted(LINES):
-    print line
+    print(line.encode('ascii', 'ignore').decode('ascii'))
     
 
 # D - replace with a non-zero length value that may be a dummy value and consistent with the VR