Index: pubmed_integration_manual.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pubmed_integration/pubmed_integration_manual.module,v retrieving revision 1.1 diff -u -r1.1 pubmed_integration_manual.module --- pubmed_integration_manual.module 13 Nov 2009 16:10:34 -0000 1.1 +++ pubmed_integration_manual.module 25 Nov 2009 18:49:20 -0000 @@ -3,7 +3,7 @@ /** * @file - * This module allows a site administrator to + * This module allows a site administrator to * import citations by entering a number of * PubMed Ids */ @@ -18,7 +18,7 @@ 'title' => t('Import citations by Pubmed Id'), 'page callback' => 'drupal_get_form', 'page arguments' => array('pubmed_integration_manual_import_form'), - 'access arguments' => array('pubmed integration manual import'), + 'access arguments' => array('pubmed integration manual import'), 'type' => MENU_LOCAL_TASK, 'weight' => 8, ); @@ -109,3 +109,44 @@ drupal_set_message("Successfully Imported: " . $node->biblio_custom3 . " - " . l($node->title, 'node/' . $node->nid)); } } +function pubmed_integration_form_biblio_node_form_alter(&$form, &$form_state) { + + if(phpversion() > 5 && !isset($form_state['storage']) && !isset($form['#node']->nid)) { + $form['biblio_pubmed_lookup'] = array( + '#type' => 'fieldset', + '#title' => t('PubMed Lookup'), + '#weight' => -20, + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['biblio_pubmed_lookup']['PMID'] = array( + '#type' => 'textfield', + '#title' => t('PubMed ID'), + '#required' => FALSE, + '#default_value' => '', + '#description' => t('Enter a PubMed ID'), + '#size' => 60, + '#maxlength' => 255, + '#weight' => -4 + ); + $form['biblio_pubmed_lookup']['pubmed_submit'] = array( + '#type' => 'submit', + '#value' => t('Populate using PubMed') + ); + $form['#validate'] = array_merge(array('pubmed_integration_form_biblio_node_form_validate'), $form['#validate']); // put my validator first +// $form['#validate'][] = 'biblio_pm_form_biblio_node_form_validate'; + } +} + +function pubmed_integration_form_biblio_node_form_validate($form, &$form_state) { + + if (strlen($pmid = $form_state['values']['PMID'])) { + $node_data = (array) pubmed_integration_load_citation_by_pmid($pmid); + } + if(!empty($node_data)) { + $form_state['values'] = array_merge($form_state['values'], $node_data); + $form_state['storage']['biblio_type'] = $node_data['biblio_type']; + return; + } +} Index: pubmed_integration.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pubmed_integration/pubmed_integration.module,v retrieving revision 1.1 diff -u -r1.1 pubmed_integration.module --- pubmed_integration.module 13 Nov 2009 16:10:34 -0000 1.1 +++ pubmed_integration.module 25 Nov 2009 18:49:19 -0000 @@ -15,7 +15,7 @@ * nodes. PubMed is used as the authoritative source, so if this module locates a previously imported citation * it will overwrite any data that is coming in from PubMed. Other fields will remain intact. * - * Project Sponsors: + * Project Sponsors: * Joslin Diabetes Center, Harvard Medical School * Science Collaboration Framework project, http://sciencecollaboration.org/ * Alzheimer Forum Foundation @@ -513,7 +513,7 @@ $batch['operations'] = $batch_operations; // Set the batch - batch_set($batch); + batch_set($batch); } else { drupal_set_message('No citations available to process', 'error'); @@ -530,7 +530,7 @@ else { $message = t('Finished with an error.'); } - + drupal_set_message($message); } @@ -539,7 +539,7 @@ */ function pubmed_integration_manual_query_run($pmid, &$context) { $nid = pubmed_integration_import_data($pmid, FALSE); - + if (!empty($nid)) { $context['results'][] = $nid[0]; } @@ -702,7 +702,7 @@ * @param $webenv - a key returned by Entrez to cache results * @param $querykey - a key returned by Entrez to cache results */ -function pubmed_integration_load_citation_by_pmid($pmid, $db = 'pubmed', $webenv, $querykey, $ignore_duplicates = FALSE) { +function pubmed_integration_load_citation_by_pmid($pmid, $db = 'pubmed', $webenv = '', $querykey = '', $ignore_duplicates = FALSE) { $biblio = new stdClass(); // First check to see whether the PMID already exists @@ -711,7 +711,7 @@ $existing_node = node_load($pmid_biblio_nid); // Merge in the existing node data foreach ($existing_node as $key => $value) { - $biblio->$key = $value; + $biblio->$key = $value; } if ($ignore_duplicates) return; } @@ -791,7 +791,7 @@ $epubdate = $summary; break; case "DOI": - $doi = $summary; + $doi = $summary; break; case "Source": $journal = $summary; @@ -860,7 +860,7 @@ // Return if not successful if (!is_object($llink_load)) { drupal_set_message(t("Failed to fetch object from eutils.ncbi.nlm.nih.gov."), 'error'); - + // @debug drupal_set_message('
ELINK ERROR: '.var_export($llink_load,TRUE).'
', 'error'); @@ -959,10 +959,10 @@ foreach($name_initials as $initial) { //$initials_correct .= $initial . '. '; $initials_correct .= $initial; - } + } $name[count($name) - 1] = null; $name_correct = trim(implode(' ', $name)) . ', ' . $initials_correct; - + return $name_correct; }