Skip to main content

repository

The reviews domain's repository methods.

The reviews in force, and recording or removing one.

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

Module​

Functions​

review_summary​

def review_summary(    project_id: str, review: PatientReviewRecord,) ‑> PatientReviewSummary:

Box one review in force for a trial.

Arguments

  • project_id: The trial (project) ID.
  • review: The review in force for that trial.

Returns The review's summary.

Classes​

ReviewsRepositoryMixin​

class ReviewsRepositoryMixin():

One domain's methods, mixed into the repository.

Methods​


add_patient_note​

def add_patient_note(    self,    bitfount_patient_id: str,    project_id: str,    note: str,    *,    user_id: str,    username: str,) ‑> ReviewTimelineEntry | None:

Add a note to a patient for a trial, or return None.

A note added this way stands on its own: no review is recorded, and the review in force — if there is one — is left exactly as it was.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: The trial (project) ID.
  • note: The note's text.
  • user_id: The author's Bitfount user ID.
  • username: The author's username.

Returns The note as the timeline serves it, or None if the patient is unknown.

delete_patient_note​

def delete_patient_note(    self,    bitfount_patient_id: str,    project_id: str,    note_id: str,    *,    user_id: str,    username: str,) ‑> bool | None:

Delete one of a patient's notes for a trial, or return None.

The note is soft-deleted: hidden from every read, with who deleted it and when. A note written with a review is deleted on its own — the review it was written with is left exactly as it was.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: The trial (project) ID.
  • note_id: The note's ID.
  • user_id: The deleter's Bitfount user ID.
  • username: The deleter's username.

Returns True if a live note was deleted; False if that (patient, trial) has no such note, or it is already deleted; None if the patient is unknown.

get_patient_review​

def get_patient_review(    self, bitfount_patient_id: str, project_id: str,) ‑> TrialReview | None:

Return a patient's review in force for one trial, or None.

Arguments

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

Returns The review in force, or None when the site has not reviewed this patient for this trial.

get_review_timeline​

def get_review_timeline(    self, bitfount_patient_id: str, project_id: str,) ‑> ReviewTimeline:

Return a patient's history of reviews and notes for one trial.

Every review ever made, and every note still standing, newest first: the review in force, the ones it replaced, and the ones removed. A note written with a review is served as one entry with it, since the site shows the two as one.

The two tables are read separately and paired here rather than joined in one statement: the history is small enough to serve whole, so there is nothing for a join to page, and the rule that pairs a note with its review stays in the API rather than in SQL.

Arguments

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

Returns The entries, newest first; empty for a (patient, trial) with no reviews and no notes.

list_patient_reviews​

def list_patient_reviews(    self, bitfount_patient_id: str,) ‑> PatientReviewList:

Return the reviews in force for one patient, one per reviewed trial.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.

Returns The reviews in force, ascending by trial id; empty for a patient the site has not reviewed.

list_trial_reviews​

def list_trial_reviews(    self,    project_id: str,    *,    review_statuses: Collection[ReviewStatus] | None = None,    page: int = 1,    page_size: int = 50,) ‑> ReviewedPatientList:

Return one page of a trial's reviews, most recent review first.

A review stands on its own trial, so this needs no published patient_eligibility partition: a trial that has not been analysed still serves the reviews its site has recorded. The identity rows are fetched for just the page, as in list_trial_patients.

Arguments

  • project_id: The trial (project) ID.
  • review_statuses: The review verdicts to admit. None admits every current review.
  • page: 1-indexed page number.
  • page_size: Items per page.

Returns A ReviewedPatientList of the requested page, most recent review first, and the count of all admitted reviews before pagination.

remove_patient_review​

def remove_patient_review(    self,    bitfount_patient_id: str,    project_id: str,    *,    remove_note: bool = False,    user_id: str,    username: str,) ‑> bool | None:

Remove a patient's review in force for a trial, or return None.

The review is recorded as removed rather than erased: the event log keeps every review ever made.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: The trial (project) ID.
  • remove_note: Delete the note written with the review too, rather than keeping it. Soft-deleted, so its body is retained.
  • user_id: The remover's Bitfount user ID.
  • username: The remover's username.

Returns True if a review was in force and has been removed, False if there was nothing to remove; None if the patient is unknown.

review_patient​

def review_patient(    self,    bitfount_patient_id: str,    project_id: str,    review_status: ReviewStatus,    *,    note: str | None = None,    user_id: str,    username: str,) ‑> TrialReview | None:

Record a review of a patient for a trial, or return None.

Arguments

  • bitfount_patient_id: The Bitfount patient ID.
  • project_id: The trial (project) ID.
  • review_status: The verdict to record.
  • note: The note to record with the review, if any.
  • user_id: The reviewer's Bitfount user ID.
  • username: The reviewer's username.

Returns The review now in force, or None if the patient is unknown.