functions
Cache-persistence helpers for the lesion_calculation step (v1).
Extracted from lesion_calculation_task to keep the cache-write orchestration
(building the lesion_calculation.cache accessor and upserting the per-file rows)
apart from the task body.
Unlike the version-agnostic pure compute in steps.lesion_calculation.functions,
these are v1-specific and perform cache I/O: they bind to this version's
LesionCalculation ORM, LesionCalculationRecord, and LesionCalculationResult.
Module
Functions
build_lesion_accessor
def build_lesion_accessor( cache: CacheProtocol, task_hash: str, config: LesionCalculationConfig, *filter_fields: str,) ‑> CacheAccessor:Build the CacheAccessor for this step's lesion_calculation partition.
Arguments
cache: The cache backend.task_hash: The step's partition key.config: The step config (source of any config-derived equality filters).*filter_fields: The step'scache_filter_fields— empty for this step, whose rows are keyed bytask_hashalone.
Returns
A CacheAccessor scoped to this task_hash.
persist_lesion_metrics
def persist_lesion_metrics( cache: CacheProtocol, task_hash: str, config: LesionCalculationConfig, output: dict[str, LesionMetrics | str | None], *, project_id: str | None = None, run_id: str | None = None, filter_fields: tuple[str, ...] = (),) ‑> LesionCalculationResult:Upsert per-file area rows and return the cache-backed result.
Arguments
cache: The cache backend to persist into.task_hash: Partition key for thelesion_calculationtable.config: The step config (passed through to the accessor).output: Per-file result map — aLesionMetrics(success), astr(missing-data reason orcalculation_error:...), orNone.project_id: Provenance only — not part of the cache key.run_id: Optional provenance run ID.filter_fields: The step'scache_filter_fields, forwarded to the accessor.
Returns
LesionCalculationResult carrying the row count and a scoped accessor.