o
    i                    @   sh  U d Z ddlZddlmZ ddlmZmZ ddlZddlm	Z	m
Z
mZ ddlmZmZmZ ddlmZmZmZ ddlmZ dd	lmZ d
Zh dZdhZdddddddddd	ZdedefddZdddddedededdd d!
Zd"d# e D Z d$d# e D Z!d%ed&ed'e"e#e"e"f B de#e$ef fd(d)Z%d%ed&ede#e$ef fd*d+Z&d%ed&ede#e$ef fd,d-Z'd%ed&ede#e$ef fd.d/Z(d%ed&ede#e$ef fd0d1Z)d%ed&ed2e"de#e$ef fd3d4Z*d%ed&ede#e$ef fd5d6Z+d%ed&ede#e$ef fd7d8Z,d%ed&ede#e$ef fd9d:Z-d&ee.B ddfd;d<Z/d=d=d>d>d?d?d>d?d@Z0d%ed&edAe1dBe1de#e$ef f
dCdDZ2i dEe+dFe)dGe+dHdIdJ dKe+dLdMdJ dNdOdJ dPdQdJ dRe+dSe'dTe'dUdVdJ dWdXdJ dYdZdJ d[d\dJ d]d^dJ d_d`dJ e-e'dadJ dbdJ e'dcdJ dddJ e+dedJ dfdJ e)dgdJ dhZ3	dd%ed&edie1djeeege#e$ef f dB ddf
dkdlZ4eG dmdn dneeZ5h e5j6e5j7e5j8e5j9e5j:e5j;e5j<e5j=e5j>e5j?e5j@e5jAe5jBe5jCe5jDe5jEe5jFe5jGe5jHe5jIe5jJe5jKe5jLe5jMe5jNe5jOe5jPe5jQe5jRe5jSe5jTe5jUe5jVe5jWZXe5jYe5jZe5j[e5j\hZ]e5j6e5j7e5j9e5j:e5j;e5j<e5j?e5jOe5jQe5jTh
Z^e5j@e5jAe5jHe5jIe5jMe5jPe5jVhZ_e5jBe5jCe5jDe5jEe5jGe5jFe5jShZ`e5j;e5j=e5j>hZae5j8e5j?e5jJe5jLe5jNe5jRe5jUe5jWhZbe5jKhZce^e_B Zde5jAe5jMe5jVe5jYe5j[e5j\he`B Zee5jAe5jPe5jVhe`B e]B Zfe5j6e5j7e5j8e5j9e5j:e5j;e5j<e5j>e5j=e5j?e5j@e5jAe5jHe5jIe5jJe5jLe5jMe5jOe5jQe5jRe5jUhZgeXeg Zhe`e5j\hB e5jSh ZiG dodp dpZjG dqdH dHejejkZ:G drdL dLejejZ<G dsdt dtejejlZOduede$fdvdwZmdxeneB defdydzZoG d{d| d|enZpG d}d~ d~eZqeerd< ejsrBeqZtnepZt		ddxdeB e1B enB eB de$die1dB ddeB epB eqB fddKZ;G dd denZuG ddR dRe1Z?deee B dB de#edf dB fddZvdee. dee de#edf fddZwdee dee de.fddZxG dd dZydS )z4Special classes for DICOM value representations (VR)    N)Decimal)Enumunique)floorisfinitelog10)OptionalAnycast)CallableSequenceIterator)config)warn_and_logiso8859>   	   
         ^      r   @   i (  i   )	AECSDSISLOLTSHSTUIregexreturnc                 C   s$   d|  d|  d|  d|  d|  dS )zvCompose a regex that allows ranges of the given regex,
    as defined for VRs DA, DT and TM in PS 3.4, C.2.2.2.5.
    ^z$|^\-z ?$|^z\- ?$|^z\-z ?$ )r!   r$   r$   F/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/valuerep.py_range_regex/   s   $r&   z^[\x20-\x7e]*$z^\d\d\d[DWMY]$z^[A-Z0-9 _]*$z0^ *[+\-]?(\d+|\d+\.\d*|\.\d+)([eE][+\-]?\d+)? *$z^ *[+\-]?\d+ *$z#\d{4}(0[1-9]|1[0-2])([0-2]\d|3[01])zs\d{4}((0[1-9]|1[0-2])(([0-2]\d|3[01])(([01]\d|2[0-3])([0-5]\d((60|[0-5]\d)(\.\d{1,6} ?)?)?)?)?)?)?([+-][01]\d\d\d)?z6([01]\d|2[0-3])([0-5]\d((60|[0-5]\d)(\.\d{1,6} ?)?)?)?z%^(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*$z)^[A-Za-z_\d:/?#\[\]@!$&'()*+,;=%\-.~]* *$)
r   ASr   r   r   DADTTMr    URc                 C   s   i | ]
\}}|t |qS r$   )recompile.0vrr!   r$   r$   r%   
<dictcomp>G   s    r1   c                 C   s    i | ]\}}|t | qS r$   )r,   r-   encoder.   r$   r$   r%   r1   H   s     r0   valuetypesc                 C   s2   |durt ||sddt|j d|  dfS dS )ay  Checks for valid types for a given VR.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.
    types: Type or Tuple[Type]
        The type or tuple of types supported for the given VR.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    NFzA value of type 'z&' cannot be assigned to a tag with VR .T )
isinstancetype__name__)r0   r3   r4   r$   r$   r%   validate_typeK   s   r;   c                 C   sD   t | d}|dkr t|}||kr dd| d| d|  dfS dS )a  Validate the value length for a given VR.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    r   FzThe value length (z ) exceeds the maximum length of z allowed for VR r5   r6   )MAX_VALUE_LENgetlen)r0   r3   
max_lengthvalue_lengthr$   r$   r%   validate_vr_lengthe   s   rA   c                 C   *   t | |ttf\}}|s||fS t| |S )a3  Validate the correct type and the value length for a given VR.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    )r;   strbytesrA   r0   r3   validmsgr$   r$   r%   validate_type_and_length~   s   
rH   c                 C   s^   |r-t |trt|  }d}nt|  }d}t||r"|r-|d |kr-dd|  d|dfS dS )	aM  Validate the value for a given VR for allowed characters
    using a regular expression.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    
r   FzInvalid value for VR z: r5   r6   )r8   rC   STR_VR_REGEXESBYTE_VR_REGEXESr,   match)r0   r3   r!   newliner$   r$   r%   validate_regex   s   
rO   c                 C   rB   )ay  Validate that the value is of type :class:`str` or :class:`bytes`
    and that the value matches the VR-specific regular expression.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    )r;   rC   rD   rO   rE   r$   r$   r%   validate_type_and_regex   s   
rP   date_time_typec                 C   s   |r	t ||r	dS t| |S )a  Checks for valid values for date/time related VRs.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.
    date_time_type: type
        The specific type supported for the given VR (additional to str/bytes).

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    r6   )r8   rP   )r0   r3   rQ   r$   r$   r%   validate_date_time   s   
rR   c                 C   sf   t | |ttf\}}|s||fS t| |\}}t| |\}}d||g }|r-|d7 }|o0||fS )a  Validate the value for a given VR for maximum length, for the correct
    value type, and for allowed characters using a regular expression.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
     z~ Please see <https://dicom.nema.org/medical/dicom/current/output/html/part05.html#table_6.2-1> for allowed values for each VR.)r;   rC   rD   rA   rO   joinstrip)r0   r3   rF   rG   is_valid_lenmsg1is_valid_exprmsg2r$   r$   r%   "validate_length_and_type_and_regex   s   rZ   c                 C   s$   t |dkrddt | dfS dS )a  Validate the PN component value for the maximum length.

    Parameters
    ----------
    vr : str
        Ignored.
    value : str
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    r   FzThe PN component length (z+) exceeds the maximum allowed length of 64.r6   )r>   r0   r3   r$   r$   r%   validate_pn_component_length   s
   r\   c                 C   s   |rt |tr	dS t| |ttf\}}|s||fS t |tr$|d}n|d}t|dkr9ddt| dfS |D ]}td|\}}|sLd|f  S q;dS )	aC  Validate the value for VR PN for the maximum number of components
    and for the maximum length of each component.

    Parameters
    ----------
    vr : str
        Ignored.
    value : str
        The value to validate.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    r6      ==   Fz$The number of PN components length (z*) exceeds the maximum allowed number of 3.PN)r8   
PersonNamer;   rC   rD   splitr>   r\   )r0   r3   rF   rG   
componentscompr$   r$   r%   validate_pn  s$   

re   c                 C   s   t d| tjjt dS )a$  Validate the value of a single component of VR PN for maximum length.

    Parameters
    ----------
    value : str or bytes
        The component value to validate.

    Raises
    ------
    ValueError
        If the validation fails and the validation mode is set to
        `RAISE`.
    r`   N)validate_valuer   settingswriting_validation_moder\   )r3   r$   r$   r%   validate_pn_component2  s   ri            )USSSULSLUVSVFLFD	min_value	max_valuec                 C   s   t | |ttf\}}|s||fS t|tr-||k s||kr+dd|  d| d| dfS d	S t|t|   rGddt| d|  dt|   dfS d	S )
