This commit is contained in:
2023-02-04 17:17:48 -08:00
parent bfbf2ff239
commit ea2aea1fc8
6 changed files with 97 additions and 44 deletions

View File

@@ -1,18 +1,45 @@
searchQuery = "science[journal]+AND+breast+cancer+AND+2008[pdat]";
let searchQuery = "science[journal]+AND+breast+cancer+AND+2008[pdat]";
let url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
function testSearch(query) {
fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${query}`)
function testSearchPubmed(query) {
fetch(`${url}/esearch.fcgi?db=pubmed&term=${query}`)
.then((res) => {
console.log(`Status: ${res.status}`);
let reader = res.body.getReader();
// while (!reader.closed) {
reader.read().then(out => {
// console.log(out)
var decoder = new TextDecoder('utf8');
console.log(decoder.decode(out.value));
res.blob().then(val => {
val.text().then(val => {
let xmlParser = (new DOMParser()).parseFromString(val, "text/xml");
let els = xmlParser.getElementsByTagName("Id");
let ids = [];
for (let i = 0; i < els.length; i++) {
ids.push(els[i].innerHTML);
}
console.log(ids);
return ids;
})
})
});
}
function testSearchGene(query) {
fetch(`${url}/esearch.fcgi?db=gene&term=${query}`)
.then((res) => {
res.blob().then(val => {
val.text().then(val => {
console.log(val);
})
})
});
}
function testLookupGeneById(ids) {
fetch(`${url}/esummary.fcgi?db=gene&id=${String(ids)}`)
.then(res => {
res.blob().then(val => {
val.text().then(val => {
console.log(val)
})
})
// }
})
}
testSearch(searchQuery);
testLookupGeneById(7157);