simulate
Evaluate a criteria_tree against example patients, without a task run.
Each example patient is one study-eye scan, an optional fellow-eye scan, and
the EHR records the patient's rows would carry. They go through the same
filters, outcomes and tree verdict as a real run, so the result is what a run
would serve for that patient. The matching spec
(tests/bitfount/steps/criteria_matching/spec/) checks its statements with
it, and so can anyone checking a trial's tree.
Records take the shape the ehr_data cache stores: the fields of the
bitfount.externals.ehr.types dataclasses, with ISO dates. A date may also
be relative to the run date ("-3m", "-2y", "+10d"), so an example keeps
testing the same side of a date window whenever it runs. An EHR key left out
means that record type was never read; an empty list means it was read and
holds nothing.
Module
Functions
resolve_relative_dates
def resolve_relative_dates(value: Any, today: date) ‑> Any:value with every relative date string made an ISO date.
Arguments
value: A record, a list or mapping of them, or a single value.today: The date relative dates count from.
Returns
value with each "-3m"-style string replaced by the ISO date it
names; everything else unchanged.
simulate
def simulate( criteria_tree: CriterionTreeNode | Mapping[str, Any], patients: Iterable[ExamplePatient], today: date | None = None,) ‑> list[ExampleResult]:Evaluate criteria_tree against each example patient.
Arguments
criteria_tree: A validated tree, or one as written in a config.patients: The example patients.today: The date the run counts from: relative record dates and the tree's date windows both count from it. Defaults to today in UTC.
Returns One result per patient, in order.
Classes
ExamplePatient
class ExamplePatient( id: str, scan: Mapping[str, Any] = {}, ehr: Mapping[str, Any] = {}, fellow_scan: Mapping[str, Any] | None = None,):One patient to evaluate a tree against.
Attributes
id: Names the patient; it also groups the study and fellow scans.scan: The study-eye scan's columns, e.g."Scan Laterality","Age (yrs)",total_ga_area.Deceaseddefaults to false.ehr: EHR record lists keyed by column (Conditions,Procedures,Observations,Medications,Allergies,Devices).fellow_scan: The other eye's scan columns, formulti_scannodes, orNonefor a patient with one scan.
Variables
-
ehr : Mapping[str, typing.Any]
-
fellow_scan : collections.abc.Mapping[str, typing.Any] | None
-
id : str
-
scan : Mapping[str, typing.Any]
ExampleResult
class ExampleResult( status: str, score: float | None, review_flags: list[str], served_tree: AnnotatedTreeNode,):What a run would serve for one example patient's study-eye scan.
Attributes
status: The tree's root state:pass,failorunknown.score: The root's eligibility score, orNonewhen unscored.review_flags: The review reasons the tree raised.served_tree: The annotated tree, with every node's state.
Variables
-
review_flags : list[str]
-
score : float | None
-
served_tree : AnnotatedTreeNode
-
status : str