protocol
What the patients domain needs of the data layer.
The cohort listings and their counts, a patient's own summary, and the queue of candidates a trial keeps.
Classes
PatientsRepository
class PatientsRepository(*args, **kwargs):Read-facade over patient-eligibility data.
Methods speak the API's vocabulary (trial/project and patient IDs) and
return pydantic response models. Implementations hide any underlying
storage detail (e.g. the cache's task_hash keying).
Ancestors
Subclasses
Methods
get_eligibility_counts
def get_eligibility_counts( self, trial_ids: list[str],) ‑> dict[str, EligibilityCounts]:Return eligibility counts keyed by trial (project) ID.
Arguments
trial_ids: The trial (project) IDs to return counts for.
Returns A mapping of each requested trial ID to its status counts.
get_patient
def get_patient( self, bitfount_patient_id: str, project_id: str | None = None,) ‑> PatientSummary | None:Return a single patient summary, or None if not found.
Arguments
bitfount_patient_id: The Bitfount patient ID.project_id: When given, scopeslast_analysed_image_dateto that trial; omitted, it spans every trial the pod publishes.
Returns The patient summary, or None if no patient with that ID exists.
get_trial_candidate_counts
def get_trial_candidate_counts( self, project_id: str,) ‑> CandidateCounts:Return one trial's candidate counts, bucketed by review status.
Arguments
project_id: The trial (project) ID.
Returns
A CandidateCounts: the queue's to_review count and a count per
review status, over patients with an identity row.
list_patients
def list_patients( self, *, search: str | None = None, trials: list[str] | None = None, statuses: Collection[EligibilityStatus] | None = None, project_id: str | None = None, page: int = 1, page_size: int = 50,) ‑> PatientList:Return one page of patients, filtered and searched server-side.
Arguments
search: Case-insensitive substring matched against a patient's name or EHR id;None/blank matches everyone.trials: If given, restrict to patients with a verdict for any of these trials (union). Each returned patient'strial_statusesstays complete regardless of the filter.statuses: Which verdictstrialsadmits.Noneadmits all three, selecting those trials' whole cohorts. Ignored whentrialsisNone.project_id: When given, scopeslast_analysed_image_dateto that trial; omitted, it spans every trial the pod publishes.page: 1-indexed page number.page_size: Number of items per page.
Returns
A PatientList whose items are the requested page and whose
total is the count of all matching patients before pagination.
list_trial_patients
def list_trial_patients( self, project_id: str, *, statuses: Collection[EligibilityStatus] | None = None, review_state: ReviewState = unreviewed, review_statuses: Collection[ReviewStatus] | None = None, page: int = 1, page_size: int = 50,) ‑> TrialPatientList:Return one page of a single trial's patients, ranked for display.
Ordered by verdict (eligible, then unknown, then ineligible), then
eligibility score descending with an absent score last, then patient ID.
Arguments
project_id: The trial (project) ID.statuses: The verdicts to admit.Noneadmits all three.review_state: Which patients to list: the unreviewed queue (the default), the reviewed ones, orall(reviewed first).review_statuses: When given, restrict the reviewed group to patients whose review in force carries one of these statuses, so one funnel stage (orrejected) can be listed on its own. Takes precedence overstatusesfor the reviewed group; the unreviewed group still honoursstatuses.page: 1-indexed page number.page_size: Number of items per page.
Returns
A TrialPatientList whose items are the requested page, each with
the patient's criteria counts for the trial, and whose total is
the count of all admitted patients before pagination; empty for a
trial with no published eligibility.