o
    iI                     @   s  U d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ i Zeeeeef f ed< eD ]Zeeddd	Zed
dd eD d	Zeefee< q1dededB fddZ		
dFdededededededdfddZdeeeeeeeef f ddfddZ	dGdedededededdfddZdedeeeeeeef f ddfd d!Zdedeeeeeef fd"d#Zd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defd*d+Z!dedefd,d-Z"dedefd.d/Z#dedefd0d1Z$dedefd2d3Z%d4d5 eD Z&eeef ed6< dededB fd7d8Z'dedefd9d:Z(d;d e) D Z*dedefd<d=Z+dededeeeeef fd>d?Z,dededefd@dAZ-dededefdBdCZ.dededefdDdEZ/dS )Hz#Access dicom dictionary information    )DicomDictionaryRepeatersDictionary)warn_and_log)private_dictionaries)TagBaseTagTagTypemasksx0    c                 C   s   g | ]}d |dk qS )F0r
    ).0cr   r   F/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/datadict.py
<listcomp>       r   tagreturnNc                 C   s2   t  D ]\}\}}| |A |@ dkr|  S qdS )a  Return the repeaters tag mask for `tag`.

    Parameters
    ----------
    tag : int
        The tag to check.

    Returns
    -------
    str or None
        If the tag is in the repeaters dictionary then returns the
        corresponding masked tag, otherwise returns ``None``.
    r   N)r	   items)r   mask_xmask1mask2r   r   r   
mask_match   s
   r   1VRkeyworddescriptionVM
is_retiredc                 C   s   t | |||||fi dS )a#  Update the DICOM dictionary with a new non-private entry.

    Parameters
    ----------
    tag : int
        The tag number for the new dictionary entry.
    VR : str
        DICOM value representation.
    description : str
        The descriptive name used in printing the entry. Often the same as the
        keyword, but with spaces between words.
    VM : str, optional
        DICOM value multiplicity. If not specified, then ``'1'`` is used.
    is_retired : str, optional
        Usually leave as blank string (default). Set to ``'Retired'`` if is a
        retired data element.

    Raises
    ------
    ValueError
        If the tag is a private tag.

    Notes
    -----
    Does not permanently update the dictionary, but only during run-time.
    Will replace an existing entry if the tag already exists in the dictionary.

    See Also
    --------
    pydicom.examples.add_dict_entry
        Example file which shows how to use this function
    add_dict_entries
        Update multiple values at once.

    Examples
    --------

    >>> from pydicom import Dataset
    >>> add_dict_entry(0x10021001, "UL", "TestOne", "Test One")
    >>> add_dict_entry(0x10021002, "DS", "TestTwo", "Test Two", VM='3')
    >>> ds = Dataset()
    >>> ds.TestOne = 'test'
    >>> ds.TestTwo = ['1', '2', '3']

    N)add_dict_entries)r   r   r   r   r    r!   r   r   r   add_dict_entry-   s   5r#   new_entries_dictc                 C   s@   t dd | D rtdt|  tdd |  D  dS )a?  Update the DICOM dictionary with new non-private entries.

    Parameters
    ----------
    new_entries_dict : dict
        :class:`dict` of form:
        ``{tag: (VR, VM, description, is_retired, keyword), ...}``
        where parameters are as described in :func:`add_dict_entry`.

    Raises
    ------
    ValueError
        If one of the entries is a private tag.

    See Also
    --------
    add_dict_entry
        Add a single entry to the dictionary.

    Examples
    --------

    >>> from pydicom import Dataset
    >>> new_dict_items = {
    ...        0x10021001: ('UL', '1', "Test One", '', 'TestOne'),
    ...        0x10021002: ('DS', '3', "Test Two", '', 'TestTwo'),
    ... }
    >>> add_dict_entries(new_dict_items)
    >>> ds = Dataset()
    >>> ds.TestOne = 'test'
    >>> ds.TestTwo = ['1', '2', '3']

    c                 S      g | ]}t |jqS r   r   
