diff --git a/bus-gateway/controllers/iti67.js b/bus-gateway/controllers/iti67.js index bb079b6..5024ad3 100644 --- a/bus-gateway/controllers/iti67.js +++ b/bus-gateway/controllers/iti67.js @@ -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)