pubmed.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. // thre are multiple places where a PMID is present in the XML and
  213. // since this code does not descend into every branch of the XML tree
  214. // we will encounter many of them here. Therefore, we only want the
  215. // PMID that we first encounter. If we already have the PMID we will
  216. // just skip it. Examples of other PMIDs are in the articles that
  217. // cite this one.
  218. $xml->read(); // get the value for this element
  219. if(!$pub['Publication Dbxref']) {
  220. $pub['Publication Dbxref'] = 'PMID:' . $xml->value;
  221. }
  222. break;
  223. case 'Article':
  224. $pub_model = $xml->getAttribute('PubModel');
  225. $pub['Publication Model'] = $pub_model;
  226. tripal_pub_PMID_parse_article($xml, $pub);
  227. break;
  228. case 'MedlineJournalInfo':
  229. tripal_pub_PMID_parse_medline_journal_info($xml, $pub);
  230. break;
  231. case 'ChemicalList':
  232. // TODO: handle this
  233. break;
  234. case 'SupplMeshList':
  235. // TODO: meant for protocol list
  236. break;
  237. case 'CitationSubset':
  238. // TODO: not sure this is needed.
  239. break;
  240. case 'CommentsCorrections':
  241. // TODO: handle this
  242. break;
  243. case 'GeneSymbolList':
  244. // TODO: handle this
  245. break;
  246. case 'MeshHeadingList':
  247. // TODO: Medical subject headings
  248. break;
  249. case 'NumberOfReferences':
  250. // TODO: not sure we should keep this as it changes frequently.
  251. break;
  252. case 'PersonalNameSubjectList':
  253. // TODO: for works about an individual or with biographical note/obituary.
  254. break;
  255. case 'OtherID':
  256. // TODO: ID's from another NLM partner.
  257. break;
  258. case 'OtherAbstract':
  259. // TODO: when the journal does not contain an abstract for the publication.
  260. break;
  261. case 'KeywordList':
  262. // TODO: handle this
  263. break;
  264. case 'InvestigatorList':
  265. // TODO: personal names of individuals who are not authors (can be used with collection)
  266. break;
  267. case 'GeneralNote':
  268. // TODO: handle this
  269. break;
  270. case 'DeleteCitation':
  271. // TODO: need to know how to handle this
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. }
  278. $pub['Citation'] = $pub['Authors'] . '. ' . $pub['Title'] . '. ' .
  279. $pub['Journal ISO Abbreviation'] . '. ' . $pub['Publication Date'];
  280. if ($pub['Volume'] or $pub['Issue']) {
  281. $pub['Citation'] .= '; ';
  282. }
  283. if ($pub['Volume']) {
  284. $pub['Citation'] .= $pub['Volume'];
  285. }
  286. if ($pub['Issue']) {
  287. $pub['Citation'] .= '(' . $pub['Issue'] . ')';
  288. }
  289. if ($pub['Pages']) {
  290. $pub['Citation'] .= ':' . $pub['Pages'];
  291. }
  292. //$pub['xml'] = $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 ISO 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. }