ba81ab811f
01a: fechas clínicas, disponibilidad en origen y referencia por campo; evidencia FHIR independiente. 01b (parcial): proyección de elegibilidad por instancia y lector con comprobación del esquema gold. Pendiente: las exclusiones propias de cada escenario conservan solo el motivo prioritario; fechas FHIR parciales o sin zona, estados de resultado y actualización desde instalaciones anteriores. Ver PLAN_CONTEXTO_CACU.md.
47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
"""The cohort eligibility reader checks gold's contract and supports patient queries."""
|
|
|
|
import pytest
|
|
|
|
from persistance import destination, gold
|
|
|
|
|
|
def test_cacu_eligibility_report_checks_schema_and_filters(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("ISSSTELEON_DATA", str(tmp_path))
|
|
monkeypatch.setenv("PLATFORM_DATABASE_URL", f"sqlite:///{tmp_path / 'platform.db'}")
|
|
monkeypatch.setenv("DBT_TARGET", "sqlite")
|
|
monkeypatch.setattr(destination, "DATA_DIR", tmp_path)
|
|
destination.engine.cache_clear()
|
|
engine = destination.engine()
|
|
|
|
try:
|
|
with pytest.raises(gold.GoldSchemaError, match="not materialized"):
|
|
gold.cacu_eligibility_report("pre_colposcopy", "patient-1")
|
|
|
|
with engine.begin() as con:
|
|
con.exec_driver_sql(
|
|
"create table gold.cacu_eligibility (person_id text, scenario text)"
|
|
)
|
|
with pytest.raises(gold.GoldSchemaError, match="schema is outdated"):
|
|
gold.cacu_eligibility_report()
|
|
|
|
with engine.begin() as con:
|
|
con.exec_driver_sql("drop table gold.cacu_eligibility")
|
|
con.exec_driver_sql(
|
|
"create table gold.cacu_eligibility (scenario text, person_id text, "
|
|
"index_date date, index_sample_id text, criterion text, eligible boolean)"
|
|
)
|
|
con.exec_driver_sql(
|
|
"insert into gold.cacu_eligibility values "
|
|
"('pre_colposcopy', 'patient-1', '2025-01-01', 'sample-1', 'hysterectomy', 0), "
|
|
"('pre_colposcopy', 'patient-1', '2025-01-01', 'sample-1', 'under_18', 0), "
|
|
"('pre_colposcopy', 'patient-2', '2025-02-01', 'sample-2', null, 1), "
|
|
"('post_colposcopy', 'patient-1', '2025-03-01', null, 'outcome_by_index', 0)"
|
|
)
|
|
|
|
found = gold.cacu_eligibility_report("pre_colposcopy", "patient-1")
|
|
assert found["criterion"].tolist() == ["hysterectomy", "under_18"]
|
|
assert found["eligible"].tolist() == [False, False]
|
|
assert len(gold.cacu_eligibility_report("pre_colposcopy")) == 3
|
|
finally:
|
|
destination.engine.cache_clear()
|