42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
"""TEA's follow-up list (core.tea.follow_up): the route stage, the case, and the study EEG."""
|
|
|
|
from datetime import date
|
|
|
|
from core.tea import follow_up as fu
|
|
|
|
CUTOFF = date(2026, 11, 28)
|
|
START = date(2026, 6, 1)
|
|
|
|
|
|
def child(person="a", **kw):
|
|
return {"person_id": person, "birth_date": "2024-09-01", "age_group": "16-23",
|
|
"mchat_date": "2026-07-01", "score": 9.0, **kw} # fmt: skip
|
|
|
|
|
|
def test_the_stage_is_the_last_step_reached_by_the_cutoff():
|
|
rows = [child(psychology_date="2026-08-01", neuro_date="2026-09-01", eeg_date="2026-12-01")]
|
|
found = fu.listed(rows, START, CUTOFF)[0]
|
|
assert found["status"] == "neuropediatrics" # the EEG came after the cut-off
|
|
assert found["case"] == "in_process" and found["eeg_status"] == "no_valid_eeg"
|
|
|
|
|
|
def test_the_study_eeg_is_the_first_valid_and_its_alterations_make_it_abnormal():
|
|
base = child(confirmed_date="2026-09-10")
|
|
rows = [
|
|
{**base, "eeg_id": "e1", "eeg_study_date": "2026-09-01", "valid": False},
|
|
{**base, "eeg_id": "e2", "eeg_study_date": "2026-10-01", "valid": True,
|
|
"metric": "theta_power", "outside": 1.4},
|
|
{**base, "eeg_id": "e2", "eeg_study_date": "2026-10-01", "valid": True,
|
|
"metric": "spindle_density", "outside": -0.3},
|
|
{**base, "eeg_id": "e3", "eeg_study_date": "2026-11-01", "valid": True},
|
|
] # fmt: skip
|
|
found = fu.listed(rows, START, CUTOFF)[0]
|
|
assert found["case"] == "confirmed" and found["eeg_status"] == "abnormal"
|
|
assert found["alterations"] == ["spindle_density:below", "theta_power:above"]
|
|
assert found["last_eeg"] == date(2026, 11, 1)
|
|
|
|
|
|
def test_a_child_with_nothing_in_the_window_is_not_listed():
|
|
assert fu.listed([child(mchat_date="2026-01-10")], START, CUTOFF) == []
|
|
assert fu.listed([child(mchat_date="2026-12-10")], START, CUTOFF) == [] # after the cut-off
|