def verifyNotZero(elem: DataElement, verbose: bool, log: list, which: int, warningNotError: bool) -> bool: success = True if elem.is_empty: return True val = elem.value vm = elem.VM if type(val) == MultiValue: if which == -1: candidate = val else: if which >= vm: return False else: candidate = [val[which]] else: if which >= 1: return False else: candidate = [val] for i, count in zip(candidate, range(0, len(candidate))): if not isPydicomNumeric(i): log.append("{} {} <{}>".format( EMsgDC("TriedToVerifyNotZeroForNonNumericAttribute"), MMsgDC("ForAttribute"), elem.description())) return False if i == 0: log.append("{} {} {} {} <{}>".format( (WMsgDC("ZeroValue") if warningNotError else EMsgDC("ZeroValue")), MMsgDC("ForValue"), (count + 1), MMsgDC("OfAttribute"), elem.description())) success = False return success
def test_description_unknown_private(self): """Test DataElement.description with an unknown private element""" elem = DataElement(0x00110010, 'LO', 12345) elem.private_creator = 'TEST' assert 'Private tag data' == elem.description() elem = DataElement(0x00110F00, 'LO', 12345) assert elem.tag.is_private assert elem.private_creator is None assert 'Private tag data' == elem.description()
def test_description_unknown_private(self): """Test DataElement.description with an unknown private element""" elem = DataElement(0x00110010, 'LO', 12345) elem.private_creator = 'TEST' assert elem.description() == 'Private tag data' elem = DataElement(0x00110F00, 'LO', 12345) assert elem.tag.is_private assert not hasattr(elem, 'private_creator') assert elem.description() == 'Private tag data'
def test_elem_description_deprecated(): """Test deprecation warning for DataElement.description()""" elem = DataElement("PatientName", "PN", "Citizen^Jan") msg = ( r"'DataElement.description\(\)' is deprecated and will be removed in " r"v3.0, use 'DataElement.name' instead") with pytest.warns(DeprecationWarning, match=msg): assert elem.description() == "Patient's Name"
def verifyEnumValues(elem: DataElement, str_val: dict, verbose: bool, log: list, which: int) -> bool: success = True val = elem.value vm = elem.VM if type(val) == MultiValue: if which == -1: candidate = val else: if which >= vm: return False else: candidate = [val[which]] else: if which >= 1: return False else: candidate = [val] for i, count in zip(candidate, range(0, len(candidate))): converted_i = i if type(i) == DSfloat or \ type(i) == DSdecimal or type(i) == IS: converted_i = str(i) elif type(i) == str: converted_i = i else: log.append( EMsgDC("TriedToVerifyEnumeratedValueForNonStringAttribute") + \ MMsgDC("ForAttribute") + " <" + elem.description() + ">") return False if converted_i in str_val: if verbose: log.append( MMsgDC("RecognizedEnumeratedValue") \ + " <" + i + "> " + MMsgDC("Is") + " <" + str_val[i] \ + "> " + MMsgDC("ForValue") + " {}".format(count + 1) \ + " " + MMsgDC("OfAttribute") + " <" \ + elem.description() + ">") else: msg = "{} <{}> {} {} {} {}".format( EMsgDC("UnrecognizedEnumeratedValue"), i, MMsgDC("ForValue"), count + 1, MMsgDC("OfAttribute"), elem.description()) log.append(msg) success = False return success
def verifyEnumValues_uint16(elem: DataElement, bin_method, verbose: bool, log: list, which: int) -> bool: success = True val = elem.value vm = elem.VM if type(val) == MultiValue: if which == -1: candidate = val else: if which >= vm: return False else: candidate = [val[which]] else: if which >= 1: return False else: candidate = [val] for i, count in zip(candidate, range(0, len(candidate))): if not isPydicomNumeric(i): log.append( EMsgDC("TriedToVerifyEnumeratedValueForNonNumericAttribute") + \ MMsgDC("ForAttribute") + " <" + elem.description() + ">") try: int_input = uint16(i) output = bin_method(int_input) except: output = [] if len(output) == 0: msg = "{} <{}> {} {} {} {} {}".format( EMsgDC("UnrecognizedEnumeratedValue"), i, MMsgDC("ForValue"), count + 1, MMsgDC("OfAttribute"), elem.description(), bin_method.__name__) log.append(msg) success = False else: if verbose: log.append( MMsgDC("RecognizedEnumeratedValue") \ + " <{}> ".format(i) + MMsgDC("Is") + " <" + output \ + "> " + MMsgDC("ForValue") + " {}".format(count + 1) \ + " " + MMsgDC("OfAttribute") + " <" \ + elem.description() + ">") return success
def verifyEnumValues_tag(elem: DataElement, tag_method, verbose: bool, log: list, which: int) -> bool: # I think group and element for all values of multivalue attribs is the same. I should ask this? success = True val = elem.value vm = elem.VM g = uint16(elem.tag.group) e = uint16(elem.tag.elemnt) output = tag_method(g, e) if len(output) == 0: msg = "{} <({},{})> {} {} {}".format( EMsgDC("UnrecognizedEnumeratedValue"), g,e, MMsgDC("ForValue"), MMsgDC("OfAttribute"), elem.description()) log.append(msg) success = False else: if verbose: log.append( MMsgDC("RecognizedEnumeratedValue") \ + " <" + "({},{})".format(g, e) + "> " + MMsgDC( "Is") + " <" + output \ + "> " + MMsgDC("ForValue") + val \ + " " + MMsgDC("OfAttribute") + " <" \ + elem.description() + ">") # if which == -1: # candidate = val # else: # if which >= vm: # return False # else: # candidate = val[which] # for i in candidate: # if type(i) != int: # return False # output = tag_method(uint16(elem.tag.group), uint16(elem.tag.elemnt)) # if len(output) == 0: # print("Unrecognized defined term for {}".format(elem.keyword)) # success = False # else: # print("print sth if verbose") return success
def verifyDefinedTerms(elem: DataElement, str_val: dict, verbose: bool, log: list, which: int) -> bool: val = elem.value vm = elem.VM if type(val) == MultiValue: if which == -1: candidate = val else: if which >= vm: return False else: candidate = [val[which]] else: if which >= 1: return False else: candidate = [val] for i, count in zip(candidate, range(0, len(candidate))): if type(i) != str: log.append( EMsgDC("TriedToVerifyDefinedTermsForNonStringAttribute") + \ MMsgDC("ForAttribute") + " <" + elem.description() + ">") return False if i in str_val: if verbose: log.append( MMsgDC("RecognizedDefinedTerms") \ + " <" + i + "> " + MMsgDC("Is") + " <" + str_val[i] \ + "> " + MMsgDC("ForValue") + " {}".format(count + 1) \ + " " + MMsgDC("OfAttribute") + " <" \ + elem.description() + ">") else: msg = "{} <{}> {} {} {} {}".format( WMsgDC("UnrecognizedDefinedTerm"), i, MMsgDC("ForValue"), count + 1, MMsgDC("OfAttribute"), elem.description()) log.append(msg) return True return False
def test_description_group_length(self): """Test DataElement.description for Group Length element""" elem = DataElement(0x00100000, 'LO', 12345) assert 'Group Length' == elem.description()
def test_description_unknown(self): """Test DataElement.description with an unknown element""" elem = DataElement(0x00000004, 'LO', 12345) assert '' == elem.description()
def test_description_unknown(self): """Test DataElement.description with an unknown element""" elem = DataElement(0x00000004, 'LO', 12345) assert elem.description() == ''
def test_description_group_length(self): """Test DataElement.description for Group Length element""" elem = DataElement(0x00100000, 'LO', 12345) assert elem.description() == 'Group Length'