dicom-validator


Namedicom-validator JSON
Version 0.5.1 PyPI version JSON
download
home_pageNone
SummaryPython DICOM validator using input from DICOM specs in docbook format
upload_time2024-04-06 06:08:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords dicom python
VCS
bugtrack_url
requirements pydicom lxml
Travis-CI No Travis.
coveralls test coverage
            # dicom-validator

[![PyPI version](https://badge.fury.io/py/dicom-validator.svg)](https://pypi.org/project/dicom-validator) [![Test Suite](https://github.com/pydicom/dicom-validator/workflows/Testsuite/badge.svg)](https://github.com/pydicom/dicom-validator/actions) [![Python version](https://img.shields.io/pypi/pyversions/dicom-validator.svg)](https://pypi.org/project/dicom-validator)

*dicom-validator* provides the command line tool `validate_iods` that
checks a DICOM file for missing or unexpected attributes. The check is done by
comparing the contents of the DICOM file against the modules and
attributes required by the DICOM standard for the SOP class of the given
dataset.

The tool gets its input from the newest version of the DICOM standard (or a
specific version given as command line parameter) as provided by
[ACR NEMA](http://medical.nema.org/) in docbook format.
[pydicom](https://github.com/pydicom/pydicom) is used to read and parse
the DICOM files.

Additionally, the command line tool `dump_dcm_info` is available that displays
the tag values of one or several DICOM files in a readable format. It is
provided as a proof of concept of getting information directly from the
DICOM standard.

*Disclaimer:*
No guarantees are given for the correctness of the results.
This is alpha-stage software and mostly thought as a proof of concept.
Also check the limitations for `validate_iods` described below.

*Note:*
The original name of the package (`dcm-spec-tools`) has been
changed to `dicom-validator` together with the move to the `pydicom`
organization to reflect the fact that no other tools are planned, and that the
DICOM validator is the relevant tool.


## Installation

The latest version is available on pypi and can be installed via
```
pip install dicom-validator
```

## Usage
```
validate_iods.py [-h] [--standard-path STANDARD_PATH]
                      [--revision REVISION] [--force-read] [--recreate-json]
                      [--verbose]
                      dicomfiles [dicomfiles ...]

dump_dcm_info.py [-h] [--standard-path STANDARD_PATH]
                      [--revision REVISION] [--max-value-len MAX_VALUE_LEN]
                      [--show-tags [SHOW_TAGS [SHOW_TAGS ...]]]
                      [--show-image-data] [--recreate-json]
                      dicomfiles [dicomfiles ...]
```
Use the `--help` option for each script do get usage info.

## Access to the DICOM standard

Upon first start of a tool, part of the latest version of the DICOM standard
in docbook format (specifically, parts 3.3, 3.4 and 3.6) are downloaded,
parsed, and the needed information saved in json files. If the `--src`
parameter is not provided, the files are downloaded to and looked up in
`<user home>/dicom-validator/`.
These files are then used by the tools. Periodically (once a month), the tools
check for a newer version of the DICOM standard and download it if found.

It is also possible to use older versions of the standard via the command line
option `--revision` or `-r`, provided they are available for download
(at the time of writing, standards are available since revision 2014a). A
list of currently available editions can be found in
*<user home>/dicom-validator/editions.json* after a tool has been called
the first time.

## validate_iods

This checks a given DICOM file, or all DICOM files recursively in a given
directory, for correct tags for the related SOP class. The presence or
absence of the tag and the presence of a tag value are checked, and in the
case that an enumeration is defined for the value, the value is also checked for validity.
More checks may be added later.
This is done by looking up all required and optional modules for this
SOP class, and checking the tags for these modules. Tags that are not allowed or
missing in a module are listed. Parts 3 and 4 of the DICOM standard are used
to collect the needed information.
Conditions for type 1C and 2C modules and tags are evaluated if possible.
If the evaluation fails, the respective modules and tags are considered
optional.
The return value of the function represents the  number of errors found during the check.

The output for a single file may look like this:
```
(py3_test) c:\dev\GitHub\dicom-validator>validate_iods "c:\dev\DICOM Data\WG02\Enhanced-XA\ENHXA"

Using DICOM revision 2023c
SOP class is "1.2.840.10008.5.1.4.1.1.12.1.1" (Enhanced XA Image IOD)

Errors
======
Module "Enhanced XA/XRF Image":
Tag (0018,9410) (Planes in Acquisition) is missing

Module "Mask":
Tag (0028,6100) (Mask Subtraction Sequence) is missing

Module "X-Ray Frame Acquisition":
Tag (0018,9328) (Exposure Time in ms) is unexpected in  Multi-frame Functional Groups > (5200,9230) > (0018,9417)
Tag (0018,9332) (Exposure in mAs) is unexpected in  Multi-frame Functional Groups > (5200,9230) > (0018,9417)

Module "X-Ray Geometry":
Tag (0018,9476) (X-Ray Geometry Sequence) is missing in  Multi-frame Functional Groups > (5200,9230)

Module "XA/XRF Multi-frame Presentation":
Tag (0028,1090) (Recommended Viewing Mode) is missing in  XA/XRF Multi-frame Presentation > (0008,9458)
Tag (0028,9411) (Display Filter Percentage) is missing in  XA/XRF Multi-frame Presentation > (0008,9458)

General:
Tag (0008,0022) (Acquisition Date) is unexpected
Tag (0008,0032) (Acquisition Time) is unexpected
Tag (0028,9411) (Display Filter Percentage) is unexpected
Tag (0018,1164) (Imager Pixel Spacing) is unexpected


Process finished with exit code 6
```

### Limitations

#### Condition evaluation
As mentioned, if the evaluation of conditions fails, the related module or
tag is considered optional, which may hide some non-conformity.
Condition evaluation may fail if:
- the needed information is not contained in the DICOM file (e.g. verbose
  descriptions like "if the Patient is an animal")
- the information is related to other DICOM files (e.g. referenced images)
- the parsing failed because the condition is too complicated, unexpected,
  or due to a bug (please write an issue if you encounter such a problem)

#### Retired tags
Also note that only the given standard is used to evaluate the files. If
the DICOM file has been written using an older standard, it may conform to
that standard, but not to the newest one. Tags that are retired in the
version of the standard used for parsing are not considered at all.

#### Unsupported cases (support may be added in future versions)
- SOP classes not in the table in PS3.3 such as Presentation States are not
  handled


## dump_dcm_info

This is a very simple DICOM dump tool, which uses
the DICOM dictionary as read from part 6 of the standard. It prints the
DICOM header of the given DICOM file, or of all DICOM files recursively in a
given directory. The output looks like this:
```
(py3_test) c:\dev\GitHub\dicom-validator>dump_dcm_info "c:\dev\DICOM
Data\SR\image12.dcm"

c:\dev\DICOM Data\SR\image12.dcm
(0005,0010) [Unknown]                                LO    1  [AEGIS_DICOM_2.00]
(0005,1000) [Unknown]                                UN    1  [\x00\x05 \x08\x00\x00\x00\n  RIGHT   \x00\x05\xc1X\x00\x00\x00\x06 0.09 \x00\x05...]
(0008,0008) Image Type                               CS    0  []
(0008,0016) SOP Class UID                            UI    1  [Ultrasound Image Storage (Retired)]
(0008,0018) SOP Instance UID                         UI    1  [1.2.840.113680.3.103.775.2873347909.282313.2]
(0008,0020) Study Date                               DA    1  [19950119]
(0008,0030) Study Time                               TM    1  [092854.0]
(0008,0050) Accession Number                         SH    1  [ACN000001]
(0008,0060) Modality                                 CS    1  [US]
(0008,0070) Manufacturer                             LO    1  [Acuson]
(0008,0090) Referring Physician's Name               PN    1  []
(0008,1010) Station Name                             SH    1  [QV-00775]
(0008,1030) Study Description                        LO    1  [ABDOMEN]
(0008,1050) Performing Physician's Name              PN    1  [DOE,JOHN]
(0008,1060) Name of Physician(s) Reading Study       PN    1  []
(0008,1070) Operators' Name                          PN    1  [DO]
(0008,1080) Admitting Diagnoses Description          LO    1  [RSNA'95 Data Not Delete]
(0009,0010) [Unknown]                                LO    1  [AEGIS_DICOM_2.00]
...
```

If you want to show only specific tags, you can use the option `--show-tags`:
```
(py3_test) c:\dev\GitHub\dicom-validator>dump_dcm_info "c:\dev\DICOM Data\SR\image12.dcm" --show-tags 0010,0010 PatientID

c:\dev\DICOM Data\SR\image12.dcm
(0010,0010) Patient's Name                           PN    1  [DOE^JANE]
(0010,0020) Patient ID                               LO    1  [ACN000001]
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dicom-validator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "dicom, python",
    "author": null,
    "author_email": "mrbean-bremen and contributors <hansemrbean@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8f/5f/086e3b07c59b8bde1f7ee517e2f86c2c565ce0e4cf2b0dddda57ae4341e0/dicom-validator-0.5.1.tar.gz",
    "platform": null,
    "description": "# dicom-validator\n\n[![PyPI version](https://badge.fury.io/py/dicom-validator.svg)](https://pypi.org/project/dicom-validator) [![Test Suite](https://github.com/pydicom/dicom-validator/workflows/Testsuite/badge.svg)](https://github.com/pydicom/dicom-validator/actions) [![Python version](https://img.shields.io/pypi/pyversions/dicom-validator.svg)](https://pypi.org/project/dicom-validator)\n\n*dicom-validator* provides the command line tool `validate_iods` that\nchecks a DICOM file for missing or unexpected attributes. The check is done by\ncomparing the contents of the DICOM file against the modules and\nattributes required by the DICOM standard for the SOP class of the given\ndataset.\n\nThe tool gets its input from the newest version of the DICOM standard (or a\nspecific version given as command line parameter) as provided by\n[ACR NEMA](http://medical.nema.org/) in docbook format.\n[pydicom](https://github.com/pydicom/pydicom) is used to read and parse\nthe DICOM files.\n\nAdditionally, the command line tool `dump_dcm_info` is available that displays\nthe tag values of one or several DICOM files in a readable format. It is\nprovided as a proof of concept of getting information directly from the\nDICOM standard.\n\n*Disclaimer:*\nNo guarantees are given for the correctness of the results.\nThis is alpha-stage software and mostly thought as a proof of concept.\nAlso check the limitations for `validate_iods` described below.\n\n*Note:*\nThe original name of the package (`dcm-spec-tools`) has been\nchanged to `dicom-validator` together with the move to the `pydicom`\norganization to reflect the fact that no other tools are planned, and that the\nDICOM validator is the relevant tool.\n\n\n## Installation\n\nThe latest version is available on pypi and can be installed via\n```\npip install dicom-validator\n```\n\n## Usage\n```\nvalidate_iods.py [-h] [--standard-path STANDARD_PATH]\n                      [--revision REVISION] [--force-read] [--recreate-json]\n                      [--verbose]\n                      dicomfiles [dicomfiles ...]\n\ndump_dcm_info.py [-h] [--standard-path STANDARD_PATH]\n                      [--revision REVISION] [--max-value-len MAX_VALUE_LEN]\n                      [--show-tags [SHOW_TAGS [SHOW_TAGS ...]]]\n                      [--show-image-data] [--recreate-json]\n                      dicomfiles [dicomfiles ...]\n```\nUse the `--help` option for each script do get usage info.\n\n## Access to the DICOM standard\n\nUpon first start of a tool, part of the latest version of the DICOM standard\nin docbook format (specifically, parts 3.3, 3.4 and 3.6) are downloaded,\nparsed, and the needed information saved in json files. If the `--src`\nparameter is not provided, the files are downloaded to and looked up in\n`<user home>/dicom-validator/`.\nThese files are then used by the tools. Periodically (once a month), the tools\ncheck for a newer version of the DICOM standard and download it if found.\n\nIt is also possible to use older versions of the standard via the command line\noption `--revision` or `-r`, provided they are available for download\n(at the time of writing, standards are available since revision 2014a). A\nlist of currently available editions can be found in\n*<user home>/dicom-validator/editions.json* after a tool has been called\nthe first time.\n\n## validate_iods\n\nThis checks a given DICOM file, or all DICOM files recursively in a given\ndirectory, for correct tags for the related SOP class. The presence or\nabsence of the tag and the presence of a tag value are checked, and in the\ncase that an enumeration is defined for the value, the value is also checked for validity.\nMore checks may be added later.\nThis is done by looking up all required and optional modules for this\nSOP class, and checking the tags for these modules. Tags that are not allowed or\nmissing in a module are listed. Parts 3 and 4 of the DICOM standard are used\nto collect the needed information.\nConditions for type 1C and 2C modules and tags are evaluated if possible.\nIf the evaluation fails, the respective modules and tags are considered\noptional.\nThe return value of the function represents the  number of errors found during the check.\n\nThe output for a single file may look like this:\n```\n(py3_test) c:\\dev\\GitHub\\dicom-validator>validate_iods \"c:\\dev\\DICOM Data\\WG02\\Enhanced-XA\\ENHXA\"\n\nUsing DICOM revision 2023c\nSOP class is \"1.2.840.10008.5.1.4.1.1.12.1.1\" (Enhanced XA Image IOD)\n\nErrors\n======\nModule \"Enhanced XA/XRF Image\":\nTag (0018,9410) (Planes in Acquisition) is missing\n\nModule \"Mask\":\nTag (0028,6100) (Mask Subtraction Sequence) is missing\n\nModule \"X-Ray Frame Acquisition\":\nTag (0018,9328) (Exposure Time in ms) is unexpected in  Multi-frame Functional Groups > (5200,9230) > (0018,9417)\nTag (0018,9332) (Exposure in mAs) is unexpected in  Multi-frame Functional Groups > (5200,9230) > (0018,9417)\n\nModule \"X-Ray Geometry\":\nTag (0018,9476) (X-Ray Geometry Sequence) is missing in  Multi-frame Functional Groups > (5200,9230)\n\nModule \"XA/XRF Multi-frame Presentation\":\nTag (0028,1090) (Recommended Viewing Mode) is missing in  XA/XRF Multi-frame Presentation > (0008,9458)\nTag (0028,9411) (Display Filter Percentage) is missing in  XA/XRF Multi-frame Presentation > (0008,9458)\n\nGeneral:\nTag (0008,0022) (Acquisition Date) is unexpected\nTag (0008,0032) (Acquisition Time) is unexpected\nTag (0028,9411) (Display Filter Percentage) is unexpected\nTag (0018,1164) (Imager Pixel Spacing) is unexpected\n\n\nProcess finished with exit code 6\n```\n\n### Limitations\n\n#### Condition evaluation\nAs mentioned, if the evaluation of conditions fails, the related module or\ntag is considered optional, which may hide some non-conformity.\nCondition evaluation may fail if:\n- the needed information is not contained in the DICOM file (e.g. verbose\n  descriptions like \"if the Patient is an animal\")\n- the information is related to other DICOM files (e.g. referenced images)\n- the parsing failed because the condition is too complicated, unexpected,\n  or due to a bug (please write an issue if you encounter such a problem)\n\n#### Retired tags\nAlso note that only the given standard is used to evaluate the files. If\nthe DICOM file has been written using an older standard, it may conform to\nthat standard, but not to the newest one. Tags that are retired in the\nversion of the standard used for parsing are not considered at all.\n\n#### Unsupported cases (support may be added in future versions)\n- SOP classes not in the table in PS3.3 such as Presentation States are not\n  handled\n\n\n## dump_dcm_info\n\nThis is a very simple DICOM dump tool, which uses\nthe DICOM dictionary as read from part 6 of the standard. It prints the\nDICOM header of the given DICOM file, or of all DICOM files recursively in a\ngiven directory. The output looks like this:\n```\n(py3_test) c:\\dev\\GitHub\\dicom-validator>dump_dcm_info \"c:\\dev\\DICOM\nData\\SR\\image12.dcm\"\n\nc:\\dev\\DICOM Data\\SR\\image12.dcm\n(0005,0010) [Unknown]                                LO    1  [AEGIS_DICOM_2.00]\n(0005,1000) [Unknown]                                UN    1  [\\x00\\x05 \\x08\\x00\\x00\\x00\\n  RIGHT   \\x00\\x05\\xc1X\\x00\\x00\\x00\\x06 0.09 \\x00\\x05...]\n(0008,0008) Image Type                               CS    0  []\n(0008,0016) SOP Class UID                            UI    1  [Ultrasound Image Storage (Retired)]\n(0008,0018) SOP Instance UID                         UI    1  [1.2.840.113680.3.103.775.2873347909.282313.2]\n(0008,0020) Study Date                               DA    1  [19950119]\n(0008,0030) Study Time                               TM    1  [092854.0]\n(0008,0050) Accession Number                         SH    1  [ACN000001]\n(0008,0060) Modality                                 CS    1  [US]\n(0008,0070) Manufacturer                             LO    1  [Acuson]\n(0008,0090) Referring Physician's Name               PN    1  []\n(0008,1010) Station Name                             SH    1  [QV-00775]\n(0008,1030) Study Description                        LO    1  [ABDOMEN]\n(0008,1050) Performing Physician's Name              PN    1  [DOE,JOHN]\n(0008,1060) Name of Physician(s) Reading Study       PN    1  []\n(0008,1070) Operators' Name                          PN    1  [DO]\n(0008,1080) Admitting Diagnoses Description          LO    1  [RSNA'95 Data Not Delete]\n(0009,0010) [Unknown]                                LO    1  [AEGIS_DICOM_2.00]\n...\n```\n\nIf you want to show only specific tags, you can use the option `--show-tags`:\n```\n(py3_test) c:\\dev\\GitHub\\dicom-validator>dump_dcm_info \"c:\\dev\\DICOM Data\\SR\\image12.dcm\" --show-tags 0010,0010 PatientID\n\nc:\\dev\\DICOM Data\\SR\\image12.dcm\n(0010,0010) Patient's Name                           PN    1  [DOE^JANE]\n(0010,0020) Patient ID                               LO    1  [ACN000001]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python DICOM validator using input from DICOM specs in docbook format",
    "version": "0.5.1",
    "project_urls": {
        "documentation": "https://github.com/pydicom/dicom-validator#readme",
        "download": "https://github.com/pydicom/dicom-validator/archive/main.zip",
        "homepage": "https://github.com/pydicom/dicom-validator",
        "repository": "https://github.com/pydicom/dicom-validator"
    },
    "split_keywords": [
        "dicom",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06484790493fa17b3a3f0826dbbca4c92412d8341a020c4375f77330407f8e44",
                "md5": "1c369a5a5b24275a202d7dfba59d8a41",
                "sha256": "0d75ea0d4e48baf819770703f730e9f8738e2ff808d9fbaf83ff7c7e70b8e888"
            },
            "downloads": -1,
            "filename": "dicom_validator-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1c369a5a5b24275a202d7dfba59d8a41",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 61989,
            "upload_time": "2024-04-06T06:08:51",
            "upload_time_iso_8601": "2024-04-06T06:08:51.388608Z",
            "url": "https://files.pythonhosted.org/packages/06/48/4790493fa17b3a3f0826dbbca4c92412d8341a020c4375f77330407f8e44/dicom_validator-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f5f086e3b07c59b8bde1f7ee517e2f86c2c565ce0e4cf2b0dddda57ae4341e0",
                "md5": "05b0dd4da0ee8ebfef89b1f8ff5db78e",
                "sha256": "ae4c356d13412f24d796a3436c12223b961522aa290b9a35c9736292fcac39fe"
            },
            "downloads": -1,
            "filename": "dicom-validator-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "05b0dd4da0ee8ebfef89b1f8ff5db78e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 53608,
            "upload_time": "2024-04-06T06:08:53",
            "upload_time_iso_8601": "2024-04-06T06:08:53.358208Z",
            "url": "https://files.pythonhosted.org/packages/8f/5f/086e3b07c59b8bde1f7ee517e2f86c2c565ce0e4cf2b0dddda57ae4341e0/dicom-validator-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 06:08:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pydicom",
    "github_project": "dicom-validator#readme",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "pydicom",
            "specs": [
                [
                    ">=",
                    "2.3.0"
                ]
            ]
        },
        {
            "name": "lxml",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "dicom-validator"
}
        
Elapsed time: 0.20872s