a  Validate the value for a numerical VR for type and allowed range.

    Parameters
    ----------
    vr : str
        The value representation to validate against.
    value : Any
        The value to validate.
    min_value : int
        The minimum allowed value.
    max_value : int
        The maximum allowed value.

    Returns
    -------
        A tuple of a boolean validation result and the error message.
    Fz)Invalid value: a value for a tag with VR z must be between z and r5   zInvalid value length z%: the value length for a tag with VR z must be a multiple of r6   )r;   intrD   r8   r>   VALUE_LENGTH)r0   r3   ru   rv   rF   rG   r$   r$   r%   validate_numberK  s,   
	ry   r   r'   r   r(   c                 C      t | |tjS N)rR   datetimedater[   r$   r$   r%   <lambda>t      r~   r   r)   c                 C   s   t | |tjS r{   )rR   r|   r[   r$   r$   r%   r~   v  r   rt   c                 C      t | |ttfS r{   r;   floatrw   r[   r$   r$   r%   r~   w      rs   c                 C   r   r{   r   r[   r$   r$   r%   r~   x  r   r   r   r   OBc                 C   r   r{   r;   rD   	bytearrayr[   r$   r$   r%   r~   |  r   ODc                 C   r   r{   r   r[   r$   r$   r%   r~   }  r   OFc                 C   r   r{   r   r[   r$   r$   r%   r~   ~  r   OLc                 C   r   r{   r   r[   r$   r$   r%   r~     r   OWc                 C   r   r{   r   r[   r$   r$   r%   r~     r   OVc                 C   r   r{   r   r[   r$   r$   r%   r~     r   c                 C      t | |ddS )N   iry   r[   r$   r$   r%   r~     r   c                 C   r   )Ni i  r   r[   r$   r$   r%   r~     r   c                 C   r   )Nl         l    r   r[   r$   r$   r%   r~     s    c                 C   rz   r{   )rR   r|   timer[   r$   r$   r%   r~     r   c                 C   r   )Nr   l    r   r[   r$   r$   r%   r~     r   c                 C   r   )Nr   i  r   r[   r$   r$   r%   r~     r   c                 C   r   )Nr   l    r   r[   r$   r$   r%   r~     r   )r`   r   rp   rn   r   rr   r*   r    ro   rm   r+   rq   validation_mode	validatorc                 C   sh   |t jkrdS |dur.|pt| }|dur0|| |\}}|s2|t jkr(t|t| dS dS dS dS )aa  Validate the given value against the DICOM standard.

    Parameters
    ----------
    vr : str
        The VR of the tag the value is added to.
    value : Any
        The value to be validated.
    validation_mode : int
        Defines if values are validated and how validation errors are
        handled.
    validator : Callable or None
        Function that does the actual validation. If not given,
        the validator is taken from the VR-specific validator table instead.

    Raises
    ------
    ValueError
        If the validation fails and the validation mode is set to
        `RAISE`.
    N)r   IGNORE
VALIDATORSr=   RAISE
ValueErrorr   )r0   r3   r   r   is_validrG   r$   r$   r%   rf     s   

