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
17 changes: 11 additions & 6 deletions versioned_docs/version-3.0/references/clinical/condition.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A `Condition` records a clinical problem, diagnosis, or symptom against a patien
A `Condition` lives across two layers, and the split matters when you read the code:

- The Django model (`care/emr/models/condition.py`) is storage. Its coded and timing fields (`code`, `body_site`, `onset`, `abatement`) are opaque `JSONField`s — the model says nothing about their shape.

- The Pydantic resource specs (`care/emr/resources/condition/spec.py`) are the API. They define the enums, the structure inside each JSON field, field validation, the value-set binding for `code`, and the separate read and write schemas.

## Models
Expand All @@ -41,7 +42,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. On write, an optional single [`Coding`](#coding-shape) bound to the body-site value set (`system-body-site-observation`, `CARE_BODY_SITE_VALUESET`). On read, a plain `Coding` or `null`. |

### Timing

Expand Down Expand Up @@ -139,27 +140,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]` — a `Coding` checked against the body-site value set (`care/emr/resources/observation/valueset.py`, slug `system-body-site-observation`), the same value set observations use. It is optional on `ConditionSpec` and `ConditionUpdateSpec`, and defaults to `null`. The read spec 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, and `body_site` must belong to the body-site value set when it is supplied.
- `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.
- `recorded_date` exists on the model but no current spec reads or writes it — storage-only, outside the standard `Condition` API surface.

## Related models

Expand Down
Loading