To trigger an Awell care flow off a Healthie webhook event, there are currently two possible options:
Enable the webhooks of the Healthie Extension in Awell. We currently support two types of Healthie events that will start a new Awell care flow, which are Webhook: appointmentCreated and Webhook: patientCreated (see screen capture below)
Set up your own webhook listener to act as a 'traffic cop' and control
the type of events that should trigger an action
what type of action you want to perform against the Awell Orchestration API (e.g. create patient)
Awell webhooks supported by the Healthie Extension:
In this article we'll dive deeper on option #2, configuring your own AWS Lambda function.
How to configure your AWS Lambda function
Webhook Reception: An incoming HTTP request triggers the Lambda function, invoking the
lambda_handlerfunction with the incoming event and the AWS Lambda context. The event includes all the information about the webhook.
Event Logging: The function starts by logging the received event using logger.info. It dumps the event data into a string format and logs it for debugging and record purposes.
Webhook Data Extraction: It then extracts the webhook data from the event. It assumes that the webhook data is in the
bodyof the event and parses it from JSON into a Python dictionary.
Event Type Identification: The function then identifies the event type from the webhook data, using
Event Handling: Based on the event type, it calls the appropriate function to handle the event. For instance, if the event type is
form_answer_group_created, it calls the
handle_form_answer_group_created, it first identifies the resource_id from the event data.
It then constructs a GraphQL query to get more data (hydrating the data) from the EHR system about the form answer group.
It sends this query to the EHR GraphQL endpoint, using a POST request with necessary headers for authorization and content type.
After it gets the response from the EHR system, it checks the response status and format. If everything is okay, it extracts the required data from the response.
It gets the user_id from the response data and calls the
check_or_create_patientfunction, which checks if the user exists as a patient in the Awell system. If the patient doesn't exist, it creates a new patient.
The function then collects specific data points based on the event and calls the
start_pathwayfunction. This function constructs a mutation to start a pathway in the Awell system, sends the mutation to the Awell API, and logs the success message. The pathway definition ID is hardcoded inside the form_answer_group_created function.
Response Generation: After processing the event data and calling the relevant functions, it generates a response indicating that the webhook was successfully received. This response includes an HTTP status code of 200, and a JSON body containing a success message.