rf   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(e*fd)d*Z+d+S ),VRz.DICOM Data Element's Value Representation (VR)r   r'   ATr   r(   r   r)   rt   rs   r   r   r   r   r   r   r   r   r   r`   r   rp   SQrn   r   rr   r*   UCr    ro   UNr+   rm   UTrq   zUS or SS or OWzUS or SSzUS or OWzOB or OWr"   c                 C   s
   t | S r{   )rC   __str__selfr$   r$   r%   r        
z
VR.__str__N),r:   
__module____qualname____doc__r   r'   r   r   r(   r   r)   rt   rs   r   r   r   r   r   r   r   r   r   r`   r   rp   r   rn   r   rr   r*   r   r    ro   r   r+   rm   r   rq   US_SS_OWUS_SSUS_OWOB_OWrC   r   r$   r$   r$   r%   r     sR    r   c                       s   e Zd ZU dZeed< deeef fddZdeeef ddfdd	Z	d
e
deedf f fddZdef fddZdefddZ  ZS )_DateTimeBasez1Base class for DT, DA and TM element sub-classes.original_stringr"   c                 C   s
   | j  S r{   )__dict__copyr   r$   r$   r%   __getstate__a  r   z_DateTimeBase.__getstate__stateNc                 C   s   | j | d S r{   )r   update)r   r   r$   r$   r%   __setstate__d     z_DateTimeBase.__setstate__protocol.c                    s(   t ttdf t |}||  f S )N.)r
   tupler	   super__reduce_ex__r   )r   r   	reduce_ex	__class__r$   r%   r   g  s   z_DateTimeBase.__reduce_ex__c                    s   t | dr| jS t  S Nr   )hasattrr   r   r   r   r   r$   r%   r   n  s   

z_DateTimeBase.__str__c                 C   s   d|  dS )N"r$   r   r$   r$   r%   __repr__t  s   z_DateTimeBase.__repr__)r:   r   r   r   rC   __annotations__dictr	   r   r   rw   r   r   r   r   __classcell__r$   r$   r   r%   r   [  s   
 r   c                	       sP   e Zd ZdZded  dededed  f fddZdededdfd	d
Z  Z	S )r(   zStore value for an element with VR **DA** as :class:`datetime.date`.

    Note that the :class:`datetime.date` base class is immutable.
    clsargskwargsr"   c              
      sV  |r|d du r
dS |d }t |tru| dkrdS t|dkrBt|dd }t|dd }t|dd }t | |||S t|dkru|d dkru|d	 dkrut|dd }t|d
d	 }t|dd }t | |||S t |tjrt | |j	|j
|jS zt j| g|R i |W S  ty } z	td| d|d}~ww )a#  Create an instance of DA object.

        Raise an exception if the string cannot be parsed or the argument
        is otherwise incompatible.

        The arguments (``*args`` and ``**kwargs``) are either the ones
        inherited from :class:`datetime.date`, or the first argument is
        a string conformant to the DA definition in the DICOM Standard,
        Part 5, :dcm:`Table 6.2-1<part05/sect_6.2.html#table_6.2-1>`,
        or it is a :class:`datetime.date` object, or an object of type
        :class:`~pydicom.valuerep.DA`.
        r   Nr7   rl   rk      r   r5         Unable to convert 'z' to 'DA' object)r8   rC   rU   r>   rw   r   __new__r|   r}   yearmonthday	Exceptionr   )r   r   r   valr   r   r   excr   r$   r%   r   ~  s0   
$z
DA.__new__Nc                 O   sl   |d }t |tr|| _dS t |trt|dr|j| _dS t |tjr4|j |jd|j	d| _dS dS )z"Create a new **DA** element value.r   r   02N)
r8   rC   r   r(   r   r|   r}   r   r   r   r   r   r   r   r$   r$   r%   __init__  s   

 zDA.__init__)
r:   r   r   r   r9   r	   r   r   r   r   r$   r$   r   r%   r(   x  s    -c                	       sr   e Zd ZdZedZedede	j
fddZded  ded	eded  f fd
dZded	eddfddZ  ZS )r)   zStore value for an element with VR **DT** as :class:`datetime.datetime`.

    Note that the :class:`datetime.datetime` base class is immutable.
    z&((\d{4,14})(\.(\d{1,6}))?)([+-]\d{4})?r3   r"   c                 C   s\   t | dd d }t | dd }|| d }| d dkr!| n|}tjtj|d| dS )	a  Return the UTC Offset suffix as a :class:`datetime.timezone`.

        Parameters
        ----------
        value : str
            The value of the UTC offset suffix, such as ``'-1000'`` or
            ``'+0245'``.

        Returns
        -------
        datetime.timezone
           r_   <   r   r   -)seconds)name)rw   r|   timezone	timedelta)r3   hourminuteoffsetr$   r$   r%   _utc_offset  s
   zDT._utc_offsetr   r   r   c              
      s(  |r|d du r
dS |d }t |tr| dkrdS | j|}|r)t|dkr1td| d|d}t|dd t|d	k rEd
nt|dd	 t|dk rTd
nt|d	d f}t|dk rednt|dd t|dk rtdnt|dd t|dk rdnt|dd dd}t|dkr|drt|d	 
d	d|d< |d}|r| |nd|d< |d dkrtd d|d< t j| g|R i |S t |tjrt j| g| dd	 |j|jR  S zt j| g|R i |W S  ty } z	td| d|d}~ww )a+  Create an instance of DT object.

        Raise an exception if the string cannot be parsed or the argument
        is otherwise incompatible.

        The arguments (``*args`` and ``**kwargs``) are either the ones
        inherited from :class:`datetime.datetime`, or the first argument is
        a string conformant to the DT definition in the DICOM Standard,
        Part 5, :dcm:`Table 6.2-1<part05/sect_6.2.html#table_6.2-1>`,
        or it is a :class:`datetime.datetime` object, or an object of type
        :class:`~pydicom.valuerep.DT`.
        r   Nr7      (Unable to convert non-conformant value 'z' to 'DT' objectrj   rk   r   r   rl   r   r      )r   r   secondmicrosecond0r   r   tzinfor   r   z]'datetime.datetime' doesn't allow a value of '60' for the seconds component, changing to '59';   r   )r8   rC   rU   	_regex_dtrM   r>   r   grouprw   rstripljustr   r   r   r   r|   	timetupler   r   r   )r   r   r   r   rM   dt_matchtz_matchr   r   r$   r%   r     s^   



