I am creating a standalone provider-facing app (not connected to an EHR) that needs to pull patient data (only need USCDI data for now). I am trying to use SMART on FHIR to pull this patient data.
My code looks like:
import FHIR from "fhirclient"
FHIR.oauth2.authorize({
'client_id': {client_id},
'scope': 'launch launch/patient patient/read offline_access',
'redirect_uri': {app_url},
'iss': 'https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4'
});
FHIR.oauth2.ready()
.then(function(client){
const accessToken: string = client.state?.tokenResponse?.access_token ?? "";
doRequests(accessToken);
});
async function doRequests(accessToken: string) {
const patientID: string = "egqBHVfQlt4Bw3XGXoxVxHg3"; // Testing with sample patient from Epic's sandbox test data
var obs = await fetch("https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/AllergyIntolerance?patient=" + patientID, {
headers: {
"Accept": "application/json+fhir",
"Authorization": "Bearer " + accessToken
}
}).then(function(data){
return data
});
}
I am logging in using the provider test data provided by Epic (i.e. username = FHIR, password = EpicFhir11!).
However, the entire “client.state.tokenResponse” object returned in the “FHIR.oauth2.ready” function is empty. Because I don’t have an accessToken, the fetch inside of doRequests is returning a 401 error (unauthorized status code).
How I authorize the app properly so that it returns an accessToken properly and I can fetch patient data?
Thanks for all your help!