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

# Tag

> Query the Elation Billing tags applied to claims, patients, and other billing entities.

One row per applied Elation Billing tag - an individual tag placed on a billing entity such as a claim or patient. The tag's label and color come from its definition in the `tag_system` table via `tag_system_id`. The tagged object is identified polymorphically: `related_id` holds the entity's id and `tag_type` records which kind of entity it is.

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

> [!NOTE]
>
> `related_id` is a **polymorphic** Elation Billing identifier - the table it points at depends on `tag_type` (and, for the secondary association, `sub_related_id` depends on `sub_tag_type`). These are raw Elation Billing ids and are not resolved to HDB ids. For claim-type tags, `related_id` is the Elation Billing claim id and can be joined to `claim.id`. Resolve the tag's label through `tag_system_id`.

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

* Which tags are applied to claims or patients
* Resolving applied tags to their labels and colors via `tag_system`
* Tag usage counts across a practice

## Applied tags with their labels

Joins each applied tag to its definition for the human-readable label and color.

```sql sql theme={null}
select
    t.id as tag_id
  , t.practice_id
  , t.tag_type
  , t.related_id
  , ts.tag as label
  , ts.color
  , ts.type as definition_type
from tag t
  join tag_system ts on ts.id = t.tag_system_id
where t.is_deleted = false
  and ts.is_deleted = false
order by t.practice_id, ts.tag;
```

## Tags applied to claims

Filters to claim tags and joins the tagged claim. The `related_id` of a claim-type tag is the Elation Billing claim id, so it joins directly to `claim.id`.

```sql sql theme={null}
select
    c.id as claim_id
  , c.local_id
  , c.practice_id
  , ts.tag as label
  , ts.color
from tag t
  join tag_system ts on ts.id = t.tag_system_id
  join claim c on c.id = t.related_id
where t.is_deleted = false
  and ts.is_deleted = false
  and t.tag_type = 'claim'
  and c.is_deleted = false
order by c.id;
```

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