Interact with activities
Redirect stakeholders to an Awell Hosted Page to complete activities
This integration enables you to orchestrate activities over time for multiple stakeholders on an Awell Hosted Activity page.
This use case is perfect to set up longitudinal outcomes (such as PROMs / PREMs) collection, triage & eligibility flows and clinicial decision support with limited engineering effort.
The lifecycle for a hosted activity experience looks like this:
activity.created
webhook.activity.completed
webhook.This lifecycle is repeated for every activity that is created in a care pathway.
To get started, there are a couple of things you need:
Your pathway should minimally be subscribed to the activity.created
webhook as that is the trigger to initiate a Hosted Activity session. Depending on the type of integration and events you want to receive, you can configure other wehooks as well ( see list of all webhooks).
Webhooks are configured on a per pathway basis via the pathway settings so if you want to receive webhooks for events, you will have to configure them via the pathway settings.
Configure webhooks
We will create a Webhook listener that is able to process and handle incoming webhooks from Awell every time an activity is created.
Interactive webhook builder
Handle the event
Handle the activity.created
event on your server.
Only handle user activities
Care flows/pathways in Awell consist of different types of activities. We are only interested in activities that need an action by a human.
Store pathway id and stakeholder id
In order to create a Hosted activity session, you will need to pass the pathway id and stakeholder id. So make sure you store or pass these 2 properties.
Resources:
Notify the stakeholders
Depending for what stakeholder there is an activity to complete, define and call the methods to notify these stakeholders via your appropriate channels.
01const express = require('express');02const app = express();0304// If you are using Express v4 - v4.16 you need to use body-parser, not express, to retrieve the request body05app.post('/awell-webhooks', express.json({type: 'application/json'}), (request, response) => {06 const event = request.body;0708 // Handle the event09 switch (event.event_type) {10 case 'activity.created': {11 const { isUserActivity } = event.activity1213 if (isUserActivity) {14 const pathway_id = event.pathway.id15 const { stakeholder } = event.activity.indirect_object16 const stakeholderId = stakeholder.id1718 if (stakeholder.type === 'PATIENT') {19 // Email is only available if this property is set in the patient's Awell profile20 // Contact details can also be fetched from your internal systems.21 const patientEmail = stakeholder.email2223 // Then define and call a method to notify the patient24 }25 if (stakeholder.type === 'STAKEHOLDER') {26 switch (stakeholder.name) {27 case 'Nurse': {28 // Then define and call a method to notify the nurse of the patient29 break30 }31 case 'Physician': {32 // Then define and call a method to notify the physician of the patient33 break34 }35 default:36 console.log(`Unhandled stakeholder: ${stakeholder.name}`)37 }38 }39 }40 break;41 }42 default:43 console.log(`Unhandled event type ${event.event_type}`);44 }4546 // Return a response to acknowledge receipt of the event47 response.json({received: true});48});4950app.listen(8000, () => console.log('Running on port 8000'));
Table to help you map user activities to the right stakeholder:
Stakeholder type (indirect_object.type) | Stakeholder name (indirect_object.name) | Contact details of stakeholder |
---|---|---|
PATIENT | Name of the actual patient as stored in the Awell patient profile | See stakeholder.email (if contact details are stored in Awell) or look up in your internal systems. |
STAKEHOLDER | nurse | Look up in your internal systems. |
STAKEHOLDER | Physician | Look up in your internal systems. |
STAKEHOLDER | Dietician | Look up in your internal systems. |
STAKEHOLDER | (any other stakeholder that is not the patient) | Look up in your internal systems. |
In the previous step we created a webhook listener and notified the relevant stakeholders of an activity that needs to be completed. When the stakeholder react to the notification (eg: presses a button), we will create a hosted activity session we can redirect the stakeholder to.
Prerequisites
You will need to have stored or passed (eg: via query parameters) the following data in order to start a hosted activity session (see step 1):
Get stakeholder and pathway id
Make sure you have the id of the stakeholder the activity is for and the pathway id. These parameters were returned in the body of the webhook. In the example we passed them via query parameters.
Define success and cancel URL
Specifiy where the stakeholder needs to be redirected to when the session is completed or interrupted.
Redirect to Hosted Pathway page
After creating the session, redirect your client to the URL for the hosted pathway page returned in the response.
01const express = require('express');02const app = express();0304const AWELL_API_URL = process.env.AWELL_API_URL || ''05const AWELL_API_KEY = process.env.AWELL_API_KEY || ''0607// If you are using Express v4 - v4.16 you need to use body-parser, not express, to retrieve the request body08app.post('/start-hosted-activity-session', express.json({type: 'application/json'}), (request, response) => {09 // Assumption: these parameters are passed as query parameters10 // Replace this code if you have implemented a different way11 // to keep track of stakeholder and pathway id.12 const STAKEHOLDER_ID = req.query.stakeholder_id13 const PATHWAY_ID = req.query.pathway_id1415 const body = JSON.stringify({16 query: `17 mutation StartHostedActivitySession($input: StartHostedActivitySessionInput!) {18 startHostedActivitySession(input: $input) {19 session_id20 session_url21 }22 }`,23 variables: {24 input: {25 pathway_id: PATHWAY_ID,26 stakeholder_id: STAKEHOLDER_ID,27 success_url: 'https://your-domain.com/?success=true',28 cancel_url: 'https://your-domain.com/?canceled=true',29 },30 },31 })3233 const session = await fetch(AWELL_API_URL, {34 method: 'POST',35 headers: {36 apiKey: AWELL_API_KEY,37 Accept: 'application/json',38 'Content-Type': 'application/json',39 },40 body,41 })42 .then((response) => response.json())43 .then((response) => response.data.startHostedActivitySession)4445 res.redirect(303, session.session_url)46});4748app.listen(8000, () => console.log('Running on port 8000'));
In order to test your integration, make sure to do the following steps:
If you can't find what you're looking for, you can always send us a message over Intercom with your enquiry.