KitwareMedical / dicom-anonymizer

Tool to anonymize DICOM files according to the DICOM standard
BSD 3-Clause "New" or "Revised" License
104 stars 47 forks source link

PatientName and PatientID not getting properly replaced #46

Open apt2000 opened 1 year ago

apt2000 commented 1 year ago

I used the following JSON file: { "(0x0010, 0x0010)": { "action": "regexp", "find": ".", "replace": "ID001^ID002" }, "(0x0010, 0x0020)": { "action": "regexp", "find": ".", "replace": "ID003" }, } In the anonymized DICOM files, the PatientID tag gets set to ID003ID003 (i.e. it is duplicated). The PatientName tag is similarly duplicated and set to ID001^ID002ID001^ID002

apt2000 commented 1 year ago

FYI. I am seeing this duplication issue only with DicomAnonymizer.exe. When I invoke anonymize() from Python code, it appears to behave correctly.

pchoisel commented 1 year ago

Hello @apt2000,

I suspect that this comes from the regexp. "find": "." is going to take each character of the initial value and replace it with whatever is in replace. So in my test file, 3860448 is replaced by ID003ID003ID003ID003ID003ID003ID003 (7xID003 because there are 7 characters in 3860448)

What do you intend to do with this regexp ?

apt2000 commented 1 year ago

Hello @apt2000,

I suspect that this comes from the regexp. "find": "." is going to take each character of the initial value and replace it with whatever is in replace. So in my test file, 3860448 is replaced by ID003ID003ID003ID003ID003ID003ID003 (7xID003 because there are 7 characters in 3860448)

What do you intend to do with this regexp ?

Thanks for looking into this. I am just looking to simply replace, the original PatientID with something different. Is there a way to specify this in the JSON file? I don't think "find": "*" worked for me.

In Python code which works fine, I am just using: def setupPatientID(dataset, tag): element = dataset.get(tag) if element is not None: element.value = args.new_id

extraAnonymizationRules[(0x0010, 0x0020)] = setupPatientID