allergy_intolerance
Criteria on a patient's allergies and intolerances (FHIR AllergyIntolerance).
The allergy leaf (AllergyCriterion): an allergy to a matching substance is
recorded for the patient. A record matches on its own code or text, or on the
substance of one of its reactions. Some EHRs (NextGen) give no SNOMED code
for an allergen, so a text match is often what finds it.
Module
Functions
allergy_leaf_filter
def allergy_leaf_filter( criterion: AllergyCriterion, ctx: FilterBuildContext,) ‑> MethodFilter:Build a MethodFilter for an AllergyCriterion criteria_tree leaf.
Uses _build_code_date_matcher for its code/date/selector handling
exactly as every other code-addressed leaf does (see
code_leaf_filter's docstring), passing _allergy_entry_matches_code
as its entry_matches_code override in place of the default
single-location predicate: an allergy's code can live in either its own
code_code or a reaction[].substance, not one fixed place. It reads
against the fixed ALLERGIES_COLUMN rather than a resource-keyed one —
AllergyCriterion has no condition-vs-procedure resource choice to make,
the same reason MedicationCriterion has none.
Arguments
criterion: The leaf to compile.ctx: What the filter builders share. Itsreference_dateis "today", for resolvingdate_range.
Returns
A MethodFilter degrading to unknown when ALLERGIES_COLUMN is
absent from the row, or the row's cell is unreadable — the same
missing-data convention code_leaf_filter uses.
Classes
AllergyCriterion
class AllergyCriterion(**data: Any):An EHR allergy/intolerance, matched by code, reaction substance, or text.
Per FHIR R4's AllergyIntolerance
(https://hl7.org/fhir/R4/allergyintolerance.html), a qualifying code can
live in either the resource's own top-level code (a CodeableConcept,
0..1 — a resource may carry no coded diagnosis at all) or any of its
reaction[].substance entries (also a CodeableConcept, 0..*). An
entry qualifies against code/code_system if either location
matches — see allergy_leaf_filter, which implements this OR across
both locations.
text matches the entry's own code_text instead, for allergens that
arrive with no code at all. That is not a rare edge case: NextGen
resolves an allergen's vocabulary from its allergyTypeId rather than
from what the allergen is, so a food recorded as a Base Ingredient is
pointed at RxNorm, finds no concept there, and arrives uncoded — a
wheat-flour allergy no coded criterion can ever match.
code is optional here (unlike every other code-addressed leaf) so that
a text-only criterion is expressible; supplying neither is rejected.
When both are given they are additional restrictions, not alternatives:
an entry must match both its code and its text to qualify — text
narrows a code match rather than offering an alternative route around
it (unlike the OR the two code locations use against each other). To
match the same conceptual allergen across a coded-vs-uncoded record
split, use two leaves under an OrGroup instead of combining code and
text on one.
Arguments
node: Discriminator identifying this as anallergy-typecriteria_treenode.code: As_BareCodeAddressedLeaf.code; omit it for a text-only criterion.text: Free text matched against the entry'scode_text, glob-capable the same waycodeis (e.g."*PISTACHIO*"), or a list of alternatives. Matched case-insensitively, unlikecode: the same allergen is described in different casing by different backends (NextGen upper-cases descriptions, a FHIR server carries whatever its source system holds), so a case-sensitive match would silently depend on which EHR answered. Searched across every field that names the allergen:code_text, eachcodings[].display, and each reaction'ssubstance_text/substance_codings[].display— see_allergy_text_candidates. A NextGen-sourced entry carries no reactions at all (its reaction records name the symptom, not the allergen, so its querier drops them), so in practice only the first two are populated there.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Variables
- static
criterion_noun : ClassVar[str]
- static
model_config
- static
node : Literal['allergy']
Methods
model_post_init
def model_post_init(self: BaseModel, context: Any, /) ‑> None:This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.
Arguments
self: The BaseModel instance.context: The context.