Fix ITI-67 patient national ID resolution to use the Federador identifier

listDocumentReference was using the Patient entry's fullUrl as the
national ID passed to the document registry search. It now extracts
the Patient identifier whose system is the Federador national-id
system and builds a system|value token, wiring in the previously
unused extractNationalIdentifier helper.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Alejandro Gomez Auad 2026-07-16 22:28:22 +00:00
parent 387ee331ed
commit b2bc5549ff

View File

@ -56,12 +56,15 @@ async function listDocumentReference(req, res, next) {
config.bus.documentRegistryScope
].join(',')
);
// 1. Obtengo el identificador nacional del paciente en forma de referencia
// 1. Obtengo el identificador nacional del paciente (identifier con system
// NATIONAL_ID_SYSTEM), como token FHIR `system|value`.
const patientSearchset = await findPatient(token, { identifier: localPatientIdentifier });
if (!patientSearchset) {
const patientResource = patientSearchset?.entry?.[0]?.resource;
const nationalIdentifier = patientResource && extractNationalIdentifier(patientResource);
if (!nationalIdentifier) {
throw createError(422, 'Could not resolve national identifier for the given patient');
}
const patientNationalId = patientSearchset.entry[0].fullUrl
const patientNationalId = `${nationalIdentifier.system}|${nationalIdentifier.value}`;
// 2. Obtengo el listado de entradas del indice de atenciones asociadada al id de paciente
// (y, si se pidió, al tipo de documento).
const documentReferenceSearchset = await findDocumentReferenceByPatient(token, patientNationalId, documentType)