# Create Advanced Automations

## Overview

Automations instantly trigger predefined actions based on specific conditions within Welkin. While many automations handle simple scenarios (such as sending a notification when an Assessment is completed), complex situations may require advanced automations with multiple triggers, conditions, and actions. This guide covers examples of advanced automation patterns and explains how to implement them effectively.

## Core Concepts

### Automation Components

Every automation requires three elements:

1. **Trigger Event** – The action that initiates the automation (e.g., Assessment completed, data field updated, date milestone reached)
2. **Conditions** – Logical rules that must be satisfied for the automation to execute
3. **Actions** – The response triggered when conditions are met (send notification, send message, create task, update data)

Advanced automations combine multiple conditions with AND/OR logic and may include time-based delays.

## Example: BMI Change Follow-up Automation

This automation monitors BMI changes and sends a follow-up message when no improvement is detected after three weeks.

### Trigger

* **Event Type:** "Data Type Updated"
* **Data Type Name:** "cdt-bmi" (system-calculated BMI field)

### Conditions

The automation includes the following conditions (all must be true for execution):

1. **Patient in Program/Phase:** Patient is enrolled in the "Physical Therapy-Education" program
2. **Initial Check:** On data update, record the BMI value and timestamp
3. **Delayed Check:** 3 weeks (21 days) after the original BMI update, check if:
   * The patient is still in the Physical Therapy-Education program
   * The BMI has **not improved** (current BMI ≥ original BMI from 3 weeks ago)
   * The patient remains enrolled in the care program

### Actions

If all conditions are met:

* **Send Message** to the care team: "Patient's BMI has not improved after 3 weeks. Consider adjusting the care plan."
* **Create Task** for the assigned care team member to review the patient's exercise and nutrition plan
* **Send Notification** to supervisory role alerting them of the patient requiring intervention

### Implementation Steps

1. Log into Designer and create a new Automation
2. Set the trigger to "Data Type Updated" and select "cdt-bmi"
3. Add conditions using the condition builder:
   * Add program/phase enrollment condition
   * Set time-based condition for 21-day delay
   * Add BMI comparison condition
4. Configure actions:
   * Select "Send Message" and compose the follow-up notification
   * Select "Create Task" and define the task details
   * Add "Send Notification" and select recipient roles
5. Save and publish the automation

## Example: Conditional Assessment Escalation

This automation escalates patients to a higher level of care based on assessment scores.

### Trigger

* **Event Type:** "Assessment Completed"
* **Assessment Name:** "Depression Screening"

### Conditions

1. **Score Threshold:** Assessment score is ≥ 15 (indicating moderate-to-severe depression)
2. **Not Yet Escalated:** Patient is still in "Standard Care" program (not already escalated)
3. **Consent Status:** Patient has consented to behavioral health referrals

### Actions

* Move patient to "Intensive Behavioral Health" program automatically
* Send notification to behavioral health team that new patient was escalated
* Create task for care coordinator to schedule behavioral health appointment
* Send message to patient with behavioral health resources

## Example: Encounter-Based Follow-up Automation

This automation schedules a follow-up assessment after an encounter is completed.

### Trigger

* **Event Type:** "Encounter Completed"
* **Encounter Type:** "Initial Assessment"

### Conditions

1. Patient is enrolled in "Chronic Disease Management" program
2. Encounter was marked as "completed" (not cancelled)
3. 30 days have not already passed since encounter completion

### Actions

1. Schedule follow-up assessment to be sent 14 days post-encounter
2. Send message to patient asking them to complete the follow-up assessment
3. Create task for care team member to monitor completion

## Advanced Condition Patterns

### Time-Based Conditions

* **Absolute Dates:** "After January 1, 2026"
* **Relative Dates:** "30 days from today"
* **Field-Based Dates:** "21 days from when field X was last updated"
* **Periodic Checks:** "Check every Monday"

### Complex Logic

* **AND Conditions:** All must be true (e.g., "in program AND score > 10 AND not completed")
* **OR Conditions:** Any can be true (e.g., "high risk OR overdue assessment")
* **Nested Logic:** Combine AND/OR for sophisticated rules

### Field Comparisons

* **Field vs. Value:** "BMI > 30"
* **Field vs. Field:** "Current value > Previous value"
* **Field vs. Range:** "Score between 10 and 20"

## Best Practices for Advanced Automations

1. **Clear Naming** – Use descriptive names that indicate the trigger and purpose (e.g., "BMI-Monitor-21DayNoImprovement")
2. **Test Before Publishing** – Create test patients and verify automation behavior before enabling for production
3. **Avoid Recursive Triggers** – Ensure automations don't trigger themselves indefinitely
   * Example: Don't set an automation that updates a field to trigger another automation that updates the same field
4. **Consider Performance** – Complex automations with many conditions may impact system performance
   * Test with realistic data volumes
   * Limit the number of daily-running automations
5. **Monitor Execution** – Regularly review automation logs to ensure they're working as intended
6. **Document Logic** – Maintain clear documentation of complex automations for team knowledge
7. **Use Drafts for Development** – Always work in Designer drafts before publishing to production

## Limitations

* Automations cannot reference fields from different CDTs in cross-type comparisons
* Circular trigger patterns (A triggers B, B triggers A) will be blocked
* Maximum execution time limits apply to prevent infinite loops
* Some real-time actions may have latency depending on system load

## Related Topics

* [Designer: How to Create Automations](/designer/automations/designer-how-to-create-automations.md) – Basic automation setup guide
* [Automated Notifications](/designer/automations/automated-notifications.md) – Sending notifications via automations
* [Automations that Trigger Outbound Communications](/designer/automations/automations-that-trigger-outbound-communications.md) – Message and SMS automations
* [Programs and Phases](/designer/programs-and-profiles/programs-and-phases.md) – Managing care pathways that automations reference
* [How to Add Conditionality to Assessments](/designer/documents-and-assessments/how-to-add-conditionality-to-assessments.md) – Assessment-based conditional logic


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.welkinhealth.com/designer/automations/create-advanced-automations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
