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/$icvp */ async function getICVP(req, res, next) { try { const response = await transformBundle(req.params.id, 'icvp', 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, getICVP, getICVP2, getMeow, };