3. Add Branching Logic

In this lesson you’ll learn:

  • How to search for existing records using the Get Patients action

  • How to add Branch Logic to control workflow decisions

  • How to dynamically choose between creating or updating a patient

Introduction

In real-world automations, it’s common to check whether a record already exists before creating a new one. This prevents duplicate records and ensures your data stays clean.

In this lesson, you’ll learn how to:

  1. Search for a patient by email using the Get Patients action.

  2. Add Branch Logic to handle both possible outcomes:

    • Create a new patient if they don’t exist.

    • Update the patient information if they already exist.

Step 1: Add the Search Action (Get Patients)

The fastest way is to describe it in the chat panel (left side of the editor):

"Add a Get Patients step from DrChrono and map the email field from Jotform."

Click Update workflow to confirm.

Manual option:

  1. Click the + icon after the Continue If step
  2. Select the DrChrono connector
  3. Choose the Get Patients action

image 30.png

📌 Note: We can delete the "Create patient" action in our workflow that we added in the previous beginner course, as we are implementing the search and create/update functionality now.

  1. Configure the search criteria:

    • Email: Map this to the email field from your Jotform submission.

    • Example: email = {{emailFromJotform}}

  2. Test the step to ensure that the action works as expected.

get-patients-min.gif

📌 Note: This action always returns a list of patients. If the list is empty, it means no patient was found.

Step 2: Add the Branch Logic

Describe it in the chat panel first:

"Add a Branch step after Get Patients — if the patients array is empty, create a new patient; otherwise, update the existing one."

Click Update workflow to confirm.

Manual option:

  1. Click the + icon after the Get Patients step
  2. In the Add new step panel, go to the Logic tab
  3. Select Branch

  1. Configure the branch conditions:

Branch A (Patient Does Not Exist):

  • Value 1: Select the Patients array from the Get Patients step
  • Condition: is empty
  • This branch handles creating a new patient

get-patients-search-min-3.gif

  • Default Branch (Patient Exists):

    • No configuration needed.

    • If the list is not empty, the workflow will automatically follow this branch to update the patient.

💡 Tip: Rename your branches to keep things organized—e.g., "New patient"

Frame 3.png

Step 3: Configure Actions Under Each Branch

Branch A — Create New Patient:

Describe it in the chat panel:

"Under the New patient branch, add a Create Patient action and map the fields from the Jotform submission."

Or manually:

  1. Add the Create Patient action
  2. Map the necessary fields from the Jotform submission and click Save

image 32.png

Default Branch — Update Existing Patient:

Describe it in the chat panel:

"Under the Default branch, add an Update Patient action and use the Patient ID from the Get Patients step."

Or manually:

  1. Add the Update Patient action
  2. Use data from the first item in the Patients array to retrieve the Patient ID

How to provide the Record ID for Update actions

All Update actions in Keragon, including Update Patient, require a Record ID to identify which record to update. In this case, the Patient ID comes from the results of the earlier Get Patients step.

To find and map the Patient ID:

  1. Click on the Patient ID input field in the Update action
  2. Navigate to the Steps tab
  3. Select the ID from the Get Patients step — this is usually the ID of the first item in the returned list
  4. Update the relevant patient details and click Save
    update-patient-blue.gif

image 33.png

Success!

You’ve now built a smart workflow that automatically decides whether to create or update a patient—no manual intervention needed!

Step 4: Test Your Create Patient Action

  1. Select the "Create patient" action in "New patient" branch
  2. Click the "Test step" button to perform this action in DrChrono with all the data from Jotform that we have configured in the action's inputs.

Frame 4.png

Error: Date Format Mismatch

During testing, the workflow returned an error. Reviewing the error details shows that the date field sent from Jotform to DrChrono is not in the correct format expected by DrChrono.

You can describe this error in the chat panel to get help identifying the fix:

"My test failed with a date format error — how do I fix it?"

We'll address this properly in the next lesson by applying data transformations.

error.gif

Try it yourself

Using the chat, describe the full branching logic for your workflow:

"Add a Branch step after Get Patients — if the patients array is empty, create a new patient; otherwise, update the existing one."

Run a test on the Create Patient action and note any errors before moving to the next lesson.

Next Lesson

Now that you’ve implemented logic branching, let’s address the error we found in the next lesson by applying Data Transformations to ensure all dates are correctly formatted before sending them to DrChrono.

Next Lesson: Add Data Transformations: Format Dates Correctly

Was this article helpful?
0 out of 0 found this helpful

Articles in this section