Here are some samples scripts using the TRHC MedWise Risk API , these samples are using test resources from the smarthealthit demo fhir server.
Prerequisites: We are assuming the developer has obtained a Client ID and Secret from eHealth Services. These "keys" represent a developer application that is approved to use the MedWise Risk API.
Get access token using OAuth2 Client Credentials. Warning! Be sure to keep the secret safe! Don't store your secrets in souce code control. Don't expose secrets within the code of a user agent such as a web browser or mobile client.
require('isomorphic-fetch')
// authentication url
const authUrl = process.env.AUTH_URL
// create basic authentication with id and secret
const basicAuth = Buffer.from(`${process.env.MW_RISK_API_TEST_APP_CLIENTID}:${process.env.MW_RISK_API_TEST_APP_SECRET}`).toString('base64')
// get access token from authentication server
const doc = await fetch(authUrl, {
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': 'application/json'
},
method: 'POST'
}).then(res => res.json())
const accessToken = doc.access_token
console.log('access token', accessToken)
Now that we have the access token, we need to create a temporary profile to be used to generate the visualizations. We fetch a patient from the FHIR server using a patientId. Next, we grab an array of MedicationOrder FHIR resources for the patient.
and submit to MedWise Risk API. Note the absense of the risk score data in the response JSON. This has been moved to a new GET /profiles/{profile id}/scoredata endpoint which provide the risk score as JSON data. See call to scoredata toward the end of this runkit.