Skip to content

Commit

Permalink
Merge pull request ABI-Software#220 from akhuoa/bugfix/pubmed-link
Browse files Browse the repository at this point in the history
Fix CORS errors for searching multiple PubMed IDs
  • Loading branch information
alan-wu authored Dec 11, 2024
2 parents 5b76129 + 945f11b commit b442289
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/services/flatmapQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,25 @@ let FlatmapQueries = function () {
//
const promises = []
const results = []
idsList.forEach((id) => {
const wrapped = '"' + id + '"'
const params = new URLSearchParams({
db: 'pubmed',
term: wrapped,
format: 'json'
})
const promise = fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?${params}`, {
method: 'GET',
})
.then((response) => response.json())
.then((data) => {
const newIds = data.esearchresult ? data.esearchresult.idlist : []
results.push(...newIds)
})
promises.push(promise)
let wrapped = ''
idsList.forEach((id, i) => {
wrapped += i > 0 ? 'OR"' + id + '"' : '"' + id + '"'
})

const params = new URLSearchParams({
db: 'pubmed',
term: wrapped,
format: 'json'
})
const promise = fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?${params}`, {
method: 'GET',
})
.then((response) => response.json())
.then((data) => {
const newIds = data.esearchresult ? data.esearchresult.idlist : []
results.push(...newIds)
})
promises.push(promise)

Promise.all(promises).then(() => {
resolve(results)
Expand Down

0 comments on commit b442289

Please sign in to comment.