z
DT.__new__Nc                 O   s$  |d }t |tr|| _dS t |trt|dr|j| _dS t |tjr|jd|jd|jd|j	d|j
d|jd| _|jdkrP|  jd|jd7  _|jdur|j|}|dur|jd d	 |jd	  }|dkrqd
nd}t|}|  j| |d	 d|d	 d7  _dS dS dS dS )z"Create a new **DT** element value.r   r   04r   r5   06N   r   +r   )r8   rC   r   r)   r   r|   r   r   r   r   r   r   r   r   	utcoffsetdaysr   abs)r   r   r   r   r   
offset_minsignr$   r$   r%   r     s8   




	zDT.__init__)r:   r   r   r   r,   r-   r   staticmethodrC   r|   r   r   r9   r	   r   r   r   r   r$   r$   r   r%   r)     s    
Dc                	       s^   e Zd ZdZedZded  dedede	d  f fddZ
dededd	f fd
dZ  ZS )r*   zStore value for an element with VR **TM** as :class:`datetime.time`.

    Note that the :class:`datetime.time` base class is immutable.
    zd(?P<h>^([01][0-9]|2[0-3]))((?P<m>([0-5][0-9]))((?P<s>([0-5][0-9]|60))(\.(?P<ms>([0-9]{1,6})?))?)?)?$r   r   r   r"   c           
   
      sd  |r|d du r
dS |d }t |trz| dkrdS | j|}|s+td| dt|d}|ddu r;dnt|d}|ddu rKdnt|d}|d	kr\td
 d}d}|drpt|d	 
dd}t | ||||S t |tjrt | |j|j|j|jS zt j| g|R i |W S  ty }	 z	td| d|	d}	~	ww )a1  Create an instance of TM object from a string.

        Raise an exception if the string cannot be parsed or the argument
        is otherwise incompatible.

        The arguments (``*args`` and ``**kwargs``) are either the ones
        inherited from :class:`datetime.time`, or the first argument is
        a string conformant to the TM definition in the DICOM Standard,
        Part 5, :dcm:`Table 6.2-1<part05/sect_6.2.html#table_6.2-1>`,
        or it is a :class:`datetime.time` object, or an object of type
        :class:`~pydicom.valuerep.TM`.
        r   Nr7   r   z' to 'TM' objecthmsr   zY'datetime.time' doesn't allow a value of '60' for the seconds component, changing to '59'r   msr   r   r   )r8   rC   rU   _RE_TIMErM   r   rw   r   r   r   r   r   r   r|   r   r   r   r   r   r   )
r   r   r   r   rM   r   r   r   r   r   r   r$   r%   r   A  sB   

  
z
TM.__new__Nc                    s   t    |d }t|tr|| _d S t|tr#t|dr#|j| _d S t|tjrK|j	d|j
d|jd| _|jdkrM|  jd|jd7  _d S d S d S )Nr   r   r   r5   r   )r   r   r8   rC   r   r*   r   r|   r   r   r   r   r   r   r   r$   r%   r   y  s   



zTM.__init__)r:   r   r   r   r,   r-   r   r9   r	   r   r   r   r   r$   r$   r   r%   r*   4  s    "8r*   r   c                 C   s   t d| d S )aS  Check whether this string is a valid decimal string.

    Valid decimal strings must be 16 characters or fewer, and contain only
    characters from a limited set.

    Parameters
    ----------
    s: str
        String to test.

    Returns
    -------
    bool
        True if the string is a valid decimal string. Otherwise False.
    r   r   )rZ   r   r$   r$   r%   is_valid_ds  s   r   r   c                 C   s   t | ttB stdt| std|  dt| }t|dkr#|S tt	ttB t
