Advertisement
4tolexx

dicom anonymization

Apr 25th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # anonymization of dicom tags issue
  2.  
  3. * add deny or allow list of dicom tags to study configuration yml
  4. * upon upload of study configuration remove list of dicom tags included in the deny list
  5. * the removed list should not be part of the dicom metadata information
  6.  
  7. def apply_tag_deny_list!(dicom)
  8. deny_list = study.locked_configuration.dig("filtered_dicom_tags", "deny_list") || []
  9. all_tags = deny_list + ["0010,0010"]
  10.  
  11. all_tags.each do |tag|
  12. tag_existed = dicom.exists?(tag)
  13. dicom.delete_element(tag) if tag_existed
  14.  
  15. next unless tag_existed
  16.  
  17. original_attributes_seq = dicom[DICOM::Tag.OriginalAttributesSequence]
  18. original_attributes_seq ||= DICOM::Sequence.new(DICOM::Tag.OriginalAttributesSequence, parent: dicom)
  19. original_attributes = original_attributes_seq.add_item
  20.  
  21. original_attributes.add_element(
  22. DICOM::Tag.AttributeModificationDateTime,
  23. DateTime.now.utc.strftime("%Y%m%d%H%M%S.%6N")
  24. )
  25. original_attributes.add_element(DICOM::Tag.ModifyingSystem, "Pharmtrace ERICA SaaS #{ERICA.version}")
  26. original_attributes.add_element(DICOM::Tag.ReasonForTheAttributeModification, "COERCE")
  27.  
  28. modified_attributes_seq = DICOM::Sequence.new(DICOM::Tag.ModifiedAttributesSequence, parent: original_attributes)
  29. modified_attributes = modified_attributes_seq.add_item
  30. modified_attributes.add_element(tag, "")
  31. end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement