Compare commits

...

5 Commits

11 changed files with 53 additions and 50 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);
} }
/** /**
@ -36,7 +36,7 @@ async function getDocumentReferencesForPatient(token, patient) {
* Required query parameter: * Required query parameter:
* subject local Patient ID in the Bus. * subject local Patient ID in the Bus.
*/ */
async function findDocumentReferences(req, res, next) { async function listDocumentReference(req, res, next) {
try { try {
const localPatientIdentifier = req.query.subject; const localPatientIdentifier = req.query.subject;
if (!localPatientIdentifier) { if (!localPatientIdentifier) {
@ -65,4 +65,4 @@ async function findDocumentReferences(req, res, next) {
} }
} }
module.exports = { findDocumentReferences }; module.exports = { listDocumentReference };

View File

@ -2,12 +2,12 @@ const createError = require('http-errors');
const axios = require('axios'); const axios = require('axios');
async function getRemoteDocument(url){ async function getRemoteDocument(url) {
const response = await axios.get(parsedUrl.toString(), { const response = await axios.get(parsedUrl.toString(), {
responseType: 'arraybuffer', responseType: 'arraybuffer',
headers: { headers: {
Accept: req.headers['accept'] || '*/*', Accept: req.headers['accept'] || '*/*',
}, },
}); });
return response return response
} }
@ -23,7 +23,7 @@ async function getRemoteDocument(url){
* 2. This gateway performs a P2P GET to that URL, bypassing the Bus. * 2. This gateway performs a P2P GET to that URL, bypassing the Bus.
* 3. The raw document (PDF, XML, etc.) is forwarded back to HIS_A. * 3. The raw document (PDF, XML, etc.) is forwarded back to HIS_A.
*/ */
async function download(req, res, next) { async function getBundleById(req, res, next) {
try { try {
const url = req.query.url; const url = req.query.url;
if (!url) { if (!url) {
@ -52,4 +52,4 @@ async function download(req, res, next) {
} }
} }
module.exports = { download }; module.exports = { getBundleById };

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)
@ -8,10 +8,10 @@ const { searchPatient, getPatientById } = require('../services/patient');
* GET /fhir/Patient * GET /fhir/Patient
* Forwards the raw FHIR query parameters to the Bus and returns the Bundle result. * Forwards the raw FHIR query parameters to the Bus and returns the Bundle result.
*/ */
async function queryPatientDemographics(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);
@ -22,15 +22,15 @@ async function queryPatientDemographics(req, res, next) {
* GET /fhir/Patient/:id * GET /fhir/Patient/:id
* Forwards the request to the Bus and returns the Patient resource. * Forwards the request to the Bus and returns the Patient resource.
*/ */
async function findPatientById(req, res, next) { 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);
} }
} }
module.exports = { queryPatientDemographics, getPatientById: findPatientById }; module.exports = { listPatient, getPatientById };

View File

@ -1,9 +1,9 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { findDocumentReferences } = require('../controllers/iti67'); const { listDocumentReference } = require('../controllers/iti67');
// ITI-67: Find Document References // ITI-67: Find Document References
// TODO: Cambiar ruta por ITI67 // TODO: Cambiar ruta por ITI67
router.get('/iti67', findDocumentReferences); router.get('/iti67', listDocumentReference);
module.exports = router; module.exports = router;

View File

@ -1,8 +1,8 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { download } = require('../controllers/iti68'); const { getBundleById } = require('../controllers/iti68');
// ITI-68: Retrieve Document → GET /fhir/Binary?url=[URL_Directa] // ITI-68: Retrieve Document → GET /fhir/Binary?url=[URL_Directa]
router.get('/Binary', download); router.get('/Bundle', getBundleById);
module.exports = router; module.exports = router;

View File

@ -1,10 +1,10 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { queryPatientDemographics, getPatientById } = require('../controllers/iti78'); const { listPatient, getPatientById } = require('../controllers/iti78');
// ITI-78: Mobile Patient Demographics Query // ITI-78: Mobile Patient Demographics Query
// TOOD: Cambiar ruta por ITI78 // TOOD: Cambiar ruta por ITI78
router.get('/iti78', queryPatientDemographics); router.get('/iti78', listPatient);
router.get('/iti78/:id', getPatientById); router.get('/iti78/:id', getPatientById);
module.exports = router; module.exports = router;

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 };

View File

@ -66,7 +66,7 @@ services:
image: postgres:16-alpine image: postgres:16-alpine
restart: always restart: always
volumes: volumes:
- db-data:/var/lib/postgresql/data - gdhcn-data:/var/lib/postgresql/data
networks: networks:
- hapi-network - hapi-network
environment: environment:
@ -122,6 +122,9 @@ volumes:
hapi-data: hapi-data:
name: hapi-data name: hapi-data
driver: local driver: local
gdhcn-data:
name: gdhcn-data
driver: local
secrets: secrets:
ssl_cert: ssl_cert:
file: ${SSL_CERT_PATH:-./certs/server.crt} file: ${SSL_CERT_PATH:-./certs/server.crt}