| }| dk r4dnd}|dk p?|d	| k}|r`d
| }| d| d}t|dkr^| d|d  d}|S |dkrod	| tt| }nd	| }| d| dS )a  Truncate a float's representation to give a valid Decimal String (DS).

    DICOM's decimal string (DS) representation is limited to strings with 16
    characters and a limited set of characters. This function represents a
    float that satisfies these constraints while retaining as much
    precision as possible. Some floats are represented using scientific
    notation to make more efficient use of the limited number of characters.

    Note that this will incur a loss of precision if the number cannot be
    represented with 16 characters. Furthermore, non-finite floats (infs and
    nans) cannot be represented as decimal strings and will cause an error to
    be raised.

    Parameters
    ----------
    val: float | Decimal
        The floating point value whose representation is required.

    Returns
    -------
    str
        String representation of the float satisfying the constraints of the
        decimal string representation.

    Raises
    ------
    ValueError
        If val does not represent a finite value

    z.'val' must be of type float or decimal.Decimalz?Cannot encode non-finite floats as DICOM decimal strings. Got ''r   g        r   r   r   r   r5   eg      ?f)r8   r   r   	TypeErrorr   r   rC   r>   r   r
   r   rw   r   )r   valstrlogval
sign_charsuse_scientificremaining_chars	trunc_strr$   r$   r%   format_number_as_ds  s,   
	r  c                       s   e Zd ZU dZeed< 		dded  ddeB eB e	B e
B dededB dd	f
 fd
dZ		ddeeB e	B e
B dededB ddfddZdedef fddZdef fddZdedefddZdefddZdef fddZ  ZS )DSfloata  Store value for an element with VR **DS** as :class:`float`.

    If constructed from an empty string, return the empty string,
    not an instance of this class.

    Parameters
    ----------
    val: str | int | float | Decimal
        Value to store as a DS.
    auto_format: bool
        If True, automatically format the string representation of this
        number to ensure it satisfies the constraints in the DICOM standard.
        Note that this will lead to loss of precision for some numbers.

    auto_formatFNr   r   r   r"   zstr | DSfloat | Nonec                    s4   |d u r|S t |tr| dkr|S t | |S Nr7   r8   rC   rU   r   r   r   r   r  r   r   r$   r%   r     s
   zDSfloat.__new__c                 C   s   |du rt jj}|  t|d}d}t|tr| | _nt|tt	B r0|j
r*d}d}|r0|j| _|| _
| j
rP|sPt| drKt| jsJtt| j| _nt| | _|t jkrr| j
sttt| dkrdtdtt| svtd|  ddS dS dS )	zaStore the original string if one given, for exact write-out of same
        value later.
        Nr   FTr   aA  Values for elements with a VR of 'DS' must be <= 16 characters long, but the float provided requires > 16 characters to be accurately represented. Use a smaller string, set 'config.settings.reading_validation_mode' to 'WARN' to override the length check, or explicitly construct a DS object with 'auto_format' set to TrueValue "+" is not valid for elements with a VR of DS)r   rg   reading_validation_moder   r8   rC   rU   r   r  	DSdecimalr  r   r  r   r   r>   OverflowErrorr   )r   r   r  r   has_attributepre_checkedr$   r$   r%   r   
  sB   	





	
zDSfloat.__init__otherc                    "   t |trt| |kS t |S z.Override to allow string equality comparisons.r8   rC   r   __eq__r   r  r   r$   r%   r  B     
zDSfloat.__eq__c                    
   t   S r{   r   __hash__r   r   r$   r%   r  I  r   zDSfloat.__hash__c                 C   
   | |k S r{   r$   r  r$   r$   r%   __ne__L  r   zDSfloat.__ne__c                 C   s&   t | dr| js| jS t| dd S Nr   r   rJ   )r   r  r   reprr   r$   r$   r%   r   O  s   zDSfloat.__str__c                    s*   t | drd| j dS dt   dS Nr   r   )r   r   r   r   r   r   r$   r%   r   V  s   
zDSfloat.__repr__FNr:   r   r   r   boolr   r9   rC   rw   r   r   r   r   r	   r  r  r  r   r   r   r$   r$   r   r%   r    s@   
 
8r  c                       s   e Zd ZU dZeed< 		dded  ddeB eB e	B e
B dededB dd	f
 fd
dZ		ddeeB e	B e
B dededB ddfddZdedef fddZdef fddZdedefddZdef fddZdefddZ  ZS )r  a  Store value for an element with VR **DS** as :class:`decimal.Decimal`.

    Parameters
    ----------
    val: str | int | float | Decimal
        Value to store as a DS.
    auto_format: bool
        If True, automatically format the string representation of this
        number to ensure it satisfies the constraints in the DICOM standard.
        Note that this will lead to loss of precision for some numbers.

    Notes
    -----
    If constructed from an empty string, returns the empty string, not an
    instance of this class.

    r  FNr   r   r   r"   zstr | DSdecimal | Nonec                    sL   |du r|S t |tr| dkr|S t |trtjstdt | |S )a  Create an instance of DS object, or return a blank string if one is
        passed in, e.g. from a type 2 DICOM blank value.

        Parameters
        ----------
        val : str or numeric
            A string or a number type which can be converted to a decimal.
        Nr7   z'DS' cannot be instantiated with a float value unless 'config.allow_DS_float' is set to True. You should convert the value to a string with the desired number of digits, or use 'Decimal.quantize()' and pass a 'Decimal' instance.)	r8   rC   rU   r   r   allow_DS_floatr   r   r   r  r   r$   r%   r   r  s   zDSdecimal.__new__c                 C   s"  |du rt jj}|  d}t|tr| | _nt|ttB r.|j	r%d}d}t
|dr.|j| _|| _	| j	rN|sNt
| drIt| jsHtt| j| _nt| | _|t jkrtt| ddkrod}|t jkrit|t| dS tt| dsd|  d	}|t jkrt|t| dS dS dS )
zStore the original string if one given, for exact write-out of same
        value later. E.g. if set ``'1.23e2'``, :class:`~decimal.Decimal` would
        write ``'123'``, but :class:`DS` will use the original.
        NFTr   r   r   a?  Values for elements with a VR of 'DS' values must be <= 16 characters long. Use a smaller string, set 'config.settings.reading_validation_mode' to 'WARN' to override the length check, use 'Decimal.quantize()' and initialize with a 'Decimal' instance, or explicitly construct a DS instance with 'auto_format' set to Truer  r  )r   rg   r  r8   rC   rU   r   r  r  r  r   r   r  r   r   r>   r   r   r  r   r   )r   r   r  r   r  rG   r$   r$   r%   r     sF   








	
zDSdecimal.__init__r  c                    r  r  r  r  r   r$   r%   r    r  zDSdecimal.__eq__c                    r  r{   r  r   r   r$   r%   r    r   zDSdecimal.__hash__c                 C   r  r{   r$   r  r$   r$   r%   r    r   zDSdecimal.__ne__c                    s,   t | d}|rt| jdkr| jS t  S )Nr   r   )r   r>   r   r   r   )r   has_strr   r$   r%   r     s   

zDSdecimal.__str__c                 C   s$   t | drd| j dS d|  dS r!  )r   r   r   r$   r$   r%   r     s   
zDSdecimal.__repr__r"  r#  r$   r$   r   r%   r  ]  s@   
 !
=r  DSclassFr  c                 C   s`   | du r| S |du rt jj}t| tr!|  dkr| S td| | t jr*t| ||S t	| ||S )a  Factory function for creating DS class instances.

    Checks for blank string; if so, returns that, else calls :class:`DSfloat`
    or :class:`DSdecimal` to create the class instance. This avoids overriding
    ``DSfloat.__new__()`` (which carries a time penalty for large arrays of
    DS).

    Similarly the string clean and check can be avoided and :class:`DSfloat`
    called directly if a string has already been processed.
    Nr7   r   )
r   rg   r  r8   rC   rU   rf   use_DS_decimalr  r  )r   r  r   r$   r$   r%   r     s   
c                
       sp   e Zd ZdZ	dded  deeB eB dedB deeB f fddZ		ddeeB eB dedB ddfd	d
