(element)
Extracts the UUID of a patient from an entry's "content" node.

    >>> element = etree.XML('''<entry>
    ...     <content type="application/vnd.atomfeed+xml">
    ...         <![CDATA[/openmrs/ws/rest/v1/patient/e8aa08f6-86cd-42f9-8924-1b3ea021aeb4?v=full]]>
    ...     </content>
    ... </entry>''')
    >>> get_patient_uuid(element)
    'e8aa08f6-86cd-42f9-8924-1b3ea021aeb4'
Extracts the UUID of a patient from an entry's "content" node.
Extracts the UUID of a patient from an entry s content node .
def get_patient_uuid(element):
    """
    Extracts the UUID of a patient from an entry's "content" node.

    >>> element = etree.XML('''<entry>
    ...     <content type="application/vnd.atomfeed+xml">
    ...         <![CDATA[/openmrs/ws/rest/v1/patient/e8aa08f6-86cd-42f9-8924-1b3ea021aeb4?v=full]]>
    ...     </content>
    ... </entry>''')
    >>> get_patient_uuid(element)
    'e8aa08f6-86cd-42f9-8924-1b3ea021aeb4'

    """
    # "./*[local-name()='content']" ignores namespaces and matches all
    # child nodes with tag name "content". This lets us traverse the
    # feed regardless of whether the Atom namespace is explicitly given.
    content = element.xpath("./*[local-name()='content']")
    pattern = re.compile(r'/patient/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b')
    if content and len(content) == 1:
        cdata = content[0].text
        matches = pattern.search(cdata)
        if matches:
            return matches.group(1)
    raise ValueError('Patient UUID not found')
def get_patient_uuid ( element ) : # "./*[local-name()='content']" ignores namespaces and matches all # child nodes with tag name "content". This lets us traverse the # feed regardless of whether the Atom namespace is explicitly given. content = element . xpath ( "./*[local-name()='content']" ) pattern = re . compile ( r'/patient/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b' ) if content and len ( content ) == 1 : cdata = content [ 0 ] . text matches = pattern . search ( cdata ) if matches : return matches . group ( 1 ) raise ValueError ( 'Patient UUID not found' )