diff --git a/bus-gateway/controllers/iti104.js b/bus-gateway/controllers/iti104.js index 391e3f7..f038a96 100644 --- a/bus-gateway/controllers/iti104.js +++ b/bus-gateway/controllers/iti104.js @@ -1,5 +1,5 @@ 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'); /** @@ -11,8 +11,8 @@ const { getBusToken} = require('../utils/busAuth'); 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 postPatient(token, req.body) - const patientResponse = await getPatientById(token, response.headers['location']); + const response = await busCreatePatient(token, req.body) + const patientResponse = await findPatientById(token, response.headers['location']); res.status(200).json(patientResponse.data); } catch (err) { next(err); @@ -26,7 +26,7 @@ async function createPatient(req, res, next) { async function updatePatient(req, res, next) { try { 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); } catch (err) { next(err); diff --git a/bus-gateway/controllers/iti65.js b/bus-gateway/controllers/iti65.js index d63969e..514f64b 100644 --- a/bus-gateway/controllers/iti65.js +++ b/bus-gateway/controllers/iti65.js @@ -2,8 +2,8 @@ const axios = require('axios'); const createError = require('http-errors'); const config = require('../config'); const { getBusToken, createBusRequest } = require('../utils/busAuth'); -const { searchPatient } = require('../services/patient'); -const { postDocumentReference, fetchDocumentReference } = require('../services/documentReference'); +const { findPatient } = require('../services/patient'); +const { createDocumentReference, findDocumentReferenceById } = require('../services/documentReference'); const { logger } = require('../utils/logger'); const { v4: uuidv4 } = require('uuid'); @@ -62,7 +62,7 @@ async function getBusCustodianIdentifier() { async function getBusPatientReference(patient, token) { 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; if (nationalPatientBundle.total == 0) { throw createError(404, 'Patient does not exists'); @@ -120,8 +120,8 @@ async function createBusDocumentReference(token, localIPSDocument, localPatient) }, ], }; - const response = await postDocumentReference(token, busDocumentReference); - const created = await fetchDocumentReference(token, response.headers['location']); + const response = await createDocumentReference(token, busDocumentReference); + const created = await findDocumentReferenceById(token, response.headers['location']); return created.data; } diff --git a/bus-gateway/controllers/iti67.js b/bus-gateway/controllers/iti67.js index d4799e8..49c49c4 100644 --- a/bus-gateway/controllers/iti67.js +++ b/bus-gateway/controllers/iti67.js @@ -1,8 +1,8 @@ const createError = require('http-errors'); const config = require('../config'); const { getBusToken } = require('../utils/busAuth'); -const { getPatientById, searchPatient } = require('../services/patient'); -const { searchDocumentReferenceByPatient } = require('../services/documentReference'); +const { findPatient } = require('../services/patient'); +const { findDocumentReferenceByPatient } = require('../services/documentReference'); const NATIONAL_ID_SYSTEM = 'https://federador.msal.gob.ar/patient-id'; @@ -15,12 +15,12 @@ function extractNationalIdentifier(patient) { } 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); } async function getDocumentReferencesForPatient(token, patient) { - const response = await searchDocumentReferenceByPatient(token, patient) + const response = await findDocumentReferenceByPatient(token, patient) return Promise.resolve(response.data); } /** diff --git a/bus-gateway/controllers/iti78.js b/bus-gateway/controllers/iti78.js index 5afc0bb..4ba5aa4 100644 --- a/bus-gateway/controllers/iti78.js +++ b/bus-gateway/controllers/iti78.js @@ -1,6 +1,6 @@ const config = require('../config'); 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) @@ -11,7 +11,7 @@ const { searchPatient, getPatientById } = require('../services/patient'); async function listPatient(req, res, next) { try { 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); } catch (err) { next(err); @@ -26,7 +26,7 @@ async function getPatientById(req, res, next) { try { const { id } = req.params; 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); } catch (err) { next(err); diff --git a/bus-gateway/services/documentReference.js b/bus-gateway/services/documentReference.js index 09fd886..3ca08c6 100644 --- a/bus-gateway/services/documentReference.js +++ b/bus-gateway/services/documentReference.js @@ -11,10 +11,10 @@ function maskPrivateURL(patientId) { return patientId.replace(LOCAL_URL, INDICE_ATENCION_URL); } -async function fetchDocumentReference(token, id) { +async function findDocumentReferenceById(token, id) { const request = createBusRequest(token); const response = await request.get( - URL.parse(id, INDICE_ATENCION_URL) + URL.parse(`${INDICE_ATENCION_URL}/${id}`) ); return response; } @@ -28,7 +28,7 @@ async function fetchDocumentReference(token, id) { * @returns {Promise} 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| */ -async function postDocumentReference(token, documentReference) { +async function createDocumentReference(token, documentReference) { const request = createBusRequest(token); const response = await request.post( URL.parse(INDICE_ATENCION_URL), @@ -46,7 +46,7 @@ async function postDocumentReference(token, documentReference) { * @param {string} subjectValue - Identifier value of the patient. * @returns {Promise} FHIR Bundle (searchset) with matching DocumentReferences. */ -async function searchDocumentReferenceBySubject(token, subjectSystem, subjectValue) { +async function findDocumentReferenceBySubject(token, subjectSystem, subjectValue) { const request = createBusRequest(token); const response = await request.get( 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. * @returns {Promise} FHIR Bundle (searchset) with matching DocumentReferences. */ -async function searchDocumentReferenceByPatient(token, patientId) { +async function findDocumentReferenceByPatient(token, patientId) { const request = createBusRequest(token); const response = await request.get( URL.parse(INDICE_ATENCION_URL), @@ -101,9 +101,9 @@ async function searchDocumentReference(token, subject, custodian, type) { } module.exports = { - fetchDocumentReference, - postDocumentReference, - searchDocumentReferenceBySubject, - searchDocumentReferenceByPatient, + findDocumentReferenceById, + createDocumentReference, + findDocumentReferenceBySubject, + findDocumentReferenceByPatient, searchDocumentReference, }; diff --git a/bus-gateway/services/patient.js b/bus-gateway/services/patient.js index d702418..0a2ac1c 100644 --- a/bus-gateway/services/patient.js +++ b/bus-gateway/services/patient.js @@ -18,7 +18,7 @@ function maskPrivateURL(patientId) { * @param {object} patient - The Patient resource. * @returns {Promise} Response data from the MPI. */ -async function postPatient(token, patient) { +async function createPatient(token, patient) { const request = createBusRequest(token); const response = await request.post( 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 response = await request.put( URL.parse(`${MPI_URL}/${id}`), @@ -54,7 +54,7 @@ async function putPatient(token, patient, id) { * @param {string} [criteria.gender] - Gender (male | female | other | unknown) * @returns {Promise} FHIR Bundle (searchset) with matching patients. */ -async function searchPatient(token, criteria = {}) { +async function findPatient(token, criteria = {}) { const request = createBusRequest(token); const params = {}; @@ -93,7 +93,7 @@ async function searchPatient(token, criteria = {}) { * @param {string} id - Logical Patient ID. * @returns {Promise} FHIR Patient resource. */ -async function getPatientById(token, id) { +async function findPatientById(token, id) { const request = createBusRequest(token); const response = await request.get( 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). * @returns {Promise} FHIR Bundle (searchset) with match scores. */ -async function matchPatient(token, patient, count) { +async function findPatientByMatch(token, patient, count) { const request = createBusRequest(token); const parameters = { resourceType: 'Parameters', @@ -135,4 +135,4 @@ async function matchPatient(token, patient, count) { return response; } -module.exports = { putPatient, postPatient, getPatientById, searchPatient, matchPatient }; +module.exports = { createPatient, updatePatient, findPatient, findPatientById, findPatientByMatch };