Corregido errores en llamada de servicios de Patient y DocumentRefernece en el bus

This commit is contained in:
Alejandro Gomez Auad 2026-04-30 11:14:55 +00:00
parent afe6f59ae0
commit 9f5dac1a30
4 changed files with 26 additions and 6 deletions

View File

@ -1,5 +1,5 @@
const config = require('../config');
const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById } = require('../services/patient');
const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById, findPatientByUrl } = require('../services/patient');
const { getBusToken } = require('../utils/busAuth');
/**
@ -12,7 +12,7 @@ async function createPatient(req, res, next) {
try {
const token = await getBusToken(config.bus.url, config.bus.jwtSecret, config.bus.issuer, config.bus.mpiScope);
const response = await busCreatePatient(token, req.body)
const patientResponse = await findPatientById(token, response.headers['location']);
const patientResponse = await findPatientByUrl(token, response.headers['location']);
res.status(200).json(patientResponse.data);
} catch (err) {
next(err);

View File

@ -3,7 +3,7 @@ const createError = require('http-errors');
const config = require('../config');
const { getBusToken, createBusRequest } = require('../utils/busAuth');
const { findPatient } = require('../services/patient');
const { createDocumentReference, findDocumentReferenceById } = require('../services/documentReference');
const { createDocumentReference, findDocumentReferenceById, findDocumentReferenceByUrl } = require('../services/documentReference');
const { logger } = require('../utils/logger');
const { v4: uuidv4 } = require('uuid');
@ -121,7 +121,7 @@ async function createBusDocumentReference(token, localIPSDocument, localPatient)
],
};
const response = await createDocumentReference(token, busDocumentReference);
const created = await findDocumentReferenceById(token, response.headers['location']);
const created = await findDocumentReferenceByUrl(token, response.headers['location']);
return created.data;
}

View File

@ -11,6 +11,8 @@ function maskPrivateURL(patientId) {
return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL);
}
async function findDocumentReferenceById(token, id) {
const request = createBusRequest(token);
const response = await request.get(
@ -19,6 +21,15 @@ async function findDocumentReferenceById(token, id) {
return response;
}
async function findDocumentReferenceByUrl(token, id) {
const request = createBusRequest(token);
const response = await request.get(
URL.parse(id, INDICE_ATENCION_URL)
);
return response;
}
/**
* Posts a DocumentReference to the document registry
* (POST /fhir/DocumentReference).
@ -106,4 +117,5 @@ module.exports = {
findDocumentReferenceBySubject,
findDocumentReferenceByPatient,
searchDocumentReference,
findDocumentReferenceByUrl
};

View File

@ -86,6 +86,14 @@ async function findPatient(token, criteria = {}) {
return response;
}
async function findPatientByUrl(token, url) {
const request = createBusRequest(token);
const response = await request.get(
URL.parse(url, MPI_URL)
);
return response;
}
/**
* Fetches a single Patient by logical ID from the MPI (GET /fhir/Patient/:id).
* @param {string} mpiUrl - Base URL of the MPI service.
@ -135,4 +143,4 @@ async function findPatientByMatch(token, patient, count) {
return response;
}
module.exports = { createPatient, updatePatient, findPatient, findPatientById, findPatientByMatch };
module.exports = { createPatient, findPatientById, findPatientByMatch, findPatientByUrl, updatePatient, findPatient };