Z
  ZS )ISfloata`  Store value for an element with VR **IS** as :class:`float`.

    Stores original integer string for exact rewriting of the string
    originally read or stored.

    Note: By the DICOM standard, IS can only be an :class:`int`,
    however, it is not uncommon to see float IS values.  This class
    is used if the config settings allow non-strict reading.

    Generally, use :class:`~pydicom.valuerep.IS` to create IS values,
    this is returned instead if the value cannot be represented as an
    :class:`int`.  See :class:`~pydicom.valuerep.IS` for details of the
    parameters and return values.
    Nr   r   r   r"   c                    s(   t |tr| dkrdS t | |S r	  r
  )r   r   r   r   r$   r%   r      s   zISfloat.__new__c                 C   s~   t |tr| | _nt |ttB rt|dr|j| _|r;d|  d}|tjkr.t	| d S |tj
kr=|d7 }t|d S d S )Nr   r  z+" is not valid for elements with a VR of ISz8
Set reading_validation_mode to WARN or IGNORE to bypass)r8   rC   rU   r   r   r)  r   r   WARNr   r   r   )r   r   r   rG   r$   r$   r%   r   *  s   


zISfloat.__init__r{   )r:   r   r   r   r9   rC   r   r   rw   r   r   r   r$   r$   r   r%   r)    s(    

r)  c                	       s   e Zd ZdZ	dded  ddeB eB eB eB dedB ddf fdd	Z		ddeeB eB eB dedB ddfd
dZ
dedef fddZdef fddZdedefddZdefddZdef fddZ  ZS )r   zStore value for an element with VR **IS** as :class:`int`.

    Stores original integer string for exact rewriting of the string
    originally read or stored.
    Nr   r   r   r"   zstr | IS | ISfloat | Nonec                    s   |du r|S |du rt jj}t|tr!| dkr|S td|| z	t | |}W n t	y<   t | t
|}Y nw t|t
tB tB rQ|t
|krQt||}d|  kr[dk sen |t jkretd|S )z%Create instance if new integer stringNr7   r   r   l        zElements with a VR of IS must have a value between -2**31 and (2**31 - 1). Set 'config.settings.reading_validation_mode' to 'WARN' to override the value check)r   rg   r  r8   rC   rU   rf   r   r   r   r   r   r)  r   r  )r   r   r   newvalr   r$   r%   r   B  s(   

 z
IS.__new__c                 C   s@   t |tr| | _d S t |trt|dr|j| _d S d S d S r   )r8   rC   rU   r   r   r   )r   r   r   r$   r$   r%   r   j  s
   
zIS.__init__r  c                    r  r  r  r  r   r$   r%   r  s  r  z	IS.__eq__c                    r  r{   r  r   r   r$   r%   r  z  r   zIS.__hash__c                 C   r  r{   r$   r  r$   r$   r%   r  }  r   z	IS.__ne__c                 C   s    t | dr| jS t| dd S r  )r   r   r   r   r$   r$   r%   r     s   
z
IS.__str__c                    s   dt    dS )Nr   )r   r   r   r   r$   r%   r     s   zIS.__repr__r{   )r:   r   r   r   r9   rC   rw   r   r   r   r   r	   r  r  r  r   r   r   r$   r$   r   r%   r   ;  s2    	)
		encodings.c                 C   s$   | du rdS t | tr| fS t| S )z+Checks the encoding to ensure proper formatN)r8   rC   r   r,  r$   r$   r%   _verify_encodings  s
   
r.  rc   c                    sP   ddl m   fdd| D }t|r$|d s$|  t|r$|d rt|S )a?  Return a list of decoded person name components.

    Parameters
    ----------
    components : list of bytes
        The list of the up to three encoded person name components
    encodings : list of str
        The Python encodings uses to decode `components`.

    Returns
    -------
    text type
        The unicode string representing the person name.
        If the decoding of some component parts is not possible using the
        given encodings, they are decoded with the first encoding using
        replacement characters for bytes that cannot be decoded.
    r   )decode_bytesc                    s   g | ]} |t qS r$   )	PN_DELIMSr/   cr/  r,  r$   r%   
<listcomp>  s    z&_decode_personname.<locals>.<listcomp>rJ   )pydicom.charsetr/  r>   popr   )rc   r,  compsr$   r3  r%   _decode_personname  s   r8  c                    sz   ddl m  g }| D ]} fdd|dD }d|}|| q
t|r8|d s8|  t|r8|d r,d|S )	aO  Encode a list of text string person name components.

    Parameters
    ----------
    components : list of str
        The list of the up to three unicode person name components
    encodings : list of str
        The Python encodings uses to encode `components`.

    Returns
    -------
    byte string
        The byte string that can be written as a PN DICOM tag value.
        If the encoding of some component parts is not possible using the
        given encodings, they are encoded with the first encoding using
        replacement bytes for characters that cannot be encoded.
    r   )encode_stringc                    s   g | ]} |qS r$   r$   )r/   r   r9  r,  r$   r%   r4    s    z&_encode_personname.<locals>.<listcomp>r#      ^rJ   r]   )r5  r9  rb   rT   appendr>   r6  )rc   r,  encoded_compsrd   groupsencoded_compr$   r:  r%   _encode_personname  s   

r@  c                $       s  e Zd ZdZded  dededed  f fddZ			ddd	d
dee	 dB de
dB dedB ddf
ddZdee	e	f fddZedee	df fddZdede	fddZede	fddZede	fddZede	fddZede	fddZede	fd d!Zede	fd"d#Zede	fd$d%Zede	fd&d'Zd(edefd)d*Zd(edefd+d,Zde	fd-d.Zdee	 fd/d0Zdefd1d2Z d3ede!fd4d5Z"de	fd6d7Z#defd8d9Z$dedee	 dB dd fd:d;Z%dedee	 dB de
fd<d=Z&de	fd>d?Z'd@e	de	fdAdBZ(de!fdCdDZ)e*	dedEee	e
B  dFee	e
B  dGee	e
B  de+e	 dB de
f
dHdIZ,e-	J	J	J	J	J	J	J	J	J	J	J	J	J	J	J	dfdKe	e
B dLe	e
B dMe	e
B dNe	e
B dOe	e
B dPe	e
B dQe	e
B dRe	e
B dSe	e
B dTe	e
B dUe	e
B dVe	e
B dWe	e
B dXe	e
B dYe	e
B de+e	 dB dd f"dZd[Z.e-	J	J	J	J	J	J	dgd\e	e
B d]e	e
B d^e	e
B d_e	e
B d`e	e
B dae	e
B de+e	 dB dd fdbdcZ/  Z0S )hra   z:Representation of the value for an element with VR **PN**.r   r   r   r"   c                    s$   t |r|d d u rd S t | S )Nr   )r>   r   r   )r   r   r   r   r$   r%   r     s   zPersonName.__new__Nr   zbytes | str | PersonNamer,  r   r   c                 C   s   |  d| _ |  |du rtjj}|| _t|tr)|j}|j| _t	t
|d| _ n@t|tr;|| _td|| d| _ n.tt|| _td|rG|n|| |d}t|rd|d sd|  t|rd|d rXt	|| _ t|| _dS )a  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: bytes, optional
            When creating a ``PersonName`` using a decoded string, this is the
            original encoded value.

        Notes
        -----
        A :class:`PersonName` may also be constructed by specifying individual
        components using the :meth:`from_named_components` and
        :meth:`from_named_components_veterinary` class methods.
        Nr^   r`   rJ   )_componentsr   rg   r  r   r8   ra   r,  r   r   rC   rb   rD   rf   r
   r>   r6  r.  )r   r   r,  r   r   rc   r$   r$   r%   r     s0   



zPersonName.__init__c                    s   g d} fdd|D S )zCreates a dictionary of person name group and component names.

        Used exclusively for `formatted` for backwards compatibility.
        )family_name
given_namemiddle_namename_prefixname_suffixideographicphoneticc                    s   i | ]	}|t  |d qS )r7   )getattrr1  r   r$   r%   r1   *  s    z+PersonName._create_dict.<locals>.<dictcomp>r$   )r   partsr$   r   r%   _create_dict  s   	zPersonName._create_dict.c                 C   s4   | j du r| jd}| jptg}t||| _ | j S )a-  Returns up to three decoded person name components as a
        :class:`tuple` of :class:`str`.

        Returns
        -------
        Tuple[str, ...]
            The (alphabetic, ideographic, phonetic) components of the
            decoded person name. Any of the components may be absent.
        Nr]   )rA  r   rb   r,  default_encodingr8  )r   r>  r,  r$   r$   r%   rc   ,  s
   
zPersonName.componentsic                 C   s,   z| j d d| W S  ty   Y dS w )z"Return the `i`th part of the name.r   r#   r7   )rc   rb   
IndexError)r   rM  r$   r$   r%   
_name_part>  s
   zPersonName._name_partc                 C   
   |  dS )zvReturn the first (family name) group of the alphabetic person name
        representation as a unicode string
        r   rO  r   r$   r$   r%   rB  E     
zPersonName.family_namec                 C   rP  )zvReturn the second (given name) group of the alphabetic person name
        representation as a unicode string
        r   rQ  r   r$   r$   r%   rC  L  rR  zPersonName.given_namec                 C   rP  )zvReturn the third (middle name) group of the alphabetic person name
        representation as a unicode string
        rj   rQ  r   r$   r$   r%   rD  S  rR  zPersonName.middle_namec                 C   rP  )zwReturn the fourth (name prefix) group of the alphabetic person name
        representation as a unicode string
        r_   rQ  r   r$   r$   r%   rE  Z  rR  zPersonName.name_prefixc                 C   rP  )zvReturn the fifth (name suffix) group of the alphabetic person name
        representation as a unicode string
        rk   rQ  r   r$   r$   r%   rF  a  rR  zPersonName.name_suffixc                 C   "   z| j d W S  ty   Y dS w )zXReturn the first (alphabetic) person name component as a
        unicode string
        r   r7   rc   rN  r   r$   r$   r%   
alphabetich  
   zPersonName.alphabeticc                 C   rS  )zZReturn the second (ideographic) person name component as a
        unicode string
        r   r7   rT  r   r$   r$   r%   rG  r  rV  zPersonName.ideographicc                 C   rS  )zVReturn the third (phonetic) person name component as a
        unicode string
        rj   r7   rT  r   r$   r$   r%   rH  |  rV  zPersonName.phoneticr  c                 C   s   t | |kS )z3Return ``True`` if `other` equals the current name.)rC   r  r$   r$   r%   r       zPersonName.__eq__c                 C   r  )z:Return ``True`` if `other` doesn't equal the current name.r$   r  r$   r$   r%   r       
zPersonName.__ne__c                 C      d | j S )z+Return a string representation of the name.r^   )rT   rc   r   r   r$   r$   r%   r        zPersonName.__str__c                 c   s    |   E dH  dS )zIterate through the name.Nr   r   r$   r$   r%   __iter__  s   zPersonName.__iter__c                 C   s   t |  S )z%Return the length of the person name.)r>   r   r   r$   r$   r%   __len__  rW  zPersonName.__len__xc                 C   s   ||   v S )z&Return ``True`` if `x` is in the name.r[  )r   r^  r$   r$   r%   __contains__  rW  zPersonName.__contains__c                 C   rY  )z$Return a representation of the name.r^   )rT   rc   r   r   r$   r$   r%   r     rZ  zPersonName.__repr__c                 C   s
   t | jS )zReturn a hash of the name.)hashrc   r   r$   r$   r%   r    rX  zPersonName.__hash__c                 C   sZ   |du s	|| j kr| S t|}| jdu r't| j| j ptg| _td| j| j t| j|S )a"  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
        -------
        valuerep.PersonName
            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.
        Nr`   )	r,  r.  r   r@  rc   rL  rf   r   ra   r   r,  r$   r$   r%   decode  s   
