The kit's silver load, reference tables, table maps and follow-up list move into the WebApi; the kit is no longer a dependency
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
"""Las tablas de un proyecto, juntas, para pasarlas al código común.
|
||||
|
||||
El código común (carga, registro, cálculo, contratos) no importa clases
|
||||
de tabla: recibe las del proyecto en un `TablasKit`. Así cada proyecto
|
||||
puede tener sus propias clases, aunque las columnas sean las mismas, y
|
||||
CaCu y CaMa corren en el mismo proceso sin un "proyecto activo".
|
||||
|
||||
Cada proyecto declara la suya en `<proyecto>/tablas.py` como `TABLAS`.
|
||||
"""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from importlib import import_module
|
||||
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
PROJECTS = ("cacu", "cama")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TablasKit:
|
||||
"""Las tablas de un proyecto: el registro, el oro y la plata genérica (una sola plata, ADR-MD-009)."""
|
||||
|
||||
Persona: type[SQLModel]
|
||||
PeriodoObservacion: type[SQLModel]
|
||||
Carga: type[SQLModel]
|
||||
DefParametro: type[SQLModel]
|
||||
DimPeriodo: type[SQLModel]
|
||||
DimFecha: type[SQLModel]
|
||||
DimGrupoEdad: type[SQLModel]
|
||||
MeasureReport: type[SQLModel]
|
||||
# Los catálogos de la plata (F1): estudio -> resultado -> valor, de `core/catalogos/<proyecto>.toml`.
|
||||
CatEstudio: type[SQLModel]
|
||||
CatResultado: type[SQLModel]
|
||||
CatValor: type[SQLModel]
|
||||
# La plata de dos tablas (F5, ADR-MD-007).
|
||||
Procedimiento: type[SQLModel]
|
||||
Observacion: type[SQLModel]
|
||||
# El oro por unidad y su catálogo (§6f, MD-19): opcionales para que un registro de prueba no los necesite.
|
||||
CatMeasure: type[SQLModel] | None = None
|
||||
CatMeasureResultado: type[SQLModel] | None = None
|
||||
CatMeasureValor: type[SQLModel] | None = None
|
||||
CatMeasureGrupo: type[SQLModel] | None = None
|
||||
CatEstrato: type[SQLModel] | None = None
|
||||
CatEstratoValor: type[SQLModel] | None = None
|
||||
CatMeasureEstrato: type[SQLModel] | None = None
|
||||
MeasureReportUnidad: type[SQLModel] | None = None
|
||||
MeasureReportUnidadEstrato: type[SQLModel] | None = None
|
||||
# De una fila de `paciente` de staging, las columnas que este proyecto agrega a su `persona`.
|
||||
persona_propias: Callable[[object], dict] = lambda paciente: {}
|
||||
|
||||
def comunes(self) -> list[type[SQLModel]]:
|
||||
return [
|
||||
self.Persona,
|
||||
self.PeriodoObservacion,
|
||||
self.Carga,
|
||||
self.DefParametro,
|
||||
self.DimPeriodo,
|
||||
self.DimFecha,
|
||||
self.DimGrupoEdad,
|
||||
self.MeasureReport,
|
||||
self.CatEstudio,
|
||||
self.CatResultado,
|
||||
self.CatValor,
|
||||
self.Procedimiento,
|
||||
self.Observacion,
|
||||
]
|
||||
|
||||
def publicacion(self) -> list[type[SQLModel]]:
|
||||
"""Las tablas de §6f (MD-19) que el proyecto declara, en orden de llaves foráneas."""
|
||||
return [m for m in (self.CatMeasure, self.CatMeasureResultado, self.CatMeasureValor, self.CatMeasureGrupo, self.CatEstrato, self.CatEstratoValor, self.CatMeasureEstrato, self.MeasureReportUnidad, self.MeasureReportUnidadEstrato) if m is not None]
|
||||
|
||||
def catalogo_de_publicacion(self) -> list[type[SQLModel]]:
|
||||
"""Las siete tablas `cat_*` de §6f, padres antes que hijos (lo que sincroniza la arista `definiciones`)."""
|
||||
return [m for m in (self.CatEstrato, self.CatEstratoValor, self.CatMeasure, self.CatMeasureResultado,
|
||||
self.CatMeasureValor, self.CatMeasureGrupo, self.CatMeasureEstrato) if m is not None]
|
||||
|
||||
def todas(self) -> list[type[SQLModel]]:
|
||||
"""Todo lo que la base del proyecto lleva del kit (sin staging ni cohortes)."""
|
||||
return [*self.comunes(), *self.publicacion()]
|
||||
|
||||
|
||||
def tablas_de(proyecto: str) -> TablasKit:
|
||||
"""El `TablasKit` del proyecto, de `<proyecto>/tablas.py`."""
|
||||
if proyecto not in PROJECTS:
|
||||
raise KeyError(f"Proyecto desconocido: {proyecto!r}.")
|
||||
return import_module(f"webapi.orchestration.tables.{proyecto}").TABLAS
|
||||
@@ -0,0 +1,77 @@
|
||||
"""Las tablas de CaCu: viven en `Core`, en el registro del dominio (ADR-004).
|
||||
|
||||
`TABLAS` es lo que el código común recibe para trabajar con este proyecto.
|
||||
"""
|
||||
|
||||
from core.cacu.indicadores.models import (
|
||||
CatMeasure,
|
||||
CatMeasureResultado,
|
||||
CatMeasureValor,
|
||||
CatMeasureGrupo,
|
||||
CatEstrato,
|
||||
CatEstratoValor,
|
||||
CatMeasureEstrato,
|
||||
MeasureReportUnidad,
|
||||
MeasureReportUnidadEstrato,
|
||||
CatEstudio,
|
||||
CatResultado,
|
||||
CatValor,
|
||||
Observacion,
|
||||
Procedimiento,
|
||||
CohorteArmado,
|
||||
CohorteExclusion,
|
||||
CohorteMiembro,
|
||||
CohorteVariable,
|
||||
EvaluacionRiesgo,
|
||||
EvaluacionRiesgoLote,
|
||||
Carga,
|
||||
DefParametro,
|
||||
DimFecha,
|
||||
DimGrupoEdad,
|
||||
DimPeriodo,
|
||||
MeasureReport,
|
||||
PeriodoObservacion,
|
||||
Persona,
|
||||
)
|
||||
|
||||
from webapi.orchestration.silver.persons import de_derechohabiente
|
||||
from core.indicadores.cohortes import TablasCohorte
|
||||
from webapi.orchestration.tables import TablasKit
|
||||
|
||||
__all__ = ["TABLAS", "COHORTES"]
|
||||
|
||||
TABLAS = TablasKit(
|
||||
Persona=Persona,
|
||||
PeriodoObservacion=PeriodoObservacion,
|
||||
Carga=Carga,
|
||||
DefParametro=DefParametro,
|
||||
DimPeriodo=DimPeriodo,
|
||||
DimFecha=DimFecha,
|
||||
DimGrupoEdad=DimGrupoEdad,
|
||||
MeasureReport=MeasureReport,
|
||||
CatEstudio=CatEstudio,
|
||||
CatResultado=CatResultado,
|
||||
CatValor=CatValor,
|
||||
Procedimiento=Procedimiento,
|
||||
Observacion=Observacion,
|
||||
CatMeasure=CatMeasure,
|
||||
CatMeasureResultado=CatMeasureResultado,
|
||||
CatMeasureValor=CatMeasureValor,
|
||||
CatMeasureGrupo=CatMeasureGrupo,
|
||||
CatEstrato=CatEstrato,
|
||||
CatEstratoValor=CatEstratoValor,
|
||||
CatMeasureEstrato=CatMeasureEstrato,
|
||||
MeasureReportUnidad=MeasureReportUnidad,
|
||||
MeasureReportUnidadEstrato=MeasureReportUnidadEstrato,
|
||||
persona_propias=de_derechohabiente,
|
||||
)
|
||||
|
||||
# Las cohortes para modelos y sus estimaciones de riesgo (oro restringido, ADR-MD-003).
|
||||
COHORTES = TablasCohorte(
|
||||
CohorteArmado=CohorteArmado,
|
||||
CohorteMiembro=CohorteMiembro,
|
||||
CohorteExclusion=CohorteExclusion,
|
||||
CohorteVariable=CohorteVariable,
|
||||
EvaluacionRiesgoLote=EvaluacionRiesgoLote,
|
||||
EvaluacionRiesgo=EvaluacionRiesgo,
|
||||
)
|
||||
@@ -0,0 +1,77 @@
|
||||
"""Las tablas de CaMa: viven en `Core`, en el registro del dominio (ADR-004).
|
||||
|
||||
`TABLAS` es lo que el código común recibe para trabajar con este proyecto.
|
||||
"""
|
||||
|
||||
from core.cama.indicadores.models import (
|
||||
CatMeasure,
|
||||
CatMeasureResultado,
|
||||
CatMeasureValor,
|
||||
CatMeasureGrupo,
|
||||
CatEstrato,
|
||||
CatEstratoValor,
|
||||
CatMeasureEstrato,
|
||||
MeasureReportUnidad,
|
||||
MeasureReportUnidadEstrato,
|
||||
CatEstudio,
|
||||
CatResultado,
|
||||
CatValor,
|
||||
Observacion,
|
||||
Procedimiento,
|
||||
CohorteArmado,
|
||||
CohorteExclusion,
|
||||
CohorteMiembro,
|
||||
CohorteVariable,
|
||||
EvaluacionRiesgo,
|
||||
EvaluacionRiesgoLote,
|
||||
Carga,
|
||||
DefParametro,
|
||||
DimFecha,
|
||||
DimGrupoEdad,
|
||||
DimPeriodo,
|
||||
MeasureReport,
|
||||
PeriodoObservacion,
|
||||
Persona,
|
||||
)
|
||||
|
||||
from webapi.orchestration.silver.persons import de_derechohabiente
|
||||
from core.indicadores.cohortes import TablasCohorte
|
||||
from webapi.orchestration.tables import TablasKit
|
||||
|
||||
__all__ = ["TABLAS", "COHORTES"]
|
||||
|
||||
TABLAS = TablasKit(
|
||||
Persona=Persona,
|
||||
PeriodoObservacion=PeriodoObservacion,
|
||||
Carga=Carga,
|
||||
DefParametro=DefParametro,
|
||||
DimPeriodo=DimPeriodo,
|
||||
DimFecha=DimFecha,
|
||||
DimGrupoEdad=DimGrupoEdad,
|
||||
MeasureReport=MeasureReport,
|
||||
CatEstudio=CatEstudio,
|
||||
CatResultado=CatResultado,
|
||||
CatValor=CatValor,
|
||||
Procedimiento=Procedimiento,
|
||||
Observacion=Observacion,
|
||||
CatMeasure=CatMeasure,
|
||||
CatMeasureResultado=CatMeasureResultado,
|
||||
CatMeasureValor=CatMeasureValor,
|
||||
CatMeasureGrupo=CatMeasureGrupo,
|
||||
CatEstrato=CatEstrato,
|
||||
CatEstratoValor=CatEstratoValor,
|
||||
CatMeasureEstrato=CatMeasureEstrato,
|
||||
MeasureReportUnidad=MeasureReportUnidad,
|
||||
MeasureReportUnidadEstrato=MeasureReportUnidadEstrato,
|
||||
persona_propias=de_derechohabiente,
|
||||
)
|
||||
|
||||
# Las cohortes para modelos y sus estimaciones de riesgo (oro restringido, ADR-MD-003; MD-12).
|
||||
COHORTES = TablasCohorte(
|
||||
CohorteArmado=CohorteArmado,
|
||||
CohorteMiembro=CohorteMiembro,
|
||||
CohorteExclusion=CohorteExclusion,
|
||||
CohorteVariable=CohorteVariable,
|
||||
EvaluacionRiesgoLote=EvaluacionRiesgoLote,
|
||||
EvaluacionRiesgo=EvaluacionRiesgo,
|
||||
)
|
||||
Reference in New Issue
Block a user