Trans: Change PubMed to support import
This commit is contained in:
parent
5ff4bd6326
commit
6958518063
|
@ -1,14 +1,15 @@
|
||||||
{
|
{
|
||||||
"translatorID":"fcf41bed-0cbc-3704-85c7-8062a0068a7a",
|
"translatorID":"fcf41bed-0cbc-3704-85c7-8062a0068a7a",
|
||||||
"translatorType":12,
|
"translatorType":13,
|
||||||
"label":"NCBI PubMed",
|
"label":"NCBI PubMed",
|
||||||
"creator":"Simon Kornblith, Michael Berkowitz, Avram Lyon, and Rintze Zelle",
|
"creator":"Simon Kornblith, Michael Berkowitz, Avram Lyon, and Rintze Zelle",
|
||||||
"target":"https?://[^/]*(www|preview)\\.ncbi\\.nlm\\.nih\\.gov[^/]*/(pubmed|sites/pubmed|sites/entrez|entrez/query\\.fcgi\\?.*db=PubMed)",
|
"target":"https?://[^/]*(www|preview)\\.ncbi\\.nlm\\.nih\\.gov[^/]*/(pubmed|sites/pubmed|sites/entrez|entrez/query\\.fcgi\\?.*db=PubMed)",
|
||||||
"minVersion":"2.1b1",
|
"minVersion":"2.1b1",
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":100,
|
"priority":100,
|
||||||
|
"configOptions":{"dataMode":"block"},
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2010-11-17 10:15:00"
|
"lastUpdated":"2011-01-27 10:15:00"
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
|
@ -61,115 +62,145 @@ function detectSearch(item) {
|
||||||
|
|
||||||
|
|
||||||
function lookupPMIDs(ids, doc) {
|
function lookupPMIDs(ids, doc) {
|
||||||
|
var newUri = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=PubMed&tool=Zotero&retmode=xml&rettype=citation&id="+ids.join(",");
|
||||||
|
Zotero.debug(newUri);
|
||||||
|
Zotero.Utilities.HTTP.doGet(newUri, doImportFromText, function () {Zotero.done()});
|
||||||
Zotero.wait();
|
Zotero.wait();
|
||||||
var newUri = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=PubMed&retmode=xml&rettype=citation&id="+ids.join(",");
|
}
|
||||||
Zotero.Utilities.HTTP.doGet(newUri, function(text) {
|
|
||||||
// Remove xml parse instruction and doctype
|
|
||||||
text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, "");
|
|
||||||
|
|
||||||
var xml = new XML(text);
|
function doImport() {
|
||||||
|
var text = "";
|
||||||
|
var line;
|
||||||
|
while((line = Zotero.read(4096)) !== false) {
|
||||||
|
text += line;
|
||||||
|
}
|
||||||
|
return doImportFromText(text);
|
||||||
|
}
|
||||||
|
|
||||||
for(var i=0; i<xml.PubmedArticle.length(); i++) {
|
function detectImport() {
|
||||||
var newItem = new Zotero.Item("journalArticle");
|
Zotero.debug("Detecting Pubmed content....");
|
||||||
|
var text = "";
|
||||||
|
var line;
|
||||||
|
while(line = Zotero.read(1000)) {
|
||||||
|
text += line;
|
||||||
|
// Look for the PubmedArticle tag in the first 1000 characters
|
||||||
|
if (text.match(/<PubmedArticle>/)) return "journalArticle";
|
||||||
|
else if (text.length > 1000) return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var citation = xml.PubmedArticle[i].MedlineCitation;
|
function doImportFromText(text) {
|
||||||
|
// Remove xml parse instruction and doctype
|
||||||
|
text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, "");
|
||||||
|
|
||||||
var PMID = citation.PMID.text().toString();
|
if (!text.substr(0,1000).match(/<PubmedArticleSet>/)) {
|
||||||
newItem.url = "http://www.ncbi.nlm.nih.gov/pubmed/" + PMID;
|
// Pubmed data in the wild, perhaps copied from the web site's search results,
|
||||||
newItem.extra = "PMID: "+PMID;
|
// can be missing the <PubmedArticleSet> root tag. Let's add a pair!
|
||||||
|
Zotero.debug("No root <PubmedArticleSet> tag found, wrapping in a new root tag.");
|
||||||
|
text = "<PubmedArticleSet>" + text + "</PubmedArticleSet>";
|
||||||
|
}
|
||||||
|
|
||||||
var article = citation.Article;
|
var xml = new XML(text);
|
||||||
if(article.ArticleTitle.length()) {
|
|
||||||
var title = article.ArticleTitle.text().toString();
|
for(var i=0; i<xml.PubmedArticle.length(); i++) {
|
||||||
if(title.substr(-1) == ".") {
|
var newItem = new Zotero.Item("journalArticle");
|
||||||
title = title.substring(0, title.length-1);
|
|
||||||
}
|
var citation = xml.PubmedArticle[i].MedlineCitation;
|
||||||
newItem.title = title;
|
|
||||||
|
var PMID = citation.PMID.text().toString();
|
||||||
|
newItem.url = "http://www.ncbi.nlm.nih.gov/pubmed/" + PMID;
|
||||||
|
newItem.extra = "PMID: "+PMID;
|
||||||
|
|
||||||
|
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()){
|
|
||||||
var fullPageRange = article.Pagination.MedlinePgn.text().toString();
|
|
||||||
var pageRange = fullPageRange.match(/\d+-\d+/g);
|
|
||||||
for (var j in pageRange) {
|
|
||||||
var pageRangeStart = pageRange[j].match(/^\d+/)[0];
|
|
||||||
var pageRangeEnd = pageRange[j].match(/\d+$/)[0];
|
|
||||||
if (pageRangeStart.length > pageRangeEnd.length) {
|
|
||||||
pageRangeEnd = pageRangeStart.substring(0,pageRangeStart.length-pageRangeEnd.length) + pageRangeEnd;
|
|
||||||
fullPageRange = fullPageRange.replace(pageRange[j],pageRangeStart+"-"+pageRangeEnd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newItem.pages = fullPageRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(article.Journal.length()) {
|
|
||||||
var issn = article.Journal.ISSN.text().toString();
|
|
||||||
if(issn) {
|
|
||||||
newItem.ISSN = issn;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(citation.Article.Journal.ISOAbbreviation.length()) {
|
|
||||||
newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.Article.Journal.ISOAbbreviation.text().toString());
|
|
||||||
} else if(citation.MedlineJournalInfo.MedlineTA.length()) {
|
|
||||||
newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.MedlineJournalInfo.MedlineTA.text().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(article.Journal.Title.length()) {
|
|
||||||
newItem.publicationTitle = Zotero.Utilities.superCleanString(article.Journal.Title.text().toString());
|
|
||||||
} else if(newItem.journalAbbreviation.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();
|
|
||||||
} else if(article.Journal.JournalIssue.PubDate.MedlineDate.text().toString() != "") {
|
|
||||||
newItem.date = article.Journal.JournalIssue.PubDate.MedlineDate.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 == "") {
|
|
||||||
firstName = authors[j].ForeName.text().toString();
|
|
||||||
}
|
|
||||||
var suffix = authors[j].Suffix.text().toString();
|
|
||||||
if(suffix && firstName != "") {
|
|
||||||
firstName += ", " + authors[j].Suffix.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();
|
if (article.Pagination.MedlinePgn.length()){
|
||||||
});
|
var fullPageRange = article.Pagination.MedlinePgn.text().toString();
|
||||||
|
var pageRange = fullPageRange.match(/\d+-\d+/g);
|
||||||
|
for (var j in pageRange) {
|
||||||
|
var pageRangeStart = pageRange[j].match(/^\d+/)[0];
|
||||||
|
var pageRangeEnd = pageRange[j].match(/\d+$/)[0];
|
||||||
|
if (pageRangeStart.length > pageRangeEnd.length) {
|
||||||
|
pageRangeEnd = pageRangeStart.substring(0,pageRangeStart.length-pageRangeEnd.length) + pageRangeEnd;
|
||||||
|
fullPageRange = fullPageRange.replace(pageRange[j],pageRangeStart+"-"+pageRangeEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newItem.pages = fullPageRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(article.Journal.length()) {
|
||||||
|
var issn = article.Journal.ISSN.text().toString();
|
||||||
|
if(issn) {
|
||||||
|
newItem.ISSN = issn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(citation.Article.Journal.ISOAbbreviation.length()) {
|
||||||
|
newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.Article.Journal.ISOAbbreviation.text().toString());
|
||||||
|
} else if(citation.MedlineJournalInfo.MedlineTA.length()) {
|
||||||
|
newItem.journalAbbreviation = Zotero.Utilities.superCleanString(citation.MedlineJournalInfo.MedlineTA.text().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(article.Journal.Title.length()) {
|
||||||
|
newItem.publicationTitle = Zotero.Utilities.superCleanString(article.Journal.Title.text().toString());
|
||||||
|
} else if(newItem.journalAbbreviation.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();
|
||||||
|
} else if(article.Journal.JournalIssue.PubDate.MedlineDate.text().toString() != "") {
|
||||||
|
newItem.date = article.Journal.JournalIssue.PubDate.MedlineDate.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 == "") {
|
||||||
|
firstName = authors[j].ForeName.text().toString();
|
||||||
|
}
|
||||||
|
var suffix = authors[j].Suffix.text().toString();
|
||||||
|
if(suffix && firstName != "") {
|
||||||
|
firstName += ", " + authors[j].Suffix.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doWeb(doc, url) {
|
function doWeb(doc, url) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user