pydicom.valuerep.PersonName

class pydicom.valuerep.PersonName(*args, **kwargs)[source]

Representation of the value for an element with VR PN.

__init__(val: Union[bytes, str, PersonName], encodings: Optional[List[str]] = None, original_string: Optional[str] = None)None[source]

Create a new PersonName.

Parameters
  • val (str, bytes, PersonName) – The value to use for the PN element.

  • encodings (list of str, optional) – A list of the encodings used for the value.

  • original_string (str, optional) – When creating a PersonName using a decoded string, this is the original encoded value.

Methods

__init__(val[, encodings, original_string])

Create a new PersonName.

decode([encodings])

Return the patient name decoded by the given encodings.

encode([encodings])

Return the patient name decoded by the given encodings.

family_comma_given()

Return the name as “Family, Given”.

formatted(format_str)

Return the name as a str formatted using format_str.

Attributes

components

Returns up to three decoded person name components.

family_name

Return the first (family name) group of the alphabetic person name representation as a unicode string

given_name

Return the second (given name) group of the alphabetic person name representation as a unicode string

ideographic

Return the second (ideographic) person name component as a unicode string

middle_name

Return the third (middle name) group of the alphabetic person name representation as a unicode string

name_prefix

Return the fourth (name prefix) group of the alphabetic person name representation as a unicode string

name_suffix

Return the fifth (name suffix) group of the alphabetic person name representation as a unicode string

phonetic

Return the third (phonetic) person name component as a unicode string

property components

Returns up to three decoded person name components.

New in version 1.2.

The returned components represent the alphabetic, ideographic and phonetic representations as a list of unicode strings.

decode(encodings: Optional[List[str]] = None)pydicom.valuerep.PersonName[source]

Return the patient name decoded by the given encodings.

Parameters

encodings (list of str, optional) – The list of encodings used for decoding the byte string. If not given, the initial encodings set in the object are used.

Returns

A person name object that will return the decoded string with the given encodings on demand. If the encodings are not given, the current object is returned.

Return type

valuerep.PersonName

encode(encodings: Optional[List[str]] = None)bytes[source]

Return the patient name decoded by the given encodings.

Parameters

encodings (list of str, optional) – The list of encodings used for encoding the unicode string. If not given, the initial encodings set in the object are used.

Returns

The person name encoded with the given encodings as a byte string. If no encoding is given, the original byte string is returned, if available, otherwise each group of the patient name is encoded with the first matching of the given encodings.

Return type

bytes

family_comma_given()str[source]

Return the name as “Family, Given”.

property family_name

Return the first (family name) group of the alphabetic person name representation as a unicode string

New in version 1.2.

formatted(format_str: str)str[source]

Return the name as a str formatted using format_str.

property given_name

Return the second (given name) group of the alphabetic person name representation as a unicode string

New in version 1.2.

property ideographic

Return the second (ideographic) person name component as a unicode string

New in version 1.2.

property middle_name

Return the third (middle name) group of the alphabetic person name representation as a unicode string

New in version 1.2.

property name_prefix

Return the fourth (name prefix) group of the alphabetic person name representation as a unicode string

New in version 1.2.

property name_suffix

Return the fifth (name suffix) group of the alphabetic person name representation as a unicode string

New in version 1.2.

property phonetic

Return the third (phonetic) person name component as a unicode string

New in version 1.2.