I have a nodejs app that connects to an FHIR server and queries patient data. I am not sure how do I pass the Oauth2 token to the getPatient function. I am using fhir.js node library for the application.
var Fhir = require('fhir.js');
var user = require('user.js);
function getPatient(response){
return new Promise(function(resolve,reject) {
var patientid = 123456;
var Oauth2Token = user.token;
// Create fhir instance
var fhir = Fhir({
baseUrl: process.env.baseUrl,
});
// Execute the search
fhir.search({
type: 'Patient',
query: {id: patientid}
})
.then(function(response){
//manipulate your data here.
var data = response.data.entry[0].resource;
console.log("FHIR Data :",data);
resolve(data);
})
.catch(function(error){
//Error responses
if (error.status){
console.log('Error', error.status);
reject(error);
}
//Errors
if (error.message){
console.log('Error', error.message);
reject(error);
}
});
});
}
You can look at the Readme:
var fhir = Fhir({
baseUrl: process.env.baseUrl,
auth: {
bearer: 'YOURTOKEN'
}
});