Browse Source

Fixed bug in Pub importer when no scope is provided for PMID search

spficklin 11 years ago
parent
commit
ec32991998
2 changed files with 80 additions and 78 deletions
  1. 76 77
      tripal_pub/api/tripal_pub.api.inc
  2. 4 1
      tripal_pub/includes/importers/PMID.inc

+ 76 - 77
tripal_pub/api/tripal_pub.api.inc

@@ -1029,13 +1029,13 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
   if ($citation) {
   if ($citation) {
     $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value', $options);
     $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value', $options);
     if (count($citation) > 1) {
     if (count($citation) > 1) {
-    	watchdog('tripal_pub', "Publication has multiple citations already: %pub_id",
-    	array('%pub_id' => $pubid), WATCHDOG_ERROR);
-    	return FALSE;
+      watchdog('tripal_pub', "Publication has multiple citations already: %pub_id",
+      array('%pub_id' => $pubid), WATCHDOG_ERROR);
+      return FALSE;
     }
     }
     elseif (count($citation) == 1 and $skip_existing == TRUE) {
     elseif (count($citation) == 1 and $skip_existing == TRUE) {
-    	// skip this publication, it already has a citation
-    	return FALSE;
+      // skip this publication, it already has a citation
+      return FALSE;
     }
     }
   }  
   }  
 
 
@@ -1080,7 +1080,7 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
     $sql = "SELECT string_agg(surname || ' ' || givennames, ', ') FROM {pubauthor} WHERE pub_id = %d GROUP BY pub_id";
     $sql = "SELECT string_agg(surname || ' ' || givennames, ', ') FROM {pubauthor} WHERE pub_id = %d GROUP BY pub_id";
     $au = db_result(chado_query($sql));
     $au = db_result(chado_query($sql));
     if ($au) {
     if ($au) {
-    	$pub_array['Authors'] = $au;
+      $pub_array['Authors'] = $au;
     }
     }
   }
   }
 
 
