(requests, identifier_type)
Returns the ID of the identifier source to be used for generating
    values for identifiers of the given type.

    The idgen module doesn't offer an API to list identifier sources.
    This function scrapes /module/idgen/manageIdentifierSources.list
Returns the ID of the identifier source to be used for generating
    values for identifiers of the given type.
Returns the ID of the identifier source to be used for generating values for identifiers of the given type .
def get_identifier_source_id(requests, identifier_type):
    """
    Returns the ID of the identifier source to be used for generating
    values for identifiers of the given type.

    The idgen module doesn't offer an API to list identifier sources.
    This function scrapes /module/idgen/manageIdentifierSources.list
    """
    response = requests.get('/ws/rest/v1/patientidentifiertype/{}'.format(identifier_type))
    identifier_type_name = response.json()['name']

    response = requests.get('/module/idgen/manageIdentifierSources.list', headers={'Accept': 'text/html'})
    if not 200 <= response.status_code < 300:
        raise OpenmrsHtmlUiChanged(
            'Domain "{}": Unexpected response from OpenMRS idgen module at "{}". '
            'Is it installed?'.format(requests.domain_name, response.url)
        )

    tree = html.fromstring(response.content)
    for row in tree.xpath('//table[@id="sourceTable"]/tbody/tr'):
        ident_type, source_type, source_name, actions = row.xpath('td')
        if ident_type.text == identifier_type_name:
            try:
                onclick = actions.xpath('button')[1].attrib['onclick']
            except (AttributeError, IndexError, KeyError):
                raise OpenmrsHtmlUiChanged(
                    'Domain "{}": Unexpected page format at "{}".'.format(requests.domain_name, response.url)
                )
            match = re.match(r"document\.location\.href='viewIdentifierSource\.form\?source=(\d+)';", onclick)
            if not match:
                raise OpenmrsHtmlUiChanged(
                    'Domain "{}": Unexpected "onclick" value at "{}".'.format(requests.domain_name, response.url)
                )
            source_id = match.group(1)
            return source_id
def get_identifier_source_id ( requests , identifier_type ) : response = requests . get ( '/ws/rest/v1/patientidentifiertype/{}' . format ( identifier_type ) ) identifier_type_name = response . json ( ) [ 'name' ] response = requests . get ( '/module/idgen/manageIdentifierSources.list' , headers = { 'Accept' : 'text/html' } ) if not 200 <= response . status_code < 300 : raise OpenmrsHtmlUiChanged ( 'Domain "{}": Unexpected response from OpenMRS idgen module at "{}". ' 'Is it installed?' . format ( requests . domain_name , response . url ) ) tree = html . fromstring ( response . content ) for row in tree . xpath ( '//table[@id="sourceTable"]/tbody/tr' ) : ident_type , source_type , source_name , actions = row . xpath ( 'td' ) if ident_type . text == identifier_type_name : try : onclick = actions . xpath ( 'button' ) [ 1 ] . attrib [ 'onclick' ] except ( AttributeError , IndexError , KeyError ) : raise OpenmrsHtmlUiChanged ( 'Domain "{}": Unexpected page format at "{}".' . format ( requests . domain_name , response . url ) ) match = re . match ( r"document\.location\.href='viewIdentifierSource\.form\?source=(\d+)';" , onclick ) if not match : raise OpenmrsHtmlUiChanged ( 'Domain "{}": Unexpected "onclick" value at "{}".' . format ( requests . domain_name , response . url ) ) source_id = match . group ( 1 ) return source_id