pubmed.inc 25 KB

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