Compare commits
7 Commits
main
...
fix/134-uv-lock
| Author | SHA1 | Date | |
|---|---|---|---|
| 28eba44e9c | |||
| b452a35759 | |||
| 1dcbb74247 | |||
| c7c4e01006 | |||
| 8499427650 | |||
| 70a018a8fb | |||
| fe9ba433ec |
@@ -19,8 +19,10 @@ def client(wire_domain):
|
||||
|
||||
|
||||
def test_imported_rows_are_what_models_reads_and_model_writes_are_what_the_api_serves(client):
|
||||
"""Rows imported over HTTP are read back through `models`' repository, and a row written there is served by
|
||||
the API. Fails if `resolve_repository` stops returning the objects WebApi writes with."""
|
||||
from core.cama.models import Mastografia
|
||||
from models.cama import CaMaModel
|
||||
from models.io.repositories import resolve_repository
|
||||
|
||||
csv = b"Expediente,BIRADS\nRT-1,BI-RADS 4\nRT-2,2\n"
|
||||
response = client.post(
|
||||
@@ -38,11 +40,11 @@ def test_imported_rows_are_what_models_reads_and_model_writes_are_what_the_api_s
|
||||
)
|
||||
assert response.get_json()["results"][0]["created"] == 2
|
||||
|
||||
model = CaMaModel()
|
||||
seen = {row["pac_id_hospital"]: row["mast_birads"] for row in model.dataset("mastografia")}
|
||||
repository = resolve_repository("cama", "mastografia")
|
||||
seen = {row.pac_id_hospital: row.mast_birads for row in repository.iter_all()}
|
||||
assert seen == {"RT-1": "B4", "RT-2": "B2"}
|
||||
|
||||
model.repository("mastografia").create(Mastografia(pac_id_hospital="RT-FROM-MODEL", mast_birads="B1"))
|
||||
repository.create(Mastografia(pac_id_hospital="RT-FROM-MODEL", mast_birads="B1"))
|
||||
served = client.get("/data/cama.Mastografia").get_json()
|
||||
assert served["total"] == 3
|
||||
assert "RT-FROM-MODEL" in {row["pac_id_hospital"] for row in served["rows"]}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"""What this module covers: the timeline repository that `repositorios_de` wires into `ctx.repos.plata`
|
||||
reads the same rows as the kit's own query, in each project.
|
||||
|
||||
Fixtures: `base` (from `conftest.py`), a project database for each of CaCu, CaMa and TEA; each test loads
|
||||
its catalogs and data with `base.correr("catalogos", "cargar")`. `kit_rows` reads the same timeline
|
||||
straight through the kit (`filas_de_linea`) to compare against.
|
||||
"""
|
||||
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from importlib import import_module
|
||||
|
||||
from indicadores_kit.oro.cohortes.armado import filas_de_linea
|
||||
from indicadores_kit.tablas import tablas_de
|
||||
from sqlmodel import Session
|
||||
|
||||
CORTE = date(2025, 12, 31)
|
||||
|
||||
|
||||
def kit_rows(base, **filters):
|
||||
"""The project's timeline read through the kit with `filters` (the kit's Spanish keywords)."""
|
||||
fuentes = import_module(f"indicadores_kit.{base.proyecto}.linea_de_tiempo").FUENTES_PLATA
|
||||
with Session(base.motor) as session:
|
||||
return filas_de_linea(session, tablas_de(base.proyecto), fuentes, **filters)
|
||||
|
||||
|
||||
def test_the_whole_timeline_matches_the_kit(base):
|
||||
"""Pins down: with only a clinical cut-off, the wired repository returns exactly the kit's rows, and
|
||||
there are some.
|
||||
|
||||
Fails if the orchestration binds another query, another project's tables or sources, or `until`
|
||||
stops reaching the kit as `hasta`.
|
||||
"""
|
||||
base.correr("catalogos", "cargar")
|
||||
rows = base.ctx.repos.plata.timeline.read(until=CORTE)
|
||||
assert rows
|
||||
assert rows == kit_rows(base, hasta=CORTE)
|
||||
|
||||
|
||||
def test_the_patient_filter_matches_the_kit(base):
|
||||
"""Pins down: `patients` reaches the kit as `pacientes`: only those patients come back, with the
|
||||
kit's rows.
|
||||
|
||||
Fails if the patient filter is dropped or renamed on the way to the kit's query.
|
||||
"""
|
||||
base.correr("catalogos", "cargar")
|
||||
patients = sorted({row["pac_id"] for row in kit_rows(base)})[:2]
|
||||
rows = base.ctx.repos.plata.timeline.read(patients=patients, until=CORTE)
|
||||
assert {row["pac_id"] for row in rows} == set(patients)
|
||||
assert rows == kit_rows(base, pacientes=patients, hasta=CORTE)
|
||||
|
||||
|
||||
def test_known_until_cuts_at_what_was_loaded(base):
|
||||
"""Pins down: `known_until` reaches the kit as `conocida_hasta`: before the load nothing is known,
|
||||
after it everything is, the same as reading without the cut.
|
||||
|
||||
Fails if the load cut-off is ignored, or applied to the clinical date instead of the load time.
|
||||
"""
|
||||
before = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
base.correr("catalogos", "cargar")
|
||||
after = datetime.now(timezone.utc) + timedelta(days=1)
|
||||
timeline = base.ctx.repos.plata.timeline
|
||||
assert timeline.read(until=CORTE, known_until=before) == []
|
||||
assert timeline.read(until=CORTE, known_until=after) == kit_rows(base, hasta=CORTE, conocida_hasta=after)
|
||||
assert timeline.read(until=CORTE, known_until=after) == timeline.read(until=CORTE)
|
||||
@@ -1608,6 +1608,7 @@ name = "models"
|
||||
version = "0.1.0"
|
||||
source = { editable = "../models" }
|
||||
dependencies = [
|
||||
{ name = "apache-hamilton" },
|
||||
{ name = "extraction" },
|
||||
{ name = "mlflow" },
|
||||
{ name = "persistance" },
|
||||
@@ -1620,6 +1621,7 @@ export = [
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "apache-hamilton", specifier = ">=1.90" },
|
||||
{ name = "extraction", editable = "../Extraction" },
|
||||
{ name = "mlflow", specifier = ">=2.9" },
|
||||
{ name = "onnx", marker = "extra == 'export'", specifier = ">=1.15" },
|
||||
@@ -2090,7 +2092,10 @@ requires-dist = [
|
||||
provides-extras = ["drivers"]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [{ name = "pytest", specifier = ">=8.0.0" }]
|
||||
dev = [
|
||||
{ name = "apache-hamilton", specifier = ">=1.90" },
|
||||
{ name = "pytest", specifier = ">=8.0.0" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pillow"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Model governance (ML, MLD, EL and VAR requirements): model versions and
|
||||
their promotion, and the OCR extraction jobs with their manual review queue.
|
||||
|
||||
Versions and artifacts live in MLflow (`models.registry`); training runs
|
||||
Versions and artifacts live in MLflow (`models.io.registry`); training runs
|
||||
elsewhere and registers its result through `POST /model-versions`, naming
|
||||
the indicator kit cohort build it was trained on (`cohorte_armado_id`).
|
||||
"""
|
||||
@@ -11,8 +11,8 @@ from core.governance.enums import EstatusExtraccion
|
||||
from core.governance.models import ExtractionRun
|
||||
from core.ocr import OcrEstatus
|
||||
from flask import Blueprint, Response, jsonify, request
|
||||
from models.io.registry import REPORT_TAGS, PromotionBlocked, registry
|
||||
from models.ocr import OCR_JOBS, OcrJob, run_pending_extractions
|
||||
from models.registry import REPORT_TAGS, PromotionBlocked, registry
|
||||
from persistance.governance import extraction_run_repository
|
||||
from persistance.repository import Repository
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ dominio. Aquí solo se juntan: la orquestación no nombra ninguna conexión.
|
||||
from dataclasses import dataclass
|
||||
from importlib import import_module
|
||||
|
||||
from indicadores_kit.plata.linea_de_tiempo import linea_de_tiempo_plata
|
||||
from indicadores_kit.tablas import tablas_de
|
||||
from persistance.aristas.bronce import StagingRepository
|
||||
from persistance.aristas.oro import (
|
||||
CalculoRepository,
|
||||
@@ -19,6 +21,8 @@ from persistance.aristas.plata import (
|
||||
CargaRepository,
|
||||
CatalogoRepository,
|
||||
ObservacionRepository,
|
||||
TimelineQuery,
|
||||
TimelineRepository,
|
||||
VinculosRepository,
|
||||
VistasRepository,
|
||||
)
|
||||
@@ -41,6 +45,7 @@ class Plata:
|
||||
vistas: VistasRepository
|
||||
observacion: ObservacionRepository
|
||||
vinculos: VinculosRepository
|
||||
timeline: TimelineRepository | None = None # the patients' timeline, through the kit's query
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -77,6 +82,7 @@ def repositorios_de(proyecto: str) -> Repositorios:
|
||||
vistas=dominio.vistas_repository,
|
||||
observacion=dominio.observar_repository,
|
||||
vinculos=dominio.vinculos_repository,
|
||||
timeline=dominio.timeline_repository.with_query(timeline_query(proyecto)),
|
||||
),
|
||||
materializador=dominio.materializador,
|
||||
oro=Oro(
|
||||
@@ -89,3 +95,14 @@ def repositorios_de(proyecto: str) -> Repositorios:
|
||||
grupos_edad=getattr(dominio, "dim_grupo_edad_repository", None),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def timeline_query(proyecto: str) -> TimelineQuery:
|
||||
"""The project's timeline query: the kit's `linea_de_tiempo_plata` over its `FUENTES_PLATA`."""
|
||||
tablas = tablas_de(proyecto)
|
||||
fuentes = import_module(f"indicadores_kit.{proyecto}.linea_de_tiempo").FUENTES_PLATA
|
||||
|
||||
def query(*, patients, until, known_until):
|
||||
return linea_de_tiempo_plata(tablas, fuentes, pacientes=patients, hasta=until, conocida_hasta=known_until)
|
||||
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user