Skip to main content

routes

HTTP routes for the patients domain.

The cohort listings, a patient's summary and the trial queue.

Module​

Functions​

get_eligibility_counts​

def get_eligibility_counts(    trial_ids: Annotated[list[str], Query(min_length=1, description="Trial (project) IDs, repeated once per ID (`?trial_ids=t1&trial_ids=t2`). At least one non-blank ID is required. The counts cover the trial\'s effective cohort: a site review overrides the analysis verdict, and a review for a patient the trial has not analysed still counts. A trial with neither comes back with all three counts zeroed rather than being omitted."), AfterValidator(_require_non_empty_ids)],    repository: PatientDataRepository = Depends(dependency=<function get_repository>, use_cache=True, scope=None),    user: AuthenticatedUser = Depends(dependency=<function verify_jwt>, use_cache=True, scope=None),) ‑> dict[str, EligibilityCounts]:

Return eligibility counts for the requested trials.

Arguments

  • trial_ids: Trial (project) IDs, one per repeated trial_ids query param (e.g. ?trial_ids=t1&trial_ids=t2); at least one required.
  • repository: The patient-data repository.
  • user: The authenticated caller.

Returns A mapping of each requested trial ID to its status counts.

get_patient​

def get_patient(    bitfount_patient_id: BitfountPatientIdPath,    project_id: LastAnalysedScopeQuery = None,    repository: PatientDataRepository = Depends(dependency=<function get_repository>, use_cache=True, scope=None),    user: AuthenticatedUser = Depends(dependency=<function verify_jwt>, use_cache=True, scope=None),) ‑> PatientSummary:

Return a single patient by ID.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: Scopes last_analysed_image_date to one trial.
  • repository: The patient-data repository.
  • user: The authenticated caller.

Returns The patient summary.

Raises

  • HTTPException: 404 if the patient is not found.

get_trial_candidate_counts​

def get_trial_candidate_counts(    project_id: "Annotated[str, Path(description='The trial (project) ID whose candidate counts to return.')]",    repository: PatientDataRepository = Depends(dependency=<function get_repository>, use_cache=True, scope=None),    user: AuthenticatedUser = Depends(dependency=<function verify_jwt>, use_cache=True, scope=None),) ‑> CandidateCounts:

Return a trial's candidate counts, bucketed by review status.

The candidates still to review, plus a count per review status a site user can record. Every count is over patients with an identity row, so it matches what a listing of that bucket serves.

Arguments

  • project_id: The trial (project) ID.
  • repository: The patient-data repository.
  • user: The authenticated caller.

Returns The trial's CandidateCounts.

list_patients​

def list_patients(    search: Annotated[str | None, Query(description="Case-insensitive substring matched against a patient\'s name or EHR ID. Omitted or blank matches everyone.")] = None,    trial: Annotated[str | None, Query(description="One trial (project) ID; return that trial\'s cohort — every patient it evaluated, whatever the verdict. Narrow to particular verdicts with `statuses`. Single-valued, unlike `eligible_trials`: repeating it is a 400, not a union. Each summary\'s `trial_statuses` still reports every trial the patient has a verdict for, unaffected by this filter.")] = None,    statuses: "Annotated[list[EligibilityStatus] | None, Query(description='Which verdicts `trial` (or `eligible_trials`) admits, repeated once per value (`?statuses=ineligible&statuses=unknown`). Omitted, every verdict is admitted. Ignored when neither trial filter is given.')]" = None,    eligible_trials: "Annotated[list[str] | None, Query(description='Zero or more trial (project) IDs, repeated once per ID; return only patients eligible for **any** of them. The multi-trial filter: `trial` takes one trial and reads any verdict, this takes several and reads only `eligible`, so neither subsumes the other. Pass one or the other, never both.')]" = None,    project_id: LastAnalysedScopeQuery = None,    page: Annotated[int, Query(ge=1, description=PAGE_DESCRIPTION)] = 1,    page_size: Annotated[int, Query(ge=1, le=200, description=PAGE_SIZE_DESCRIPTION)] = 50,    repository: PatientDataRepository = Depends(dependency=<function get_repository>, use_cache=True, scope=None),    user: AuthenticatedUser = Depends(dependency=<function verify_jwt>, use_cache=True, scope=None),) ‑> PatientList:

