From 1554bd1f64ea8915611e96d14aa6909bc08563fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Wed, 13 Nov 2024 12:00:54 +0100 Subject: [PATCH] fix(openalex): Use "affiliations" instead of "raw_affiliations_strings" in OpenAlex API --- server/src/utils/works.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/server/src/utils/works.js b/server/src/utils/works.js index 0ac8555..c7ee839 100644 --- a/server/src/utils/works.js +++ b/server/src/utils/works.js @@ -320,21 +320,24 @@ const getTypeFromOpenAlex = (type) => { const getOpenAlexAffiliation = (author) => { const source = 'OpenAlex'; - const rawAffiliation = author.raw_affiliation_strings.join('; '); - let key = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]'); - const label = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]'); - const rors = []; - const rorsToCorrect = []; - author?.institutions?.forEach((institution) => { - if (institution.ror) { - const rorId = (institution.ror).replace('https://ror.org/', '').replace('ror.org/', ''); - const rorElt = { rorCountry: institution.country_code, rorId, rorName: institution.display_name }; - key = `${key}##${rorId}`; - rors.push(rorElt); - rorsToCorrect.push(rorId); - } + return author.affiliations.map((affiliation) => { + const rawAffiliation = affiliation.raw_affiliation_string; + let key = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]'); + const label = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]'); + const rors = []; + const rorsToCorrect = []; + const affiliationIds = affiliation.institution_ids; + const matchedInstitutions = author.institutions.filter((institution) => affiliationIds.includes(institution.id)); + return matchedInstitutions.map((matchedInstitution) => { + if (matchedInstitution?.ror) { + const rorId = (matchedInstitution.ror).replace('https://ror.org/', '').replace('ror.org/', ''); + key = `${label}##${rorId}`; + rors.push({ rorCountry: matchedInstitution.country_code, rorId, rorName: matchedInstitution.display_name }); + rorsToCorrect.push(rorId); + } + return { key, label, rawAffiliation, rors, rorsToCorrect, source }; + }); }); - return { key, label, rawAffiliation, rors, rorsToCorrect, source }; }; const getOpenAlexPublicationsByYear = (options, cursor = '*', previousResponse = [], remainingTries = 3) => {