> ## Documentation Index
> Fetch the complete documentation index at: https://help.elationhealth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Patient forms emails

> The emails Elation sent asking patients to fill in the forms their appointment requires, with whether each one went out.

The `patient_form_email` table has one row per email Elation sent asking a patient to fill in the forms their appointment requires. It holds the address the email went to, when Elation queued it, when it went out, and how many attempts failed. Join `appointment_id` to `appointment.id`, `patient_id` to `patient.id`, and `practice_id` to `practice.id`.

This is how appointment forms reach patients. Forms that staff send by hand go out as [Patient form requests](https://help.elationhealth.com/articles/hdb/patient-form-request.md) instead. For how practices send forms, see [Sending forms to patients](https://help.elationhealth.com/articles/Sending-forms-to-patients.md).

This table's columns and relationships are shown in the [Hosted Database schema](https://help.elationhealth.com/articles/hdb/schema.md).

**For reporting on but not limited to:**

* Whether an appointment's forms email actually went out
* Delivery problems by practice or period
* When an appointment's forms were first asked for
* How long patients take to submit after the email

## Before you query patient forms emails

### Reading whether an email went out

Every forms email Elation queued is recorded, whether or not it went out. Read the outcome from two columns together:

* `delivered_time` set: the email went out, even if earlier attempts failed.
* `delivered_time` null and `failed_attempt_count` above 0: sending failed.
* `delivered_time` null and `failed_attempt_count` of 0: Elation has no record of sending it.

An email that still has no `delivered_time` a day after its `sent_time` did not go out. The vast majority do go out, so a practice with more than a handful of the last two cases is worth looking at.

### `sent_time` is when Elation queued the email

`delivered_time` is when Elation handed the email to its email service, usually within seconds of `sent_time`. Neither is when the patient received or opened the message. Whether the email reached the inbox or bounced, and whether the patient opened it or the forms, is not recorded.

### `status` is always `sent`

Elation writes `status` when it queues the email, so every row reads `sent`. It tells you nothing about the outcome; use `delivered_time` for that.

### An email covers all of the appointment's forms

There is one email per send, not one per form, and which forms it listed is not recorded. You can tell that an appointment's patient was emailed, but not which of the appointment's forms that email asked for. Who sent an email is not included either, and many go out automatically.

### An appointment can be emailed more than once

Use the earliest `sent_time` for an `appointment_id` as the point its forms were first asked for, and count distinct `appointment_id` rather than rows when you are counting appointments.

### Emails for deleted appointments are kept

A row stays after its appointment is deleted, because the email was still sent. To leave those out, join `appointment` and filter on its `deletion_time`. The row's own `deletion_time` means something different: the record of the email was removed from Elation. Exclude those rows.

## Delivery outcome by practice

Groups each practice's forms emails into the three outcomes, so delivery problems stand out.

```sql sql theme={null}
select
    e.practice_id
  , pr.name as practice_name
  , count(*) as emails
  , count_if(e.delivered_time is not null) as went_out
  , count_if(e.delivered_time is null and e.failed_attempt_count > 0) as failed
  , count_if(e.delivered_time is null and e.failed_attempt_count = 0) as no_record_of_sending
  , round(100 * count_if(e.delivered_time is not null) / count(*), 2) as pct_went_out
from patient_form_email e
  left join practice pr on pr.id = e.practice_id
where e.deletion_time is null
  and e.sent_time >= '2026-01-01'
group by e.practice_id, pr.name
order by emails desc;
```

## When an appointment's forms were first asked for

Returns one row per appointment with the first time its forms email went out, how many emails were sent in total, and whether any of them failed.

```sql sql theme={null}
select
    e.appointment_id
  , a.appt_time
  , e.patient_id
  , e.practice_id
  , min(e.sent_time) as first_sent_at
  , min_by(e.contact_info, e.sent_time) as first_sent_to
  , count(*) as emails_sent
  , count_if(e.delivered_time is not null) as emails_that_went_out
  , max(e.failed_attempt_count) as most_failed_attempts
from patient_form_email e
  join appointment a on a.id = e.appointment_id
where e.deletion_time is null
  and a.deletion_time is null
  and a.appt_time >= '2026-01-01'
group by e.appointment_id, a.appt_time, e.patient_id, e.practice_id
order by first_sent_at desc
limit 100;
```

## How long patients take to submit after the email

Measures from the first forms email that went out for an appointment to each form the patient submitted for it after that.

```sql sql theme={null}
with first_email as (
    select
        e.appointment_id
      , e.practice_id
      , min(e.sent_time) as first_sent_at
    from patient_form_email e
    where e.deletion_time is null
      and e.delivered_time is not null
      and e.sent_time >= '2026-01-01'
    group by e.appointment_id, e.practice_id
)
select
    fe.practice_id
  , pr.name as practice_name
  , date_trunc('month', fe.first_sent_at)::date as month
  , count(distinct fe.appointment_id) as appointments_emailed
  , count(s.id) as forms_submitted
  , round(median(datediff('hour', fe.first_sent_at, s.creation_time)), 1) as median_hours_to_submit
  , count_if(datediff('hour', fe.first_sent_at, s.creation_time) <= 24) as submitted_within_a_day
from first_email fe
  left join practice pr on pr.id = fe.practice_id
  left join patient_form_submission s
    on s.appointment_id = fe.appointment_id
   and s.deletion_time is null
   and s.creation_time >= fe.first_sent_at
group by fe.practice_id, pr.name, month
order by month, appointments_emailed desc;
```

*If you have any questions about this topic please reach out to [Elation Support Portal](https://help.elationhealth.com/articles/support-portal-introduction.md) with the subject line HDB - \<your\_question>*