@@ -1156,95 +1156,94 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
  *   A text string containing the citation
  *   A text string containing the citation
  */
  */
 function tripal_pub_create_citation($pub) {
 function tripal_pub_create_citation($pub) {
-	$citation = '';
-	$pub_type = '';
-	
-	// An article may have more than one publication type. For example,
-	// a publication type can be 'Journal Article' but also a 'Clinical Trial'.
-	// Therefore, we need to select the type that makes most sense for 
-	// construction of the citation. Here we'll iterate through them all
-	// and select the one that matches best.
-	if(is_array($pub['Publication Type'])) {
-	  foreach ($pub['Publication Type'] as $ptype) {
-	    if ($ptype == 'Journal Article' ) {
-	      $pub_type = $ptype;
-	      break;
-	    } else if ($ptype == 'Conference Proceedings'){ 
-	      $pub_type = $ptype;
-	      break;
-	    } else if ($ptype == 'Book') {
-	      $pub_type = $ptype;
-	      break;
-	    } else if ($ptype == 'Book Chapter') {
-	      $pub_type = $ptype;
-	      break;
-	    }
-	  }
-	  if (!$pub_type) {
+  $citation = '';
+  $pub_type = '';
+  
+  // An article may have more than one publication type. For example,
+  // a publication type can be 'Journal Article' but also a 'Clinical Trial'.
+  // Therefore, we need to select the type that makes most sense for 
+  // construction of the citation. Here we'll iterate through them all
+  // and select the one that matches best.
+  if(is_array($pub['Publication Type'])) {
+    foreach ($pub['Publication Type'] as $ptype) {
+      if ($ptype == 'Journal Article' ) {
+        $pub_type = $ptype;
+        break;
+      } else if ($ptype == 'Conference Proceedings'){ 
+        $pub_type = $ptype;
+        break;
+      } else if ($ptype == 'Book') {
+        $pub_type = $ptype;
+        break;
+      } else if ($ptype == 'Book Chapter') {
+        $pub_type = $ptype;
+        break;
+      }
+    }
+    if (!$pub_type) {
       watchdog('tripal_pub', "Cannot generate citation for publication type: %types", 
       watchdog('tripal_pub', "Cannot generate citation for publication type: %types", 
         array('%types' => print_r($pub['Publication Type'], TRUE)), WATCHDOG_ERROR);
         array('%types' => print_r($pub['Publication Type'], TRUE)), WATCHDOG_ERROR);
       return FALSE;
       return FALSE;
     }
     }
-	}
-	else {
-	  $pub_type = $pub['Publication Type'];
-	}		
-  print "[$pub_type]\n";
-	//----------------------
+  }
+  else {
+    $pub_type = $pub['Publication Type'];
+  }    
+  //----------------------
   // Journal Article
   // Journal Article
   //----------------------
   //----------------------
-	if ($pub_type == 'Journal Article') {
-	  $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
-	
-	  if ($pub['Journal Name']) {
-	    $citation .= $pub['Journal Name'] . '. ';
-	  }
-	  elseif ($pub['Journal Abbreviation']) {
-	    $citation .= $pub['Journal Abbreviation'] . '. ';
-	  }
-	  elseif ($pub['Series Name']) {
-	    $citation .= $pub['Series Name'] . '. ';	
-	  }
-	  elseif ($pub['Series Abbreviation']) {
+  if ($pub_type == 'Journal Article') {
+    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+  
+    if ($pub['Journal Name']) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    elseif ($pub['Journal Abbreviation']) {
+      $citation .= $pub['Journal Abbreviation'] . '. ';
+    }
+    elseif ($pub['Series Name']) {
+      $citation .= $pub['Series Name'] . '. ';  
+    }
+    elseif ($pub['Series Abbreviation']) {
       $citation .= $pub['Series Abbreviation'] . '. ';
       $citation .= $pub['Series Abbreviation'] . '. ';
     }
     }
     if ($pub['Publication Date']) {
     if ($pub['Publication Date']) {
-	    $citation .= $pub['Publication Date'];
+      $citation .= $pub['Publication Date'];
     }
     }
     elseif ($pub['Year']) {
     elseif ($pub['Year']) {
-    	$citation .= $pub['Year'];
+      $citation .= $pub['Year'];
     }
     }
-	  if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
-	    $citation .= '; ';
-	  }
-	  if ($pub['Volume']) {
-	    $citation .= $pub['Volume'];
-	  }
-	  if ($pub['Issue']) {
-	    $citation .= '(' . $pub['Issue'] . ')';
-	  }
-	  if ($pub['Pages']) {
-	    if($pub['Volume']) {
-	      $citation .= ':';
-	    }
-	    $citation .= $pub['Pages'];
-	  }
-	  $citation .= '.';
-	}
-	//----------------------
+    if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
+      $citation .= '; ';
+    }
+    if ($pub['Volume']) {
+      $citation .= $pub['Volume'];
+    }
+    if ($pub['Issue']) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if ($pub['Pages']) {
+      if($pub['Volume']) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
+  //----------------------
   // Book
   // Book
   //----------------------
   //----------------------
-	elseif ($pub_type == 'Book') {
-	
-	}
-	//----------------------
+  elseif ($pub_type == 'Book') {
+  
+  }
+  //----------------------
   // Book Chapter
   // Book Chapter
   //----------------------
   //----------------------
   elseif ($pub_type == 'Book Chapter') {
   elseif ($pub_type == 'Book Chapter') {
-  	
+    
   }
   }
-	//----------------------
-	// Conference Proceedings
+  //----------------------
+  // Conference Proceedings
   //----------------------
   //----------------------
   elseif ($pub_type == 'Conference Proceedings') {
   elseif ($pub_type == 'Conference Proceedings') {
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';

+ 4 - 1
tripal_pub/includes/importers/PMID.inc

@@ -100,6 +100,9 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
       $search_str = preg_replace('/PMID:([^\s]*)/', '$1', $search_str);
       $search_str = preg_replace('/PMID:([^\s]*)/', '$1', $search_str);
       $search_str = preg_replace('/\|SCOPE\|/', '[Uid]', $search_str);
       $search_str = preg_replace('/\|SCOPE\|/', '[Uid]', $search_str);
     }
     }
+    else {
+      $search_str = preg_replace('/\|SCOPE\|/', '', $search_str);  
+    }
   }
   }
   if ($days) {
   if ($days) {
     // get the date of the day suggested
     // get the date of the day suggested
@@ -111,7 +114,7 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
   $search_array['limit'] = $num_to_retrieve;
   $search_array['limit'] = $num_to_retrieve;
   $search_array['search_string'] = $search_str;
   $search_array['search_string'] = $search_str;
 
 
-  //dpm($search_str);
+  dpm($search_str);
   unset($_SESSION['tripal_pub_PMID_query']);
   unset($_SESSION['tripal_pub_PMID_query']);
   // we want to get the list of pubs using the search terms but using a Drupal style pager
   // we want to get the list of pubs using the search terms but using a Drupal style pager
   $pubs = tripal_pager_callback('tripal_pub_PMID_range',  $num_to_retrieve, $pager_id,
   $pubs = tripal_pager_callback('tripal_pub_PMID_range',  $num_to_retrieve, $pager_id,