repository
The scans domain's repository methods.
A patient's per-scan evidence, and the image of one scan.
Mixed into CacheBackedPatientDataRepository, which supplies the cache handle
they read through.
Classes
ScansRepositoryMixin
class ScansRepositoryMixin():One domain's methods, mixed into the repository.
Ancestors
Subclasses
Methods
get_scan_enface
def get_scan_enface( self, *, scan_id: str | None, path: str | None, modality: str | None, laterality: str | None,) ‑> ScanEnfaceMap:Resolve the scan reference and build its en-face map.
Arguments
scan_id: The scan identifier, or None (exactly one of scan_id/path).path: An explicit, allowlisted file path, or None.modality: Optional series selector for multi-series files.laterality: Optional "L"/"R" series selector.
Returns The en-face map: its backdrop and every class's outlines.
Raises
ScanNotFoundError: The feature is not enabled, or the reference does not resolve to an authorised file.ScanRequestError: Not exactly one ofscan_id/path, or an undecodable file.enface.EnfaceUnavailableError: En-face does not apply to this scan.
get_scan_image
def get_scan_image( self, *, scan_id: str | None, path: str | None, modality: str | None, laterality: str | None, width: int | None, refresh: bool, include_masks: bool = False, include_vectors: bool = False, segmentation_classes: list[str] | None = None,) ‑> bytes:Resolve the scan reference and dispatch to the image service.
Arguments
scan_id: The scan identifier, or None (exactly one of scan_id/path).path: An explicit, allowlisted file path, or None.modality: Optional series selector for multi-series files.laterality: Optional "L"/"R" series selector.width: Optional output width (px); None uses the configured default.refresh: When True, bypass and overwrite any cached archive.include_masks: Whether the archive should carry a rendered mask PNG per segmentation class; passed straight through to the image service.include_vectors: Whether the served index should carry each class's raw drawable instances; also passed straight through.segmentation_classes: Optional class-name filter, applied only when an overlay output was requested.
Returns
The application/zip archive bytes.
Raises
ScanNotFoundError: The scan-image feature is not enabled, or the reference does not resolve to an authorised file.ScanRequestError: Not exactly one ofscan_id/pathwas supplied, or the width/file is invalid (raised by the image service).
list_scan_evidence
def list_scan_evidence( self, bitfount_patient_id: str, project_id: str, *, page: int = 1, page_size: int = 50,) ‑> ScanEvidenceList:Return a patient's per-scan evidence for a trial, one page at a time.
Scoped to the trial's published scan_eligibility partition, narrowed
from the all-projects map so a scan analysed under a different trial
cannot leak in.
Sorted most recent study_date first with scan_id breaking ties —
matching how roll_up_patient picks its determining scan, so the scan
the rollup names tends to sort near the top and the order is stable
across calls. Rows are sorted before the page is cut, so paging is
consistent.
Each scan's scan_id is its file's key. Its file_path is the file as
spelled on disk, where the walk stored a spelling that differs from the
key, and the key otherwise.
Arguments
bitfount_patient_id: The Bitfount patient ID.project_id: The trial (project) ID.page: 1-indexed page number.page_size: Items per page.
Returns
A ScanEvidenceList; empty when the trial publishes no
scan_eligibility partition or the patient has no scans in it.
resolve_scan_path
def resolve_scan_path(self, *, scan_id: str | None, path: str | None) ‑> str | None:Resolve a scan reference to a validated absolute file path.
Arguments
scan_id: The scan identifier to resolve, or None.path: An explicit filesystem path to validate, or None.
Both branches resolve only against the published scan partitions, so a scan whose only rows belong to a superseded run is not reachable — the same scoping the eligibility reads use.
Returns The validated real path, or None if unknown/unauthorised.
Raises
ValueError: If not exactly one ofscan_id/pathis supplied.