Mercurial > hg > orthanc
annotate Resources/DicomConformanceStatement.py @ 2387:a60a79929007
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Aug 2017 09:29:31 +0200 |
parents | a3a65de1840f |
children | 878b59270859 |
rev | line source |
---|---|
1073
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
3 # Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
6 # Copyright (C) 2017 Osimis, Belgium |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
7 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
9 # modify it under the terms of the GNU General Public License as |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
10 # published by the Free Software Foundation, either version 3 of the |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
11 # License, or (at your option) any later version. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
12 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
13 # In addition, as a special exception, the copyright holders of this |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
14 # program give permission to link the code of its release with the |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
15 # OpenSSL project's "OpenSSL" library (or with modified versions of it |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
16 # that use the same license as the "OpenSSL" library), and distribute |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
17 # the linked executables. You must obey the GNU General Public License |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
18 # in all respects for all of the code used other than "OpenSSL". If you |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
19 # modify file(s) with this exception, you may extend this exception to |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
20 # your version of the file(s), but you are not obligated to do so. If |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
21 # you do not wish to do so, delete this exception statement from your |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
22 # version. If you delete this exception statement from all source files |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
23 # in the program, then also delete it here. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
24 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
25 # This program is distributed in the hope that it will be useful, but |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
26 # WITHOUT ANY WARRANTY; without even the implied warranty of |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
28 # General Public License for more details. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
29 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
30 # You should have received a copy of the GNU General Public License |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
31 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
32 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
33 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
34 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
35 |
1073
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 # This file injects the UID information into the DICOM conformance |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 # statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 import re |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 # Read the conformance statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 with open('DicomConformanceStatement.txt', 'r') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 statements = f.readlines() |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 # Create an index of all the DICOM UIDs that are known to DCMTK |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 uids = {} |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 with open('/usr/include/dcmtk/dcmdata/dcuid.h', 'r') as dcmtk: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 for l in dcmtk.readlines(): |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 m = re.match(r'#define UID_(.+?)\s*"(.+?)"', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 uids[m.group(1)] = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 # Loop over the lines of the statement, looking for the "|" separator |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 with open('/tmp/DicomConformanceStatement.txt', 'w') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 for l in statements: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 m = re.match(r'(\s*)(.*?)(\s*)\|.*$', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 name = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 uid = uids[name] |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 f.write('%s%s%s| %s\n' % (m.group(1), name, m.group(3), uid)) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 else: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 # No "|" in this line, just output it |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 f.write(l) |