Skip to main content

served_tree

The served criteria_tree: the evaluated tree as the evidence carries it.

attach_criteria_tree_verdict evaluates the tree for each evaluation and stores the result on it. annotate_criteria_tree gives every node its state and source, and every leaf its findings, with the findings builders of the domain modules.

Module​

Functions​

annotate_criteria_tree​

def annotate_criteria_tree(    criteria_tree: CriterionTreeNode,    node_outcomes: Sequence[CriterionOutcome],    authored: Mapping[str, Any] | None = None,    identity: SubjectIdentity | None = None,) ‑> AnnotatedTreeNode:

Add the results of one row to the configured tree.

Each node keeps its configured keys, and gets these keys:

  • state: pass, fail or unknown, the result of the condition of the node itself. A not node reverses the result of its child, so below a not, pass means that the condition matched. Every node of a not-analysed criterion (see is_not_analysed) is not_assessed, and gets none of the keys below.
  • source: the CriterionProvenance values of the node, or of the leaves below it. Not included if no leaf has a known source.
  • findings: only on a leaf. The records that the leaf read and decided on, as TreeFindings, whatever its state. An empty list means that the leaf read no record. Not included if the leaf has no records to show.
  • checked_window: only on a leaf. The dates within which the leaf searched for records. Not included if the leaf searched all records, or could not search.
  • unknown_reason: only on a node whose state is unknown, and only when the node has a reason of its own. Why it could not decide. A leaf usually has one; a combinator usually does not, since its children's reasons explain it. A multi_scan node that selected no scan has one, and so does a not with on_match: unknown whose child matched (flagged_match).

Arguments

  • criteria_tree: The configured tree. The node ids must be set.
  • node_outcomes: The outcome of each node for the row, from evaluate_criterion_tree.
  • authored: The result of authored_criteria_tree(criteria_tree). Give it to use one dump for many rows.
  • identity: The subject of the row. A scan finding gets the date and the eye of its scan.

Returns A new JSON-safe dict. This function does not change authored.

attach_criteria_tree_verdict​

def attach_criteria_tree_verdict(    evaluations: list[CriteriaEvaluation], criteria_tree: CriterionTreeNode | None,) ‑> None:

Fold a criteria_tree's verdict into each evaluation, in place.

For each evaluation:

  1. Moves every outcome whose tree_node_id is set out of outcomes into a leaf-id-to-outcome map.
  2. Evaluates criteria_tree against that map via evaluate_criterion_tree, which builds one outcome per node (leaf and combinator alike, stamping each one's resolved tree_group along the way) and collects review_flags in the same pass.
  3. Stores every node's outcome on tree_node_outcomes. A copy of the root's outcome — with config_field/output_field/column_name set to the fixed CRITERIA_TREE_FIELD and tree_node_id cleared, same as every prior phase's hand-built synthetic outcome — is appended back into outcomes.
  4. Puts the annotated tree in criteria_tree.

The copy, not the same object, is what goes back into outcomes: the root's real tree_node_id/output_field/column_name (its own node address, f"criteria_tree.{id}" for a combinator, or a real leaf's own identity when the whole tree is a single leaf) must survive unchanged in tree_node_outcomes for per-node introspection, while outcomes still needs exactly the fixed CRITERIA_TREE_FIELD tag: tabulate_criteria_outcomes keys off that constant (via column_name) to recognise the tree's synthetic combined outcome and exclude it from FILTER_CONTEXT_COLUMN, and attach_criteria_tree_verdict itself keys off tree_node_id is not None to recognise a tree outcome and move it out of outcomes — the copy must clear it, or a second pass over the same evaluations would mistake this already-attached root for a leaf to move again.

The root's outcome — and every combinator's — has grain/provenance derived from its children by _combinator_outcome, not fixed: a tree of only EHR-provenance, patient-grain leaves derives grain=PATIENT, provenance=EHR and routes through build_patient_level_evidence/ patient_grain_status accordingly. A tree with an eye-scoped EHR leaf derives grain=ORGAN and routes through build_scan_evidence, because its verdict depends on the study eye.

Leaf outcomes are split for every evaluation first, so a multi_scan node can read the outcomes of the patient's other rows.

A no-op when criteria_tree is None.

Arguments

  • evaluations: The evaluations to update in place.
  • criteria_tree: The configured tree, or None.