Mercurial > hg > orthanc
annotate Resources/DicomConformanceStatement.py @ 1382:1cd2e09cb0e5
case insensitive search by default
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 May 2015 14:46:06 +0200 |
parents | 01414536c930 |
children | de54c19fc44d |
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 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 # This file injects the UID information into the DICOM conformance |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 import re |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # Read the conformance statement of Orthanc |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 with open('DicomConformanceStatement.txt', 'r') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 statements = f.readlines() |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # 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
|
13 uids = {} |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 with open('/usr/include/dcmtk/dcmdata/dcuid.h', 'r') as dcmtk: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 for l in dcmtk.readlines(): |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 m = re.match(r'#define UID_(.+?)\s*"(.+?)"', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 uids[m.group(1)] = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # Loop over the lines of the statement, looking for the "|" separator |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 with open('/tmp/DicomConformanceStatement.txt', 'w') as f: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 for l in statements: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 m = re.match(r'(\s*)(.*?)(\s*)\|.*$', l) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 if m != None: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 name = m.group(2) |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 uid = uids[name] |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 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
|
28 |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 else: |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 # No "|" in this line, just output it |
01414536c930
complete DICOM conformance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 f.write(l) |