TEA: an answer as of a knowledge cut-off reads each child's version known then, and the measures waiting for a validation stay hidden outside FHIR too

This commit is contained in:
2026-11-12 19:47:19 -06:00
parent a0407e41d6
commit 0f9433949f
6 changed files with 93 additions and 26 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ with the ADOS-2, neuropediatrics note, good-quality EEG). Ages are at the first
stays at psychology.
- 4, H-T04, 39 months: out of the cohort, never counted.
- 5, H-T05, 21 months: M-CHAT 15 Jun, a F84.0 note 1 Jul and a good EEG 20 Jul without the ADOS-2: steps go in
order, so it stays at M-CHAT.
order, so it stays at M-CHAT and in process.
- 6, H-T06, 26 months: M-CHAT 5 Apr, ADOS-2 20 Apr, a good EEG 1 Jun before its F84.0 note of 2 Jun: the EEG
step is dated by the note, so it reaches EEG on 2 Jun and leaves after June.
- 7, H-T07, without birth date: in the cohort with age group `sin_dato`. M-CHAT 1 May, nothing else.
+10
View File
@@ -82,6 +82,16 @@ def test_the_measures_hide_m30_until_the_alterations_are_validated(client, monke
assert "M30-resultado-eeg" in {m["id"] for m in resources(get(client, "/tea/fhir/Measure"))}
def test_the_routes_outside_fhir_hide_m30_too(client, monkeypatch):
"""Pins down: `/tea/indicadores` neither lists nor answers M30 until the alterations are validated, and does both
with the switch on. Fails if the measures answered outside `/tea/fhir/` stop waiting for the validation."""
assert "M30_resultado_eeg" not in {m["id"] for m in client.get("/tea/indicadores").get_json()}
assert client.get("/tea/indicadores/M30_resultado_eeg?periodos=2025-S1").status_code == 404
monkeypatch.setenv("TEA_ALTERACIONES_VALIDADAS", "1")
assert "M30_resultado_eeg" in {m["id"] for m in client.get("/tea/indicadores").get_json()}
assert client.get("/tea/indicadores/M30_resultado_eeg?periodos=2025-S1").status_code == 200
def test_a_measure_carries_what_the_page_needs(client):
"""Pins down: a Measure has its absolute canonical, title, scoring (a C2 is a cohort), its strata and its category
labels. Fails if the page's catalog fields stop reaching the Measure."""
+42 -14
View File
@@ -19,7 +19,7 @@ from sqlmodel import select
import staging.tea as fixture
from conftest import base_de
from core.tea.models import Eeg, EegMetrica
from core.tea.models import Ados2, Eeg, EegMetrica, Mchat
from webapi.compositions import answer_composition, composition_definitions
from webapi.durations import answer_duration, duration_definitions
from webapi.metrics import Question, answer, measure_definitions
@@ -106,9 +106,9 @@ RESULTS = {
"2025-03": {"CONFIRMADO": 1, "EN_PROCESO": 2},
"2025-04": {"CONFIRMADO": 1, "EN_PROCESO": 2},
"2025-06": {"CONFIRMADO": 1, "EN_PROCESO": 3},
"2025-07": {"CONFIRMADO": 1, "EN_PROCESO": 2},
"2025-07": {"EN_PROCESO": 3},
"2025-S1": {"CONFIRMADO": 2, "EN_PROCESO": 3},
"2025-S2": {"CONFIRMADO": 1, "EN_PROCESO": 2},
"2025-S2": {"EN_PROCESO": 3},
}
@@ -116,18 +116,19 @@ RESULTS = {
def test_m23_counts_the_confirmed_and_in_process_but_not_a_note_without_f84_0(base, manifest, period):
"""Pins down M23: the confirmed (a F84.0 note by the period's end) and those in process (no note yet). Child 2's
note says F84 without the subcode: from April it's out of M23, though still in the screening. Child 5's F84.0 note
confirms it in July even without the ADOS-2. Fails if F84 counts as a confirmation or a note without F84.0 counts
as in process."""
of July doesn't confirm it without the ADOS-2: it stays in process. Fails if F84 counts as a confirmation, if a
note without F84.0 counts as in process, or if a note counts before the psychology step."""
assert composition(base, manifest, "M23_pacientes_evaluados", period) == RESULTS[period]
@pytest.mark.parametrize(("period", "numerator", "denominator", "excluded"), [
("2025-03", 1, 3, 0), ("2025-04", 1, 3, 1), ("2025-06", 1, 4, 1), ("2025-07", 1, 3, 1), ("2025-S1", 2, 5, 1),
("2025-03", 1, 3, 0), ("2025-04", 1, 3, 1), ("2025-06", 1, 4, 1), ("2025-07", 0, 3, 1), ("2025-S1", 2, 5, 1),
])
def test_m24_is_the_confirmed_out_of_the_confirmed_and_in_process(base, manifest, period, numerator, denominator,
excluded):
"""Pins down M24: confirmed over confirmed plus in process, with child 2 (a note without F84.0) as its exclusion
from April. Fails if the denominator takes the children without TEA or the exclusion stops being counted."""
from April. In July child 5's F84.0 note, without the ADOS-2, leaves it in process. Fails if the denominator takes
the children without TEA, the exclusion stops being counted, or a note confirms without the psychology step."""
result = proportion(base, manifest, "M24_confirmacion_diagnostico", period)
assert (result.numerator, result.denominator, result.excluded) == (numerator, denominator, excluded)
@@ -142,15 +143,15 @@ def test_m24_is_stratified_by_the_age_group_at_the_first_m_chat(base, manifest):
@pytest.mark.parametrize(("period", "with_eeg", "without_eeg", "confirmed"), [
("2025-03", 0, 1, 1), ("2025-05", 1, 0, 1), ("2025-06", 1, 0, 1), ("2025-07", 0, 1, 1),
("2025-S1", 2, 0, 2), ("2025-S2", 0, 1, 1),
("2025-03", 0, 1, 1), ("2025-05", 1, 0, 1), ("2025-06", 1, 0, 1), ("2025-07", 0, 0, 0),
("2025-S1", 2, 0, 2), ("2025-S2", 0, 0, 0),
])
def test_m21_and_m22_split_the_confirmed_by_a_good_eeg_by_the_period_s_end(base, manifest, period, with_eeg,
without_eeg, confirmed):
"""Pins down M21 and its complement M22: of the confirmed at the period's end, those whose chain reached a good EEG
by then. Child 1 is confirmed in March without its EEG (20 May), and with it in May; child 5, confirmed in July,
has a good EEG but no ADOS-2, so its chain never reaches it. Fails if the EEG is read beyond the period's end or
outside the chain."""
by then. Child 1 is confirmed in March without its EEG (20 May), and with it in May; child 5 has a F84.0 note and
a good EEG in July but no ADOS-2, so it isn't confirmed and July has nobody. Fails if the EEG is read beyond the
period's end, or the note or the EEG count outside the chain."""
m21 = proportion(base, manifest, "M21_diagnosticados_con_eeg", period)
m22 = proportion(base, manifest, "M22_diagnosticados_sin_eeg", period)
assert (m21.numerator, m21.denominator) == (with_eeg, confirmed)
@@ -164,14 +165,14 @@ def test_m21_and_m22_split_the_confirmed_by_a_good_eeg_by_the_period_s_end(base,
("M26_dias_mchat_ados2", "2025-S1", 6, 4, 20.5),
("M27_dias_ados2_diagnostico", "2025-S1", 6, 3, 40.0),
("M25_dias_mchat_diagnostico", "2025-S1", 6, 2, 59.5),
("M25_dias_mchat_diagnostico", "2025-S2", 4, 1, 16.0),
("M25_dias_mchat_diagnostico", "2025-S2", 4, 0, None),
])
def test_the_day_counts_take_the_period_s_children_whose_interval_ended_by_its_end(base, manifest, measure_id, period,
initial, n, median):
"""Pins down M26, M27 and M25: every child the period counts is in the initial population; those whose interval
ended by the period's end have days (repeated in each period that counts them), the rest count as without event.
In February, child 1 (26 days) and child 3 (14) have their ADOS-2 and child 2 doesn't yet. Child 5's F84.0 note of
1 July gives 16 days in the second semester only. Fails if the value is read beyond the period's end or the
1 July gives no days without the ADOS-2. Fails if the value is read beyond the period's end or the
population goes back to the facts in the period."""
result = duration(base, manifest, measure_id, period)
assert (result.initial, result.n, result.median) == (initial, n, median)
@@ -243,3 +244,30 @@ def test_a_knowledge_cut_off_leaves_out_a_step_loaded_later(tmp_path, manifest):
assert composition(later, manifest, "M28_casos_por_estado", "2025-05")["EEG"] == 1
finally:
base.motor.dispose()
def test_a_knowledge_cut_off_keeps_what_was_known_when_an_earlier_fact_arrives_later(tmp_path, manifest):
"""Pins down: an answer as of a load doesn't change when a later load brings an earlier-dated fact. A second load
adds an ADOS-2 of 20 Feb for child 3 (its known one is of 28 Feb) and an M-CHAT of 1 Apr for child 7 (its known
one is of 1 May). Asked as of the first load, March still counts child 3 at psychology and May still counts
child 7; asked as of now, child 7 is in the screening from April. Fails if a child's first fact is chosen among
every load's facts and then dropped for being known after the cut-off."""
base = base_de("tea", tmp_path)
try:
base.run(*UNTIL_MODELS, allow_undecided=True)
with base.motor.begin() as connection:
(first_load,) = connection.execute(text("select max(fin) from carga")).one()
known = datetime.fromisoformat(str(first_load)).replace(tzinfo=timezone.utc)
with base.staging() as session:
session.add(Ados2(ado_id="ado-3-earlier", ado_pac_id=3, ado_fecha=date(2025, 2, 20), ado_modulo="MODULO_2",
ado_css=2))
session.add(Mchat(mch_id="mch-7-earlier", mch_pac_id=7, mch_fecha=date(2025, 4, 1), mch_puntaje=7))
session.commit()
base.run("load", allow_undecided=True)
later = replace(base, ctx=replace(base.ctx, allow_undecided=True))
for period in ("2025-03", "2025-05"):
assert composition(later, manifest, "M28_casos_por_estado", period, knowledge_cutoff=known) == STAGES[period]
assert composition(later, manifest, "M28_casos_por_estado", "2025-04") == {
"SOLO_MCHAT": 1, "PSICOLOGIA": 2, "NEUROPEDIATRIA": 2}
finally:
base.motor.dispose()