37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
const config = require('../config');
|
|
const { postPatient, putPatient, getPatientById } = 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 postPatient(token, req.body)
|
|
const patientResponse = await getPatientById(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 putPatient(token, req.body)
|
|
res.status(200).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
module.exports = { createPatient, updatePatient };
|