Skip to main content

protocol

What the scans domain needs of the data layer.

A patient's per-scan evidence for a trial, and the image of one scan.

Classes​

ScansRepository​

class ScansRepository(*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).

Methods​


get_scan_enface​

def get_scan_enface(    self,    *,    scan_id: str | None,    path: str | None,    modality: str | None,    laterality: str | None,) ‑> ScanEnfaceMap:

Resolve a 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 reference does not resolve, or the feature is not enabled.
  • ScanRequestError: Bad inputs 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 a scan reference and return its frames as a WebP ZIP.

Resolves scan_id/path to a validated file (the allowlist check), then renders the file to a ZIP of scaled WebP frames.

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. Callers pass an already-resolved value (resolving the query params into a selection is the route's job, not this seam's).
  • include_vectors: Whether the served index should carry each class's raw drawable instances. Also already-resolved.
  • segmentation_classes: Optional class-name filter, applied only when an overlay output was requested. A name that matches no class the model produced yields no output for it, never an error.

Returns The application/zip archive bytes: frame_NNN.webp per frame, a manifest.json, and — when an overlay output was requested and segmentation is available — a segmentations.json index, plus one masks/ PNG per class when include_masks is True.

Raises

  • ScanNotFoundError: The reference does not resolve to an authorised file, or the scan-image feature is not enabled.
  • ScanRequestError: Bad inputs, non-positive width, or undecodable file.

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.

Unlike get_eligibility_evidence, which serves the rollup's single determined_by_scan, this serves every scan the trial evaluated for the patient, each with its own verdict and criteria.

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 has no published 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.

Exactly one of scan_id/path must be supplied. A scan_id is looked up in the scan_eligibility store; an explicit path is accepted only if its real path matches a stored scan's file_path (allowlist), which blocks path traversal and symlink escape.

Arguments

  • scan_id: The scan identifier to resolve, or None.
  • path: An explicit filesystem path to validate, or None.

Returns The validated absolute (real) path, or None if unknown/unauthorised.

Raises

  • ValueError: If not exactly one of scan_id/path is supplied.