Indexing: the first invasive biopsy reads the scenario's event grades and keeps its rules
The whole-frame version of primera_biopsia_invasora looked for the single code CARCINOMA_INVASOR, so CaCu's survival, which indexes on CIS and CARCINOMA, had no members and could not train. It also dropped the two rules the per-patient version applied (no birth date, a death on or before the biopsy) and the prior observation threshold. It now takes the grades from event_grades (invasive_code stays the fallback) and applies the rules in the same order, with the same attrition.
This commit is contained in:
@@ -170,6 +170,31 @@ def test_the_node_reindexes_the_frame_with_the_source_cohorts_window():
|
||||
assert closed.empty and indexing.cohort(source, lineage, None) is source
|
||||
|
||||
|
||||
def test_the_first_invasive_biopsy_index_reads_the_scenarios_event_grades_and_applies_its_rules():
|
||||
"""Pins down `primera_biopsia_invasora` over the whole frame: the index is the first biopsy reported with one of the
|
||||
scenario's `event_grades` (CaCu's CIS and carcinoma, CaMa's invasive carcinoma), a grade of another scenario does
|
||||
not index, and without `event_grades` the CaMa code is the default; then, in order, the patient with no birth date
|
||||
and the one who died on or before the biopsy are out, each charged in the attrition. Fails if the index looks for
|
||||
one fixed code, so that CaCu's survival has no members, if a grade outside the list indexes, or if a rule stops
|
||||
applying."""
|
||||
birth = [_row(pac, "nacimiento", date(1980, 1, 1)) for pac in (1, 2, 3, 5)]
|
||||
rows = [*birth, _row(1, "biopsia", date(2025, 3, 1), "CIS"), _row(1, "biopsia", date(2025, 1, 1), "LIEAG"),
|
||||
_row(2, "biopsia", date(2025, 6, 1), "CARCINOMA"), _row(3, "biopsia", date(2025, 7, 1), "CARCINOMA_INVASOR"),
|
||||
_row(4, "biopsia", date(2025, 8, 1), "CARCINOMA"),
|
||||
_row(5, "biopsia", date(2025, 9, 1), "CIS"), _row(5, "defuncion", date(2025, 9, 1))]
|
||||
|
||||
def indexed(**index):
|
||||
members, attrition = indexing._indexed_members(_frame(rows), {"kind": "primera_biopsia_invasora", **index})
|
||||
return members.values.tolist(), attrition
|
||||
|
||||
members, attrition = indexed(event_grades=["CIS", "CARCINOMA"])
|
||||
assert members == [[1, date(2025, 3, 1)], [2, date(2025, 6, 1)]]
|
||||
assert attrition == [("pacientes", 5), ("indexed", 4), ("sin_nacimiento", 3), ("defuncion_hasta_el_indice", 2),
|
||||
("observacion_previa_insuficiente", 2)]
|
||||
assert indexed(event_grades=["CARCINOMA_INVASOR"])[0] == [[3, date(2025, 7, 1)]]
|
||||
assert indexed()[0] == [[3, date(2025, 7, 1)]]
|
||||
|
||||
|
||||
def test_prior_observation_is_a_threshold_on_the_days_before_the_index():
|
||||
"""Pins down the left-truncation rule: with the default 0 nobody is out; with 230 days, patient 1 (first event 30
|
||||
days before her colposcopy, visit 1 at 200 days: 230 days observed) stays and with 231 she is out; the summary
|
||||
|
||||
Reference in New Issue
Block a user