Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions versioned_docs/version-3.0/references/clinical/condition.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ A `Condition` lives across two layers, and the split matters when you read the c
| Field | Type | Notes |
| --- | --- | --- |
| `code` | `JSONField` (`default=dict`, not null/blank) | The condition itself. On write, a single [`Coding`](#coding-shape) bound to the [`CARE_CODITION_CODE_VALUESET`](#code-value-set-binding) value set (SNOMED CT clinical findings). On read, serialized as a plain `Coding`. |
| `body_site` | `JSONField` (`default=dict`, not null/blank) | Anatomical location(s). Exists on the model but no current spec exposes it — never written or read through the standard `Condition` API. |
| `body_site` | `JSONField` (`default=dict`, not null/blank) | Anatomical location. Optional on write: a single [`Coding`](#coding-shape) bound to `CARE_BODY_SITE_VALUESET` (slug `system-body-site-observation`, SNOMED CT). On read, serialized as a plain `Coding` or `null`. |

### Timing

Expand Down Expand Up @@ -139,27 +139,31 @@ These spec classes (all extend `EMRResource`) are the real structure behind the

On write, `code` is typed `ValueSetBoundCoding[CARE_CODITION_CODE_VALUESET.slug]` — a `Coding` checked against the Condition code value set (`care/emr/resources/condition/valueset.py`, slug `system-condition-code`), which covers SNOMED CT concepts that are `is-a` `404684003` (*Clinical finding*). Codes outside it are rejected on `ConditionSpec`, `ConditionUpdateSpec`, and `ChronicConditionUpdateSpec`. The read spec falls back to a plain `Coding` and skips value-set validation, so reads stay cheap.

### `body_site` value-set binding

On write, `body_site` is typed `ValueSetBoundCoding[CARE_BODY_SITE_VALUESET.slug]` and is optional (`None` by default). The value set (`care/emr/resources/observation/valueset.py`, slug `system-body-site-observation`) is the same one [Observation](../clinical/observation.mdx) uses: a curated list of SNOMED CT body-structure concepts plus every descendant of `442083009` (*Body structure, altered from its original anatomical structure*). `ConditionSpec` and `ConditionUpdateSpec` both accept it; `ConditionReadSpec` returns a plain `Coding` or `null`.

## Resource specs (API schema)

Every spec extends `BaseConditionSpec` → `EMRResource` and round-trips through `serialize` (DB → Pydantic) and `de_serialize` (Pydantic → DB). `BaseConditionSpec` sets `__model__ = Condition`, sets `__exclude__ = ["patient", "encounter"]` (both server-maintained, never trusted from the client), and exposes `id: UUID4`.

| Spec class | Role | Exposes / behaviour |
| --- | --- | --- |
| `BaseConditionSpec` | shared base | `id`; excludes `patient` and `encounter` from direct mapping. |
| `ConditionSpec` | write · create | `clinical_status?`, `verification_status` (**required**), `severity?`, `code` (value-set bound, **required**), `encounter` (UUID4, **required**), `onset` (`={}`), `abatement` (`={}`), `note?`, `category` (**required**). Validates that the encounter exists; on create sets `obj.encounter` and `obj.patient = encounter.patient`. |
| `ConditionUpdateSpec` | write · update | `clinical_status?`, `verification_status` (**required**), `severity?`, `code` (value-set bound, **required**), `onset` (`={}`), `abatement` (`={}`), `note?`. Does **not** accept `encounter`, `category`, or `patient`. |
| `ConditionSpec` | write · create | `clinical_status?`, `verification_status` (**required**), `severity?`, `code` (value-set bound, **required**), `body_site?` (value-set bound), `encounter` (UUID4, **required**), `onset` (`={}`), `abatement` (`={}`), `note?`, `category` (**required**). Validates that the encounter exists; on create sets `obj.encounter` and `obj.patient = encounter.patient`. |
| `ConditionUpdateSpec` | write · update | `clinical_status?`, `verification_status` (**required**), `severity?`, `code` (value-set bound, **required**), `body_site?` (value-set bound), `onset` (`={}`), `abatement` (`={}`), `note?`. Does **not** accept `encounter`, `category`, or `patient`. |
| `ChronicConditionUpdateSpec` | write · update (chronic) | Extends `ConditionUpdateSpec` and adds `encounter` (UUID4). On deserialize, if `encounter` is set, resolves it (`get_object_or_404`) and assigns `obj.encounter`. |
| `ConditionReadSpec` | read · detail/list | `clinical_status`, `verification_status`, `category`, `criticality`, `severity` (all plain `str`), `code` (plain `Coding`), `encounter` (UUID4), `onset`, `abatement`, `created_by?`, `updated_by?`, `note?`, `created_date`, `modified_date`. |
| `ConditionReadSpec` | read · detail/list | `clinical_status`, `verification_status`, `category`, `criticality`, `severity` (all plain `str`), `code` (plain `Coding`), `body_site` (plain `Coding \| None`), `encounter` (UUID4), `onset`, `abatement`, `created_by?`, `updated_by?`, `note?`, `created_date`, `modified_date`. |

### Validation & server-side behaviour

- Encounter is required and verified on create. `ConditionSpec.validate_encounter_exists` rejects unknown encounter UUIDs; `perform_extra_deserialization` (create only) loads the encounter and derives `patient` from it. Clients never set `patient` or `encounter` directly.
- `verification_status` is mandatory on both `ConditionSpec` and `ConditionUpdateSpec`; `category` is mandatory only on create (`ConditionSpec`).
- `code` must belong to the bound value set (SNOMED CT clinical findings) on every write spec.
- `code` must belong to the bound value set (SNOMED CT clinical findings) on every write spec; `body_site`, when sent, must belong to the body-site value set.
- `onset_datetime` cannot be in the future and is forced timezone-aware; `abatement_datetime` carries no such constraint.
- `ConditionReadSpec` exposes `criticality`, a string in the read schema with no backing column on the `Condition` model. The standard serializer never populates it, so it comes back unset.
- Read serialization (`perform_extra_serialization`) maps `id = external_id`, replaces `encounter` with its `external_id`, and expands `created_by`/`updated_by` via `serialize_audit_users` (cached `UserSpec`).
- `body_site` and `recorded_date` exist on the model but no current spec reads or writes them — storage-only, outside the standard `Condition` API surface.
- `body_site` and `recorded_date` exist on the model. `body_site` is read and written by the specs as a bound `Coding`; `recorded_date` is storage-only and outside the standard `Condition` API surface.

## Related models

Expand All @@ -182,7 +186,7 @@ Deleting a `Patient` or `Encounter` cascades to its `Condition` rows. The column

## API integration notes

- Send `code` as a structured `Coding` (`{system, code, display}`) drawn from the SNOMED CT clinical-finding value set, not as free text. Always include `verification_status`; add `category` and `encounter` when creating.
- Send `code` as a structured `Coding` (`{system, code, display}`) drawn from the SNOMED CT clinical-finding value set, not as free text. Always include `verification_status`; add `category` and `encounter` when creating. Send `body_site` as a `Coding` from the body-site value set when the anatomical location matters.
- `onset` and `abatement` are structured choice-of-type objects (`*_datetime`, `*_age`, `*_string`, `note`), not arbitrary JSON. `onset_datetime` must be timezone-aware and not in the future.
- Don't send `patient`, `external_id`, audit fields, or `deleted` from the client — the server owns them.

Expand Down
Loading