Skip to content

Commit

Permalink
Fix check for empty string values
Browse files Browse the repository at this point in the history
- broke handling of empty type 2 enumerated values
- fixes #147
  • Loading branch information
mrbean-bremen committed Dec 16, 2024
1 parent 27bd9a4 commit 5d3ceec
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
47 changes: 47 additions & 0 deletions dicom_validator/tests/validator/test_iod_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dicom_validator/validator/iod_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5d3ceec

Please sign in to comment.