37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
const config = require('../config');
|
|
const { getBusToken, createBusRequest } = require('../utils/busAuth');
|
|
const { searchPatient, getPatientById } = require('../services/patient');
|
|
|
|
/**
|
|
* ITI-78: Mobile Patient Demographics Query (PDQm)
|
|
*
|
|
* GET /fhir/Patient
|
|
* Forwards the raw FHIR query parameters to the Bus and returns the Bundle result.
|
|
*/
|
|
async function queryPatientDemographics(req, res, next) {
|
|
try {
|
|
const token = await getBusToken(config.bus.url, config.bus.jwtSecret, config.bus.issuer, config.bus.mpiScope);
|
|
const response = await searchPatient(token, req.query);
|
|
res.status(200).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET /fhir/Patient/:id
|
|
* Forwards the request to the Bus and returns the Patient resource.
|
|
*/
|
|
async function findPatientById(req, res, next) {
|
|
try {
|
|
const { id } = req.params;
|
|
const token = await getBusToken(config.bus.url, config.bus.jwtSecret, config.bus.issuer, config.bus.mpiScope);
|
|
const response = await getPatientById(token, id)
|
|
res.status(200).json(response.data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
module.exports = { queryPatientDemographics, getPatientById: findPatientById };
|