Validate patient identity in breast cohort links

This commit is contained in:
Angel Capetillo Zavala
2026-11-13 14:52:55 -06:00
parent 1d5f1e0cc4
commit 7bc214b50c
2 changed files with 27 additions and 8 deletions
+17
View File
@@ -169,3 +169,20 @@ def test_newer_noneligible_result_changes_revision_and_excludes_patient(client,
aggregate = client.get('/cama/analisis/indicadores?corte=2026-10-20').get_json()
assert next(g for g in aggregate['grupos'] if g['codigo'] == 'BIRADS_5')['n'] == 5
assert len(client.get('/cama/seguimiento' + query(client)).get_json()['items']) == 5
def test_cross_patient_links_and_observations_are_not_used(cohort_db):
"""A mismatched patient or an order before the mammogram cannot supply a result."""
with Session(cohort_db) as session:
# The biopsy order is linked to patient 1's mammogram but belongs to patient 2.
session.get(TABLAS.Procedimiento, 102).pac_id = 2
# Patient 3's otherwise linked biopsy order predates the mammogram.
session.get(TABLAS.Procedimiento, 106).fecha = date(2025, 1, 1)
# The BI-RADS observation belongs to a different patient.
session.get(TABLAS.Observacion, 6).pac_id = 5
session.commit()
reader = CamaCohort(session, b'x' * 32)
rows = {row['id_seudonimo']: row for row in reader.rows(date(2027, 12, 1))}
assert reader._id(6) not in rows
assert rows[reader._id(1)]['biopsia'] is None
assert rows[reader._id(3)]['biopsia'] is None