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

DICOM Redaction Updates #184

Merged
merged 11 commits into from
Feb 13, 2024
Merged

DICOM Redaction Updates #184

merged 11 commits into from
Feb 13, 2024

Conversation

naglepuff
Copy link
Collaborator

@naglepuff naglepuff commented Jan 30, 2024

Fix #182

Changes

  1. Additional DICOM metadata rules have been added based on tags found in NEMA data that were not previously supported.
  2. Less reliance on file extension to try and redact files, more emphasis on checking the file type. Previously, DICOM files without the .dcm extension failed to be redacted.
  3. Custom metadata fields found in DICOM images are deleted by default. Rules overrides can change this behavior.

@naglepuff
Copy link
Collaborator Author

Note that a0346cc is necessary due to psf/black#3887

@naglepuff naglepuff marked this pull request as ready for review January 30, 2024 19:00
@manthey
Copy link
Contributor

manthey commented Feb 2, 2024

Should we suppress UserWarnings from pydicom, since we aren't going to do anything about them? In the test files, I get pydicom/valuerep.py:443: UserWarning: Invalid value for VR UI: '1.3.6.1.4.1.36533.0106114253531497724413917111421208341787'. Please see <https://dicom.nema.org/medical/dicom/current/output/html/part05.html#table_6.2-1> for allowed values for each VR. Ironically, as far as I can tell from that link this UI is conformant to what they say, though I suspect the chunk with the leading 0 is the complaint.

@manthey
Copy link
Contributor

manthey commented Feb 2, 2024

I get a pydantic error when I try to use the following rule set override:

---
dicom:
  delete_custom_metadata: false

Pydantic says Field required [type=missing, input_value={'dicom': {'delete_custom_metadata': False}}, input_type=dict], but doesn't say what field is required.

@manthey
Copy link
Contributor

manthey commented Feb 2, 2024

I get a pydantic error when I try to use the following rule set override:

---
dicom:
  delete_custom_metadata: false

Pydantic says Field required [type=missing, input_value={'dicom': {'delete_custom_metadata': False}}, input_type=dict], but doesn't say what field is required.

Aside from pydantic having terrible error messages, we should make it so that a custom rule set has as little required as possible (it can be a separate PR).

self.metadata_redaction_steps[element.tag] = DeleteRule(
key_name=custom_metadata_key, action="delete"
)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be slightly later in the plan: That is, if there is a rule for a specific custom metadata tag, that should take priority over the keep/delete custom metadata.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can definitely move it. But a good point that this raises is that we're relying onpydicom to get a tag's name, which doesn't work for custom metadata. This means we'll need to also support checking by tag.

@naglepuff
Copy link
Collaborator Author

I get a pydantic error when I try to use the following rule set override:

---
dicom:
  delete_custom_metadata: false

Pydantic says Field required [type=missing, input_value={'dicom': {'delete_custom_metadata': False}}, input_type=dict], but doesn't say what field is required.

Aside from pydantic having terrible error messages, we should make it so that a custom rule set has as little required as possible (it can be a separate PR).

Was that the entirety of your rules override file? In that case, the errors are looking for all of the other properties of a Rule Set (name, description, tiff, etc.), since none of it is optional.

It would be easy enough to make those things optional as part of this PR.

For what its worth, I did end up seeing exactly what fields pydantic was complaining about.

There was actually a bug that would have caused that property to not get overridden, so I will address that here.

This allows more minimal override rulesets.
Move it to later in the build step to give a chance to match a rule.
key_name=custom_metadata_key, action="delete"
)
else:
self.metadata_redaction_steps[element.tag] = KeepRule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ultimately should have three states, delete custom metadata, keep custom metadata, or do not have auto rules on custom metadata. This could be a future PR, though. Maybe it is a pair of booleans: delete_custom_metadata and keep_custom_metadata which would then make no sense if both true.

@naglepuff naglepuff merged commit b1930b2 into main Feb 13, 2024
4 checks passed
@naglepuff naglepuff deleted the 182-update-dicom-rules branch February 13, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update DICOM Rules
2 participants