Normalizados los nombres de los metodos de bus-gateway

This commit is contained in:
Alejandro Gomez Auad 2026-04-30 04:41:23 +00:00
parent a873231843
commit 1a0f7b76b8
6 changed files with 31 additions and 31 deletions

View File

@ -1,5 +1,5 @@
const config = require('../config'); const config = require('../config');
const { postPatient, putPatient, getPatientById } = require('../services/patient'); const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById } = require('../services/patient');
const { getBusToken} = require('../utils/busAuth'); const { getBusToken} = require('../utils/busAuth');
/** /**
@ -11,8 +11,8 @@ const { getBusToken} = require('../utils/busAuth');
async function createPatient(req, res, next) { 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 postPatient(token, req.body) const response = await busCreatePatient(token, req.body)
const patientResponse = await getPatientById(token, response.headers['location']); const patientResponse = await findPatientById(token, response.headers['location']);
res.status(200).json(patientResponse.data); res.status(200).json(patientResponse.data);
} catch (err) { } catch (err) {
next(err); next(err);
@ -26,7 +26,7 @@ async function createPatient(req, res, next) {
async function updatePatient(req, res, next) { async function updatePatient(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 putPatient(token, req.body) const response = await busUpdatePatient(token, req.body)
res.status(200).json(response.data); res.status(200).json(response.data);
} catch (err) { } catch (err) {
next(err); next(err);

View File

@ -2,8 +2,8 @@ const axios = require('axios');
const createError = require('http-errors'); 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 { searchPatient } = require('../services/patient'); const { findPatient } = require('../services/patient');
const { postDocumentReference, fetchDocumentReference } = require('../services/documentReference'); const { createDocumentReference, findDocumentReferenceById } = require('../services/documentReference');
const { logger } = require('../utils/logger'); const { logger } = require('../utils/logger');
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
@ -62,7 +62,7 @@ async function getBusCustodianIdentifier() {
async function getBusPatientReference(patient, token) { async function getBusPatientReference(patient, token) {
const localIdentifier = extractLocalIdentifier(patient); const localIdentifier = extractLocalIdentifier(patient);
const nationalPatientResponse = await searchPatient(token, { identifier: `${localIdentifier.system}|${localIdentifier.value}` }); const nationalPatientResponse = await findPatient(token, { identifier: `${localIdentifier.system}|${localIdentifier.value}` });
const nationalPatientBundle = nationalPatientResponse.data; const nationalPatientBundle = nationalPatientResponse.data;
if (nationalPatientBundle.total == 0) { if (nationalPatientBundle.total == 0) {
throw createError(404, 'Patient does not exists'); throw createError(404, 'Patient does not exists');
@ -120,8 +120,8 @@ async function createBusDocumentReference(token, localIPSDocument, localPatient)
}, },
], ],
}; };
const response = await postDocumentReference(token, busDocumentReference); const response = await createDocumentReference(token, busDocumentReference);
const created = await fetchDocumentReference(token, response.headers['location']); const created = await findDocumentReferenceById(token, response.headers['location']);
return created.data; return created.data;
} }

View File

@ -1,8 +1,8 @@
const createError = require('http-errors'); const createError = require('http-errors');
const config = require('../config'); const config = require('../config');
const { getBusToken } = require('../utils/busAuth'); const { getBusToken } = require('../utils/busAuth');
const { getPatientById, searchPatient } = require('../services/patient'); const { findPatient } = require('../services/patient');
const { searchDocumentReferenceByPatient } = require('../services/documentReference'); const { findDocumentReferenceByPatient } = require('../services/documentReference');
const NATIONAL_ID_SYSTEM = 'https://federador.msal.gob.ar/patient-id'; const NATIONAL_ID_SYSTEM = 'https://federador.msal.gob.ar/patient-id';
@ -15,12 +15,12 @@ function extractNationalIdentifier(patient) {
} }
async function getPatient(token, identifier) { async function getPatient(token, identifier) {
const response = await searchPatient(token, { identifier: identifier }); const response = await findPatient(token, { identifier: identifier });
return Promise.resolve(response.data.entry[0].fullUrl); return Promise.resolve(response.data.entry[0].fullUrl);
} }
async function getDocumentReferencesForPatient(token, patient) { async function getDocumentReferencesForPatient(token, patient) {
const response = await searchDocumentReferenceByPatient(token, patient) const response = await findDocumentReferenceByPatient(token, patient)
return Promise.resolve(response.data); return Promise.resolve(response.data);
} }
/** /**

View File

@ -1,6 +1,6 @@
const config = require('../config'); const config = require('../config');
const { getBusToken, createBusRequest } = require('../utils/busAuth'); const { getBusToken, createBusRequest } = require('../utils/busAuth');
const { searchPatient, getPatientById } = require('../services/patient'); const { findPatient, findPatientById } = require('../services/patient');
/** /**
* ITI-78: Mobile Patient Demographics Query (PDQm) * ITI-78: Mobile Patient Demographics Query (PDQm)
@ -11,7 +11,7 @@ const { searchPatient, getPatientById } = require('../services/patient');
async function listPatient(req, res, next) { async function listPatient(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 searchPatient(token, req.query); const response = await findPatient(token, req.query);
res.status(200).json(response.data); res.status(200).json(response.data);
} catch (err) { } catch (err) {
next(err); next(err);
@ -26,7 +26,7 @@ async function getPatientById(req, res, next) {
try { try {
const { id } = req.params; const { id } = req.params;
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 getPatientById(token, id) const response = await findPatientById(token, id)
res.status(200).json(response.data); res.status(200).json(response.data);
} catch (err) { } catch (err) {
next(err); next(err);

View File

@ -11,10 +11,10 @@ function maskPrivateURL(patientId) {
return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL); return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL);
} }
async function fetchDocumentReference(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(
URL.parse(id, INDICE_ATENCION_URL) URL.parse(`${INDICE_ATENCION_URL}/${id}`)
); );
return response; return response;
} }
@ -28,7 +28,7 @@ async function fetchDocumentReference(token, id) {
* @returns {Promise<object>} The created DocumentReference resource returned by the registry. * @returns {Promise<object>} The created DocumentReference resource returned by the registry.
* @todo Agregar system http://federador.msal.gob.ar/uri para armar el identificador del custodian: http://federador.msal.gob.ar/uri|<custodianId> * @todo Agregar system http://federador.msal.gob.ar/uri para armar el identificador del custodian: http://federador.msal.gob.ar/uri|<custodianId>
*/ */
async function postDocumentReference(token, documentReference) { async function createDocumentReference(token, documentReference) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.post( const response = await request.post(
URL.parse(INDICE_ATENCION_URL), URL.parse(INDICE_ATENCION_URL),
@ -46,7 +46,7 @@ async function postDocumentReference(token, documentReference) {
* @param {string} subjectValue - Identifier value of the patient. * @param {string} subjectValue - Identifier value of the patient.
* @returns {Promise<object>} FHIR Bundle (searchset) with matching DocumentReferences. * @returns {Promise<object>} FHIR Bundle (searchset) with matching DocumentReferences.
*/ */
async function searchDocumentReferenceBySubject(token, subjectSystem, subjectValue) { async function findDocumentReferenceBySubject(token, subjectSystem, subjectValue) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.get( const response = await request.get(
URL.parse(INDICE_ATENCION_URL), URL.parse(INDICE_ATENCION_URL),
@ -65,7 +65,7 @@ async function searchDocumentReferenceBySubject(token, subjectSystem, subjectVal
* @param {string} patientId - Internal patient ID in the document registry. * @param {string} patientId - Internal patient ID in the document registry.
* @returns {Promise<object>} FHIR Bundle (searchset) with matching DocumentReferences. * @returns {Promise<object>} FHIR Bundle (searchset) with matching DocumentReferences.
*/ */
async function searchDocumentReferenceByPatient(token, patientId) { async function findDocumentReferenceByPatient(token, patientId) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.get( const response = await request.get(
URL.parse(INDICE_ATENCION_URL), URL.parse(INDICE_ATENCION_URL),
@ -101,9 +101,9 @@ async function searchDocumentReference(token, subject, custodian, type) {
} }
module.exports = { module.exports = {
fetchDocumentReference, findDocumentReferenceById,
postDocumentReference, createDocumentReference,
searchDocumentReferenceBySubject, findDocumentReferenceBySubject,
searchDocumentReferenceByPatient, findDocumentReferenceByPatient,
searchDocumentReference, searchDocumentReference,
}; };

View File

@ -18,7 +18,7 @@ function maskPrivateURL(patientId) {
* @param {object} patient - The Patient resource. * @param {object} patient - The Patient resource.
* @returns {Promise<object>} Response data from the MPI. * @returns {Promise<object>} Response data from the MPI.
*/ */
async function postPatient(token, patient) { async function createPatient(token, patient) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.post( const response = await request.post(
URL.parse(MPI_URL), URL.parse(MPI_URL),
@ -29,7 +29,7 @@ async function postPatient(token, patient) {
} }
async function putPatient(token, patient, id) { async function updatePatient(token, patient, id) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.put( const response = await request.put(
URL.parse(`${MPI_URL}/${id}`), URL.parse(`${MPI_URL}/${id}`),
@ -54,7 +54,7 @@ async function putPatient(token, patient, id) {
* @param {string} [criteria.gender] - Gender (male | female | other | unknown) * @param {string} [criteria.gender] - Gender (male | female | other | unknown)
* @returns {Promise<object>} FHIR Bundle (searchset) with matching patients. * @returns {Promise<object>} FHIR Bundle (searchset) with matching patients.
*/ */
async function searchPatient(token, criteria = {}) { async function findPatient(token, criteria = {}) {
const request = createBusRequest(token); const request = createBusRequest(token);
const params = {}; const params = {};
@ -93,7 +93,7 @@ async function searchPatient(token, criteria = {}) {
* @param {string} id - Logical Patient ID. * @param {string} id - Logical Patient ID.
* @returns {Promise<object>} FHIR Patient resource. * @returns {Promise<object>} FHIR Patient resource.
*/ */
async function getPatientById(token, id) { async function findPatientById(token, id) {
const request = createBusRequest(token); const request = createBusRequest(token);
const response = await request.get( const response = await request.get(
URL.parse(`${MPI_URL}/${id}`) URL.parse(`${MPI_URL}/${id}`)
@ -109,7 +109,7 @@ async function getPatientById(token, id) {
* @param {number} [count] - Maximum number of results to return (must be > 0). * @param {number} [count] - Maximum number of results to return (must be > 0).
* @returns {Promise<object>} FHIR Bundle (searchset) with match scores. * @returns {Promise<object>} FHIR Bundle (searchset) with match scores.
*/ */
async function matchPatient(token, patient, count) { async function findPatientByMatch(token, patient, count) {
const request = createBusRequest(token); const request = createBusRequest(token);
const parameters = { const parameters = {
resourceType: 'Parameters', resourceType: 'Parameters',
@ -135,4 +135,4 @@ async function matchPatient(token, patient, count) {
return response; return response;
} }
module.exports = { putPatient, postPatient, getPatientById, searchPatient, matchPatient }; module.exports = { createPatient, updatePatient, findPatient, findPatientById, findPatientByMatch };