Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for empty string values #149

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading