You are here

function biblio_pubmed_query in Bibliography Module 6

File

./biblio.import.export.inc, line 1374
Functions that are used to import and export biblio data.

Code

function biblio_pubmed_query() {
  $query = '';

  //your query term
  $dnum = 100;

  // total number of documents here it's set to 100
  $pids = '';

  // PubMED record ID's from e-search initialize to NULL
  $term = 360;

  // time interval of when documents were published - this one is one year=360days

  //retreive PID's of all articles published withing past year that contain query term
  $esearch = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term={$query}&reldate={$term}&datetype=edat&retmax=100&usehistory=y";
  $handle = fopen($esearch, "r");
  $rettype = "abstract";

  //retreives abstract of the record, rather than full record
  $retmode = "xml";
  $utils = "http://www.ncbi.nlm.nih.gov/entrez/eutils";
  if (!$handle) {
    die;
  }

  //collect returned pubmed PID's
  while (!feof($handle)) {
    $pids .= fgets($handle, 4096);
  }
  fclose($handle);

  //Get query string from eSearch
  preg_match("/(\\w+)<\\/QueryKey>/i", $pids, $match);
  $queryKey = $match[1];

  //get webenv
  preg_match("/(\\S+)<\\/WebEnv>/i", $pids, $match);
  $webEnv = $match[1];
  $retstart = 0;

  //fetch xml docs from PUBMED for returned PID's
  $efetch = "{$utils}/efetch.fcgi?rettype={$rettype}&retmode={$retmode}&retstart={$retstart}&retmax={$dnum}&db=pubmed&query_key={$queryKey}&WebEnv={$webEnv}&email=abc@xyz.com";
  $pids = '';
  $handle = fopen($efetch, "r");
  if (!$handle) {
    die;
  }
  while (!feof($handle)) {
    $pids .= fgets($handle, 4096);
  }
  fclose($handle);
}