deid icon indicating copy to clipboard operation
deid copied to clipboard

fix: handle colons in private creator names for field expanders

Open Simlomb opened this issue 1 month ago • 1 comments

fix: handle colons in private creator names for field expanders

Fixed a bug where colons that appear inside quoted private creator names, such as "Siemens: Thorax/Multix FD Post Processing" would incorrectly be splitted like field expanders.

The code split on the first colon without considering whether it was inside a quoted string. For example, a recipe rule like:

REMOVE (0021,"Siemens: Thorax/Multix FD Post Processing",15)

Would be incorrectly parsed, splitting at the colon inside the quoted private creator name instead of parsing the field as a whole, separating the expander from the expression.

Changes:

  • Added _split_expander_expression() function to handle quote-aware splitting
    • Tracks whether the parser is inside a quoted string
    • Only splits on colons that appear outside of quotes
    • Returns properly separated expander and expression components
    • Returns a single element when no colon exists outside quotes (specific field case)
  • Modified expand_field_expression() to use the new splitting logic
  • Added test case for private tags with colons in creator names
  • Updated example recipe file with edge case

Fixes handling of DICOM private tags with special characters in their creator names when used with field expanders.

Checklist

  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] My changes generate no new warnings
  • [x] My code follows the style guidelines of this project

Simlomb avatar Dec 16 '25 13:12 Simlomb

@vsoch I found a very specific private creator name that made the code fail for my recipe and I suggest a fix in this PR. Please let me know if you have any comment on it. Thanks as usual for taking the time to check the PRs.

Simlomb avatar Dec 16 '25 13:12 Simlomb

https://pypi.org/project/deid/0.4.12/

vsoch avatar Jan 12 '26 16:01 vsoch