PMID.inc 27 KB

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