| 1 | {"translatorID":"fcf41bed-0cbc-3704-85c7-8062a0068a7a","translatorType":4,"label":"NCBI PubMed","creator":"Simon Kornblith and Michael Berkowitz","target":"http://[^/]*www\\.ncbi\\.nlm\\.nih\\.gov[^/]*/(pubmed|sites/entrez|entrez/query\\.fcgi\\?.*db=PubMed)","minVersion":"1.0.0b3.r1","maxVersion":null,"priority":100,"inRepository":true,"lastUpdated":"2008-11-27 05:15:00"} |
|---|
| 2 | |
|---|
| 3 | function detectWeb(doc, url) { |
|---|
| 4 | var namespace = doc.documentElement.namespaceURI; |
|---|
| 5 | var nsResolver = namespace ? function(prefix) { |
|---|
| 6 | if (prefix == 'x') return namespace; else return null; |
|---|
| 7 | } : null; |
|---|
| 8 | |
|---|
| 9 | var uids = doc.evaluate('//input[@id="UidCheckBox" or @name="uid"]', doc, |
|---|
| 10 | nsResolver, XPathResult.ANY_TYPE, null); |
|---|
| 11 | if(uids.iterateNext() && doc.title.indexOf("PMC Results") == -1) { |
|---|
| 12 | if (uids.iterateNext() && doc.title.indexOf("PMC Results") == -1){ |
|---|
| 13 | return "multiple"; |
|---|
| 14 | } |
|---|
| 15 | return "journalArticle"; |
|---|
| 16 | } |
|---|
| 17 | } |
|---|
| 18 | function getPMID(co) { |
|---|
| 19 | var coParts = co.split("&"); |
|---|
| 20 | for each(part in coParts) { |
|---|
| 21 | if(part.substr(0, 7) == "rft_id=") { |
|---|
| 22 | var value = unescape(part.substr(7)); |
|---|
| 23 | if(value.substr(0, 10) == "info:pmid/") { |
|---|
| 24 | return value.substr(10); |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | function detectSearch(item) { |
|---|
| 31 | if(item.contextObject) { |
|---|
| 32 | if(getPMID(item.contextObject)) { |
|---|
| 33 | return "journalArticle"; |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | return false; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | function lookupPMIDs(ids, doc) { |
|---|
| 41 | Zotero.wait(); |
|---|
| 42 | var newUri = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=PubMed&retmode=xml&rettype=citation&id="+ids.join(","); |
|---|
| 43 | Zotero.Utilities.HTTP.doGet(newUri, function(text) { |
|---|
| 44 | // Remove xml parse instruction and doctype |
|---|
| 45 | text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, ""); |
|---|
| 46 | |
|---|
| 47 | var xml = new XML(text); |
|---|
| 48 | |
|---|
| 49 | for(var i=0; i<xml.PubmedArticle.length(); i++) { |
|---|
| 50 | var newItem = new Zotero.Item("journalArticle"); |
|---|
| 51 | |
|---|
| 52 | var citation = xml.PubmedArticle[i].MedlineCitation; |
|---|
| 53 | |
|---|
| 54 | var PMID = citation.PMID.text().toString(); |
|---|
| 55 | newItem.url = "http://www.ncbi.nlm.nih.gov/pubmed/" + PMID; |
|---|
| 56 | newItem.extra = "PMID: "+PMID; |
|---|
| 57 | // add attachments |
|---|
| 58 | if(doc) { |
|---|
| 59 | newItem.attachments.push({document:doc, title:"PubMed Snapshot"}); |
|---|
| 60 | } else { |
|---|
| 61 | var url = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=pubmed&cmd=Retrieve&dopt=AbstractPlus&list_uids="+PMID; |
|---|
| 62 | newItem.attachments.push({url:url, title:"PubMed Snapshot", |
|---|
| 63 | mimeType:"text/html"}); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | var article = citation.Article; |
|---|
| 67 | if(article.ArticleTitle.length()) { |
|---|
| 68 | var title = article.ArticleTitle.text().toString(); |
|---|
| 69 | if(title.substr(-1) == ".") { |
|---|
| 70 | title = title.substring(0, title.length-1); |
|---|
| 71 | } |
|---|
| 72 | newItem.title = title; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | if (article.Pagination.MedlinePgn.length()){ |
|---|
| 76 | newItem.pages = article.Pagination.MedlinePgn.text().toString(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | if(article.Journal.length()) { |
|---|
| 80 | var issn = article.Journal.ISSN.text().toString(); |
|---|
| 81 | if(issn) { |
|---|
| 82 | newItem.ISSN = issn; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | if(citation.MedlineJournalInfo.MedlineTA.length()) { |
|---|
| 86 | newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.MedlineJournalInfo.MedlineTA.text().toString()); |
|---|
| 87 | } |
|---|
| 88 | // newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.Article.Journal.ISOAbbreviation.text().toString()); |
|---|
| 89 | if(article.Journal.Title.length()) { |
|---|
| 90 | newItem.publicationTitle = Zotero.Utilities.superCleanString(article.Journal.Title.text().toString()); |
|---|
| 91 | } else if(citation.MedlineJournalInfo.MedlineTA.length()) { |
|---|
| 92 | newItem.publicationTitle = newItem.journalAbbreviation; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | if(article.Journal.JournalIssue.length()) { |
|---|
| 96 | newItem.volume = article.Journal.JournalIssue.Volume.text().toString(); |
|---|
| 97 | newItem.issue = article.Journal.JournalIssue.Issue.text().toString(); |
|---|
| 98 | if(article.Journal.JournalIssue.PubDate.length()) { // try to get the date |
|---|
| 99 | if(article.Journal.JournalIssue.PubDate.Day.text().toString() != "") { |
|---|
| 100 | newItem.date = article.Journal.JournalIssue.PubDate.Month.text().toString()+" "+article.Journal.JournalIssue.PubDate.Day.text().toString()+", "+article.Journal.JournalIssue.PubDate.Year.text().toString(); |
|---|
| 101 | } else if(article.Journal.JournalIssue.PubDate.Month.text().toString() != "") { |
|---|
| 102 | newItem.date = article.Journal.JournalIssue.PubDate.Month.text().toString()+" "+article.Journal.JournalIssue.PubDate.Year.text().toString(); |
|---|
| 103 | } else if(article.Journal.JournalIssue.PubDate.Year.text().toString() != "") { |
|---|
| 104 | newItem.date = article.Journal.JournalIssue.PubDate.Year.text().toString(); |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | if(article.AuthorList.length() && article.AuthorList.Author.length()) { |
|---|
| 111 | var authors = article.AuthorList.Author; |
|---|
| 112 | for(var j=0; j<authors.length(); j++) { |
|---|
| 113 | var lastName = authors[j].LastName.text().toString(); |
|---|
| 114 | var firstName = authors[j].FirstName.text().toString(); |
|---|
| 115 | if(firstName == "") { |
|---|
| 116 | var firstName = authors[j].ForeName.text().toString(); |
|---|
| 117 | } |
|---|
| 118 | if(firstName || lastName) { |
|---|
| 119 | newItem.creators.push({lastName:lastName, firstName:firstName}); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | if (citation.MeshHeadingList && citation.MeshHeadingList.MeshHeading) { |
|---|
| 126 | var keywords = citation.MeshHeadingList.MeshHeading; |
|---|
| 127 | for (var k = 0 ; k < keywords.length() ; k++) { |
|---|
| 128 | newItem.tags.push(keywords[k].DescriptorName.text().toString()); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | newItem.abstractNote = article.Abstract.AbstractText.toString() |
|---|
| 132 | |
|---|
| 133 | var articleIds = xml.PubmedArticle[i].PubmedData.ArticleIdList.ArticleId.length().toString(); |
|---|
| 134 | for (var l = 0; l < articleIds; l++) { |
|---|
| 135 | if (xml.PubmedArticle[i].PubmedData.ArticleIdList.ArticleId[l].@IdType.toString() == "doi") { |
|---|
| 136 | newItem.DOI = xml.PubmedArticle[i].PubmedData.ArticleIdList.ArticleId[l].text().toString(); |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | newItem.publicationTitle = Zotero.Utilities.capitalizeTitle(newItem.publicationTitle); |
|---|
| 140 | newItem.complete(); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | Zotero.done(); |
|---|
| 144 | }); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | function doWeb(doc, url) { |
|---|
| 148 | var namespace = doc.documentElement.namespaceURI; |
|---|
| 149 | var nsResolver = namespace ? function(prefix) { |
|---|
| 150 | if (prefix == 'x') return namespace; else return null; |
|---|
| 151 | } : null; |
|---|
| 152 | var ids = new Array(); |
|---|
| 153 | var uids = doc.evaluate('//input[@id="UidCheckBox" or @name="uid"]', doc, //edited for new PubMed |
|---|
| 154 | nsResolver, XPathResult.ANY_TYPE, null); |
|---|
| 155 | var uid = uids.iterateNext(); |
|---|
| 156 | if(uid) { |
|---|
| 157 | if (uids.iterateNext()){ |
|---|
| 158 | var items = new Array(); |
|---|
| 159 | var tablex = '//div[@class="rprt"]'; |
|---|
| 160 | if (!doc.evaluate(tablex, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) { |
|---|
| 161 | var tablex = '//div[@class="ResultSet"]/dl'; |
|---|
| 162 | var other = true; |
|---|
| 163 | } |
|---|
| 164 | var tableRows = doc.evaluate(tablex, doc, nsResolver, XPathResult.ANY_TYPE, null); |
|---|
| 165 | var tableRow; |
|---|
| 166 | // Go through table rows |
|---|
| 167 | while(tableRow = tableRows.iterateNext()) { |
|---|
| 168 | uid = doc.evaluate('.//input[@id="UidCheckBox"]', tableRow, nsResolver, XPathResult.ANY_TYPE, null).iterateNext(); |
|---|
| 169 | if (other) { |
|---|
| 170 | var article = doc.evaluate('.//h2', tableRow, nsResolver, XPathResult.ANY_TYPE, null).iterateNext(); |
|---|
| 171 | } else { |
|---|
| 172 | var article = doc.evaluate('.//p[@class="title"]', tableRow, nsResolver, XPathResult.ANY_TYPE, null).iterateNext(); |
|---|
| 173 | } |
|---|
| 174 | items[uid.value] = article.textContent; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | items = Zotero.selectItems(items); |
|---|
| 178 | |
|---|
| 179 | if(!items) { |
|---|
| 180 | return true; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | for(var i in items) { |
|---|
| 184 | ids.push(i); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | lookupPMIDs(ids); |
|---|
| 188 | } else { |
|---|
| 189 | ids.push(uid.value); |
|---|
| 190 | lookupPMIDs(ids, doc); |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | function doSearch(item) { |
|---|
| 196 | // pmid was defined earlier in detectSearch |
|---|
| 197 | lookupPMIDs([getPMID(item.contextObject)]); |
|---|
| 198 | } |
|---|