protocol
What the reviews domain needs of the data layer.
Reading the reviews in force, and recording or removing one.
Classes
ReviewsRepository
class ReviewsRepository(*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
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 None if no such patient.
The note stands on its own: it is not a review's note, so adding one records no verdict and changes nothing about the review in force.
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.
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 — that review stays in force, unchanged.
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.
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.
Each review names the trial it is for and the stage the site recorded, which is what a client groups a patient's trials by.
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 single trial's reviews, newest first.
A review stands on its own trial, so unlike list_trial_patients this
needs no published patient_eligibility partition: a trial that has not
been analysed still serves the reviews its site has recorded.
Arguments
project_id: The trial (project) ID.review_statuses: The review verdicts to admit.Noneadmits every current review.page: 1-indexed page number.page_size: Number of items per page.
Returns
A ReviewedPatientList whose items are the requested page, most
recent review first, and whose total is 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 one trial.
The patient reverts to the analysis verdict for that trial, which the
review was overriding. The removal is recorded as its own event rather
than the review being erased, so earlier reviews are kept. The note
written with the review being removed is kept too, unless remove_note
asks for it to be deleted — and then only softly, so its text is
retained.
Arguments
bitfount_patient_id: The Bitfount patient ID.project_id: The trial (project) ID.remove_note: Delete the note written with the review too.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 the
patient has no review for this trial, so 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 None if no such patient.
Earlier reviews are kept; the new one replaces the one in force. A
note, when given, is recorded with the review.
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.