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

# Per-appointment form changes

> Changes staff made to one form on one appointment, including marking a form complete without the patient submitting it.

The `patient_form_appointment_change` table has one row per change staff made to a single form on a single appointment. It is the override layer on top of the forms an appointment type asks for: a form can be removed from one appointment, added to one appointment, or marked complete for one appointment. Join `appointment_id` to `appointment.id` and `patient_form_id` to `patient_form.id`.

The forms an appointment starts with are in [Forms required by an appointment type](https://help.elationhealth.com/articles/hdb/patient-form-appointment-type.md). This table is also where the answer to "did this appointment's forms get done?" comes from, because a form can be complete without a submission.

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:**

* Forms marked complete by staff rather than submitted by the patient
* The status of every form an appointment required
* How often staff override the forms an appointment type asks for
* Which staff mark forms complete, and how often

## Before you query per-appointment form changes

### `marked_complete` is the only change type used today

`override_type` can be one of three values:

* `not_required`: the form was removed from this appointment, although its appointment type asks for it;
* `required`: the form was added to this appointment, although its appointment type does not ask for it;
* `marked_complete`: staff marked the form complete for this appointment, whether or not the patient submitted it.

In practice every row is `marked_complete`. The other two are supported and your queries should still handle them, but do not expect them in your data.

### A row counts while `deletion_time` is null

Undoing a change, for example unmarking a form that was marked complete, sets `deletion_time` rather than removing the row. Always filter on `deletion_time is null` when asking what is true now, and leave the filter off only when you want the history of overrides including the ones that were undone.

### The status of a form an appointment required, matching Elation

For a form that an appointment requires, the status is:

* **submitted** if a `patient_form_submission` that counts has the same `appointment_id` and `patient_form_id`;
* otherwise **marked complete** if a `marked_complete` row here counts for that appointment and form;
* otherwise **incomplete**.

Submitted wins over marked complete, so a form the patient later filled in reads as submitted even though staff had already marked it done.

### Start from the forms the appointment requires

This table only holds changes, so it says nothing about the forms that were never overridden. To report on an appointment's forms, build the required list first from `patient_form_appointment_type` and then layer the status on top, as the [status of every form an appointment required](#the-status-of-every-form-an-appointment-required) query does.

### There is no practice on a change

A change carries only the appointment and the form. To group by practice, join `appointment` and use its `practice_id`.

### Who undid a change is not always recorded

`created_by_user_id` is the member of staff who made the change. `deleted_by_user_id` is filled in only where Elation records who undid it, so expect nulls there.

## Forms marked complete rather than submitted

Finds the forms staff marked complete where the patient never submitted them. These are the forms that count as done in Elation but have no patient answers behind them.

```sql sql theme={null}
select
    a.practice_id
  , pr.name as practice_name
  , c.appointment_id
  , a.appt_time
  , c.patient_form_id
  , f.title as form_title
  , c.creation_time as marked_complete_at
  , concat(u.first_name, ' ', u.last_name) as marked_complete_by
from patient_form_appointment_change c
  join appointment a on a.id = c.appointment_id
  left join practice pr on pr.id = a.practice_id
  left join patient_form f on f.id = c.patient_form_id
  left join user u on u.id = c.created_by_user_id
where c.override_type = 'marked_complete'
  and c.deletion_time is null
  and a.deletion_time is null
  and a.appt_time >= '2026-01-01'
  and not exists (
      select 1
      from patient_form_submission s
      where s.appointment_id = c.appointment_id
        and s.patient_form_id = c.patient_form_id
        and s.deletion_time is null
  )
order by c.creation_time desc
limit 100;
```

## The status of every form an appointment required

Builds the appointment's required forms from its appointment type, applies the per-appointment overrides, then gives each form a status.

```sql sql theme={null}
with appt as (
    select a.id, a.practice_id, a.appt_type_id, a.appt_type, a.appt_time
    from appointment a
    where a.id = <appointment_id>
),
required as (
    select appt.id as appointment_id, t.patient_form_id
    from appt
      join patient_form_appointment_type t
        on t.appt_type_id = appt.appt_type_id
       and t.deletion_time is null
    where not exists (
        select 1
        from patient_form_appointment_change c
        where c.appointment_id = appt.id
          and c.patient_form_id = t.patient_form_id
          and c.override_type = 'not_required'
          and c.deletion_time is null
    )
    union
    select appt.id, c.patient_form_id
    from appt
      join patient_form_appointment_change c
        on c.appointment_id = appt.id
       and c.override_type = 'required'
       and c.deletion_time is null
)
select
    appt.id as appointment_id
  , appt.appt_type
  , appt.appt_time
  , r.patient_form_id
  , f.title as form_title
  , case
        when s.id is not null then 'submitted'
        when mc.id is not null then 'marked complete'
        else 'incomplete'
    end as form_status
  , s.creation_time as submitted_at
  , mc.creation_time as marked_complete_at
from required r
  join appt on appt.id = r.appointment_id
  left join patient_form f on f.id = r.patient_form_id
  left join patient_form_submission s
    on s.appointment_id = r.appointment_id
   and s.patient_form_id = r.patient_form_id
   and s.deletion_time is null
  left join patient_form_appointment_change mc
    on mc.appointment_id = r.appointment_id
   and mc.patient_form_id = r.patient_form_id
   and mc.override_type = 'marked_complete'
   and mc.deletion_time is null
where f.id is null or f.deletion_time is null
order by f.sequence, r.patient_form_id;
```

## How often staff mark forms complete

Counts marked-complete changes by practice and month, and how many of them were later undone.

```sql sql theme={null}
select
    a.practice_id
  , pr.name as practice_name
  , date_trunc('month', c.creation_time)::date as month
  , count(*) as changes_made
  , count(distinct c.appointment_id) as appointments_affected
  , count_if(c.deletion_time is not null) as later_undone
from patient_form_appointment_change c
  join appointment a on a.id = c.appointment_id
  left join practice pr on pr.id = a.practice_id
where c.override_type = 'marked_complete'
  and c.creation_time >= '2026-01-01'
group by a.practice_id, pr.name, month
order by month, changes_made 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>*