zPersonName.decodec                 C   s\   t |p| j}|| jkr| jdurt| jttt |S | jdu r+t| j|p(tg| _| jS )az  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
        -------
        bytes
            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.
        N)	r.  r,  r@  rc   r
   r   rC   r   rL  ra  r$   r$   r%   r2     s   
zPersonName.encodec                 C   s   | j  d| j S )z#Return the name as "Family, Given".z, )rB  rC  r   r$   r$   r%   family_comma_given  s   zPersonName.family_comma_given
format_strc                 C   s   ||    S )z?Return the name as a :class:`str` formatted using `format_str`.)rK  )r   rd  r$   r$   r%   	formatted  rW  zPersonName.formattedc                 C   s6   | j st| jot| jdkpt| jd S t| j S )z)Return ``True`` if the name is not empty.r   r   )r   r$  rc   r>   r   r$   r$   r%   __bool__  s
   

zPersonName.__bool__alphabetic_groupideographic_groupphonetic_groupc                    s   ddl mm dtdtffdddtdtffdd d	d
}g ddttB dtf fdddtttB  dtffdd}|| ||||g}||}||}|S )a  Creates a byte string for a person name from lists of parts.

        Each of the three component groups (alphabetic, ideographic, phonetic)
        are supplied as a list of components.

        Parameters
        ----------
        alphabetic_group: Sequence[str | bytes]
            List of components for the alphabetic group.
        ideographic_group: Sequence[str | bytes]
            List of components for the ideographic group.
        phonetic_group: Sequence[str | bytes]
            List of components for the phonetic group.
        encodings: list[str] | None
            A list of encodings used for the other input parameters.

        Returns
        -------
        bytes:
            Bytes string representation of the person name.

        Raises
        ------
        ValueError:
            If any of the input strings contain disallowed characters:
            '\' (single backslash), '^', '='.
        r   )r9  r/  r   r"   c                    s    | pt gS r{   )rL  r   r:  r$   r%   enc  r   z0PersonName._encode_component_groups.<locals>.encc                    s    | pt gt S r{   )rL  setr   r3  r$   r%   dec  s   z0PersonName._encode_component_groups.<locals>.decr#   r^   )\r^   r#   r   c                    sJ   t | tr| } | }n| }| }D ]}||v r"td| dq|S )NzStrings may not contain the z
 character)r8   rD   r   )r   val_encval_decr2  )rl  disallowed_charsrj  r$   r%   standardize_encoding'  s   

