code: def doi_query(pmid, search_limit=10):
      pubmed_meta_dict = pubmed_client.get_metadata_for_ids([pmid],
                                                          get_issns_from_nlm=True)
      if pubmed_meta_dict is None or pubmed_meta_dict.get(pmid) is None:
          logger.warning('No metadata found in Pubmed for PMID%s' % pmid)
          return None
      pubmed_meta = pubmed_meta_dict[pmid]
      if pubmed_meta.get('doi'):
          return pubmed_meta.get('doi')
      pm_article_title = pubmed_meta.get('title')
      if pm_article_title is None:
          logger.warning('No article title found in Pubmed for PMID%s' % pmid)
          return None
      pm_issn_list = pubmed_meta.get('issn_list')
      if not pm_issn_list:
          logger.warning('No ISSNs found in Pubmed for PMID%s' % pmid)
          return None
      pm_page = pubmed_meta.get('page')
      if not pm_page:
          logger.debug('No page number found in Pubmed for PMID%s' % pmid)
          return None
      url = crossref_search_url
      params = {'q': pm_article_title, 'sort': 'score'}
      try:
          res = requests.get(crossref_search_url, params)
      except requests.exceptions.ConnectionError as e:
          logger.error('CrossRef service could not be reached.')
          logger.error(e)
          return None
      except Exception as e:
          logger.error('Error accessing CrossRef service: %s' % str(e))
          return None
      if res.status_code != 200:
          logger.info('PMID%s: no search results from CrossRef, code %d' %
                      (pmid, res.status_code))
          return None
      raw_message = res.json()
      mapped_doi = None
      for result_ix, result in enumerate(raw_message):
          if result_ix > search_limit:
              logger.info('PMID%s: No match found within first %s results, '
                          'giving up!' % (pmid, search_limit))
              break
          xref_doi_url = result['doi']
          m = re.match('^http://dx.doi.org/(.*)$', xref_doi_url)
          xref_doi = m.groups()[0]
          xref_meta = get_metadata(xref_doi)
          if xref_meta is None:
              continue
          xref_issn_list = xref_meta.get('ISSN')
          xref_page = xref_meta.get('page')
          if not xref_issn_list:
              logger.debug('No ISSN found for DOI %s, skipping' % xref_doi_url)
              continue
          if not xref_page:
              logger.debug('No page number found for DOI %s, skipping' %
                            xref_doi_url)
              continue
          matching_issns = set(pm_issn_list).intersection(set(xref_issn_list))
          pm_start_page = pm_page.split('-')[0].upper()
          xr_start_page = xref_page.split('-')[0].upper()
          if xr_start_page.endswith('E'):
              xr_start_page = 'E' + xr_start_page[:-1]
          if matching_issns and pm_start_page == xr_start_page:
              mapped_doi = xref_doi
              break
      return mapped_doi