List patients, filtered and searched server-side, one page at a time.

Arguments

  • search: Case-insensitive substring matched against a patient's name or EHR id.
  • trial: One trial (project) ID whose cohort to return — every patient the trial evaluated, narrowed by statuses. Blank is ignored.
  • statuses: Which verdicts the trial filter admits, one per repeated statuses query param (e.g. ?statuses=ineligible&statuses=unknown). Omitted, all three are admitted.
  • eligible_trials: Zero or more trial (project) IDs; restricts to patients eligible for any of them (union). Blank values are ignored. Reads only the eligible verdict, whatever statuses says.
  • project_id: Scopes last_analysed_image_date to one trial.
  • page: 1-indexed page number.
  • page_size: Items per page (1–200, default 50).
  • repository: The patient-data repository.
  • user: The authenticated caller.

Returns A PatientList envelope: the requested page in items, and the count of all matching patients (before pagination) in total.

Raises

  • HTTPException: 400 if both trial and eligible_trials are given.

list_trial_patients​

def list_trial_patients(    project_id: "Annotated[str, Path(description='The trial (project) ID whose patients to list.')]",    statuses: "Annotated[list[EligibilityStatus] | None, Query(description='Which verdicts to include, repeated once per value (`?statuses=eligible&statuses=unknown`). Omitted, every verdict is included.')]" = None,    review_state: "Annotated[ReviewState, Query(description='`unreviewed` (the default) is the review queue; `reviewed` is the patients the site has reviewed, as `GET /trials/{project_id}/reviews` serves them, each with its `review`; `all` is both, reviewed patients first.')]" = unreviewed,    review_statuses: "Annotated[list[ReviewStatus] | None, Query(description='Which review statuses to admit, repeated once per value (`?review_statuses=screening`). Narrows the reviewed group to a single funnel stage — or `rejected` — so one bucket can be listed on its own; omitted, every deciding review is admitted. Ignored for the unreviewed group.')]" = None,    page: Annotated[int, Query(ge=1, description=PAGE_DESCRIPTION)] = 1,    page_size: Annotated[int, Query(ge=1, le=200, description=PAGE_SIZE_DESCRIPTION)] = 50,    repository: PatientDataRepository = Depends(dependency=<function get_repository>, use_cache=True, scope=None),    user: AuthenticatedUser = Depends(dependency=<function verify_jwt>, use_cache=True, scope=None),) ‑> TrialPatientList:

List one trial's review queue, ranked for the trial detail view.

The trial's candidates that still need review: a patient the site has already reviewed for this trial is served by GET /trials/{project_id}/reviews instead. Unlike GET /patients, which orders by name, this orders by the trial's own verdict (eligible, then unknown, then ineligible), then score highest first with unscored patients last, then patient ID. A trial with no published eligibility yields an empty list rather than a 404, as /eligibility-counts yields zeroed counts. Each patient carries criteria_counts: their protocol criteria for this trial, counted by state.

Arguments

  • project_id: The trial (project) ID.
  • statuses: Which verdicts to include, one per repeated statuses query param. Omitted, all three are included. Judged on the analysis verdict for unreviewed patients, and on the verdict the review stands in for for reviewed ones.
  • review_state: unreviewed for the queue (the default), reviewed for the reviewed patients, or all for both, reviewed first.
  • review_statuses: Which review statuses the reviewed group admits, one per repeated review_statuses query param. Omitted, every deciding review is admitted.
  • page: 1-indexed page number.
  • page_size: Items per page (1–200, default 50).
  • repository: The patient-data repository.
  • user: The authenticated caller.

Returns A TrialPatientList envelope: the requested page in items, and the count of all matching patients (before pagination) in total.