const config = require('../config'); const { createPatient: busCreatePatient, updatePatient: busUpdatePatient, findPatientById } = require('../services/patient'); const { getBusToken} = require('../utils/busAuth'); /** * ITI-104: Patient Identity Feed FHIR (PMIR) * * POST /fhir/Patient * Forwards the Patient resource to the Bus and returns the result. */ 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 busCreatePatient(token, req.body) const patientResponse = await findPatientById(token, response.headers['location']); res.status(200).json(patientResponse.data); } catch (err) { next(err); } } /** * PUT /fhir/Patient/:id * Forwards the update to the Bus and returns the result. */ 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 busUpdatePatient(token, req.body) res.status(200).json(response.data); } catch (err) { next(err); } } module.exports = { createPatient, updatePatient };