is_privater   r   r   r   r   r          z$add_dict_entries.<locals>.<listcomp>z^Private tags cannot be added using "add_dict_entries" - use "add_private_dict_entries" insteadc                 S   s   i | ]	\}}|d  |qS    r   )r   r   valr   r   r   
<dictcomp>   s    z$add_dict_entries.<locals>.<dictcomp>N)any
ValueErrorr   updatekeyword_dictr   )r$   r   r   r   r"   e   s   %
r"   private_creatorc                 C   s   |||df}t | ||i dS )a(  Update the private DICOM dictionary with a new entry.

    Parameters
    ----------
    private_creator : str
        The private creator for the new entry.
    tag : int
        The tag number for the new dictionary entry. Note that the
        2 high bytes of the element part of the tag are ignored.
    VR : str
        DICOM value representation.
    description : str
        The descriptive name used in printing the entry.
    VM : str, optional
        DICOM value multiplicity. If not specified, then ``'1'`` is used.

    Raises
    ------
    ValueError
        If the tag is a non-private tag.

    Notes
    -----
    Behaves like :func:`add_dict_entry`, only for a private tag entry.

    See Also
    --------
    add_private_dict_entries
        Add or update multiple entries at once.
    r   N)add_private_dict_entries)r2   r   r   r   r    new_dict_valr   r   r   add_private_dict_entry   s   !r5   c                 C   sB   t dd |D stddd | D }t| i | dS )a  Update pydicom's private DICOM tag dictionary with new entries.

    Parameters
    ----------
    private_creator: str
        The private creator for all entries in `new_entries_dict`.
    new_entries_dict : dict
        :class:`dict` of form ``{tag: (VR, VM, description, is_retired), ...}``
        where parameters are as described in :func:`add_private_dict_entry`.

    Raises
    ------
    ValueError
        If one of the entries is a non-private tag.

    See Also
    --------
    add_private_dict_entry
        Function to add a single entry to the private tag dictionary.

    Examples
    --------
    >>> new_dict_items = {
    ...        0x00410001: ('UL', '1', "Test One"),
    ...        0x00410002: ('DS', '3', "Test Two", '3'),
    ... }
    >>> add_private_dict_entries("ACME LTD 1.2", new_dict_items)
    >>> add_private_dict_entry("ACME LTD 1.3", 0x00410001, "US", "Test Three")
    c                 S   r%   r   r&   r(   r   r   r   r      r)   z,add_private_dict_entries.<locals>.<listcomp>zfNon-private tags cannot be added using 'add_private_dict_entries()' - use 'add_dict_entries()' insteadc                 S   s,   i | ]\}}|d ? dd|d@ d|qS )r   04Xxx   02Xr   )r   r   valuer   r   r   r-      s    z,add_private_dict_entries.<locals>.<dictcomp>N)allr/   r   r   
setdefaultr0   )r2   r$   new_entriesr   r   r   r3      s   !r3   c                 C   sZ   t | ts	t| } zt|  W S  ty,   | js$t| }|r$t|  Y S td|  dw )a-  Return an entry from the DICOM dictionary as a tuple.

    If the `tag` is not in the main DICOM dictionary, then the repeating
    group dictionary will also be checked.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose entry is to be retrieved, in any of the
        forms accepted by :func:`~pydicom.tag.Tag`. Only entries in the
        official DICOM dictionary will be checked, not entries in the
        private dictionary.

    Returns
    -------
    tuple of str
        The (VR, VM, name, is_retired, keyword) from the DICOM dictionary.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.

    See Also
    --------
    get_private_entry
        Return an entry from the private dictionary.
    Tag  not found in DICOM dictionary)
isinstancer   r   r   KeyErrorr'   r   r   r   r   r   r   r   	get_entry   s   
!
rC   c                 C   s   dt | d  v S )a9  Return ``True`` if the element corresponding to `tag` is retired.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose retirement status is being checked, in
        any of the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    bool
        ``True`` if the element's retirement status is 'Retired', ``False``
        otherwise.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.
    retired   )rC   lowerr   r   r   r   dictionary_is_retired  s   rH   c                 C      t | d S )a  Return the VR of the element corresponding to `tag`.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose value representation (VR) is being
        retrieved, in any of the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    str
        The VR of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.
    r   rC   rG   r   r   r   dictionary_VR0     rK   c                 C   s^   zt |  d W S  ty.   | d? d dks$t| }|r$t| d  Y S tdt|  dw )z$Return the VR corresponding to `tag`r   r         r>   r?   )r   rA   r   r   r   rB   r   r   r   _dictionary_vr_fastH  s   rO   c                 C   rI   )a  Return the VM of the element corresponding to `tag`.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose value multiplicity (VM) is being
        retrieved, in any of the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    str
        The VM of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.
    rN   rJ   rG   r   r   r   dictionary_VMV  rL   rP   c                 C   rI   )a  Return the description of the element corresponding to `tag`.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose description is being retrieved, in any
        of the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    str
        The description of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.
    rM   rJ   rG   r   r   r   dictionary_descriptionn  rL   rQ   c                 C   rI   )a  Return the keyword of the element corresponding to `tag`.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose keyword is being retrieved, in any of
        the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    str
        The keyword of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.
    r+   rJ   rG   r   r   r   dictionary_keyword  rL   rR   c                 C   s$   zt | tv W S  ty   Y dS w )a  Return ``True`` if `tag` is in the official DICOM data dictionary.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag to check, in any of the forms accepted by
        :func:`~pydicom.tag.Tag`.

    Returns
    -------
    bool
        ``True`` if the tag corresponds to an element present in the official
        DICOM data dictionary, ``False`` otherwise.
    F)r   r   	ExceptionrG   r   r   r   dictionary_has_tag  s
   rT   c                 C   s    zt | W S  ty   Y dS w )a  Return the keyword of the element corresponding to `tag`.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose keyword is being retrieved, in any of
        the forms accepted by :func:`~pydicom.tag.Tag`.

    Returns
    -------
    str
        If the element is in the DICOM data dictionary then returns the
        corresponding element's keyword, otherwise returns ``''``. For
        group length elements will always return ``'GroupLength'``.
    r   )rR   rA   rG   r   r   r   keyword_for_tag  s
   
