Created
April 18, 2009 13:24
-
-
Save rmzelle/97601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPMID(co) { | |
var coParts = co.split("&"); | |
for each(part in coParts) { | |
if(part.substr(0, 7) == "rft_id=") { | |
var value = unescape(part.substr(7)); | |
if(value.substr(0, 10) == "info:pmid/") { | |
return value.substr(10); | |
} | |
} | |
} | |
} | |
function detectSearch(item) { | |
if(item.contextObject) { | |
if(getPMID(item.contextObject)) { | |
return "journalArticle"; | |
} | |
} | |
return false; | |
} | |
function lookupPMIDs(ids, doc) { | |
Zotero.wait(); | |
var newUri = "http://books.google.com/books/feeds/volumes/"+ids; | |
Zotero.debug(newUri); | |
Zotero.Utilities.HTTP.doGet(newUri, function(text) { | |
// Remove xml parse instruction and doctype | |
text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, ""); | |
var xml = new XML(text); //RZ: this seems to work okay | |
Zotero.debug(xml); | |
Zotero.debug(xml.entry.id.text().toString()); //RZ: this doesn't give a result | |
for(var i=0; i<xml.entry.length(); i++) { | |
var newItem = new Zotero.Item("book"); | |
var citation = xml.PubmedArticle[i].MedlineCitation; | |
var PMID = citation.PMID.text().toString(); | |
newItem.url = "http://www.ncbi.nlm.nih.gov/pubmed/" + PMID; | |
newItem.extra = "PMID: "+PMID; | |
// add attachments | |
if(doc) { | |
newItem.attachments.push({document:doc, title:"PubMed Snapshot"}); | |
} else { | |
var url = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=pubmed&cmd=Retrieve&dopt=AbstractPlus&list_uids="+PMID; | |
newItem.attachments.push({url:url, title:"PubMed Snapshot", | |
mimeType:"text/html"}); | |
} | |
var article = citation.Article; | |
if(article.ArticleTitle.length()) { | |
var title = article.ArticleTitle.text().toString(); | |
if(title.substr(-1) == ".") { | |
title = title.substring(0, title.length-1); | |
} | |
newItem.title = title; | |
} | |
if (article.Pagination.MedlinePgn.length()){ | |
newItem.pages = article.Pagination.MedlinePgn.text().toString(); | |
} | |
if(article.Journal.length()) { | |
var issn = article.Journal.ISSN.text().toString(); | |
if(issn) { | |
newItem.ISSN = issn; | |
} | |
if(citation.MedlineJournalInfo.MedlineTA.length()) { | |
newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.MedlineJournalInfo.MedlineTA.text().toString()); | |
} | |
// newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.Article.Journal.ISOAbbreviation.text().toString()); | |
if(article.Journal.Title.length()) { | |
newItem.publicationTitle = Zotero.Utilities.superCleanString(article.Journal.Title.text().toString()); | |
} else if(citation.MedlineJournalInfo.MedlineTA.length()) { | |
newItem.publicationTitle = newItem.journalAbbreviation; | |
} | |
if(article.Journal.JournalIssue.length()) { | |
newItem.volume = article.Journal.JournalIssue.Volume.text().toString(); | |
newItem.issue = article.Journal.JournalIssue.Issue.text().toString(); | |
if(article.Journal.JournalIssue.PubDate.length()) { // try to get the date | |
if(article.Journal.JournalIssue.PubDate.Day.text().toString() != "") { | |
newItem.date = article.Journal.JournalIssue.PubDate.Month.text().toString()+" "+article.Journal.JournalIssue.PubDate.Day.text().toString()+", "+article.Journal.JournalIssue.PubDate.Year.text().toString(); | |
} else if(article.Journal.JournalIssue.PubDate.Month.text().toString() != "") { | |
newItem.date = article.Journal.JournalIssue.PubDate.Month.text().toString()+" "+article.Journal.JournalIssue.PubDate.Year.text().toString(); | |
} else if(article.Journal.JournalIssue.PubDate.Year.text().toString() != "") { | |
newItem.date = article.Journal.JournalIssue.PubDate.Year.text().toString(); | |
} | |
} | |
} | |
} | |
if(article.AuthorList.length() && article.AuthorList.Author.length()) { | |
var authors = article.AuthorList.Author; | |
for(var j=0; j<authors.length(); j++) { | |
var lastName = authors[j].LastName.text().toString(); | |
var firstName = authors[j].FirstName.text().toString(); | |
if(firstName == "") { | |
var firstName = authors[j].ForeName.text().toString(); | |
} | |
if(firstName || lastName) { | |
newItem.creators.push({lastName:lastName, firstName:firstName}); | |
} | |
} | |
} | |
if (citation.MeshHeadingList && citation.MeshHeadingList.MeshHeading) { | |
var keywords = citation.MeshHeadingList.MeshHeading; | |
for (var k = 0 ; k < keywords.length() ; k++) { | |
newItem.tags.push(keywords[k].DescriptorName.text().toString()); | |
} | |
} | |
newItem.abstractNote = article.Abstract.AbstractText.toString() | |
newItem.DOI = xml.PubmedArticle[i].PubmedData.ArticleIdList.ArticleId.(@IdType == "doi" ).text().toString(); | |
newItem.publicationTitle = Zotero.Utilities.capitalizeTitle(newItem.publicationTitle); | |
newItem.complete(); | |
} | |
Zotero.done(); | |
}); | |
} | |
function doWeb(doc, url) { | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == 'x') return namespace; else return null; | |
} : null; | |
var ids = new Array(); | |
ids.push("WDll8hA006AC"); | |
Zotero.debug(ids); | |
lookupPMIDs(ids, doc); | |
} | |
function doSearch(item) { | |
// pmid was defined earlier in detectSearch | |
lookupPMIDs([getPMID(item.contextObject)]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment