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

    >>> element = etree.XML('''<entry>
    ...   <title>Encounter</title>
    ...   <content type="application/vnd.atomfeed+xml">
    ...     <![CDATA[/openmrs/ws/rest/v1/bahmnicore/bahmniencounter/0f54fe40-89af-4412-8dd4-5eaebe8684dc?includeAll=true]]>
    ...   </content>
    ... </entry>''')
    >>> get_encounter_uuid(element)
    '0f54fe40-89af-4412-8dd4-5eaebe8684dc'
Extracts the UUID of an encounter from an entry's "content" node.
Extracts the UUID of an encounter from an entry s content node .
def get_encounter_uuid(element):
    """
    Extracts the UUID of an encounter from an entry's "content" node.

    >>> element = etree.XML('''<entry>
    ...   <title>Encounter</title>
    ...   <content type="application/vnd.atomfeed+xml">
    ...     <![CDATA[/openmrs/ws/rest/v1/bahmnicore/bahmniencounter/0f54fe40-89af-4412-8dd4-5eaebe8684dc?includeAll=true]]>
    ...   </content>
    ... </entry>''')
    >>> get_encounter_uuid(element)
    '0f54fe40-89af-4412-8dd4-5eaebe8684dc'

    """
    content = element.xpath("./*[local-name()='content']")
    pattern = re.compile(r'/bahmniencounter/([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)
        # Not everything in the Encounter atom feed is an Encounter. It
        # also includes bed assignments.
        if 'bedPatientAssignment' in cdata:
            return None
    raise ValueError('Unrecognised Encounter atom feed entry')
def get_encounter_uuid ( element ) : content = element . xpath ( "./*[local-name()='content']" ) pattern = re . compile ( r'/bahmniencounter/([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 ) # Not everything in the Encounter atom feed is an Encounter. It # also includes bed assignments. if 'bedPatientAssignment' in cdata : return None raise ValueError ( 'Unrecognised Encounter atom feed entry' )