def test_compile_rule_list(): """Just some basic initialization""" profiles = DICOMRuleSets() basic = profiles.basic_profile assert (basic.get_rule( DataElementFactory(tag="PatientName")).operation.name == "Empty") assert basic.get_rule( DataElementFactory(tag="PatientID")).operation.name == "Empty"
def a_dataset() -> Dataset: """Tiny Dataset that can be used with some_rules and a_core_with_some_rules""" dataset = Dataset() dataset.add(DataElementFactory(tag="PatientID", value="12345")) dataset.add(DataElementFactory(tag="Modality", value="CT")) dataset.add(DataElementFactory(tag="PatientName", value="Martha")) dataset.add( DataElementFactory(tag=(0x5010, 0x3000), value=b"Sensitive data")) dataset.add(DataElementFactory(tag=(0x1013, 0x0001), value=b"private tag")) block = dataset.private_block(0x00B1, "TestCreator", create=True) block.add_new(0x01, "SH", "my testvalue") return dataset
def test_annotation_serialization(): """Text representation should be something like this: (0008, 0023) Content Date - DA: '20121019' annotation: None reason: None (0010, 0010) Patient's Name - PN: 'Estey^Leah' annotation: contains_pii reason: A name is personally quite identifiable (7005, [TOSHIBA_MEC_CT3]0b) [Filter] UN: b'ORG ' annotation: must_not_change reason: this toshiba private tag is needed for computing filter functions """ element = DataElementFactory(tag="PatientName", value="WIMS^kees") annotation = ContainsPII( tag=element.tag, tag_info=str(element), explanation="This is an actual name", ) json_str = json.dumps(annotation.to_dict(), indent=2) loaded = Annotation.from_dict(json.loads(json_str)) assert annotation.tag == loaded.tag assert annotation.tag_info == loaded.tag_info assert annotation.explanation == loaded.explanation assert type(annotation) == type(loaded)
def test_data_element_factory_init(): """Check different init methods """ # factory casts tag init argument to Tag(). Verify that this works. assert type(DataElementFactory().tag) == BaseTag assert type(DataElement(tag="Modality", VR="SH", value="kees").tag) == BaseTag assert type(DataElementFactory(tag="Modality").tag) == BaseTag assert type(DataElementFactory(tag=(0x0010, 0x0020)).tag) == BaseTag # For unknown tags, just give a default VR. Assuming the default position # for users of DataElementFactory will be 'Don't care, just give me the Element' assert DataElementFactory(tag=(0xee30, 0xf120)).VR == VRs.LongString.short_name assert DataElementFactory.create(tag=(0xee30, 0xf120), value=100).VR == VRs.LongString.short_name
def test_data_element_factory_argument(fix_random_seed, tag, expected_vr, expected_value): """Try to create a DataElementFactory of several types """ element = DataElementFactory(tag=tag) assert element.tag == Tag(tag) assert element.VR == expected_vr assert element.value == expected_value
def test_compile_rule_list_overrule_action_code(): """You can overrule the function to call for an action code""" class CustomClean(Clean): name = "Custom" rule_sets = DICOMRuleSets( action_mapping={ActionCodes.CLEAN: CustomClean()}) rules = rule_sets.clean_descriptors assert (rules.get_rule( DataElementFactory(tag=(0x0018, 0x4000))).operation.name == "Custom")
def test_data_element_factory_exceptions(fix_random_seed): with pytest.raises(ValueError): DataElementFactory(tag="unknown_tag")
def apply(self, element: DataElement, dataset: Optional[Dataset] = None) -> DataElement: return DataElementFactory(tag=element.tag)