Corregido errores en llamada de servicios de Patient y DocumentRefernece en el bus
This commit is contained in:
parent
afe6f59ae0
commit
9f5dac1a30
@ -1,5 +1,5 @@
|
|||||||
const config = require('../config');
|
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');
|
const { getBusToken } = require('../utils/busAuth');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +12,7 @@ async function createPatient(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
const token = await getBusToken(config.bus.url, config.bus.jwtSecret, config.bus.issuer, config.bus.mpiScope);
|
const token = await getBusToken(config.bus.url, config.bus.jwtSecret, config.bus.issuer, config.bus.mpiScope);
|
||||||
const response = await busCreatePatient(token, req.body)
|
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);
|
res.status(200).json(patientResponse.data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const createError = require('http-errors');
|
|||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
const { getBusToken, createBusRequest } = require('../utils/busAuth');
|
const { getBusToken, createBusRequest } = require('../utils/busAuth');
|
||||||
const { findPatient } = require('../services/patient');
|
const { findPatient } = require('../services/patient');
|
||||||
const { createDocumentReference, findDocumentReferenceById } = require('../services/documentReference');
|
const { createDocumentReference, findDocumentReferenceById, findDocumentReferenceByUrl } = require('../services/documentReference');
|
||||||
const { logger } = require('../utils/logger');
|
const { logger } = require('../utils/logger');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ async function createBusDocumentReference(token, localIPSDocument, localPatient)
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
const response = await createDocumentReference(token, busDocumentReference);
|
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;
|
return created.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,8 @@ function maskPrivateURL(patientId) {
|
|||||||
return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL);
|
return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function findDocumentReferenceById(token, id) {
|
async function findDocumentReferenceById(token, id) {
|
||||||
const request = createBusRequest(token);
|
const request = createBusRequest(token);
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
@ -19,6 +21,15 @@ async function findDocumentReferenceById(token, id) {
|
|||||||
return response;
|
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
|
* Posts a DocumentReference to the document registry
|
||||||
* (POST /fhir/DocumentReference).
|
* (POST /fhir/DocumentReference).
|
||||||
@ -106,4 +117,5 @@ module.exports = {
|
|||||||
findDocumentReferenceBySubject,
|
findDocumentReferenceBySubject,
|
||||||
findDocumentReferenceByPatient,
|
findDocumentReferenceByPatient,
|
||||||
searchDocumentReference,
|
searchDocumentReference,
|
||||||
|
findDocumentReferenceByUrl
|
||||||
};
|
};
|
||||||
|
|||||||
@ -86,6 +86,14 @@ async function findPatient(token, criteria = {}) {
|
|||||||
return response;
|
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).
|
* Fetches a single Patient by logical ID from the MPI (GET /fhir/Patient/:id).
|
||||||
* @param {string} mpiUrl - Base URL of the MPI service.
|
* @param {string} mpiUrl - Base URL of the MPI service.
|
||||||
@ -135,4 +143,4 @@ async function findPatientByMatch(token, patient, count) {
|
|||||||
return response;
|
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