pydicom.valuerep.PersonName¶
- class pydicom.valuerep.PersonName(*args: Any, **kwargs: Any)[source]¶
Representation of the value for an element with VR PN.
- __init__(val: bytes | str | PersonName, encodings: Sequence[str] | None = None, original_string: bytes | None = None, validation_mode: int | None = None) None [source]¶
Create a new
PersonName
.- Parameters:
Notes
A
PersonName
may also be constructed by specifying individual components using thefrom_named_components()
andfrom_named_components_veterinary()
class methods.
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.
Return the name as "Family, Given".
formatted
(format_str)Return the name as a
str
formatted using format_str.from_named_components
([family_name, ...])Construct a PersonName from explicit named components.
Construct a PersonName from explicit named components following the veterinary usage convention.
Attributes
Return the first (alphabetic) person name component as a unicode string
Returns up to three decoded person name components as a
tuple
ofstr
.Return the first (family name) group of the alphabetic person name representation as a unicode string
Return the second (given name) group of the alphabetic person name representation as a unicode string
Return the second (ideographic) person name component as a unicode string
Return the third (middle name) group of the alphabetic person name representation as a unicode string
Return the fourth (name prefix) group of the alphabetic person name representation as a unicode string
Return the fifth (name suffix) group of the alphabetic person name representation as a unicode string
Return the third (phonetic) person name component as a unicode string
- property components: tuple[str, ...]¶
Returns up to three decoded person name components as a
tuple
ofstr
.- Returns:
The (alphabetic, ideographic, phonetic) components of the decoded person name. Any of the components may be absent.
- Return type:
Tuple[str, …]
- decode(encodings: Sequence[str] | None = None) 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:
- encode(encodings: Sequence[str] | None = 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:
- property family_name: str¶
Return the first (family name) group of the alphabetic person name representation as a unicode string
- classmethod from_named_components(family_name: str | bytes = '', given_name: str | bytes = '', middle_name: str | bytes = '', name_prefix: str | bytes = '', name_suffix: str | bytes = '', family_name_ideographic: str | bytes = '', given_name_ideographic: str | bytes = '', middle_name_ideographic: str | bytes = '', name_prefix_ideographic: str | bytes = '', name_suffix_ideographic: str | bytes = '', family_name_phonetic: str | bytes = '', given_name_phonetic: str | bytes = '', middle_name_phonetic: str | bytes = '', name_prefix_phonetic: str | bytes = '', name_suffix_phonetic: str | bytes = '', encodings: list[str] | None = None) PersonName [source]¶
Construct a PersonName from explicit named components.
The DICOM standard describes human names using five components: family name, given name, middle name, name prefix, and name suffix. Any component may be an empty string (the default) if not used. A component may contain multiple space-separated words if there are, for example, multiple given names, middle names, or titles.
Additionally, each component may be represented in ideographic or phonetic form in addition to (or instead of) alphabetic form.
For more information see the following parts of the DICOM standard: - Value Representations - PN Examples - PN Precise semantics
Example
A case with multiple given names and suffixes (DICOM standard, part 5, sect 6.2.1.1):
>>> pn = PersonName.from_named_components( family_name='Adams', given_name='John Robert Quincy', name_prefix='Rev.', name_suffix='B.A. M.Div.' )
A Korean case with phonetic and ideographic representations (PS3.5-2008 section I.2 p. 108):
>>> pn = PersonName.from_named_components( family_name='Hong', given_name='Gildong', family_name_ideographic='洪', given_name_ideographic='吉洞', family_name_phonetic='홍', given_name_phonetic='길동', encodings=[default_encoding, 'euc_kr'] )
- Parameters:
name_prefix (str | bytes) – Name prefix in alphabetic form, e.g. ‘Mrs.’, ‘Dr.’, ‘Sr.’, ‘Rev.’.
name_suffix (str | bytes) – Name prefix in alphabetic form, e.g. ‘M.D.’, ‘B.A., M.Div.’, ‘Chief Executive Officer’.
family_name_ideographic (str | bytes) – Family name in ideographic form.
given_name_ideographic (str | bytes) – Given name in ideographic form.
middle_name_ideographic (str | bytes) – Middle name in ideographic form.
name_prefix_ideographic (str | bytes) – Name prefix in ideographic form.
name_suffix_ideographic (str | bytes) – Name suffix in ideographic form.
family_name_phonetic (str | bytes) – Family name in phonetic form.
given_name_phonetic (str | bytes) – Given name in phonetic form.
middle_name_phonetic (str | bytes) – Middle name in phonetic form.
name_prefix_phonetic (str | bytes) – Name prefix in phonetic form.
name_suffix_phonetic (str | bytes) – Name suffix in phonetic form.
encodings (list[str] | None) – A list of encodings used for the other input parameters.
- Returns:
PersonName constructed from the supplied components.
- Return type:
Notes
Strings may not contain the following characters: ‘^’, ‘=’, or the backslash character.
- classmethod from_named_components_veterinary(responsible_party_name: str | bytes = '', patient_name: str | bytes = '', responsible_party_name_ideographic: str | bytes = '', patient_name_ideographic: str | bytes = '', responsible_party_name_phonetic: str | bytes = '', patient_name_phonetic: str | bytes = '', encodings: list[str] | None = None) PersonName [source]¶
Construct a PersonName from explicit named components following the veterinary usage convention.
The DICOM standard describes names for veterinary use with two components: responsible party family name OR responsible party organization name, and patient name. Any component may be an empty string (the default) if not used. A component may contain multiple space-separated words if necessary.
Additionally, each component may be represented in ideographic or phonetic form in addition to (or instead of) alphabetic form.
For more information see the following parts of the DICOM standard: - Value Representations - PN Examples - PN Precise semantics
Example
A horse whose responsible organization is named “ABC Farms”, and whose name is “Running On Water”
>>> pn = PersonName.from_named_components_veterinary( responsible_party_name='ABC Farms', patient_name='Running on Water' )
- Parameters:
responsible_party_name (str | bytes) – Name of the responsible party in alphabetic form. This may be either the family name of the responsible party, or the name of the responsible organization.
patient_name (str | bytes) – Patient name in alphabetic form.
responsible_party_name_ideographic (str | bytes) – Name of the responsible party in ideographic form.
patient_name_ideographic (str | bytes) – Patient name in ideographic form.
responsible_party_name_phonetic (str | bytes) – Name of the responsible party in phonetic form.
patient_name_phonetic (str | bytes) – Patient name in phonetic form.
encodings (list[str] | None) – A list of encodings used for the other input parameters
- Returns:
PersonName constructed from the supplied components
- Return type:
Notes
Strings may not contain the following characters: ‘^’, ‘=’, or the backslash character.
- property given_name: str¶
Return the second (given name) group of the alphabetic person name representation as a unicode string
- property ideographic: str¶
Return the second (ideographic) person name component as a unicode string
- property middle_name: str¶
Return the third (middle name) group of the alphabetic person name representation as a unicode string
- property name_prefix: str¶
Return the fourth (name prefix) group of the alphabetic person name representation as a unicode string