def test_reject_non_standard(): a_core = Core(profile=Profile(rule_sets=[]), bouncers=[RejectNonStandardDicom()]) # this should not raise anything a_core.deidentify(quick_dataset(SOPClassUID="1.2.840.10008")) with pytest.raises(DeidentificationException): a_core.deidentify(quick_dataset(SOPClassUID="123"))
def test_realistic_profile(): """Run a file through a profile that has several options""" sets = DICOMRuleSets() profile = Profile(rule_sets=[ sets.basic_profile, sets.clean_descriptors, sets.clean_graphics, sets.retain_modified_dates, sets.retain_safe_private, ]) final_set = profile.flatten() assert len(final_set.rules) == 442 core = Core(profile=profile) dataset = CTDatasetFactory() original = deepcopy(dataset) deidentified = core.deidentify(dataset) assert original.PatientID != deidentified.PatientID
"""You can set your own rules for specific DICOM tags. Be aware that this might mean the deidentification is no longer DICOM-complient """ import pydicom from idiscore.core import Core, Profile from idiscore.defaults import get_dicom_rule_sets from idiscore.identifiers import RepeatingGroup, SingleTag from idiscore.operators import Hash, Remove from idiscore.rules import Rule, RuleSet # Custom rules that will hash the patient name and remove all curve data my_ruleset = RuleSet( rules=[ Rule(SingleTag("PatientName"), Hash()), Rule(RepeatingGroup("50xx,xxxx"), Remove()), ], name="My Custom RuleSet", ) sets = get_dicom_rule_sets() # Contains official DICOM deidentification rules profile = Profile( # add custom rules to basic profile rule_sets=[sets.basic_profile, my_ruleset]) core = Core(profile) # Create an deidentification core # read a DICOM dataset from file and write to another core.deidentify(pydicom.read("my_file.dcm")).save_as("deidentified.dcm")