# Immunization

Technical reference for the `Immunization` model in Care EMR. An `Immunization` records one vaccine dose for one patient in one encounter: a dose that the facility gave, a dose that the patient or another provider reports, or a dose that was not given. It maps to the FHIR `Immunization` resource.

The Django model stores the record. Several fields are `JSONField`s. The Pydantic resource specs bind them to value sets and give them a shape, so read the spec columns below for what a write must contain.

**Source:**

* Model: [`care/emr/models/immunisation.py`](https://github.com/ohcnetwork/care/blob/develop/care/emr/models/immunisation.py) (class `Immunization`)
* Specs: [`care/emr/resources/immunisation/immunization.py`](https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/immunisation/immunization.py)
* Viewset: [`care/emr/api/viewsets/immunization/immunization.py`](https://github.com/ohcnetwork/care/blob/develop/care/emr/api/viewsets/immunization/immunization.py)
* Permissions: [`care/security/permissions/immunization.py`](https://github.com/ohcnetwork/care/blob/develop/care/security/permissions/immunization.py) · [`care/security/authorization/immunization.py`](https://github.com/ohcnetwork/care/blob/develop/care/security/authorization/immunization.py)

## Models

`care/emr/models/immunisation.py` holds three models. This page documents `Immunization`. The other two have their own pages.

| Model | Purpose | Page |
| - | - | - |
| `Immunization` | One vaccine dose given, reported or not given | This page |
| `ImmunizationRecommendation` | One planned dose, or a group of planned doses, in a patient's schedule | [Immunization recommendation](https://docs.ohc.network/references/clinical/immunization-recommendation.md) |
| `ImmunizationPolicy` | A reusable template of recommendations, for one facility or for the instance | [Immunization policy](https://docs.ohc.network/references/definitions/immunization-policy.md) |

All three extend [`EMRBaseModel`](https://docs.ohc.network/references/foundation/base-model.md), which gives `external_id`, the audit fields, soft delete through `deleted`, `history` and `meta`.

## `Immunization` fields

### Status and vaccine

| Field | Type | Spec type | Notes |
| - | - | - | - |
| `status` | `CharField(100)` | `ImmunizationStatus` | Required on create. Optional on update. See [ImmunizationStatus values](#immunizationstatus-values) |
| `reason` | `CharField(100)`, nullable | `ImmunizationReason` | Optional. Why the dose was not given. The backend does not tie it to `not_done`; the care\_fe form asks for it only when `status` is `not_done` |
| `code` | `JSONField`, default `{}` | `Coding`, bound to `system-medication` | Required on create. Optional on update. The vaccine |
| `primary_source` | `BooleanField` | `bool` | Required on create. Optional on update. `true` when the facility gave the dose. The care\_fe form sends `false` for a historical (reported) record |
| `occurrence` | `DateTimeField`, nullable | `datetime` | Optional. When the dose was given |

### Administration details

| Field | Type | Spec type | Notes |
| - | - | - | - |
| `site` | `JSONField`, nullable | `Coding`, bound to `system-body-site` | Optional |
| `route` | `JSONField`, nullable | `Coding`, bound to `system-route` | Optional |
| `dose_quantity` | `JSONField`, nullable | `Quantity` | Optional. See [Nested JSON shapes](#nested-json-shapes) |
| `is_subpotent` | `BooleanField`, nullable | `bool` | Optional |
| `subpotent_reason` | `TextField`, nullable | `str` | Optional. Free text |
| `note` | `TextField`, nullable | `str` | Optional. Free text |

### Links

| Field | Type | Spec type | Notes |
| - | - | - | - |
| `encounter` | `FK → Encounter`, `CASCADE` | `UUID4` | Required on create. Write once: the update spec has no `encounter` field. See [Encounter](https://docs.ohc.network/references/clinical/encounter.md) |
| `patient` | `FK → Patient`, `CASCADE` | — | Server-set from the encounter. Not in any read spec |
| `facility` | `FK → Facility`, `PROTECT` | — | Server-set from the encounter. Not in any read spec |
| `recommendation` | `FK → ImmunizationRecommendation`, `SET_NULL`, nullable | `UUID4` or `null` | Optional. Must belong to the same patient. `null` clears it |
| `product` | `FK → Product`, `SET_NULL`, nullable | `UUID4` or `null` | Optional. Must belong to the encounter's facility. See [Product](https://docs.ohc.network/references/supply/product.md) |
| `location` | `FK → FacilityLocation`, `SET_NULL`, nullable | `UUID4` or `null` | Optional. Must belong to the encounter's facility. See [Location](https://docs.ohc.network/references/facility/location.md) |
| `administered_by` | `FK → users.User`, `SET_NULL`, nullable | `str` (username) or `null` | Optional. Written as a username, read back as a `UserSpec` object |

Optional value fields (`reason`, `occurrence`, `site`, `route`, `dose_quantity`, `is_subpotent`, `subpotent_reason`, `note`) accept a value or no key. They do not accept `null`. The writer uses `exclude_defaults`, so a key that an update leaves out keeps its stored value.

## Enum values

### `ImmunizationStatus` values

| Value | care\_fe label |
| - | - |
| `draft` | Draft |
| `completed` | Completed |
| `entered_in_error` | Entered in error |
| `not_done` | Not given |

### `ImmunizationReason` values

HL7 v3 `ActReason` codes. The labels come from care\_fe.

| Value | care\_fe label |
| - | - |
| `IMMUNE` | Patient is immune |
| `MEDPREC` | Medical precaution |
| `OSTOCK` | Vaccine out of stock |
| `PATOBJ` | Patient objection |
| `PHILISOP` | Philosophical objection |
| `RELIG` | Religious objection |
| `VACEFF` | Vaccine efficacy concerns |
| `VACSAF` | Vaccine safety concerns |

## Nested JSON shapes

### `Coding` (`code`, `site`, `route`)

```
Coding {

  system:  str | null

  version: str | null

  code:    str            # required

  display: str | null

}
```

Extra keys are rejected. Care validates the code against the bound value set (`system-medication`, `system-body-site` or `system-route`).

### `Quantity` (`dose_quantity`)

```
Quantity {

  value: Decimal | null   # max 20 digits, 6 decimal places

  unit:  Coding | null

  code:  Coding | null

  meta:  dict | null

}
```

Extra keys are rejected.

## Resource specs (API schema)

| Spec | Role | Fields beyond `BaseImmunizationSpec` |
| - | - | - |
| `BaseImmunizationSpec` | Shared base | `id`, `status`, `reason`, `code`, `occurrence`, `primary_source`, `site`, `route`, `dose_quantity`, `note`, `is_subpotent`, `subpotent_reason` |
| `ImmunizationWriteSpec` | Shared write base | `recommendation`, `product`, `location`, `administered_by`. Resolves each link and checks its scope |
| `ImmunizationCreateSpec` | write · create | `encounter` (required). Sets `patient` and `facility` from the encounter |
| `ImmunizationUpdateSpec` | write · update | Makes `status`, `code` and `primary_source` optional. No `encounter` |
| `ImmunizationListSpec` | read · list | `encounter` (UUID), `recommendation` (UUID or `null`), `administered_by` (`UserSpec` or `null`) |
| `ImmunizationRetrieveSpec` | read · detail | List fields plus `product`, `location` (UUIDs or `null`), `created_by`, `updated_by` |

The read specs do not return `patient` or `facility`.

## API integration notes

* Endpoints are nested under the patient: `/api/v1/patient/{patient_external_id}/immunization/record/`. The viewset allows create, list, retrieve and update. It has no delete. To void a record, set `status` to `entered_in_error`.
* Create checks that the encounter belongs to the patient in the URL.
* Filters: `encounter`, `recommendation`, `facility` (UUIDs), `status` and `reason` (comma-separated, several values), `occurrence` (`occurrence_after` / `occurrence_before`), `primary_source`. Ordering: `created_date`, `modified_date`.
* Create and update need `can_write_immunization` in the encounter. Care refuses both when the encounter status is `completed`, `cancelled`, `entered_in_error` or `discontinued`. Update checks the record's own encounter.
* Read needs `can_read_immunization` on the patient, or in the record's encounter. A list without `can_read_immunization` on the patient must pass an `encounter` filter for an encounter that the user can read.
* Default roles with `can_write_immunization`: Facility Admin, Doctor, Nurse. Default roles with `can_read_immunization`: Facility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist. See [Permission](https://docs.ohc.network/references/access-governance/permission.md).
* Saving a record does not change its recommendation. care\_fe sets the recommendation's `forecast_status` to `complete` with a separate update after it saves a completed dose.
* A referral can link an immunization as a resource of type `immunization`. Care renders it with `ImmunizationListSpec` for users who can view the patient's or the encounter's clinical data.

## Related

* Reference: [Immunization recommendation](https://docs.ohc.network/references/clinical/immunization-recommendation.md)
* Reference: [Immunization policy](https://docs.ohc.network/references/definitions/immunization-policy.md)
* Reference: [Encounter](https://docs.ohc.network/references/clinical/encounter.md)
* Reference: [Patient](https://docs.ohc.network/references/clinical/patient.md)
* Reference: [Product](https://docs.ohc.network/references/supply/product.md)
* Reference: [Location](https://docs.ohc.network/references/facility/location.md)
* Reference: [Value set](https://docs.ohc.network/references/definitions/valueset.md)
* Source (model): [immunisation.py on GitHub](https://github.com/ohcnetwork/care/blob/develop/care/emr/models/immunisation.py)
* Source (specs): [resources/immunisation on GitHub](https://github.com/ohcnetwork/care/tree/develop/care/emr/resources/immunisation)
