pubmed.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. <?php
  2. /**
  3. * @file
  4. * Tripal Pub PubMed Interface
  5. *
  6. * @defgroup tripal_pub_pubmed PubMed Interface
  7. * @ingroup tripal_pub
  8. */
  9. /**
  10. *
  11. */
  12. function tripal_pub_remote_search_pubmed($search_array, $num_to_retrieve, $pager_id) {
  13. // convert the terms list provicded by the caller into a string with words
  14. // separated by a '+' symbol.
  15. $num_criteria = $search_array['num_criteria'];
  16. $days = $search_array['days'];
  17. $search_str = '';
  18. for ($i = 0; $i <= $num_criteria; $i++) {
  19. $search_terms = $search_array['criteria'][$i]['search_terms'];
  20. $scope = $search_array['criteria'][$i]['scope'];
  21. $op = $search_array['criteria'][$i]['operation'];
  22. if ($op) {
  23. $search_str .= "$op";
  24. }
  25. $search_str .= '(';
  26. $search_str .= implode("+", preg_split('/\s+/', trim($search_terms)));
  27. if($scope == 'title') {
  28. $search_str .= '[Title]';
  29. }
  30. elseif($scope == 'author') {
  31. $search_str .= '[Author]';
  32. }
  33. elseif($scope == 'abstract') {
  34. $search_str .= '[Title/Abstract]';
  35. }
  36. $search_str .= ')';
  37. }
  38. $search_array['limit'] = $num_to_retrieve;
  39. $search_array['search_terms'] = $search_str;
  40. // we want to get the list of pubs using the search terms but using a Drupal style pager
  41. $pubs = tripal_pager_callback('tripal_pub_pubmed_range',
  42. $num_to_retrieve, $pager_id, 'tripal_pub_pubmed_count', $search_array);
  43. return $pubs;
  44. }
  45. /*
  46. * This function is used as the callback function when used with the
  47. * tripal_pager_callback function. This function returns a count of
  48. * the dataset to be paged.
  49. */
  50. function tripal_pub_pubmed_count($search_array) {
  51. $terms = $search_array['search_terms'];
  52. $days = $search_array['days'];
  53. $limit = $search_array['limit'];
  54. $results = tripal_pub_pubmed_search_init($terms, $limit, $days);
  55. $_SESSION['tripal_pub_pubmed_query'][$terms]['Count'] = $results['Count'];
  56. $_SESSION['tripal_pub_pubmed_query'][$terms]['WebEnv'] = $results['WebEnv'];
  57. $_SESSION['tripal_pub_pubmed_query'][$terms]['QueryKey'] = $results['QueryKey'];
  58. return $results['Count'];
  59. }
  60. /*
  61. * This function is used as the callback function when used with the
  62. * tripal_pager_callback function. This function returns the results
  63. * within the specified range
  64. */
  65. function tripal_pub_pubmed_range($search_array, $start = 0, $limit = 10) {
  66. $terms = $search_array['search_terms'];
  67. $days = $search_array['days'];
  68. $limit = $search_array['limit'];
  69. $count = $_SESSION['tripal_pub_pubmed_query'][$terms]['Count'];
  70. // get the query_key and the web_env from the previous count query.
  71. $query_key = $_SESSION['tripal_pub_pubmed_query'][$terms]['QueryKey'];
  72. $web_env = $_SESSION['tripal_pub_pubmed_query'][$terms]['WebEnv'];
  73. // if this function has been called without calling the count function
  74. // then we need to do the query.
  75. if (!$query_key) {
  76. $results = tripal_pub_pubmed_search_init($terms, $limit, $days);
  77. $_SESSION['tripal_pub_pubmed_query']['WebEnv'] = $results['WebEnv'];
  78. $_SESSION['tripal_pub_pubmed_query']['QueryKey'] = $results['QueryKey'];
  79. $query_key = $results['QueryKey'];
  80. $web_env = $results['WebEnv'];
  81. }
  82. // now get the list of PMIDs from the previous search
  83. $pmids_txt = tripal_pub_pubmed_fetch($query_key, $web_env, 'uilist', 'text', $start, $limit);
  84. // iterate through each PMID and get the publication record. This requires a new search and new fetch
  85. $pmids = explode("\n", trim($pmids_txt));
  86. $pubs = array();
  87. foreach ($pmids as $pmid) {
  88. // now retrieve the individual record
  89. $pub_xml = tripal_pub_pubmed_fetch($query_key, $web_env, 'null', 'xml', 0, 1, array('id' => $pmid));
  90. $pub = tripal_pub_pubmed_parse_pubxml($pub_xml);
  91. $pubs[] = $pub;
  92. }
  93. return $pubs;
  94. }
  95. /*
  96. *
  97. */
  98. function tripal_pub_pubmed_search_init($terms, $retmax, $days = 0){
  99. // do a search for a single result so that we can establish a history, and get
  100. // the number of records. Once we have the number of records we can retrieve
  101. // those requested in the range.
  102. $query_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=Pubmed&retmax=$retmax&usehistory=y&term=$terms";
  103. if($days) {
  104. $query_url .= "&reldate=$days&datetype=edat";
  105. }
  106. //dpm($query_url);
  107. $rfh = fopen($query_url, "r");
  108. if (!$rfh) {
  109. drupal_set_message('Could not perform Pubmed query. Cannot connect to Entrez.', 'error');
  110. return 0;
  111. }
  112. // retrieve the XML results
  113. $query_xml = '';
  114. while (!feof($rfh)) {
  115. $query_xml .= fread($rfh, 255);
  116. }
  117. fclose($rfh);
  118. //dpm("<pre>$query_xml</pre>");
  119. $xml = new XMLReader();
  120. $xml->xml($query_xml);
  121. // iterate though the child nodes of the <eSearchResult> tag and get the count, history and query_id
  122. $result = array();
  123. while ($xml->read()) {
  124. $element = $xml->name;
  125. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'WebEnv') {
  126. // we've read as much as we need. If we go too much further our counts
  127. // will get messed up by other 'Count' elements. so we're done.
  128. break;
  129. }
  130. if ($xml->nodeType == XMLReader::ELEMENT) {
  131. switch ($element) {
  132. case 'Count':
  133. $xml->read();
  134. $result['Count'] = $xml->value;
  135. break;
  136. case 'WebEnv':
  137. $xml->read();
  138. $result['WebEnv'] = $xml->value;
  139. break;
  140. case 'QueryKey':
  141. $xml->read();
  142. $result['QueryKey'] = $xml->value;
  143. break;
  144. }
  145. }
  146. }
  147. return $result;
  148. }
  149. /*
  150. *
  151. */
  152. function tripal_pub_pubmed_fetch($query_key, $web_env, $rettype = 'null',
  153. $retmod = 'null', $start = 0, $limit = 10, $args = array()){
  154. // repeat the search performed previously (using WebEnv & QueryKey) to retrieve
  155. // the PMID's within the range specied. The PMIDs will be returned as a text list
  156. $fetch_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?rettype=$rettype&retmode=$retmod&retstart=$start&retmax=$limit&db=Pubmed&query_key=$query_key&WebEnv=$web_env";
  157. //dpm($fetch_url);
  158. foreach ($args as $key => $value) {
  159. if(is_array($value)) {
  160. $fetch_url .= "&$key=";
  161. foreach ($value as $item) {
  162. $fetch_url .= "$item,";
  163. }
  164. $fetch_url = substr($fetch_url, 0, -1); // remove trailing comma
  165. }
  166. else {
  167. $fetch_url .= "&$key=$value";
  168. }
  169. }
  170. $rfh = fopen($fetch_url, "r");
  171. if (!$rfh) {
  172. drupal_set_message('Could not perform Pubmed query. Cannot connect to Entrez.', 'error');
  173. return '';
  174. }
  175. $results = '';
  176. if($rfh) {
  177. while (!feof($rfh)) {
  178. $results .= fread($rfh, 255);
  179. }
  180. fclose($rfh);
  181. }
  182. return $results;
  183. }
  184. /*
  185. * This function parses the XML containing details of a publication and
  186. * converts it into an associative array of where keys are Tripal Pub
  187. * ontology terms and the values are extracted from the XML. The
  188. * XML should contain only a single publication record.
  189. *
  190. * Information about the valid elements in the PubMed XML can be found here:
  191. * http://www.nlm.nih.gov/bsd/licensee/elements_descriptions.html
  192. *
  193. * Information about PubMed's citation format can be found here
  194. * http://www.nlm.nih.gov/bsd/policy/cit_format.html
  195. */
  196. function tripal_pub_pubmed_parse_pubxml($pub_xml) {
  197. $pub = array();
  198. if (!$pub_xml) {
  199. return $pub;
  200. }
  201. // read the XML and iterate through it.
  202. $xml = new XMLReader();
  203. $xml->xml($pub_xml);
  204. while ($xml->read()) {
  205. $element = $xml->name;
  206. if ($xml->nodeType == XMLReader::ELEMENT) {
  207. switch ($element) {
  208. case 'PMID':
  209. $xml->read(); // get the value for this element
  210. $pub['Pub Accession'] = $xml->value;
  211. $pub['Publication Database'] = 'PMID';
  212. break;
  213. case 'Article':
  214. $pub_model = $xml->getAttribute('PubModel');
  215. $pub['Publication Model'] = $pub_model;
  216. tripal_pub_pubmed_parse_article($xml, $pub);
  217. break;
  218. case 'MedlineJournalInfo':
  219. tripal_pub_pubmed_parse_medline_journal_info($xml, $pub);
  220. break;
  221. case 'ChemicalList':
  222. // TODO: handle this
  223. break;
  224. case 'SupplMeshList':
  225. // TODO: meant for protocol list
  226. break;
  227. case 'CitationSubset':
  228. // TODO: not sure this is needed.
  229. break;
  230. case 'CommentsCorrections':
  231. // TODO: handle this
  232. break;
  233. case 'GeneSymbolList':
  234. // TODO: handle this
  235. break;
  236. case 'MeshHeadingList':
  237. // TODO: Medical subject headings
  238. break;
  239. case 'NumberOfReferences':
  240. // TODO: not sure we should keep this as it changes frequently.
  241. break;
  242. case 'PersonalNameSubjectList':
  243. // TODO: for works about an individual or with biographical note/obituary.
  244. break;
  245. case 'OtherID':
  246. // TODO: ID's from another NLM partner.
  247. break;
  248. case 'OtherAbstract':
  249. // TODO: when the journal does not contain an abstract for the publication.
  250. break;
  251. case 'KeywordList':
  252. // TODO: handle this
  253. break;
  254. case 'InvestigatorList':
  255. // TODO: personal names of individuals who are not authors (can be used with collection)
  256. break;
  257. case 'GeneralNote':
  258. // TODO: handle this
  259. break;
  260. case 'DeleteCitation':
  261. // TODO: need to know how to handle this
  262. break;
  263. default:
  264. break;
  265. }
  266. }
  267. }
  268. $pub['Citation'] = $pub['Author List'] .
  269. '. <a href="http://www.ncbi.nlm.nih.gov/pubmed/' . $pub['Pub Accession'] . '" target="_blank">' . $pub['Title'] . '</a> ' .
  270. $pub['Journal ISO Abbreviation']. '. ' . $pub['Publication Date'];
  271. if ($pub['Volume'] or $pub['Issue']) {
  272. $pub['Citation'] .= '; ';
  273. }
  274. if ($pub['Volume']) {
  275. $pub['Citation'] .= $pub['Volume'];
  276. }
  277. if ($pub['Issue']) {
  278. $pub['Citation'] .= '(' . $pub['Issue'] . ')';
  279. }
  280. if ($pub['Pages']) {
  281. $pub['Citation'] .= ':' . $pub['Pages'];
  282. }
  283. $pub['Citation'] .= '. PubMed PMID: ' . $pub['Pub Accession'];
  284. //$pub['xml'] = $pub_xml;
  285. return $pub;
  286. }
  287. /*
  288. *
  289. */
  290. function tripal_pub_pubmed_parse_medline_journal_info($xml, &$pub) {
  291. while ($xml->read()) {
  292. // get this element name
  293. $element = $xml->name;
  294. // if we're at the </Article> element then we're done with the article...
  295. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'MedlineJournalInfo') {
  296. return;
  297. }
  298. if ($xml->nodeType == XMLReader::ELEMENT) {
  299. switch ($element) {
  300. case 'Country':
  301. // the place of publication of the journal
  302. $xml->read();
  303. $pub['Journal Country'] = $xml->value;
  304. break;
  305. case 'MedlineTA':
  306. // TODO: not sure how this is different from ISOAbbreviation
  307. break;
  308. case 'NlmUniqueID':
  309. // TODO: the journal's unique ID in medline
  310. break;
  311. case 'ISSNLinking':
  312. // TODO: not sure how this is different from ISSN
  313. break;
  314. default:
  315. break;
  316. }
  317. }
  318. }
  319. }
  320. /*
  321. *
  322. */
  323. function tripal_pub_pubmed_parse_article($xml, &$pub) {
  324. while ($xml->read()) {
  325. // get this element name
  326. $element = $xml->name;
  327. // if we're at the </Article> element then we're done with the article...
  328. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Article') {
  329. return;
  330. }
  331. if ($xml->nodeType == XMLReader::ELEMENT) {
  332. switch ($element) {
  333. case 'Journal':
  334. tripal_pub_pubmed_parse_journal($xml, $pub);
  335. break;
  336. case 'ArticleTitle':
  337. $xml->read();
  338. $pub['Title'] = $xml->value;
  339. break;
  340. case 'Abstract':
  341. tripal_pub_pubmed_parse_abstract($xml, $pub);
  342. break;
  343. case 'Pagination':
  344. tripal_pub_pubmed_parse_pagination($xml, $pub);
  345. break;
  346. case 'ELocationID':
  347. $type = $xml->getAttribute('EIdType');
  348. $valid = $xml->getAttribute('ValidYN');
  349. $xml->read();
  350. $elocation = $xml->value;
  351. if ($type == 'doi' and $valid == 'Y') {
  352. $pub['DOI'] = $elocation;
  353. }
  354. if ($type == 'pii' and $valid == 'Y') {
  355. $pub['PII'] = $elocation;
  356. }
  357. $pub['Elocation'] = $elocation;
  358. break;
  359. case 'Affiliation':
  360. // the affiliation tag at this level is meant solely for the first author
  361. $xml->read();
  362. $pub['Authors'][0]['Affiliation'] = $xml->value;
  363. break;
  364. case 'AuthorList':
  365. $complete = $xml->getAttribute('CompleteYN');
  366. tripal_pub_pubmed_parse_authorlist($xml, $pub);
  367. break;
  368. case 'InvestigatorList':
  369. // TODO: perhaps handle this one day. The investigator list is to list the names of people who
  370. // are members of a collective or corporate group that is an author in the paper.
  371. break;
  372. case 'Language':
  373. $xml->read();
  374. $lang_abbr = $xml->value;
  375. // there may be multiple languages so we store these in an array
  376. $pub['Language'][] = tripal_pub_remote_search_get_language($lang_abbr);
  377. $pub['Language Abbr'][] = $lang_abbr;
  378. break;
  379. case 'DataBankList':
  380. // TODO: handle this case
  381. break;
  382. case 'GrantList':
  383. // TODO: handle this case
  384. break;
  385. case 'PublicationTypeList':
  386. tripal_pub_pubmed_parse_publication_type($xml, $pub);
  387. break;
  388. case 'VernacularTitle':
  389. $xml->read();
  390. $pub['Vernacular Title'][] = $xml->value;
  391. break;
  392. case 'ArticleDate':
  393. // TODO: figure out what to do with this element. We already have the
  394. // published date in the <PubDate> field, but this date should be in numeric
  395. // form and may have more information.
  396. break;
  397. default:
  398. break;
  399. }
  400. }
  401. }
  402. }
  403. /*
  404. * A full list of publication types can be found here:
  405. * http://www.nlm.nih.gov/mesh/pubtypes.html.
  406. *
  407. * The Tripal Pub ontology doesn't yet have terms for all of the
  408. * publication types so we store the value in the 'publication_type' term.
  409. */
  410. function tripal_pub_pubmed_parse_publication_type($xml, &$pub) {
  411. while ($xml->read()) {
  412. $element = $xml->name;
  413. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'PublicationTypeList') {
  414. // we've reached the </PublicationTypeList> element so we're done.
  415. return;
  416. }
  417. if ($xml->nodeType == XMLReader::ELEMENT) {
  418. switch ($element) {
  419. case 'PublicationType':
  420. $xml->read();
  421. $pub_cvterm = tripal_cv_get_cvterm_by_name($xml->value, NULL, 'tripal_pub');
  422. if (!$pub_cvterm) {
  423. // see if this we can find the name using a synonym
  424. $pub_cvterm = tripal_cv_get_cvterm_by_synonym($xml->value, NULL, 'tripal_pub');
  425. if (!$pub_cvterm) {
  426. watchdog('tpub_pubmed', 'Cannot find a valid vocabulary term for the publication type: "%term".',
  427. array('%term' => $xml->value), WATCHDOG_ERROR);
  428. }
  429. }
  430. else {
  431. $pub['Publication Type'][] = $pub_cvterm->name;
  432. }
  433. break;
  434. default:
  435. break;
  436. }
  437. }
  438. }
  439. }
  440. /*
  441. *
  442. */
  443. function tripal_pub_pubmed_parse_abstract($xml, &$pub) {
  444. $abstract = '';
  445. while ($xml->read()) {
  446. $element = $xml->name;
  447. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Abstract') {
  448. // we've reached the </Abstract> element so return
  449. $pub['Abstract'] = $abstract;
  450. return;
  451. }
  452. // the abstract text can be just a singe paragraph or be broken into multiple
  453. // abstract texts for structured abstracts. Here we will just combine then
  454. // into a single element in the order that they arrive in HTML format
  455. if ($xml->nodeType == XMLReader::ELEMENT) {
  456. switch ($element) {
  457. case 'AbstractText':
  458. $label = $xml->getAttribute('Label');
  459. $xml->read();
  460. if ($label) {
  461. $pub['Structured Abstract Part'][] = $xml->value;
  462. $abstract .= "<p><b>$label</b></br>" . $xml->value . '</p>';
  463. }
  464. else {
  465. $abstract .= '<p>' . $xml->value . '</p>';
  466. }
  467. break;
  468. case 'CopyrightInformation':
  469. $xml->read();
  470. $pub['Copyright'] = $xml->value;
  471. break;
  472. default:
  473. break;
  474. }
  475. }
  476. }
  477. }
  478. /*
  479. *
  480. */
  481. function tripal_pub_pubmed_parse_pagination($xml, &$pub) {
  482. while ($xml->read()) {
  483. $element = $xml->name;
  484. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Pagination') {
  485. // we've reached the </Pagination> element so we're done.
  486. return;
  487. }
  488. if ($xml->nodeType == XMLReader::ELEMENT) {
  489. switch ($element) {
  490. case 'MedlinePgn':
  491. $xml->read();
  492. if(trim($xml->value)) {
  493. $pub['Pages'] = $xml->value;
  494. }
  495. break;
  496. default:
  497. break;
  498. }
  499. }
  500. }
  501. }
  502. /*
  503. *
  504. */
  505. function tripal_pub_pubmed_parse_journal($xml, &$pub) {
  506. while ($xml->read()) {
  507. $element = $xml->name;
  508. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Journal') {
  509. return;
  510. }
  511. if ($xml->nodeType == XMLReader::ELEMENT) {
  512. switch ($element) {
  513. case 'ISSN':
  514. $issn_type = $xml->getAttribute('IssnType');
  515. $xml->read();
  516. $issn = $xml->value;
  517. $pub['ISSN'] = $issn;
  518. if ($issn_type == 'Electronic') {
  519. $pub['eISSN'] = $issn;
  520. }
  521. if ($issn_type == 'Print') {
  522. $pub['pISSN'] = $issn;
  523. }
  524. break;
  525. case 'JournalIssue':
  526. // valid values of cited_medium are 'Internet' and 'Print'
  527. $cited_medium = $xml->getAttribute('CitedMedium');
  528. tripal_pub_pubmed_parse_journal_issue($xml, $pub);
  529. break;
  530. case 'Title':
  531. $xml->read();
  532. $pub['Journal Name'] = $xml->value;
  533. break;
  534. case 'ISOAbbreviation':
  535. $xml->read();
  536. $pub['Journal ISO Abbreviation'] = $xml->value;
  537. break;
  538. default:
  539. break;
  540. }
  541. }
  542. }
  543. }
  544. /*
  545. *
  546. */
  547. function tripal_pub_pubmed_parse_journal_issue($xml, &$pub) {
  548. while ($xml->read()) {
  549. $element = $xml->name;
  550. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'JournalIssue'){
  551. // if we're at the </JournalIssue> element then we're done
  552. return;
  553. }
  554. if ($xml->nodeType == XMLReader::ELEMENT) {
  555. switch ($element) {
  556. case 'Volume':
  557. $xml->read();
  558. $pub['Volume'] = $xml->value;
  559. break;
  560. case 'Issue':
  561. $xml->read();
  562. $pub['Issue'] = $xml->value;
  563. break;
  564. case 'PubDate':
  565. $date = tripal_pub_pubmed_parse_date($xml, 'PubDate');
  566. $year = $date['year'];
  567. $month = $date['month'];
  568. $day = $date['day'];
  569. $medline = $date['medline'];
  570. $pub['Year'] = $year;
  571. if ($month and $day and $year) {
  572. $pub['Publication Date'] = "$year $month $day";
  573. }
  574. elseif ($month and !$day and $year) {
  575. $pub['Publication Date'] = "$year $month";
  576. }
  577. elseif (!$month and !$day and $year) {
  578. $pub['Publication Date'] = $year;
  579. }
  580. elseif ($medline) {
  581. $pub['Publication Date'] = $medline;
  582. }
  583. else {
  584. $pub['Publication Date'] = "Date Unknown";
  585. }
  586. break;
  587. default:
  588. break;
  589. }
  590. }
  591. }
  592. }
  593. /*
  594. *
  595. */
  596. function tripal_pub_pubmed_parse_date ($xml, $element_name) {
  597. $date = array();
  598. while ($xml->read()) {
  599. $element = $xml->name;
  600. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == $element_name){
  601. // if we're at the </$element_name> then we're done
  602. return $date;
  603. }
  604. if ($xml->nodeType == XMLReader::ELEMENT) {
  605. switch ($element) {
  606. case 'Year':
  607. $xml->read();
  608. $date['year'] = $xml->value;
  609. break;
  610. case 'Month':
  611. $xml->read();
  612. $month =
  613. $date['month'] = $xml->value;
  614. break;
  615. case 'Day':
  616. $xml->read();
  617. $date['day'] = $xml->value;
  618. break;
  619. case 'MedlineDate':
  620. // the medline date is when the date cannot be broken into distinct month day year.
  621. $xml->read();
  622. $date['medline'] = $xml->value;
  623. break;
  624. default:
  625. break;
  626. }
  627. }
  628. }
  629. }
  630. /*
  631. *
  632. */
  633. function tripal_pub_pubmed_parse_authorlist($xml, &$pub) {
  634. $num_authors = 0;
  635. while ($xml->read()) {
  636. $element = $xml->name;
  637. if ($xml->nodeType == XMLReader::END_ELEMENT){
  638. // if we're at the </AuthorList> element then we're done with the article...
  639. if($element == 'AuthorList') {
  640. // build the author list before returning
  641. $author_list = '';
  642. foreach ($pub['Authors'] as $author) {
  643. if ($author['valid'] == 'N') {
  644. // skip non-valid entries. A non-valid entry should have
  645. // a corresponding corrected entry so we can saftely skip it.
  646. continue;
  647. }
  648. if ($author['Collective']) {
  649. $author_list .= $author['Collective'] . ', ';
  650. }
  651. else {
  652. $author_list .= $author['Surname'] . ' ' . $author['First Initials'] . ', ';
  653. }
  654. }
  655. $author_list = substr($author_list, 0, -2);
  656. $pub['Author List'] = $author_list;
  657. return;
  658. }
  659. // if we're at the end </Author> element then we're done with the author and we can
  660. // start a new one.
  661. if($element == 'Author') {
  662. $num_authors++;
  663. }
  664. }
  665. if ($xml->nodeType == XMLReader::ELEMENT) {
  666. switch ($element) {
  667. case 'Author':
  668. $valid = $xml->getAttribute('ValidYN');
  669. $pub['Authors'][$num_authors]['valid'] = $valid;
  670. break;
  671. case 'LastName':
  672. $xml->read();
  673. $pub['Authors'][$num_authors]['Surname'] = $xml->value;
  674. break;
  675. case 'ForeName':
  676. $xml->read();
  677. $pub['Authors'][$num_authors]['Given Name'] = $xml->value;
  678. break;
  679. case 'Initials':
  680. $xml->read();
  681. $pub['Authors'][$num_authors]['First Initials'] = $xml->value;
  682. break;
  683. case 'Suffix':
  684. $xml->read();
  685. $pub['Authors'][$num_authors]['Suffix'] = $xml->value;
  686. break;
  687. case 'CollectiveName':
  688. $xml->read();
  689. $pub['Authors'][$num_authors]['Collective'] = $xml->value;
  690. break;
  691. case 'Identifier':
  692. // according to the specification, this element is not yet used.
  693. break;
  694. default:
  695. break;
  696. }
  697. }
  698. }
  699. }
  700. /*
  701. * Language abbreviations were obtained here:
  702. * http://www.nlm.nih.gov/bsd/language_table.html
  703. */
  704. function tripal_pub_remote_search_get_language($lang_abbr) {
  705. $languages = array(
  706. 'afr' => 'Afrikaans',
  707. 'alb' => 'Albanian',
  708. 'amh' => 'Amharic',
  709. 'ara' => 'Arabic',
  710. 'arm' => 'Armenian',
  711. 'aze' => 'Azerbaijani',
  712. 'ben' => 'Bengali',
  713. 'bos' => 'Bosnian',
  714. 'bul' => 'Bulgarian',
  715. 'cat' => 'Catalan',
  716. 'chi' => 'Chinese',
  717. 'cze' => 'Czech',
  718. 'dan' => 'Danish',
  719. 'dut' => 'Dutch',
  720. 'eng' => 'English',
  721. 'epo' => 'Esperanto',
  722. 'est' => 'Estonian',
  723. 'fin' => 'Finnish',
  724. 'fre' => 'French',
  725. 'geo' => 'Georgian',
  726. 'ger' => 'German',
  727. 'gla' => 'Scottish Gaelic',
  728. 'gre' => 'Greek, Modern',
  729. 'heb' => 'Hebrew',
  730. 'hin' => 'Hindi',
  731. 'hrv' => 'Croatian',
  732. 'hun' => 'Hungarian',
  733. 'ice' => 'Icelandic',
  734. 'ind' => 'Indonesian',
  735. 'ita' => 'Italian',
  736. 'jpn' => 'Japanese',
  737. 'kin' => 'Kinyarwanda',
  738. 'kor' => 'Korean',
  739. 'lat' => 'Latin',
  740. 'lav' => 'Latvian',
  741. 'lit' => 'Lithuanian',
  742. 'mac' => 'Macedonian',
  743. 'mal' => 'Malayalam',
  744. 'mao' => 'Maori',
  745. 'may' => 'Malay',
  746. 'mul' => 'Multiple languages',
  747. 'nor' => 'Norwegian',
  748. 'per' => 'Persian',
  749. 'pol' => 'Polish',
  750. 'por' => 'Portuguese',
  751. 'pus' => 'Pushto',
  752. 'rum' => 'Romanian, Rumanian, Moldovan',
  753. 'rus' => 'Russian',
  754. 'san' => 'Sanskrit',
  755. 'slo' => 'Slovak',
  756. 'slv' => 'Slovenian',
  757. 'spa' => 'Spanish',
  758. 'srp' => 'Serbian',
  759. 'swe' => 'Swedish',
  760. 'tha' => 'Thai',
  761. 'tur' => 'Turkish',
  762. 'ukr' => 'Ukrainian',
  763. 'und' => 'Undetermined',
  764. 'urd' => 'Urdu',
  765. 'vie' => 'Vietnamese',
  766. 'wel' => 'Welsh',
  767. );
  768. return $languages[$lang_abbr];
  769. }