References/Allergy Intolerance: Difference between revisions
More languages
More actions
OHC identity seed |
Automated edit (via update-page on MediaWiki MCP Server) |
||
| Line 268: | Line 268: | ||
* The coded status fields (<code>clinical_status</code>, <code>verification_status</code>, <code>category</code>, <code>criticality</code>) accept only the enum values listed above; anything else is rejected on write. |
* The coded status fields (<code>clinical_status</code>, <code>verification_status</code>, <code>category</code>, <code>criticality</code>) accept only the enum values listed above; anything else is rejected on write. |
||
* Never send <code>patient</code> or <code>copied_from</code> — both are server-maintained. |
* Never send <code>patient</code> or <code>copied_from</code> — both are server-maintained. |
||
{{Navbox clinical}} |
|||
{{Related}} |
{{Related}} |
||
Wiki: ohcnwiki.tellmey.fyi |
|||
Latest revision as of 09:32, 6 July 2026
AllergyIntolerance records a patient's allergy or intolerance to a substance, scoped to the encounter where it was captured. Care aligns it to FHIR AllergyIntolerance. You touch this resource when recording a known allergy during an encounter or reading a patient's allergy list.
The Django model is the storage layer. Several of its fields are opaque JSONFields whose real structure lives only in the Pydantic resource specs, which also define the enums, validation, the bound value set, and the read/write API schemas.
Source:
- Model: [https://github.com/ohcnetwork/care/blob/develop/care/emr/models/allergy_intolerance.py
care/emr/models/allergy_intolerance.py] - Specs: [https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/allergy_intolerance/spec.py
care/emr/resources/allergy_intolerance/spec.py] · [https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/allergy_intolerance/valueset.pyvalueset.py] - Base resource: [https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py
care/emr/resources/base.py]
Models
| Model | Purpose |
|---|---|
AllergyIntolerance
|
Records a patient's allergy or intolerance to a substance, scoped to an encounter |
AllergyIntolerance extends EMRBaseModel, the shared Care EMR base that provides external_id, created_date/modified_date, soft-delete via deleted, created_by/updated_by, and history/meta JSON.
AllergyIntolerance fields
Clinical classification
| Field | Type (storage) | Spec type / values | Notes |
|---|---|---|---|
clinical_status |
CharField(100), null |
ClinicalStatusChoices
| |
verification_status |
CharField(100), null |
VerificationStatusChoices
| |
category |
CharField(100), null |
CategoryChoices
| |
criticality |
CharField(100), null |
CriticalityChoices
| |
allergy_intolerance_type |
CharField(20), default "allergy" |
AllergyIntoleranceTypeOptions
|
Substance & coding
| Field | Type (storage) | Spec type / shape | Notes |
|---|---|---|---|
code |
JSONField (default=dict, not null/blank) |
Coding bound to value set system-allergy-code
|
Coding shape: { system?: str, version?: str, code: str (required), display?: str } (extra="forbid").
Timing
| Field | Type (storage) | Spec type / shape | Notes |
|---|---|---|---|
onset |
JSONField (default=dict) |
AllergyIntoleranceOnSetSpec
| |
recorded_date |
DateTimeField, null |
datetime
| |
last_occurrence |
DateTimeField, null |
datetime
|
AllergyIntoleranceOnSetSpec shape:
| Sub-field | Type | Required | Default |
|---|---|---|---|
onset_datetime
|
datetime
|
No | None
|
onset_age
|
int
|
No | None
|
onset_string
|
str
|
No | None
|
note
|
str
|
Yes | — |
Context & notes
| Field | Type (storage) | Spec type | Notes |
|---|---|---|---|
patient |
FK → Patient (CASCADE) |
excluded from specs | |
encounter |
FK → Encounter (CASCADE) |
UUID4
| |
note |
TextField, null |
str
| |
copied_from |
BigIntegerField, null (default=None) |
not exposed |
Enum values
ClinicalStatusChoices
| Value |
|---|
active
|
inactive
|
resolved
|
VerificationStatusChoices
| Value |
|---|
unconfirmed
|
presumed
|
confirmed
|
refuted
|
entered_in_error
|
CategoryChoices
| Value |
|---|
food
|
medication
|
environment
|
biologic
|
CriticalityChoices
| Value |
|---|
low
|
high
|
unable_to_assess
|
AllergyIntoleranceTypeOptions
| Value |
|---|
allergy (default)
|
intolerance
|
Bound value set
| Value set | Slug | System | Status |
|---|---|---|---|
CARE_ALLERGY_CODE_VALUESET ("Allergy")
|
system-allergy-code
|
SNOMED CT (http://snomed.info/sct)
|
active
|
On write, code binds to this value set via ValueSetBoundCoding[...slug], which validates the submitted Coding against the value set (validate_valueset). The compose admits SNOMED CT concepts that are is-a descendants of: 105590001, 418038007, 267425008, 29736007, 340519003, 190753003, 413427002, 716186003. The value set is also registered as a system (register_as_system()).
Resource specs (API schema)
Every spec extends EMRResource (care/emr/resources/base.py), which provides serialize (DB object → pydantic, via model_construct) and de_serialize (pydantic → DB object), plus the perform_extra_serialization / perform_extra_deserialization hooks. BaseAllergyIntoleranceSpec sets __model__ = AllergyIntolerance and __exclude__ = ["patient", "encounter"]; those two fields skip auto-mapping and are wired by the hooks instead. The base also carries meta on every spec.
| Spec class | Role | Fields exposed |
|---|---|---|
BaseAllergyIntoleranceSpec
|
shared base | id: UUID4
|
AllergyIntoleranceWriteSpec
|
write · create | clinical_status, verification_status, category, criticality, last_occurrence?, recorded_date?, encounter (UUID4), code (bound Coding), onset (default {}), allergy_intolerance_type (default allergy), note?
|
AllergyIntoleranceUpdateSpec
|
write · update | clinical_status, verification_status, criticality, last_occurrence?, note?, encounter (UUID4), allergy_intolerance_type (default allergy)
|
AllergyIntoleranceReadSpec
|
read · list & detail | id, clinical_status, verification_status, category, criticality, code (Coding), encounter (UUID4), onset, last_occurrence?, recorded_date?, note?, allergy_intolerance_type, created_by?, updated_by?, created_date, modified_date
|
AllergyIntoleranceOnSetSpec
|
nested (shape of onset JSON)
|
onset_datetime?, onset_age?, onset_string?, note (required)
|
category,code,onset, andrecorded_dateare accepted only on create (AllergyIntoleranceWriteSpec) and absent fromAllergyIntoleranceUpdateSpec— once set, the update path cannot change them.AllergyIntoleranceReadSpectypes the coded fields as plainstrandcodeasCoding, and skips value-set re-validation, relying onmodel_constructfor speed.
Validation
encounter(both write specs):validate_encounter_existsrejects with"Encounter not found"when noEncounterhas thatexternal_id.code(create): validated against value setsystem-allergy-code— must be a permitted SNOMED CT allergy concept.onset.noteis required whenever anonsetobject is supplied.datetimefields are stored as-is. The base enforces tz-aware handling for period-style values throughPeriodSpec(start ≤ end, both tz-aware), butAllergyIntoleranceuses scalar datetimes rather than aPeriodSpec.
Server-side side effects
- Create (
AllergyIntoleranceWriteSpec.perform_extra_deserialization): resolvesencounterbyexternal_id, setsobj.encounter, then setsobj.patient = obj.encounter.patient. The client never sendspatientdirectly. - Update (
AllergyIntoleranceUpdateSpec.perform_extra_deserialization): whenencounteris present, re-resolves it and setsobj.encounter. - Read (
AllergyIntoleranceReadSpec.perform_extra_serialization): setsmapping["id"] = obj.external_id, setsencountertoobj.encounter.external_id, and serializes audit users (created_by/updated_by) viaserialize_audit_users.
Methods & save behaviour
serialize/de_serializeare inherited fromEMRResource.de_serializemaps only DB fields that are neither in__exclude__norid/external_id, then callsperform_extra_deserializationfor the encounter/patient wiring above.patientis always derived from the encounter on create; no client payload can set it.copied_fromis platform-maintained for propagated/copied records and belongs to no spec.patientandencounterbothCASCADE-delete, so an allergy record never outlives its patient or encounter.
API integration notes
- API field names follow the spec classes above.
encounteris sent and returned as a UUIDexternal_id, not a numeric FK. - Submit
codeas aCodingdrawn from the bound value setsystem-allergy-code, not free text, so allergies can be matched against medications and other business logic. - The coded status fields (
clinical_status,verification_status,category,criticality) accept only the enum values listed above; anything else is rejected on write. - Never send
patientorcopied_from— both are server-maintained.
Related
Pages that link here:
- Reference: References/Base models & conventions
Wiki: ohcnwiki.tellmey.fyi