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

BaseTag handling in IODValidator._tag_matches() #58

Closed
sustrev opened this issue Nov 1, 2023 · 3 comments · Fixed by #61
Closed

BaseTag handling in IODValidator._tag_matches() #58

sustrev opened this issue Nov 1, 2023 · 3 comments · Fixed by #61
Assignees
Labels

Comments

@sustrev
Copy link

sustrev commented Nov 1, 2023

I was working with a DICOM with SOP class "Multi-frame True Color Secondary Capture Image IOD" and when the code was hitting iod_validator.py:563, it was raising a ValueError.

For context, the condition dictionary being passed through is condition = {'index': 0, 'op': '=', 'tag': '(0028,0009)', 'type': 'MN', 'values': ['Frame Time (0018,1063)', 'Frame Time Vector (0018,1065)']}. type(tag_value) is parsed as <class 'pydicom.tag.BaseTag'>, but the values can't be coerced into a BaseTag.

I put together a quick little bit of regex to change the str values into an int that is correctly parsed into a BaseTag and seems to then correctly finish validation, if this is helpful!

    @staticmethod
    def _tag_matches(tag_value, operator, values):
        if type(tag_value) == BaseTag:
            values = IODValidator._value_basetag_conversion(values)
        values = [type(tag_value)(value) for value in values]
        if operator == ConditionOperator.EqualsValue:
            return tag_value in values
        if operator == ConditionOperator.NotEqualsValue:
            return tag_value not in values
        if operator == ConditionOperator.GreaterValue:
            return tag_value > values[0]
        if operator == ConditionOperator.LessValue:
            return tag_value < values[0]
        if operator == ConditionOperator.EqualsTag:
            return tag_value in values
        return False
    
    @staticmethod
    def _value_basetag_conversion(values):
        values = [
            int(f"0x{''.join(re.findall('[0-9]+', value))}", 16)
            for value in values
        ]
        return values
@mrbean-bremen
Copy link
Member

Thanks for the report and the PR! I will have a closer look tonight.

@mrbean-bremen mrbean-bremen self-assigned this Nov 6, 2023
mrbean-bremen added a commit to mrbean-bremen/dicom-validator that referenced this issue Nov 7, 2023
* correctly parse the value index for some expressions
* make the parsing stricter to avoid false positives
* fix parsing of conditions for AT values with equality comparison
  (fixes pydicom#58)
mrbean-bremen added a commit to mrbean-bremen/dicom-validator that referenced this issue Nov 8, 2023
* correctly parse the value index for some expressions
* make the parsing stricter to avoid false positives
* fix parsing of conditions for AT values with equality comparison
  (fixes pydicom#58)
mrbean-bremen added a commit to mrbean-bremen/dicom-validator that referenced this issue Nov 8, 2023
* correctly parse the value index for some expressions
* make the parsing stricter to avoid false positives
* fix parsing of conditions for AT values with equality comparison
  (fixes pydicom#58)
mrbean-bremen added a commit to mrbean-bremen/dicom-validator that referenced this issue Nov 9, 2023
* correctly parse the value index for some expressions
* make the parsing stricter to avoid false positives
* fix parsing of conditions for AT values with equality comparison
  (fixes pydicom#58)
mrbean-bremen added a commit that referenced this issue Nov 9, 2023
* Fix some issues in the condition parser

* correctly parse the value index for some expressions
* make the parsing stricter to avoid false positives
* fix parsing of conditions for AT values with equality comparison
  (fixes #58)
@mrbean-bremen
Copy link
Member

I made a new patch release with the fix - please check!

@sustrev
Copy link
Author

sustrev commented Nov 9, 2023

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants