def convert_DS_string(byte_string, is_little_endian, struct_format=None): """Read and return a DS value or list of values""" if in_py3: byte_string = byte_string.decode(default_encoding) # Below, go directly to DS class instance rather than factory DS, # but need to ensure last string doesn't have blank padding (use strip()) return MultiString(byte_string.strip(), valtype=dicom.valuerep.DSclass)
def convert_UI(byte_string, is_little_endian, struct_format=None): """Read and return a UI values or values""" # Strip off 0-byte padding for even length (if there) if in_py3: byte_string = byte_string.decode(default_encoding) if byte_string and byte_string.endswith('\0'): byte_string = byte_string[:-1] return MultiString(byte_string, dicom.UID.UID)
def convert_string(byte_string, is_little_endian, struct_format=None, encoding=default_encoding): """Read and return a string or strings""" if in_py3: byte_string = byte_string.decode(encoding) return MultiString(byte_string)
""" # Copyright (c) 2012 Darcy Mason # This file is part of pydicom, relased under an MIT-style license. # See the file license.txt included with this distribution, also # available at http://pydicom.googlecode.com # import dicom # dicom.debug() from dicom.valuerep import DS, MultiString from dicom.multival import MultiValue # print("\n\nTry creating MultiValue directly") s = r"1.2000\2.30000" m = MultiString(s, DS) # print "m=", m # print "type(m) = ", type(m) # print "type(m[0]) = ", type(m[0]) # print "m[0].original_string", m[0].original_string filename = "rtplan.dcm" print( "\n\nTest reading rtplan.dcm and keeping original string for multival DS") print("---------") print("First read a file with DS as default float-derived class") ds = dicom.read_file(filename) dr = ds.DoseReferenceSequence[0] drpc0 = dr.DoseReferencePointCoordinates[0] print("Value of original_string: ".format(drpc0.original_string))
def convert_IS_string(byte_string, is_little_endian, struct_format=None): """Read and return an IS value or list of values""" if in_py3: byte_string = byte_string.decode(default_encoding) return MultiString(byte_string, valtype=dicom.valuerep.IS)
def convert_UI(bytes, is_little_endian, struct_format=None): """Read and return a UI values or values""" # Strip off 0-byte padding for even length (if there) if bytes and bytes.endswith('\0'): bytes = bytes[:-1] return MultiString(bytes, dicom.UID.UID)
def convert_string(bytes, is_little_endian, struct_format=None): """Read and return a string or strings""" return MultiString(bytes)
def convert_PN(bytes, is_little_endian, struct_format=None): """Read and return string(s) as PersonName instance(s)""" return MultiString(bytes, valtype=PersonName)
def convert_IS_string(bytes, is_little_endian, struct_format=None): """Read and return an IS value or list of values""" return MultiString(bytes, valtype=IS)