From 5d3ceec7544165702d17cbc161cd447ccf7d6024 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 16 Dec 2024 20:27:52 +0100 Subject: [PATCH] Fix check for empty string values - broke handling of empty type 2 enumerated values - fixes #147 --- CHANGES.md | 3 ++ .../tests/validator/test_iod_validator.py | 47 +++++++++++++++++++ dicom_validator/validator/iod_validator.py | 4 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8a15af7..f6e7234 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ # Dicom Validator Release Notes The released versions correspond to PyPi releases. +### Fixes +* fixed handling of empty type 2 enumerated values (see [#147](../../issues/147)) + ### Infrastructure * update the tests for current version 2024e diff --git a/dicom_validator/tests/validator/test_iod_validator.py b/dicom_validator/tests/validator/test_iod_validator.py index 53b4395..8a3cdca 100644 --- a/dicom_validator/tests/validator/test_iod_validator.py +++ b/dicom_validator/tests/validator/test_iod_validator.py @@ -476,6 +476,53 @@ def test_invalid_enum_value(self, validator): "(value: 1, allowed: 8, 9, 10, 11, 12, 13, 14, 15, 16)", ) + @pytest.mark.tag_set( + { + "SOPClassUID": uid.EnhancedXAImageStorage, + "PatientName": "XXX", + "PatientID": "ZZZ", + "ImageType": "DERIVED", + "PresentationLUTShape": "", + } + ) + def test_empty_type_1_enum_value(self, validator): + result = validator.validate() + + # Presentation LUT Shape: incorrect enum value + assert has_tag_error( + result, + "Enhanced XA/XRF Image", + "(2050,0020)", + "is empty", + ) + + @pytest.mark.tag_set( + { + "SOPClassUID": uid.OphthalmicPhotography8BitImageStorage, + "PatientName": "XXX", + "PatientID": "ZZZ", + "PatientEyeMovementCommanded": "", + "PupilDilated": "", + } + ) + def test_empty_type_2_enum_value(self, validator): + # regression test for #147 + result = validator.validate() + + assert not has_tag_error( + result, + "Ophthalmic Photography Acquisition Parameters", + "(0022,0005)", + "value is not allowed", + ) + + assert not has_tag_error( + result, + "Ophthalmic Photography Acquisition Parameters", + "(0022,000D)", + "value is not allowed", + ) + @pytest.mark.tag_set( { "SOPClassUID": uid.MRImageStorage, diff --git a/dicom_validator/validator/iod_validator.py b/dicom_validator/validator/iod_validator.py index 607a637..3719359 100644 --- a/dicom_validator/validator/iod_validator.py +++ b/dicom_validator/validator/iod_validator.py @@ -391,9 +391,9 @@ def _validate_attribute(self, tag_id, attribute): value = self._dataset_stack[-1].dataset[tag_id].value vr = self._dataset_stack[-1].dataset[tag_id].VR if value_required: - if value is None or isinstance(value, Sequence) and not value: + if value is None or isinstance(value, (Sequence, str)) and not value: error_kind = "empty" - if value is not None: + if value is not None and (not isinstance(value, str) or value): if not isinstance(value, MultiValue): value = [value] for i, v in enumerate(value):