CaMa recurrence: import schemas for the follow-up and the new patient variables, silver mappings and /cama/recurrencia
The patient takes the menopausal state, molecular and clinical subtype, integrative cluster, cellularity, mutation load, Ki-67 category and source of the record; a new import entity carries the recurrence and the last contact; hormone and anti-HER2 therapy are treatments. The route serves each cohort's scenarios, a scenario's figure and a patient's scenarios over the live cohort build, computing the models and the bootstrap in the background and caching them per build. Includes the survival import work this builds on. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,3 +117,42 @@ def _valor_y_fuente(leido, texto, tipo_valor: str) -> tuple:
|
||||
if texto is not None and str(texto.value).strip():
|
||||
return None, str(texto.value).strip()[:LARGO_DE_FUENTE]
|
||||
return None, None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ConEstructurado:
|
||||
"""`DesdeTexto` whose results the row may carry already structured: a structured column wins over what the text
|
||||
gives, and a column with no text twin is a result of its own. `estructurados`: result -> staging column;
|
||||
each result keeps the text reading as its fallback when `lector` has it."""
|
||||
|
||||
lector: DesdeTexto | None
|
||||
estructurados: dict[str, str]
|
||||
|
||||
@property
|
||||
def derivadas(self) -> dict[str, Callable]:
|
||||
columnas = dict(self.lector.derivadas) if self.lector else {}
|
||||
leidos = set(self.lector.resultado_ids) if self.lector else set()
|
||||
for resultado_id, columna in self.estructurados.items():
|
||||
clave = _columna(resultado_id)
|
||||
texto = self.lector.derivadas[clave] if resultado_id in leidos else (lambda f: None)
|
||||
fuente = self.lector.derivadas[clave + "_fuente"] if resultado_id in leidos else (lambda f: None)
|
||||
columnas[clave] = lambda f, c=columna, t=texto: _con_valor(getattr(f, c, None), t(f))
|
||||
columnas[clave + "_fuente"] = lambda f, c=columna, t=fuente: (
|
||||
None if _vacio(getattr(f, c, None)) else t(f))
|
||||
return columnas
|
||||
|
||||
@property
|
||||
def resultados(self) -> dict[str, str]:
|
||||
return {_columna(r): r for r in {*(self.lector.resultado_ids if self.lector else ()), *self.estructurados}}
|
||||
|
||||
@property
|
||||
def fuentes(self) -> dict[str, str]:
|
||||
return {columna: columna + "_fuente" for columna in self.resultados}
|
||||
|
||||
|
||||
def _vacio(valor) -> bool:
|
||||
return valor is None or (isinstance(valor, str) and not valor.strip())
|
||||
|
||||
|
||||
def _con_valor(estructurado, leido):
|
||||
return leido if _vacio(estructurado) else estructurado
|
||||
|
||||
Reference in New Issue
Block a user