Repository navigation
Conversation
vsoch
left a comment
There was a problem hiding this comment.
Overall looks good! One comment and item for discussion below.
| # If selected variable not provided, skip | ||
| if value_option not in item: | ||
| if required: | ||
| raise ValueError(f"var:{value_option} not found in item lookup.") |
There was a problem hiding this comment.
Let's add the field and file basename here as well.
My one concern about this is that a single missing value is going to raise error for the entire batch. That means you would get partial writes.
There was a problem hiding this comment.
Added in e1eb17d, e.g. var:new_name not found in item lookup. Field: PatientName, file: ctbrain1.dcm.
On the batch: replace_identifiers could catch the error per file, log it, skip writing that file and continue with the rest, then raise at the end with the files that failed. Would that work for you?
There was a problem hiding this comment.
I think that would be more ideal than stopping mid-batch without any awareness for what has been done. Others can chime in if they have opinion.
There was a problem hiding this comment.
Done in 9abb594. replace_identifiers now logs and skips a file with a missing value (it is not saved or returned), processes the rest, and raises at the end with the skipped files, e.g. 1 of 2 files were skipped because of a missing lookup: var:new_name not found in item lookup. Field: PatientName, file: ctbrain2.dcm.
Separately, CI on this PR fails at conda create with conda: command not found on the runner, before any of the code runs.
There was a problem hiding this comment.
Yes - that issue has been hitting many of the other repos I maintain too! The old ubuntu runner came with conda, and it was removed. I'll see if I can put in a fix you can rebase to.
A missing var:, func: or deid_func: made these actions skip the field, which kept the original value, also under REMOVE ALL since REPLACE and JITTER fields are kept for later. They now raise a ValueError. ADD still skips, as the default recipe relies on it. Closes pydicom#274
replace_identifiers stopped at the first file with a missing var:, func: or deid_func:, after earlier files were already written. It now logs and skips that file (not saved or returned), processes the rest, and raises a MissingLookupError (a ValueError) at the end that names every skipped file.
9abb594 to
3ee7f2a
Compare
| else: | ||
| updated_files.append(parser.dicom) | ||
|
|
||
| if missing: |
There was a problem hiding this comment.
If missing is not empty, what do we get by raising an error here? If save is True, the subset of updated files are updated (but we never return them to the user). If save is False, we lose those files.
Description
Related issues: #274
REPLACE, JITTER and REMOVE now raise a
ValueErrorwhen theirvar:,func:ordeid_func:isn't available, instead of skipping the field.Skipping kept the original value. With
and no
new_idfor a file, the originalPatientIDis written out, because REPLACE fields are kept by REMOVE ALL. A missingvar:doesn't log anything either. The same happens withfunc:,deid_func:, JITTER, andREMOVE ALL func:...(nothing gets removed).parse_valuetakesrequired=False, and REPLACE, JITTER and REMOVE passrequired=True. ADD still skips, since the default recipe hasADD PatientID var:entity_idand similar lines that most people don't provide. A REPLACE for a field the file doesn't have doesn't raise either, because the action never runs.In
replace_identifiers, a file with a missing value is logged and skipped (not saved or returned), the other files are still processed, and aMissingLookupError(aValueError) naming every skipped file is raised at the end.This changes behavior for recipes that relied on the skip, so I added a CHANGELOG entry (0.4.14) and a note in
recipe-headers.md. If you'd rather make it opt-in, for example with astrictargument, I can change it.To test:
python -m unittest deid.tests.test_dicom_funcs. The new tests cover the five cases above,replace_identifiers(raises and writes no file, and works when the variable is given), ADD still skipping, and a batch where one file has no value (only the other file is written, and the error names the skipped one). The first two fail on master. Full suite: 284 tests, onlytest_cliandtest_utilserror on my Windows machine (temp files still open during cleanup), same as on master.Checklist
Open questions
Raise by default vs. opt-in, as above.
AI assistance (Claude Code) was used for this change.