pubmed.inc 25 KB

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