--- title: "form_block" description: "Ordered blocks within a form." --- Ordered blocks within a form. ## Source | Model | Leg | Role | |---|---|---| | `form_block` | openEHR | defines this table | A form is a sequence of blocks. Narrative blocks hold their text in `content`; every other block type is backed by an entry row that points at it, which is what the check constraint enforces — `content` is present exactly when `block_type` is `text`. Entry tables reference `(form_id, id)` rather than `id` alone, so an entry cannot be attached to a block belonging to a different form. ## Columns | Column | Type | Null | Description | Source | |---|---|---|---|---| | `id` | `uuid primary key` | no | Primary key. | — | | `form_id` | `uuid` | no | The form this block belongs to. | — | | `position` | `integer` | no | Order of the block within the form, from zero. | — | | `block_type` | `text` | no | What kind of block this is; `text` blocks hold narrative, the rest are backed by an entry. | — | | `content` | `text` | yes | Narrative text, present only for `text` blocks. | — | | `content_metadata` | `json` | yes | Free-form metadata for the block's renderer. | — | ## Constraints ```sql check ((block_type = 'text' and content is not null) or (block_type <> 'text' and content is null)) ``` ## Unique - `form_id, position` - `form_id, id` ## References | Columns | Target | On delete | |---|---|---| | `form_id` | [`form`](/docs/tables/form) | cascade | ## Referenced by 155 tables reference `form_block`, via `form_id, form_block_id`. The first 15 alphabetically: - [`absence`](/docs/tables/absence) via `form_id, form_block_id` - [`acvpu`](/docs/tables/acvpu) via `form_id, form_block_id` - [`advance_care_directive`](/docs/tables/advance_care_directive) via `form_id, form_block_id` - [`advance_intervention_decisions`](/docs/tables/advance_intervention_decisions) via `form_id, form_block_id` - [`adverse_reaction_monitoring`](/docs/tables/adverse_reaction_monitoring) via `form_id, form_block_id` - [`adverse_reaction_risk`](/docs/tables/adverse_reaction_risk) via `form_id, form_block_id` - [`adverse_reaction_screening`](/docs/tables/adverse_reaction_screening) via `form_id, form_block_id` - [`age_assertion`](/docs/tables/age_assertion) via `form_id, form_block_id` - [`alcohol_consumption_summary`](/docs/tables/alcohol_consumption_summary) via `form_id, form_block_id` - [`apgar`](/docs/tables/apgar) via `form_id, form_block_id` - [`art_cycle_summary`](/docs/tables/art_cycle_summary) via `form_id, form_block_id` - [`asa_status`](/docs/tables/asa_status) via `form_id, form_block_id` - [`berg_balance_scale`](/docs/tables/berg_balance_scale) via `form_id, form_block_id` - [`blood_pressure`](/docs/tables/blood_pressure) via `form_id, form_block_id` - [`body_mass_index`](/docs/tables/body_mass_index) via `form_id, form_block_id` ## Definition ```sql create table form_block ( id uuid primary key default uuid_generate_v4(), form_id uuid not null references form (id) on delete cascade, position integer not null check (position >= 0), block_type text not null, content text, content_metadata json, check ( (block_type = 'text' and content is not null) or (block_type <> 'text' and content is null) ), unique (form_id, position), unique (form_id, id) ); ```