Development
Define the logic of what needs to happen when your action is activated
The onActivityCreated
function is called whenever orchestration or design (preview) activates a Custom Action. It will publish a message that is received by the extension server, which automatically finds the right Custom Action and calls the onActivityCreated
function defined in that action.
The onActivityCreated
function has a couple of parameters that will be useful when developing an extension:
onComplete
or onError
function.
- javascript
01export const myAction = {02 ...,03 onActivityCreated: async (payload, onComplete, onError) => {04 // Do something here05 },06}
The payload allows you to access the values of your extension settings, action fields, and patient data.
- javascript
01export const myAction = {02 onActivityCreated: async (payload) => {03 const {04 patient, // access patient profile data for patient enrolled in pathway the activity is related to05 fields, // access the values of your action fields06 settings, // access the values of your extension settings07 } = payload0809 // Do something10 },11}
The onComplete
callback can be called to confirm your activity has been completed and can be called with the following (optional) parameters:
- javascript
01export const myAction = {02 onActivityCreated: async (payload, onComplete) => {03 const randomNumber = Math.random()0405 await onComplete({06 data_points: {07 // Will create a "randomNumber" data point in the pathway and assign08 // the randomly generated number as the value09 randomNumber,10 },11 events: [12 {13 date: new Date().toISOString(),14 text: { en: 'Successfully generated a random number' },15 },16 ],17 })18 },19}
The onError
callback can be called to let Awell know something went wrong with running your extension code. However, the activity will still be completed.
The function can be called with the following (optional) parameter:
- javascript
01export const myAction = {02 onActivityCreated: async (payload, onComplete, onError) => {03 try {04 // Connect to external API05 } catch {06 await onError({07 events: [08 {09 date: new Date().toISOString(),10 text: { en: "Couldn't connect to the external API" },11 error: {12 category: 'CONNECTION_ERROR',13 message: "Couldn't connect to the external API",14 },15 },16 ],17 })18 }1920 await onComplete()21 },22}