Nuevas rutas GET /fhir/Bundle/:id/$ddcc, $dvc, $icvp2 y $meow: obtienen el Bundle del HAPI FHIR local y delegan la transformación al nodo nacional (bundle-signer), que es quien tiene las claves de firma, devolviendo la respuesta tal cual. Se agrega BUNDLE_SIGNER_URL como variable de entorno requerida para configurar la URL del nodo nacional. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
const axios = require('axios');
|
|
const config = require('../config');
|
|
|
|
/**
|
|
* Fetches the Bundle from the local HAPI FHIR server and delegates the
|
|
* transformation to the national node (bundle-signer), which holds the
|
|
* signing keys. Returns the national node's response as-is.
|
|
*/
|
|
async function transformBundle(id, operation, query) {
|
|
const bundleUrl = `${config.fhir.url}/Bundle/${id}`;
|
|
const { data: bundle } = await axios.get(bundleUrl);
|
|
|
|
const response = await axios.post(
|
|
`${config.bundleSigner.url}/Bundle/$${operation}`,
|
|
bundle,
|
|
{ params: query },
|
|
);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* GET /fhir/Bundle/:id/$ddcc
|
|
*/
|
|
async function getDDCC(req, res, next) {
|
|
try {
|
|
const response = await transformBundle(req.params.id, 'ddcc', req.query);
|
|
res.status(response.status).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET /fhir/Bundle/:id/$dvc
|
|
*/
|
|
async function getDVC(req, res, next) {
|
|
try {
|
|
const response = await transformBundle(req.params.id, 'dvc', req.query);
|
|
res.status(response.status).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET /fhir/Bundle/:id/$icvp2
|
|
*/
|
|
async function getICVP2(req, res, next) {
|
|
try {
|
|
const response = await transformBundle(req.params.id, 'icvp2', req.query);
|
|
res.status(response.status).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET /fhir/Bundle/:id/$meow
|
|
*/
|
|
async function getMeow(req, res, next) {
|
|
try {
|
|
const response = await transformBundle(req.params.id, 'meow', req.query);
|
|
res.status(response.status).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getDDCC, getDVC, getICVP2, getMeow,
|
|
};
|