zAPersonName._encode_component_groups.<locals>.standardize_encodingrc   c                    s&   fdd| D }  |}| S )Nc                    s   g | ]} |qS r$   r$   r1  )rq  r$   r%   r4  ;  s    zUPersonName._encode_component_groups.<locals>.make_component_group.<locals>.<listcomp>)rT   r   )rc   encoded_componentsjoined_components)encoded_component_seprq  r$   r%   make_component_group:  s   

zAPersonName._encode_component_groups.<locals>.make_component_group)r5  r9  r/  rC   rD   r   rT   r   )rg  rh  ri  r,  encoded_group_sepru  component_groupsjoined_groupsr$   )rl  r/  rp  rj  r9  rt  r,  rq  r%   _encode_component_groups  s   " 

z#PersonName._encode_component_groupsr7   rB  rC  rD  rE  rF  family_name_ideographicgiven_name_ideographicmiddle_name_ideographicname_prefix_ideographicname_suffix_ideographicfamily_name_phoneticgiven_name_phoneticmiddle_name_phoneticname_prefix_phoneticname_suffix_phoneticc                 C   sF   |||||g}||||	|
g}|||||g}|  ||||}| ||dS )u  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:
        - :dcm:`Value Representations <part05/sect_6.2.html>`
        - :dcm:`PN Examples <part05/sect_6.2.html#sect_6.2.1.1>`
        - :dcm:`PN Precise semantics <part05/sect_6.2.html#sect_6.2.1.2>`

        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
        ----------
        family_name: str | bytes
            Family name in alphabetic form.
        given_name: str | bytes
            Given name in alphabetic form.
        middle_name: str | bytes
            Middle name in alphabetic form.
        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:
            PersonName constructed from the supplied components.

        Notes
        -----
        Strings may not contain the following characters: '^', '=',
        or the backslash character.
        r-  ry  )r   rB  rC  rD  rE  rF  rz  r{  r|  r}  r~  r  r  r  r  r  r,  rg  rh  ri  encoded_valuer$   r$   r%   from_named_componentsH  s2   l

z PersonName.from_named_componentsresponsible_party_namepatient_name"responsible_party_name_ideographicpatient_name_ideographicresponsible_party_name_phoneticpatient_name_phoneticc                 C   s4   ||g}||g}	||g}
|  ||	|
|}| ||dS )a	  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:
        - :dcm:`Value Representations <part05/sect_6.2.html>`
        - :dcm:`PN Examples <part05/sect_6.2.html#sect_6.2.1.1>`
        - :dcm:`PN Precise semantics <part05/sect_6.2.html#sect_6.2.1.1>`

        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:
            PersonName constructed from the supplied components

        Notes
        -----
        Strings may not contain the following characters: '^', '=',
        or the backslash character.
        r-  r  )r   r  r  r  r  r  r  r,  rg  rh  ri  r  r$   r$   r%    from_named_components_veterinary  s   Ez+PersonName.from_named_components_veterinary)NNNr{   )r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   r7   N)r7   r7   r7   r7   r7   r7   N)1r:   r   r   r   r9   r	   r   r   r   rC   rD   rw   r   r   rK  propertyr   rc   rO  rB  rC  rD  rE  rF  rU  rG  rH  r  r  r   r   r\  r]  r$  r_  r   r  rb  r2   rc  re  rf  r   listry  classmethodr  r  r   r$   r$   r   r%   ra     s*   

<			! 	



O	

 
	ra   r{   r"  )zr   r|   decimalr   enumr   r   r,   mathr   r   r   typingr   r	   r
   collections.abcr   r   r   pydicomr   pydicom.miscr   rL  TEXT_VR_DELIMSr0  r<   rC   r&   
VR_REGEXESitemsrK   rL   r9   r   r$  r;   rA   rH   rO   rP   rR   rZ   r\   re   rD   ri   rx   rw   ry   r   rf   r   r   r'   r   r   r(   r   r)   rt   rs   r   r   r   r   r   r   r   r   r   r`   r   rp   r   rn   r   rr   r*   r   r    ro   r   r+   rm   r   rq   STANDARD_VRr   r   r   r   AMBIGUOUS_VRDEFAULT_CHARSET_VRCUSTOMIZABLE_CHARSET_VRBYTES_VRFLOAT_VRINT_VRLIST_VRSTR_VRALLOW_BACKSLASHLONG_VALUE_VREXPLICIT_VR_LENGTH_16EXPLICIT_VR_LENGTH_32BUFFERABLE_VRSr   r}   r   r   r   r  r  r  r   r(  r'  r)  r.  r8  r@  ra   r$   r$   r$   r%   <module>   s0  	

"%

%	
'
(1	
 !"%  $ >~SOt 
 +*P

 