Skip to main content

repository

The eligibility domain's repository methods.

The evidence behind a patient's verdict, and what it is made of.

Mixed into CacheBackedPatientDataRepository, which supplies the cache handle they read through.

Module​

Functions​

build_evidence_mapping​

def build_evidence_mapping(evidence: Mapping[str, Any]) ‑> dict[str, str]:

Map criteria-matching config input fields to their evidence criterion key.

Rebuilt from the evidence itself: each criterion in evidence["criteria"] carries the config input field(s) that produced it (config_fields, a {config_field: {operator: operand}} map stamped at evidence-build time), so this inverts its keys to {config_field: output_field} without consulting any static config→criterion table. Lets a caller resolve "which evidence entry relates to total_ga_area_lower_bound?" directly. A range criterion's lower + upper bound both resolve to the one merged criterion.

Arguments

  • evidence: A patient_eligibility evidence object (with a criteria sub-map keyed by output_field), or any mapping carrying criteria.

Returns A {config_field: output_field} map over the criteria present. Empty for evidence lacking config_fields (e.g. rows written before it was added).

criteria_counts​

def criteria_counts(    evidence: Mapping[str, Any] | None,) ‑> CriteriaCounts | None:

Count a patient's protocol criteria by state, from their stored evidence.

Arguments

  • evidence: A patient_eligibility evidence object, with a criteria sub-map keyed by output_field.

Returns The counts, or None when the evidence has no criteria_tree, or a tree with no protocol criteria.

protocol_criterion_states​

def protocol_criterion_states(    node: Mapping[str, Any], inherited_type: str | None = None,) ‑> list[str]:

Return the state of each protocol criterion in a served criteria_tree.

A protocol criterion is the highest node on its branch with an item_number and a resolved criterion_type; the nodes below it are its sub-items, so the walk stops there.

A criterion that passes only because a not_assessed part, such as a manual sub-item, is assumed met is not_assessed: it passes once a site checks that part (see _pass_needs_site_check).

Arguments

  • node: The (sub)tree to walk, as stored in the evidence.
  • inherited_type: The criterion_type resolved from the ancestors. Callers should not pass this.

Returns The states, in tree order. A criterion with no state is left out.

Classes​

EligibilityRepositoryMixin​

class EligibilityRepositoryMixin():

One domain's methods, mixed into the repository.

Methods​


get_eligibility_evidence​

def get_eligibility_evidence(    self, bitfount_patient_id: str, project_id: str,) ‑> EligibilityEvidence | None:

Return rolled-up evidence for a (patient, trial), or None.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: The trial (project) ID.

Returns The EligibilityEvidence, or None if there is no rollup.