pubmed.inc 25 KB

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