FHIR: CaCu's risk names the results of its index cytology

The cytology sampled on the risk's index date gives its squamous, glandular and HPV results in the extension
`resultados-indice`, which the record words its sentence with. CaCu's outcome codes `cin2` and `cancer` get labels.
This commit is contained in:
2026-11-22 09:34:49 -06:00
parent b63a253b19
commit b9795c02ca
2 changed files with 61 additions and 4 deletions
+29
View File
@@ -33,3 +33,32 @@ def test_a_model_without_a_scenario_has_no_estimand():
a missing scenario breaks the patient's risk."""
found = risk.risk_assessment(7, _risk("cacu-no_existe"), True, {}, "cin2_mas")
assert "text" not in found["method"] and not any(e.get("url") == risk.ESTIMAND for e in found.get("extension", []))
def test_a_cacu_risk_names_the_results_of_its_index_cytology(monkeypatch):
"""Pins down: CaCu's RiskAssessment carries the squamous, glandular and HPV results of the cytology sampled on the
risk's index date (the most complete if there are several), which the record words its sentence with; a risk
with none that day has no such extension. Fails if the extension's url or keys change, or another day's sample
is read."""
from persistance import cacu as repos
from webapi.fhir import cacu
asked = []
def rows(**filters):
asked.append(filters)
return [SimpleNamespace(cit_celulas_escamosas="LIEBG", cit_celulas_glandulares=None, cit_vph_resultado=None),
SimpleNamespace(cit_celulas_escamosas="LIEBG", cit_celulas_glandulares=None,
cit_vph_resultado="POSITIVO")]
monkeypatch.setattr(repos.citologia_cervical_repository, "list", rows)
found = cacu.risk_assessment(7, _risk("cacu-cin2_pim"), True)
extension = next(e for e in found["extension"] if e["url"] == cacu.INDEX_RESULTS)
assert {e["url"]: e["valueString"] for e in extension["extension"]} == {"escamosas": "LIEBG", "vph": "POSITIVO"}
assert asked[0]["pac_id"] == 7 and asked[0]["cit_fecha_toma"] == date(2025, 1, 1)
monkeypatch.setattr(repos.citologia_cervical_repository, "list", lambda **filters: [])
without = cacu.risk_assessment(7, _risk("cacu-cin2_pim"), True)["extension"]
assert not any(e["url"] == cacu.INDEX_RESULTS for e in without)