rU   c                 C   s   i | ]}t ||qS r   )rR   r(   r   r   r   r-     r)   r-   r1   c                 C   s
   t | S )a  Return the tag of the element corresponding to `keyword`.

    Only performs the lookup for official DICOM elements.

    Parameters
    ----------
    keyword : str
        The keyword for the element whose tag is being retrieved.

    Returns
    -------
    int or None
        If the element is in the DICOM data dictionary then returns the
        corresponding element's tag, otherwise returns ``None``.
    )r1   getr   r   r   r   tag_for_keyword  s   
rX   c                 C   s   t | tv S )a@  Return ``True`` if `tag` is in the DICOM repeaters data dictionary.

    Parameters
    ----------
    tag : int
        The tag to check.

    Returns
    -------
    bool
        ``True`` if the tag is a non-private element tag present in the
        official DICOM repeaters data dictionary, ``False`` otherwise.
    )r   r   rG   r   r   r   repeater_has_tag  s   rY   c                 C   s   g | ]}|d  qS r*   r   )r   r,   r   r   r   r     s    c                 C   s   | t v S )aO  Return ``True`` if `keyword` is in the DICOM repeaters data dictionary.

    Parameters
    ----------
    keyword : str
        The keyword to check.

    Returns
    -------
    bool
        ``True`` if the keyword corresponding to an element present in the
        official DICOM repeaters data dictionary, ``False`` otherwise.
    )REPEATER_KEYWORDSrW   r   r   r   repeater_has_keyword  s   r[   c              
      s  t | ts	t| } zt|  W n2 ty$ } z	td| d|d}~w tyA } z| j d| d}t| t||d}~ww | jd}| j	d}| | | d|dd  |dd	  d
|dd  g} fdd|D }|std|  d| d |d  }|S )a  Return an entry from the private dictionary corresponding to `tag`.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose entry is to be retrieved, in any of the
        forms accepted by :func:`~pydicom.tag.Tag`. Only entries in the
        private dictionary will be checked.
    private_creator : str
        The name of the private creator.

    Returns
    -------
    tuple of str
        The (VR, VM, name, is_retired) from the private dictionary.

    Raises
    ------
    KeyError
        If the tag or private creator is not present in the private dictionary.

    See Also
    --------
    get_entry
        Return an entry from the DICOM data dictionary.
    zPrivate creator 'z' not in the private dictionaryNz 'z ' is not a valid private creatorr6   r7   rM   xxxxc                    s   g | ]}| v r|qS r   r   )r   kprivate_dictr   r   r   ?  r   z%get_private_entry.<locals>.<listcomp>zTag 'z1' not in private dictionary for private creator ''r   )
r@   r   r   r   rA   	TypeErrorr2   r   groupelem)r   r2   excmsg	group_strelem_strkeys
dict_entryr   r_   r   get_private_entry  sB   





rk   c                 C      t | |d S )a  Return the VR of the private element corresponding to `tag`.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose value representation (VR) is being
        retrieved, in any of the forms accepted by :func:`~pydicom.tag.Tag`.
    private_creator : str
        The name of the private creator.

    Returns
    -------
    str
        The VR of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the private dictionary.
    r   rk   r   r2   r   r   r   private_dictionary_VRJ     ro   c                 C   rl   )a  Return the VM of the private element corresponding to `tag`.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose value multiplicity (VM) is being
        retrieved, in any of the forms accepted by :func:`~pydicom.tag.Tag`.
    private_creator : str
        The name of the private creator.

    Returns
    -------
    str
        The VM of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the private dictionary.
    rN   rm   rn   r   r   r   private_dictionary_VMb  rp   rq   c                 C   rl   )aD  Return the description of the private element corresponding to `tag`.

    Parameters
    ----------
    tag : int or str or Tuple[int, int]
        The tag for the element whose description is being retrieved, in any
        of the forms accepted by :func:`~pydicom.tag.Tag`.
    private_creator : str
        The name of the private creator.

    Returns
    -------
    str
        The description of the corresponding element.

    Raises
    ------
    KeyError
        If the tag is not present in the private dictionary,
        or if the private creator is not valid.
    rM   rm   rn   r   r   r   private_dictionary_descriptionz  s   rr   )r   r   )r   )0__doc__pydicom._dicom_dictr   r   pydicom.miscr   pydicom._private_dictr   pydicom.tagr   r   r   r	   dictstrtupleint__annotations__r   replacer   joinr   r   r#   r"   r5   r3   rC   boolrH   rK   rO   rP   rQ   rR   rT   rU   r1   rX   rY   valuesrZ   r[   rk   ro   rq   rr   r   r   r   r   <module>   s   
8
3
%
 .-"C