feat: add display name resolution for researchers from ORCID

- Introduced a new function to fetch and extract the display name of researchers from the ORCID API.
- Updated the researcher search response to set the display name if it is not already defined, enhancing researcher data accuracy.
This commit is contained in:
Mireya Cueto Garrido
2026-05-07 12:43:10 +02:00
parent bdb36ee13c
commit 6de277d4f0
2 changed files with 58 additions and 1 deletions
+11 -1
View File
@@ -15,7 +15,7 @@ from app.schema.researcher import (
ResearcherWithPublicationsSchema,
)
from app.services.normalizer import PublicationNormalizer
from app.services.orcid_client import get_works_summary, get_work_detail
from app.services.orcid_client import get_display_name, get_works_summary, get_work_detail
from app.schema.publication import PublicationSchema
from app.db.models import PublicationDownload
from app.security.jwt import get_optional_current_researcher
@@ -159,6 +159,16 @@ def build_search_response(orcid_id: str, db: Session, current: Researcher | None
db.add(researcher)
db.flush()
# Si todavía no conocemos el nombre del investigador (por ejemplo, recién
# creado al sincronizarse desde el buscador), lo resolvemos contra el
# endpoint `/record` público de ORCID. No tocamos un nombre ya existente
# para no pisar valores establecidos por el flujo de autenticación.
if not researcher.name:
display_name = get_display_name(orcid_id)
if display_name:
researcher.name = display_name
db.flush()
publications = _upsert_researcher_publications(researcher, orcid_id, db)
publications_out = _decorate_downloaded_by_me(db=db, current=current, publications=publications)
stats = build_researcher_stats(publications_out)