dicom-validator 0.7.3__tar.gz → 0.9.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/PKG-INFO +52 -12
  2. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/README.md +45 -9
  3. dicom_validator-0.9.dev0/dicom_validator/__init__.py +1 -0
  4. dicom_validator-0.9.dev0/dicom_validator/command_line_utils.py +53 -0
  5. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/dump_dcm_info.py +41 -50
  6. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/condition.py +24 -7
  7. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/condition_grammar.py +1 -4
  8. dicom_validator-0.9.dev0/dicom_validator/spec_reader/edition_reader.py +519 -0
  9. dicom_validator-0.9.dev0/dicom_validator/spec_reader/enum_parser.py +152 -0
  10. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/part3_reader.py +26 -3
  11. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/part4_reader.py +9 -7
  12. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/part6_reader.py +16 -13
  13. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/serializer.py +1 -1
  14. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/spec_reader.py +38 -12
  15. dicom_validator-0.9.dev0/dicom_validator/tag_tools.py +39 -0
  16. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/conftest.py +11 -11
  17. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_edition_reader.py +50 -51
  18. dicom_validator-0.9.dev0/dicom_validator/tests/spec_reader/test_enum_parser.py +335 -0
  19. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_part3_reader.py +27 -27
  20. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_part6_reader.py +1 -1
  21. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_spec_reader.py +1 -1
  22. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/test_cmdline_tools.py +3 -3
  23. dicom_validator-0.9.dev0/dicom_validator/tests/utils.py +26 -0
  24. dicom_validator-0.9.dev0/dicom_validator/tests/validator/conftest.py +135 -0
  25. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/validator/test_dicom_file_validator.py +25 -22
  26. dicom_validator-0.9.dev0/dicom_validator/tests/validator/test_error_handler.py +62 -0
  27. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/validator/test_iod_validator.py +232 -142
  28. dicom_validator-0.9.dev0/dicom_validator/tests/validator/test_iod_validator_func_groups.py +361 -0
  29. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/validate_iods.py +25 -32
  30. dicom_validator-0.9.dev0/dicom_validator/validator/__init__.py +0 -0
  31. dicom_validator-0.9.dev0/dicom_validator/validator/dicom_file_validator.py +140 -0
  32. dicom_validator-0.9.dev0/dicom_validator/validator/dicom_info.py +20 -0
  33. dicom_validator-0.9.dev0/dicom_validator/validator/error_handler.py +240 -0
  34. dicom_validator-0.9.dev0/dicom_validator/validator/html_error_handler.py +193 -0
  35. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/validator/iod_validator.py +305 -237
  36. dicom_validator-0.9.dev0/dicom_validator/validator/validation_result.py +180 -0
  37. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/PKG-INFO +52 -12
  38. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/SOURCES.txt +8 -1
  39. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/requires.txt +6 -1
  40. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/pyproject.toml +8 -2
  41. dicom_validator-0.7.3/dicom_validator/__init__.py +0 -1
  42. dicom_validator-0.7.3/dicom_validator/spec_reader/edition_reader.py +0 -265
  43. dicom_validator-0.7.3/dicom_validator/spec_reader/enum_parser.py +0 -98
  44. dicom_validator-0.7.3/dicom_validator/tag_tools.py +0 -9
  45. dicom_validator-0.7.3/dicom_validator/tests/spec_reader/test_enum_parser.py +0 -169
  46. dicom_validator-0.7.3/dicom_validator/tests/utils.py +0 -23
  47. dicom_validator-0.7.3/dicom_validator/tests/validator/conftest.py +0 -72
  48. dicom_validator-0.7.3/dicom_validator/tests/validator/test_iod_validator_func_groups.py +0 -202
  49. dicom_validator-0.7.3/dicom_validator/validator/dicom_file_validator.py +0 -67
  50. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/LICENSE +0 -0
  51. /dicom_validator-0.7.3/dicom_validator/spec_reader/__init__.py → /dicom_validator-0.9.dev0/dicom_validator/py.typed +0 -0
  52. {dicom_validator-0.7.3/dicom_validator/tests → dicom_validator-0.9.dev0/dicom_validator/spec_reader}/__init__.py +0 -0
  53. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/spec_reader/condition_parser.py +0 -0
  54. {dicom_validator-0.7.3/dicom_validator/tests/spec_reader → dicom_validator-0.9.dev0/dicom_validator/tests}/__init__.py +0 -0
  55. {dicom_validator-0.7.3/dicom_validator/tests/validator → dicom_validator-0.9.dev0/dicom_validator/tests/spec_reader}/__init__.py +0 -0
  56. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_condition.py +0 -0
  57. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_condition_parser.py +0 -0
  58. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator/tests/spec_reader/test_part4_reader.py +0 -0
  59. {dicom_validator-0.7.3/dicom_validator → dicom_validator-0.9.dev0/dicom_validator/tests}/validator/__init__.py +0 -0
  60. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/dependency_links.txt +0 -0
  61. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/entry_points.txt +0 -0
  62. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/dicom_validator.egg-info/top_level.txt +0 -0
  63. {dicom_validator-0.7.3 → dicom_validator-0.9.dev0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dicom-validator
3
- Version: 0.7.3
3
+ Version: 0.9.dev0
4
4
  Summary: Python DICOM validator using input from DICOM specs in docbook format
5
5
  Author-email: mrbean-bremen and contributors <hansemrbean@googlemail.com>
6
6
  License: MIT
@@ -15,11 +15,11 @@ Classifier: Intended Audience :: Healthcare Industry
15
15
  Classifier: Development Status :: 4 - Beta
16
16
  Classifier: Environment :: Console
17
17
  Classifier: Programming Language :: Python
18
- Classifier: Programming Language :: Python :: 3.9
19
18
  Classifier: Programming Language :: Python :: 3.10
20
19
  Classifier: Programming Language :: Python :: 3.11
21
20
  Classifier: Programming Language :: Python :: 3.12
22
21
  Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
23
  Classifier: Operating System :: POSIX :: Linux
24
24
  Classifier: Operating System :: MacOS
25
25
  Classifier: Operating System :: Microsoft :: Windows
@@ -27,13 +27,17 @@ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
27
27
  Requires-Python: >=3.9
28
28
  Description-Content-Type: text/markdown
29
29
  License-File: LICENSE
30
- Requires-Dist: pydicom>=2.3
30
+ Requires-Dist: pydicom>=3.0
31
31
  Requires-Dist: lxml
32
32
  Requires-Dist: pyparsing>=3.2
33
33
  Provides-Extra: dev
34
34
  Requires-Dist: pyfakefs>=5.0.0; extra == "dev"
35
35
  Requires-Dist: pytest; extra == "dev"
36
36
  Requires-Dist: pytest-order; extra == "dev"
37
+ Provides-Extra: docs
38
+ Requires-Dist: sphinx>=2.3.1; extra == "docs"
39
+ Requires-Dist: furo; extra == "docs"
40
+ Requires-Dist: myst-parser; extra == "docs"
37
41
  Dynamic: license-file
38
42
 
39
43
  # dicom-validator
@@ -68,6 +72,10 @@ changed to `dicom-validator` together with the move to the `pydicom`
68
72
  organization to reflect the fact that no other tools are planned, and that the
69
73
  DICOM validator is the relevant tool.
70
74
 
75
+ ## Documentation
76
+ Documentation for the [current main branch](https://dicom-validator.readthedocs.io/en/latest/)
77
+ and for the [latest release](https://dicom-validator.readthedocs.io/en/stable/) is available
78
+ on `Read the Docs`.
71
79
 
72
80
  ## Installation
73
81
 
@@ -79,12 +87,12 @@ pip install dicom-validator
79
87
  ## Usage
80
88
  ```
81
89
  validate_iods [-h] [--standard-path STANDARD_PATH]
82
- [--revision REVISION] [--force-read] [--recreate-json]
90
+ [--edition EDITION] [--force-read] [--recreate-json]
83
91
  [--suppress-vr-warnings] [--verbose]
84
92
  dicomfiles [dicomfiles ...]
85
93
 
86
94
  dump_dcm_info [-h] [--standard-path STANDARD_PATH]
87
- [--revision REVISION] [--max-value-len MAX_VALUE_LEN]
95
+ [--edition EDITION] [--max-value-len MAX_VALUE_LEN]
88
96
  [--show-tags [SHOW_TAGS [SHOW_TAGS ...]]]
89
97
  [--show-image-data] [--recreate-json]
90
98
  dicomfiles [dicomfiles ...]
@@ -102,8 +110,8 @@ These files are then used by the tools. Periodically (once a month), the tools
102
110
  check for a newer version of the DICOM standard and download it if found.
103
111
 
104
112
  It is also possible to use older versions of the standard via the command line
105
- option `--revision` or `-r`, provided they are available for download
106
- (at the time of writing, standards are available since revision 2014a). A
113
+ option `--edition` or `-e`, provided they are available for download
114
+ (at the time of writing, standards are available since edition 2014a). A
107
115
  list of currently available editions can be found in
108
116
  *<user home>/dicom-validator/editions.json* after a tool has been called
109
117
  the first time.
@@ -128,7 +136,7 @@ The output for a single file may look like this:
128
136
  ```
129
137
  (py3_test) c:\dev\GitHub\dicom-validator>validate_iods "c:\dev\DICOM Data\WG02\Enhanced-XA\ENHXA"
130
138
 
131
- Using DICOM revision 2023c
139
+ Using DICOM edition 2023c
132
140
  SOP class is "1.2.840.10008.5.1.4.1.1.12.1.1" (Enhanced XA Image IOD)
133
141
 
134
142
  Errors
@@ -177,7 +185,7 @@ Only the given standard is used to evaluate the files. If
177
185
  the DICOM file has been written using an older standard, it may conform to
178
186
  that standard, but not to the newest one. Tags that are retired in the
179
187
  version of the standard used for parsing are not considered at all.
180
- You can always check against an older standard by using the `--revision` option.
188
+ You can always check against an older standard by using the `--edition` option.
181
189
 
182
190
  #### Enumerated values and defined terms
183
191
  Most enumerated values are checked against, but some are ignored due to parsing issues.
@@ -185,10 +193,42 @@ Support for more cases may be added in the future.
185
193
  Defined terms are _not_ checked, because they are allowed to be user-defined, which means
186
194
  that any value may be valid.
187
195
 
188
- #### Unsupported cases (support may be added in future versions)
189
- - SOP classes not in the table in PS3.3 such as Presentation States are not
190
- handled
196
+ ### Using the IOD validator programmatically
197
+ The commandline tool is based on the `DicomFileValidator` and `IODValidator` classes, which
198
+ can also be used directly in another application, if you want to have better control of the output.
199
+ To initialize such a class, you need the DICOM information (as a `DicomInfo` instance)
200
+ read from the JSON files as described above.
201
+ First, the needed edition of the DICOM standard has to be downloaded and processed.
202
+ This needs to be done only once for a given edition:
203
+
204
+ ```py
205
+ from pathlib import Path
206
+ from dicom_validator.spec_reader.edition_reader import EditionReader
207
+
208
+ reader = EditionReader() # uses the default location <user home>/dicom-validator
209
+ # if the edition is not downloaded yet, load_dicom_info will download and process it
210
+ dicom_info = reader.load_dicom_info("2025b") # could also use "current" for the current standard
211
+ ```
212
+ Using this DICOM information, you can validate a DICOM file, or all DICOM files
213
+ in a given directory:
214
+ ```py
215
+ from dicom_validator.validator.dicom_file_validator import DicomFileValidator
191
216
 
217
+ validator = DicomFileValidator(dicom_info)
218
+ result = validator.validate(dicom_file_path)
219
+ ```
220
+ This will create the same output as the command line tool. If you need your own error
221
+ handling instead, you can write your own error handler, and use it instead:
222
+ ```py
223
+ from dicom_validator.validator.html_error_handler import HtmlErrorHandler
224
+ ...
225
+ handler = HtmlErrorHandler(dicom_info)
226
+ validator = DicomFileValidator(dicom_info, error_handler=handler)
227
+ validator.validate(dicom_file_path)
228
+ with open("result.html", "w") as f:
229
+ f.write(handler.html)
230
+ ```
231
+ This uses the `HtmlErrorHandler` class, which is included as a simple error handler example.
192
232
 
193
233
  ## dump_dcm_info
194
234
 
@@ -30,6 +30,10 @@ changed to `dicom-validator` together with the move to the `pydicom`
30
30
  organization to reflect the fact that no other tools are planned, and that the
31
31
  DICOM validator is the relevant tool.
32
32
 
33
+ ## Documentation
34
+ Documentation for the [current main branch](https://dicom-validator.readthedocs.io/en/latest/)
35
+ and for the [latest release](https://dicom-validator.readthedocs.io/en/stable/) is available
36
+ on `Read the Docs`.
33
37
 
34
38
  ## Installation
35
39
 
@@ -41,12 +45,12 @@ pip install dicom-validator
41
45
  ## Usage
42
46
  ```
43
47
  validate_iods [-h] [--standard-path STANDARD_PATH]
44
- [--revision REVISION] [--force-read] [--recreate-json]
48
+ [--edition EDITION] [--force-read] [--recreate-json]
45
49
  [--suppress-vr-warnings] [--verbose]
46
50
  dicomfiles [dicomfiles ...]
47
51
 
48
52
  dump_dcm_info [-h] [--standard-path STANDARD_PATH]
49
- [--revision REVISION] [--max-value-len MAX_VALUE_LEN]
53
+ [--edition EDITION] [--max-value-len MAX_VALUE_LEN]
50
54
  [--show-tags [SHOW_TAGS [SHOW_TAGS ...]]]
51
55
  [--show-image-data] [--recreate-json]
52
56
  dicomfiles [dicomfiles ...]
@@ -64,8 +68,8 @@ These files are then used by the tools. Periodically (once a month), the tools
64
68
  check for a newer version of the DICOM standard and download it if found.
65
69
 
66
70
  It is also possible to use older versions of the standard via the command line
67
- option `--revision` or `-r`, provided they are available for download
68
- (at the time of writing, standards are available since revision 2014a). A
71
+ option `--edition` or `-e`, provided they are available for download
72
+ (at the time of writing, standards are available since edition 2014a). A
69
73
  list of currently available editions can be found in
70
74
  *<user home>/dicom-validator/editions.json* after a tool has been called
71
75
  the first time.
@@ -90,7 +94,7 @@ The output for a single file may look like this:
90
94
  ```
91
95
  (py3_test) c:\dev\GitHub\dicom-validator>validate_iods "c:\dev\DICOM Data\WG02\Enhanced-XA\ENHXA"
92
96
 
93
- Using DICOM revision 2023c
97
+ Using DICOM edition 2023c
94
98
  SOP class is "1.2.840.10008.5.1.4.1.1.12.1.1" (Enhanced XA Image IOD)
95
99
 
96
100
  Errors
@@ -139,7 +143,7 @@ Only the given standard is used to evaluate the files. If
139
143
  the DICOM file has been written using an older standard, it may conform to
140
144
  that standard, but not to the newest one. Tags that are retired in the
141
145
  version of the standard used for parsing are not considered at all.
142
- You can always check against an older standard by using the `--revision` option.
146
+ You can always check against an older standard by using the `--edition` option.
143
147
 
144
148
  #### Enumerated values and defined terms
145
149
  Most enumerated values are checked against, but some are ignored due to parsing issues.
@@ -147,10 +151,42 @@ Support for more cases may be added in the future.
147
151
  Defined terms are _not_ checked, because they are allowed to be user-defined, which means
148
152
  that any value may be valid.
149
153
 
150
- #### Unsupported cases (support may be added in future versions)
151
- - SOP classes not in the table in PS3.3 such as Presentation States are not
152
- handled
154
+ ### Using the IOD validator programmatically
155
+ The commandline tool is based on the `DicomFileValidator` and `IODValidator` classes, which
156
+ can also be used directly in another application, if you want to have better control of the output.
157
+ To initialize such a class, you need the DICOM information (as a `DicomInfo` instance)
158
+ read from the JSON files as described above.
159
+ First, the needed edition of the DICOM standard has to be downloaded and processed.
160
+ This needs to be done only once for a given edition:
161
+
162
+ ```py
163
+ from pathlib import Path
164
+ from dicom_validator.spec_reader.edition_reader import EditionReader
165
+
166
+ reader = EditionReader() # uses the default location <user home>/dicom-validator
167
+ # if the edition is not downloaded yet, load_dicom_info will download and process it
168
+ dicom_info = reader.load_dicom_info("2025b") # could also use "current" for the current standard
169
+ ```
170
+ Using this DICOM information, you can validate a DICOM file, or all DICOM files
171
+ in a given directory:
172
+ ```py
173
+ from dicom_validator.validator.dicom_file_validator import DicomFileValidator
153
174
 
175
+ validator = DicomFileValidator(dicom_info)
176
+ result = validator.validate(dicom_file_path)
177
+ ```
178
+ This will create the same output as the command line tool. If you need your own error
179
+ handling instead, you can write your own error handler, and use it instead:
180
+ ```py
181
+ from dicom_validator.validator.html_error_handler import HtmlErrorHandler
182
+ ...
183
+ handler = HtmlErrorHandler(dicom_info)
184
+ validator = DicomFileValidator(dicom_info, error_handler=handler)
185
+ validator.validate(dicom_file_path)
186
+ with open("result.html", "w") as f:
187
+ f.write(handler.html)
188
+ ```
189
+ This uses the `HtmlErrorHandler` class, which is included as a simple error handler example.
154
190
 
155
191
  ## dump_dcm_info
156
192
 
@@ -0,0 +1 @@
1
+ __version__ = "0.9.dev0"
@@ -0,0 +1,53 @@
1
+ import argparse
2
+ import os
3
+ import warnings
4
+ from pathlib import Path
5
+
6
+ from dicom_validator.spec_reader.edition_reader import EditionReader
7
+ from dicom_validator.validator.dicom_info import DicomInfo
8
+
9
+
10
+ def add_edition_args(parser: argparse.ArgumentParser) -> None:
11
+ """Add edition related arguments to argument parser."""
12
+ parser.add_argument(
13
+ "--standard-path",
14
+ "-src",
15
+ help="Base path with the DICOM specs in docbook and json format",
16
+ default=str(Path.home() / "dicom-validator"),
17
+ )
18
+ parser.add_argument(
19
+ "--edition",
20
+ "-e",
21
+ help='Standard edition (e.g. "2014c"), year of '
22
+ 'edition, "current" or "local" (latest '
23
+ "locally installed)",
24
+ default="current",
25
+ )
26
+ parser.add_argument(
27
+ "--revision",
28
+ "-r",
29
+ help="Standard edition - deprecated, use --edition instead",
30
+ )
31
+
32
+
33
+ def dicom_info_from_args(args: argparse.Namespace) -> DicomInfo | None:
34
+ """Retrieve DICOM info using edition related parser arguments."""
35
+ if not os.path.exists(args.standard_path):
36
+ print(f"Invalid standard path {args.standard_path} - aborting")
37
+ if args.revision:
38
+ edition_str = args.revision
39
+ warnings.warn(
40
+ "--revision is deprecated, use --edition instead", DeprecationWarning
41
+ )
42
+ else:
43
+ edition_str = args.edition
44
+ edition_reader = EditionReader(args.standard_path)
45
+ edition = edition_reader.get_edition(edition_str)
46
+ if edition is None:
47
+ print(f"Invalid DICOM edition {edition_str} - aborting")
48
+ return None
49
+ destination = edition_reader.get_edition_path(edition, args.recreate_json)
50
+ if destination is None:
51
+ print(f"Failed to get DICOM edition {edition_str} - aborting")
52
+ return None
53
+ return edition_reader.load_dicom_info(edition)
@@ -5,51 +5,60 @@ Dumps tag information from a DICOM file using information in PS3.6.
5
5
  import argparse
6
6
  import os
7
7
  import re
8
- from pathlib import Path
9
8
  import sys
9
+ from collections.abc import Iterable, Sequence
10
10
 
11
- from pydicom import config, dcmread
11
+ from pydicom import config, dcmread, Dataset, DataElement
12
12
  from pydicom.errors import InvalidDicomError
13
13
 
14
- from dicom_validator.spec_reader.edition_reader import EditionReader
14
+ from dicom_validator.command_line_utils import dicom_info_from_args, add_edition_args
15
+ from dicom_validator.validator.dicom_info import DicomInfo
15
16
 
16
17
 
17
18
  class DataElementDumper:
18
19
  tag_regex = re.compile(r"(\(?[\dabcdefABCDEF]{4}), *([\dabcdefABCDEF]{4})\)?")
19
20
 
20
- def __init__(self, dicom_info, max_value_len, show_image_data, tags):
21
+ def __init__(
22
+ self,
23
+ dicom_info: DicomInfo,
24
+ max_value_len: int,
25
+ show_image_data: bool,
26
+ tags: Sequence[str] | None,
27
+ ):
21
28
  self.dicom_info = dicom_info
22
29
  self.max_value_len = max_value_len
23
30
  self.level = 0
24
31
  self.show_image_data = show_image_data
25
32
 
26
- self.uid_info = {}
33
+ self.uid_info: dict[str, str] = {}
27
34
  for uid_dict in dicom_info.dictionary.values():
28
35
  self.uid_info.update(uid_dict)
29
36
 
30
- tags = tags or []
31
- self.tags = []
32
- for tag in tags:
33
- match = self.tag_regex.match(tag)
34
- if match:
35
- self.tags.append(f"({match.group(1)},{match.group(2)})")
36
- else:
37
- matching = [
38
- tag_id
39
- for tag_id in dicom_info.dictionary
40
- if dicom_info.dictionary[tag_id]["name"].replace(" ", "") == tag
41
- ]
42
- if matching:
43
- self.tags.append(matching[0])
37
+ self.tags: list[str] = []
38
+ if tags is not None:
39
+ for tag in tags:
40
+ match = self.tag_regex.match(tag)
41
+ if match:
42
+ self.tags.append(f"({match.group(1)},{match.group(2)})")
44
43
  else:
45
- print(f"{tag} is not a valid tag expression - ignoring")
46
-
47
- def print_dataset(self, dataset):
44
+ matching = [
45
+ tag_id
46
+ for tag_id in dicom_info.dictionary
47
+ if dicom_info.dictionary[tag_id]["name"].replace(" ", "") == tag
48
+ ]
49
+ if matching:
50
+ self.tags.append(matching[0])
51
+ else:
52
+ print(f"{tag} is not a valid tag expression - ignoring")
53
+
54
+ def print_dataset(self, dataset: Dataset) -> None:
48
55
  dataset.walk(
49
56
  lambda data_set, data_elem: self.print_dataelement(data_set, data_elem)
50
57
  )
51
58
 
52
- def print_element(self, tag_id, name, vr, prop, value):
59
+ def print_element(
60
+ self, tag_id: str, name: str, vr: str, prop: str, value: list | bytes | str
61
+ ) -> bool:
53
62
  if self.tags and tag_id not in self.tags:
54
63
  return False
55
64
  vm = 1 if value else 0
@@ -70,7 +79,7 @@ class DataElementDumper:
70
79
  )
71
80
  return True
72
81
 
73
- def print_dataelement(self, _, dataelement):
82
+ def print_dataelement(self, _: Dataset, dataelement: DataElement) -> None:
74
83
  tag_id = f"({dataelement.tag.group:04X},{dataelement.tag.element:04X})"
75
84
  description = self.dicom_info.dictionary.get(tag_id)
76
85
  if description is None:
@@ -97,7 +106,7 @@ class DataElementDumper:
97
106
  else:
98
107
  self.print_element(tag_id, name, vr, prop, value)
99
108
 
100
- def print_sequence(self, sequence):
109
+ def print_sequence(self, sequence: Iterable[Dataset]) -> None:
101
110
  indent = 2 * self.level
102
111
  format_string = "{{}}Item {{:<{}}} [Dataset with {{}} element(s)]".format(
103
112
  56 - indent
@@ -110,7 +119,7 @@ class DataElementDumper:
110
119
  )
111
120
  self.level -= 1
112
121
 
113
- def dump_file(self, file_path):
122
+ def dump_file(self, file_path: str) -> None:
114
123
  try:
115
124
  # dcmread calls validate_value by default. If values don't match
116
125
  # required VR (value representation), it emits a warning but
@@ -126,33 +135,20 @@ class DataElementDumper:
126
135
  except (InvalidDicomError, KeyError):
127
136
  print(f"{file_path} is not a valid DICOM file - skipping.")
128
137
 
129
- def dump_directory(self, dir_path):
138
+ def dump_directory(self, dir_path: str) -> None:
130
139
  for root, _, names in os.walk(dir_path):
131
140
  for name in names:
132
141
  self.dump_file(os.path.join(root, name))
133
142
 
134
143
 
135
- def main():
144
+ def main() -> int:
136
145
  parser = argparse.ArgumentParser(
137
- description="Dumps DICOM information dictionary from " "DICOM file using PS3.6"
146
+ description="Dumps DICOM information dictionary from DICOM file using PS3.6"
138
147
  )
139
148
  parser.add_argument(
140
149
  "dicomfiles", help="Path(s) of DICOM files or directories to parse", nargs="+"
141
150
  )
142
- parser.add_argument(
143
- "--standard-path",
144
- "-src",
145
- help="Path with the DICOM specs in docbook " "and json format",
146
- default=str(Path.home() / "dicom-validator"),
147
- )
148
- parser.add_argument(
149
- "--revision",
150
- "-r",
151
- help='Standard revision (e.g. "2014c"), year of '
152
- 'revision, "current" or "local" (latest '
153
- "locally installed)",
154
- default="current",
155
- )
151
+ add_edition_args(parser)
156
152
  parser.add_argument(
157
153
  "--max-value-len",
158
154
  "-ml",
@@ -181,15 +177,10 @@ def main():
181
177
  default=False,
182
178
  )
183
179
  args = parser.parse_args()
184
-
185
- edition_reader = EditionReader(args.standard_path)
186
- destination = edition_reader.get_revision(args.revision, args.recreate_json)
187
- if destination is None:
188
- print(f"Failed to get DICOM edition {args.revision} - aborting")
180
+ dicom_info = dicom_info_from_args(args)
181
+ if dicom_info is None:
189
182
  return 1
190
183
 
191
- json_path = destination / "json"
192
- dicom_info = EditionReader.load_dicom_info(json_path)
193
184
  dumper = DataElementDumper(
194
185
  dicom_info, args.max_value_len, args.show_image_data, args.show_tags
195
186
  )
@@ -1,8 +1,9 @@
1
1
  import enum
2
2
  from typing import Optional, Any, Union
3
3
 
4
- from dicom_validator.tag_tools import tag_name_from_id
4
+ from pydicom.tag import BaseTag
5
5
 
6
+ from dicom_validator.tag_tools import tag_name_from_id
6
7
 
7
8
  ValuesType = list[Union[str, int]]
8
9
 
@@ -121,11 +122,11 @@ class Condition:
121
122
 
122
123
  def __init__(
123
124
  self,
124
- ctype: Optional[ConditionType] = None,
125
- operator: Optional[ConditionOperator] = None,
126
- tag: Optional[str] = None,
125
+ ctype: ConditionType | None = None,
126
+ operator: ConditionOperator | None = None,
127
+ tag: str | None = None,
127
128
  index: int = 0,
128
- values: Optional[ValuesType] = None,
129
+ values: ValuesType | None = None,
129
130
  ) -> None:
130
131
  self.type = ctype
131
132
  self.operator = operator
@@ -134,7 +135,7 @@ class Condition:
134
135
  self.values: ValuesType = values or []
135
136
  self.and_conditions: list[Condition] = []
136
137
  self.or_conditions: list[Condition] = []
137
- self.other_condition: Optional[Condition] = None
138
+ self.other_condition: Condition | None = None
138
139
 
139
140
  def __repr__(self):
140
141
  attribs = []
@@ -160,6 +161,20 @@ class Condition:
160
161
  attribs.append(f"values={self.values}")
161
162
  return " ".join(attribs)
162
163
 
164
+ def __eq__(self, other: object) -> bool:
165
+ if not isinstance(other, Condition):
166
+ return False
167
+ return (
168
+ self.type == other.type
169
+ and self.operator == other.operator
170
+ and self.tag == other.tag
171
+ and self.index == other.index
172
+ and self.values == other.values
173
+ and self.and_conditions == other.and_conditions
174
+ and self.or_conditions == other.or_conditions
175
+ and self.other_condition == other.other_condition
176
+ )
177
+
163
178
  @classmethod
164
179
  def read_condition(
165
180
  cls, condition_dict: dict, condition: Optional["Condition"] = None
@@ -246,7 +261,9 @@ class Condition:
246
261
  elif self.operator == ConditionOperator.Absent:
247
262
  result += " is not present"
248
263
  elif self.operator == ConditionOperator.EqualsTag:
249
- result += f" points to {tag_name_from_id(self.values[0], dict_info)}"
264
+ result += (
265
+ f" points to {tag_name_from_id(BaseTag(self.values[0]), dict_info)}"
266
+ )
250
267
  elif not self.values:
251
268
  # if no values are found here, we have some unhandled condition
252
269
  # and ignore it for the time being
@@ -1,6 +1,5 @@
1
1
  import string
2
2
  from re import RegexFlag
3
- from typing import Optional
4
3
  from urllib.parse import ParseResult
5
4
 
6
5
  from pyparsing import (
@@ -503,9 +502,7 @@ class ConditionGrammar:
503
502
  raise ParseException(f"Not a valid tag expression: {tag_expr}")
504
503
  return tag, tag_index
505
504
 
506
- def _tag_id_from_id_and_name(
507
- self, tag_id: Optional[str], tag_name: str
508
- ) -> Optional[str]:
505
+ def _tag_id_from_id_and_name(self, tag_id: str | None, tag_name: str) -> str | None:
509
506
  # print(f"_tag_id_from_id_and_name({tag_id}, {tag_name})")
510
507
  if not tag_name:
511
508
  return tag_id