PMID.inc 25 KB

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