Skip to main content
All CollectionsBuild your IntegrationsHealthie
React to Healthie events with your own listener
React to Healthie events with your own listener

How to configure a AWS Lambda function to control and act upon the events that matter to you

Sanne Willekens avatar
Written by Sanne Willekens
Updated over a year ago

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

  1. Webhook Reception: An incoming HTTP request triggers the Lambda function, invoking the lambda_handler function with the incoming event and the AWS Lambda context. The event includes all the information about the webhook.

  2. 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.

  3. Webhook Data Extraction: It then extracts the webhook data from the event. It assumes that the webhook data is in the body of the event and parses it from JSON into a Python dictionary.

  4. Event Type Identification: The function then identifies the event type from the webhook data, using webhook_data.get('event_type').

  5. 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 function.

    1. Inside handle_form_answer_group_created, it first identifies the resource_id from the event data.

    2. It then constructs a GraphQL query to get more data (hydrating the data) from the EHR system about the form answer group.

    3. It sends this query to the EHR GraphQL endpoint, using a POST request with necessary headers for authorization and content type.

    4. 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.

    5. It gets the user_id from the response data and calls the check_or_create_patient function, which checks if the user exists as a patient in the Awell system. If the patient doesn't exist, it creates a new patient.

    6. The function then collects specific data points based on the event and calls the start_pathway function. 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.

  6. 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.

Visual representation of the event exchange

Did this answer your question?