Merge pull request 'CaCu follow-up: CASO status with CIS, per-status probabilities, and a cycle that estimates with every production scenario' (#19) from integration/cacu-197-conciliacion into dev
Reviewed-on: http://10.0.10.41:3000/ISSSTELEON/WebApi/pulls/19
This commit was merged in pull request #19.
This commit is contained in:
@@ -224,20 +224,20 @@ def cohorts(event_models: int, ctx: Context) -> dict[str, tuple[int, bool]]:
|
||||
|
||||
|
||||
@config.when(with_cohorts=True)
|
||||
def estimate(cohorts: dict[str, tuple[int, bool]], ctx: Context) -> dict[str, tuple[int, bool]]:
|
||||
def estimate(cohorts: dict[str, tuple[int, bool]], ctx: Context) -> dict[str, list[tuple[int, bool]]]:
|
||||
"""El riesgo de los miembros del armado más reciente de cada cohorte que tiene estimador (ADR-MD-008).
|
||||
|
||||
Lee el marco ancho del armado (`read_frame`) en una sesión de lectura, se lo da al estimador
|
||||
(`ctx.estimators[url]`: `estimate(columnas, filas)`, `procedencia()` y `desenlace`) y escribe sus riesgos como
|
||||
un lote `preliminary` (`CohortRepository.guardar_lote`). Estimar lo mismo otra vez no duplica.
|
||||
Devuelve, por cohorte, (`lote_id`, si es nuevo). Confirmar o anular un lote es la orden
|
||||
Lee el marco ancho del armado (`read_frame`) en una sesión de lectura, se lo da a cada estimador de la cohorte
|
||||
(`ctx.estimators[url]`, una lista: `estimar(columnas, filas)`, `procedencia()` y `desenlace`) y escribe los
|
||||
riesgos de cada uno como un lote `preliminary` (`CohortRepository.save_batch`). Estimar lo mismo otra vez no
|
||||
duplica. Devuelve, por cohorte, un (`lote_id`, si es nuevo) por estimador, en su orden. Confirmar o anular un lote es la orden
|
||||
`confirm-risks`, no este paso.
|
||||
"""
|
||||
tablas_cohorte = import_module(f"webapi.orchestration.tables.{ctx.project}").COHORTES
|
||||
lotes = {}
|
||||
for url in cohort_urls(ctx.project, _manifest(ctx)):
|
||||
estimador = ctx.estimators.get(url)
|
||||
if estimador is None:
|
||||
estimadores = ctx.estimators.get(url) or []
|
||||
if not estimadores:
|
||||
continue
|
||||
|
||||
def frame(sesion, url=url):
|
||||
@@ -247,8 +247,9 @@ def estimate(cohorts: dict[str, tuple[int, bool]], ctx: Context) -> dict[str, tu
|
||||
armado_id, ancho = ctx.repos.gold.cohorts.read(frame)
|
||||
if armado_id is None:
|
||||
continue
|
||||
riesgos = [tuple(r) for r in estimador.estimar(*ancho)]
|
||||
lotes[url] = ctx.repos.gold.cohorts.save_batch(
|
||||
armado_id, estimador.procedencia().como_dict(), estimador.desenlace, riesgos
|
||||
)
|
||||
lotes[url] = []
|
||||
for estimador in estimadores:
|
||||
riesgos = [tuple(r) for r in estimador.estimar(*ancho)]
|
||||
lotes[url].append(ctx.repos.gold.cohorts.save_batch(
|
||||
armado_id, estimador.procedencia().como_dict(), estimador.desenlace, riesgos))
|
||||
return lotes
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Live estimators for `Context.estimators`: the cycle's `estimate` step scores each cohort with the model version
|
||||
its domain has in production.
|
||||
"""Live estimators for `Context.estimators`: the cycle's `estimate` step scores each cohort with every model version
|
||||
of its domain in production, one batch per model.
|
||||
|
||||
`estimate` hands an estimator the cohort build's wide frame (`estimar(columnas, filas)`, `procedencia()`,
|
||||
`desenlace`): one column per the cohort's own variables. A registered model's predictors are a different, larger
|
||||
@@ -11,7 +11,6 @@ unused by design.
|
||||
|
||||
from dataclasses import dataclass
|
||||
from importlib import import_module
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -61,45 +60,19 @@ class ScenarioEstimator:
|
||||
return self._provenance
|
||||
|
||||
|
||||
class Cin2LogisticEstimator(ScenarioEstimator):
|
||||
"""Scores CaCu's surveillance cohort with the `cacu-cin2_logistic` version in production (or `version`)."""
|
||||
|
||||
def __init__(self, domain: str = "cacu", version: str | None = None):
|
||||
super().__init__(domain, "cin2_logistic", version)
|
||||
self.desenlace = "cin2_mas"
|
||||
|
||||
|
||||
# The scenarios the cycle estimates with, per domain other than CaCu: each one that has a version in production
|
||||
# scores the cohort it names.
|
||||
LIVE_SCENARIOS = {"cama": ("survival",)}
|
||||
|
||||
|
||||
def _scenario_estimators(domain: str) -> dict[str, Any]:
|
||||
def live_estimators(domain: str) -> dict[str, list[ScenarioEstimator]]:
|
||||
"""The estimators of a domain's cohorts, by cohort url: one per scenario with a version in production in the
|
||||
registry, so promoting or retiring a version is what adds or drops it. A registered name with no scenario
|
||||
definition in `models` is skipped. Empty where none is in production, the same as no estimator being
|
||||
configured: `estimate` then does nothing."""
|
||||
from models.dags.training import Scenario
|
||||
from models.io.registry import registry
|
||||
|
||||
found = {}
|
||||
for name in LIVE_SCENARIOS.get(domain, ()):
|
||||
scenario = Scenario.load(domain, name)
|
||||
found: dict[str, list[ScenarioEstimator]] = {}
|
||||
for name in registry.in_production(domain):
|
||||
try:
|
||||
registry.resolve(domain, name)
|
||||
scenario = Scenario.load(domain, name)
|
||||
except LookupError:
|
||||
continue
|
||||
found[scenario.cohort] = ScenarioEstimator(domain, name)
|
||||
found.setdefault(scenario.cohort, []).append(ScenarioEstimator(domain, name))
|
||||
return found
|
||||
|
||||
|
||||
def live_estimators(domain: str) -> dict[str, Any]:
|
||||
"""The estimators of a domain's cohorts whose model has a version in production, by cohort url. Empty where
|
||||
none is in production yet, the same as no estimator being configured: `estimate` then does nothing."""
|
||||
if domain != "cacu":
|
||||
return _scenario_estimators(domain)
|
||||
from models.dags.training import Scenario
|
||||
from models.io.registry import registry
|
||||
|
||||
scenario = Scenario.load(domain, "cin2_logistic")
|
||||
try:
|
||||
registry.resolve(domain, scenario.scenario)
|
||||
except LookupError:
|
||||
return {}
|
||||
return {scenario.cohort: Cin2LogisticEstimator(domain)}
|
||||
|
||||
@@ -203,13 +203,20 @@ estado = "provisional"
|
||||
fuente = "Plan de seguimiento (ISSSTELEON-arquitectura/plan_seguimiento_ficha_filtros.md, §2bis), 2026-10-22; falta que clínica la confirme. Usuario, 2026-10-22: inicio del periodo"
|
||||
|
||||
[cacu.seguimiento.precedencia]
|
||||
# Qué estatus gana si aplican varios, del que más gana al que menos. Opciones: cualquier orden de
|
||||
# "POST_TRATAMIENTO", "POST_COLPOSCOPIA", "INFO_INSUFICIENTE" y "PRE_COLPOSCOPIA" (los cuatro, sin repetir).
|
||||
# Qué estatus gana si aplican varios, del que más gana al que menos. Opciones: cualquier orden de "CASO",
|
||||
# "POST_TRATAMIENTO", "POST_COLPOSCOPIA", "INFO_INSUFICIENTE" y "PRE_COLPOSCOPIA" (los cinco, sin repetir).
|
||||
# Quien no cumple ninguno cae en "INFO_INSUFICIENTE" (el estrato es exhaustivo).
|
||||
valor = ["POST_TRATAMIENTO", "POST_COLPOSCOPIA", "INFO_INSUFICIENTE", "PRE_COLPOSCOPIA"]
|
||||
valor = ["CASO", "POST_TRATAMIENTO", "POST_COLPOSCOPIA", "INFO_INSUFICIENTE", "PRE_COLPOSCOPIA"]
|
||||
estado = "provisional"
|
||||
fuente = "Plan de seguimiento (ISSSTELEON-arquitectura/plan_seguimiento_ficha_filtros.md, §2bis), 2026-10-22; falta que clínica la confirme"
|
||||
|
||||
[cacu.seguimiento.caso.grados]
|
||||
# Qué grados de biopsia hacen de la paciente un caso (ya tiene cáncer, invasor o in situ): su estatus es CASO, gane lo
|
||||
# que gane lo demás, y lo que se le sigue es la supervivencia. Opciones: grados de `GradoCIN`.
|
||||
valor = ["CIS", "CARCINOMA"]
|
||||
estado = "provisional"
|
||||
fuente = "Responsable del proyecto, 2026-11-22: un escenario para las pacientes que ya tienen cáncer, sobre el que se evalúa la supervivencia; falta que clínica la confirme"
|
||||
|
||||
[cacu.seguimiento.colposcopia.evidencias]
|
||||
# Qué cuenta como colposcopia antes de la referencia. Opciones (cualquier subconjunto):
|
||||
# "motivo" una nota de colposcopia cuyo motivo de consulta contiene uno de `colposcopia.motivos`
|
||||
|
||||
Reference in New Issue
Block a user