eHealth TRHC xMDS API Samples

node v8.17.0
version: 1.0.0
endpointsharetweet
Here are some samples scripts using the xMDS 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 xMDS 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.XMDS_CLIENT_ID}:${process.env.XMDS_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. Since xMDS API currently only accepts Medication, MedicationStatement, and MedicationDispense FHIR resources, we convert the MedicationOrders to simpler Medication resources. The patient and medications will be used to create a FHIR bundle.
const { pluck, prop, map } = require('ramda') const patientId = 'smart-1685497' const patient = await fetch('https://r2.smarthealthit.org/Patient/' + patientId) .then(res => res.json()) .then(patient => ({resource: patient})) const medications = await fetch('https://r2.smarthealthit.org/MedicationOrder?patient=' + patientId) .then(res => res.json()) .then(bundle => pluck('resource', prop('entry', bundle))) .then(pluck('medicationCodeableConcept')) .then(map(med => ({resource: { resourceType: 'Medication', code: med }})))
Now that we have our access token and our patient and converted medications, we can create a bundle
const bundle = { resourceType: 'Bundle', type: 'collection', entry: [ patient, ...medications ] } JSON.stringify(bundle, null, 2)
and submit to xMDS.
const result = await fetch(`${process.env.XMDS_URL}/profiles`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, body: JSON.stringify(bundle) }).then(res => res.json()) const profileId = result.id result
Above, you can see the returned object contains a profile Id and risk score. Now that we have a profileId, we can retrieve the 4 visualizations....
const score = await fetch(`${process.env.XMDS_URL}/profiles/${result.id}/riskscore`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } }) .then(res => res.json()) score.html
const matrix = await fetch(`${process.env.XMDS_URL}/profiles/${result.id}/matrix`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } }) .then(res => res.json()) matrix.html
const bullseye = await fetch(`${process.env.XMDS_URL}/profiles/${result.id}/bullseye`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } }) .then(res => res.json()) bullseye.html
const windrose = await fetch(`${process.env.XMDS_URL}/profiles/${result.id}/windrose`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } }) .then(res => res.json()) windrose.html
Loading…

no comments

    sign in to comment