# Model: Diagnosis

**Table**: `clinic_diagnoses` (new, Phase 6)

## Purpose

A structured, trackable problem list per patient — replaces trying to infer "does this patient
have diabetes" by parsing the `assessment_text` free text on an encounter. Built on the same
"small master-data-backed list" spirit as `clinic_medical_history_options`, but per-patient and
per-encounter rather than global reference data.

## Fields

| Column | Type | Constraints | Notes |
|---|---|---|---|
| `id` | bigint | PK | |
| `encounter_id` | bigint | `foreignId('encounter_id')->constrained('clinic_encounters')->cascadeOnDelete()` | the encounter where this diagnosis was recorded/updated |
| `patient_id` | bigint | `foreignId('patient_id')->constrained('users')->restrictOnDelete()` | denormalized from the encounter for direct "all of this patient's diagnoses across every encounter" queries without a join |
| `code` | string | nullable | ICD-10 code if the doctor selects one; free text acceptable if not — kept simple, no full ICD-10 catalog import in this phase |
| `description` | string | | e.g. "Type 2 Diabetes Mellitus", "Class III Obesity" |
| `status` | string | default `'active'` | `active` / `resolved` / `chronic` |
| `diagnosed_at` | date | | |
| `resolved_at` | date | nullable | |
| `created_at` / `updated_at` | timestamp | | |

## Relationships

| Relation | Type | Target |
|---|---|---|
| `encounter()` | `belongsTo` | `Encounter` |
| `patient()` | `belongsTo` | `User` |

## Decisions

- `code` accepts free text rather than requiring a full ICD-10 lookup table — importing/maintaining
  a complete ICD-10 catalog is a significant undertaking on its own and wasn't part of the scope
  discussed with the user; a lightweight optional code field keeps the door open for a proper
  catalog later without blocking this phase.
- `status: chronic` (distinct from `active`) exists specifically because diabetes/obesity/endocrine
  care is built around chronic-disease management — Phase 13's "diabetes control rate" report
  filters on patients with a `chronic` diabetes diagnosis, not just anyone with an `active` one
  from a single visit.
