From 945f11b75a7e11e5311af4ad5ad6ecd3fc4eef2f Mon Sep 17 00:00:00 2001 From: akhuoa Date: Tue, 10 Dec 2024 12:40:37 +1300 Subject: [PATCH] Fix CORS errors for searching multiple PubMed IDs --- src/services/flatmapQueries.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/services/flatmapQueries.js b/src/services/flatmapQueries.js index 4f69142..e16594a 100644 --- a/src/services/flatmapQueries.js +++ b/src/services/flatmapQueries.js @@ -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)