pydicom / deid

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

Adding anonymising file_meta to the deid recipe #183

Closed adildahlan closed 2 years ago

adildahlan commented 3 years ago

Hi! I hope you are doing well.

I have managed to write a script that anonymises dicom files using the deid package (many thanks for making it available!).

My script anonymises the SOPInstanceUID data element of the dicom file. We know that the MediaStorageSOPInstanceUID = SOPInstanceUID. So my anonymisiation script should also set MediaStorageSOPInstanceUID to the new anonymous SOPInstanceUID.

Because MediaStorageSOPInstanceUID is part of the dicom file file_meta (rather than the dicom file dataelements), I cant seem to find a way to add anonymising the MediaStorageSOPInstanceUID to the deid recipe.

Is there a way to change the MediaStorageSOPInstanceUID using the replace_identifiers and deid recipe?

Many thanks!

Adil

vsoch commented 3 years ago

If there isn't, there definitely can be! You are catching me at the end of the weekend so I can't work on this for you immediately - I'll add it to my TODOs and follow up with you either an evening this week if I have time, or next weekend. Thanks!

vsoch commented 3 years ago

Okay, so I think I'll need a dummy/cleaned example of a file that has this field - I chose a random template one to parse and here is what I see for file_meta:

In [6]: self.dicom.file_meta.TransferSyntaxUID
Out[6]: '1.2.840.10008.1.2'

In [7]: self.dicom.file_meta.ImplementationClassUID
Out[7]: '2.16.840.1'

In [8]: self.dicom.file_meta.ImplementationVersionName
Out[8]: 'MergeCOM3_390IB2'

In [9]: self.dicom.file_meta.to_json_dict()
Out[9]: 
{'00020000': {'vr': 'UL', 'Value': [68]},
 '00020010': {'vr': 'UI', 'Value': ['1.2.840.10008.1.2']},
 '00020012': {'vr': 'UI', 'Value': ['2.16.840.1']},
 '00020013': {'vr': 'SH', 'Value': ['MergeCOM3_390IB2']}}

But I know it can be there! https://pydicom.github.io/pydicom/stable/tutorials/dataset_basics.html

Do you have a file with this field that I can test? I'll first test replacing it there, and then add functionality to add. I'm thinking we will want the same kind of syntax for file meta fields, but some way to indicate that it's for the file meta. Something like:

FORMAT dicom

%filemeta

REPLACE MediaStorageSOPClassUID new-id

@wetzelj do you have thoughts here? Is file meta something you've needed to change /tweak before?

adildahlan commented 3 years ago

Hi @Vsoch, I hope you are doing well, Many thanks for working on this. Here is a link to DICOM files with the MediaStorageSOPInstanceUID stored as part of the DICOM file http://www.pcir.org/researchers/39419238_20010101.html. My anonymisation deid_recipe anonymises all the dicom file header dataelement, including the SOPInstanceUID, where the deid.dicom recipe file has the following line of code: REPLACE SOPInstanceUID var:new_SOPInstanceUID Ideally we could have REPLACE MediaStorageSOPInstanceUID var:new_MediaStorageSOPInstanceUID, but at the moment this gives an error. I hope you could find a way to make this work Looking forward to hearing from you Many thanks Warm regards Adil

adildahlan commented 3 years ago

Sorry I just realised that in my first message I had MediaStorageSOPClassUID instead of MediaStorageSOPInstanceUID. I fixed it above as well. I was pretty tired when I posted this issue last night 😅. Apologies about that... (The MediaStorageSOPClassUID refers to the imaging modality and so it should never be changed even when anonymising the DICOM file. Whereas the MediaStorageSOPInstanceUID is basically a UID for that specific DICOM file and so it should be changed when anonymising the DICOM file otherwise potentially the DICOM file could be backtracked to the person it belongs to).

wetzelj commented 3 years ago

@vsoch - This isn't something that has come across my radar, but now that it's been pointed out, yep... this is an issue for us as well. In our standard deid scheme, we replace the SOPInstanceUID. I didn't realize it was replicated in MediaStorageSOPInstanceUID.

BTW... cat.dcm is a sample that has the field.

vsoch commented 3 years ago

yeah I can totally support this! I think I have an idea of what I want to do - thanks for the example image @adildahlan and the feedback @wetzelj and I'll try to get something to you soon! Latest will be over the weekend.

adildahlan commented 3 years ago

Many thanks @vsoch and @wetzelj! That sounds perfect, I appreciate it 😄!

adildahlan commented 2 years ago

Many thanks @vsoch and @wetzelj for working on this! You did a great job👏🏼

adildahlan commented 2 years ago

Closed by PR #184