Mercurial > hg > orthanc
annotate OrthancServer/Resources/DicomConformanceStatement.py @ 5654:b89439c14916
back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 17:53:00 +0200 |
parents | f7adfb22e20e |
children |
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 |
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:
5185
diff
changeset
|
8 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1576
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
9 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
10 # This program is free software: you can redistribute it and/or |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
11 # 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
|
12 # published by the Free Software Foundation, either version 3 of the |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
13 # License, or (at your option) any later version. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
14 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
15 # 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
|
16 # WITHOUT ANY WARRANTY; without even the implied warranty of |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
18 # General Public License for more details. |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
19 # |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
20 # 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
|
21 # 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
|
22 |
de54c19fc44d
refactoring OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1073
diff
changeset
|
23 |
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 |
1073
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 # This file injects the UID information into the DICOM conformance |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import re |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 # Read the conformance statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 with open('DicomConformanceStatement.txt', 'r') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 statements = f.readlines() |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 # 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
|
36 uids = {} |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 with open('/usr/include/dcmtk/dcmdata/dcuid.h', 'r') as dcmtk: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 for l in dcmtk.readlines(): |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 m = re.match(r'#define UID_(.+?)\s*"(.+?)"', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 uids[m.group(1)] = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 # Loop over the lines of the statement, looking for the "|" separator |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 with open('/tmp/DicomConformanceStatement.txt', 'w') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 for l in statements: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 m = re.match(r'(\s*)(.*?)(\s*)\|.*$', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 name = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 uid = uids[name] |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 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
|
51 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 else: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 # No "|" in this line, just output it |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 f.write(l) |