Corregido errores en llamada de servicios de Patient y DocumentRefernece en el bus
This commit is contained in:
parent
afe6f59ae0
commit
9f5dac1a30
@ -1,6 +1,6 @@
|
||||
const config = require('../config');
|
||||
const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById } = require('../services/patient');
|
||||
const { getBusToken} = require('../utils/busAuth');
|
||||
const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById, findPatientByUrl } = require('../services/patient');
|
||||
const { getBusToken } = require('../utils/busAuth');
|
||||
|
||||
/**
|
||||
* ITI-104: Patient Identity Feed FHIR (PMIR)
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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 };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user