pydicom / deid

best effort anonymization for medical images using python
https://pydicom.github.io/deid/
MIT License
140 stars 43 forks source link

Add group:xxxx field expander #212

Closed jstorrs closed 1 year ago

jstorrs commented 1 year ago

Description

This is an attempt to add a group: field expander to support some CTP-style rules that target tag groups. The idea is to support rules such as:

KEEP group:0018

Checklist

Open questions

I've tested this interactively, but unfortunately, I haven't yet figured out how to get pytest to run on deid. It keeps complaining that deid.tests is an unknown module (see attached). I'm new to pytest so I'm probably messing something obvious up.

pytest-errors.txt

jstorrs commented 1 year ago

Oh, it's not pytest... do you run them:

python -m unittest deid/tests/test_*.py

vsoch commented 1 year ago

I always check the testing file to remember the command!

https://github.com/pydicom/deid/blob/6dd9c7e19a61c46e231c827163de74815628697a/.github/workflows/main.yml#L39-L43

vsoch commented 1 year ago

In what cases would someone have an identifier and not the name?

jstorrs commented 1 year ago

The various DICOM tag are organized into functional groups.

In CTP for example one of the rules that are available is to keep an entire group. See for example the "k" element in CTP scripts:

https://github.com/johnperry/CTP/blob/master/source/files/examples/example-ctp-dicom-anonymizer.script https://github.com/johnperry/CTP/blob/master/source/files/examples/example-tfs-dicom-anonymizer.script

<k en="T" t="0018">Keep group 0018</k>
<k en="T" t="0020">Keep group 0020</k>
<k en="T" t="0028">Keep group 0028</k>

In CTP, I can't remember if the documentation discusses the script files directly because in CTP you're intended to use the configuration utility and not the XML directly. But the k elements work on entire groups specified by the t attribute. en is whether that particular rule is enabled. Groups 18, 20 and 28 are often useful for this sort of targeting (the inner contents of the script elements are just descriptive text entered by the user).

https://mircwiki.rsna.org/index.php?title=The_CTP_DICOM_Anonymizer

vsoch commented 1 year ago

Oh neat!

So the formatting tests (that are failing) are fairly simple - you run black (new version) on deid.

black deid

and that should fix the test failure. And then just add a note to the CHANGELOG.md and bump the version in deid/version.py and we will be good to go!

vsoch commented 1 year ago

This looks great! :partying_face:

I think we are just about ready for merge. The last little bit (which I forgot in my last comments, sorry about that) is to add a few sentences and a quick example to the user facing docs - I think maybe on this page? https://pydicom.github.io/deid/user-docs/recipe-headers/

vsoch commented 1 year ago

Thanks @jstorrs ! This is a cool little addition (very useful!) and I'll get it released soon.