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
+32 -4
View File
@@ -1,12 +1,40 @@
"""CaCu's patients in FHIR R4: a patient's individual risk as a `RiskAssessment` (DEV only, simulated data), built by
`webapi.fhir.risk` with CaCu's outcomes."""
`webapi.fhir.risk` with CaCu's outcomes.
The results the risk was computed from, the cytology sampled on its index date, go in the extension
`resultados-indice`: one `valueString` per result it has (`escamosas`, `glandulares`, `vph`), as
`citologiacervical` holds them. A risk with no cytology sampled that day has no such extension.
"""
from webapi.fhir import risk
from webapi.fhir.common import STRUCTURE
from webapi.fhir.risk import DAYS_PER_YEAR, INTERVAL, MODEL, OUTCOME # noqa: F401 (kept for readers of this module)
OUTCOMES = {"cin2_mas": "CIN2+ por biopsia", "cin2_12m": "CIN2+ por biopsia en 12 meses"}
OUTCOMES = {"cin2_mas": "CIN2+ por biopsia", "cin2_12m": "CIN2+ por biopsia en 12 meses", "cin2": "CIN2+ por biopsia",
"cancer": "Cáncer cervicouterino por biopsia"}
INDEX_RESULTS = f"{STRUCTURE}/resultados-indice"
RESULT_COLUMNS = {"escamosas": "cit_celulas_escamosas", "glandulares": "cit_celulas_glandulares",
"vph": "cit_vph_resultado"}
def index_results(pac_id: int, fecha_indice) -> dict[str, str]:
"""The results of the patient's cytology sampled on `fecha_indice` (the one with most of them), by name."""
if fecha_indice is None:
return {}
from persistance import cacu
found = {}
for row in cacu.citologia_cervical_repository.list(pac_id=pac_id, cit_fecha_toma=fecha_indice, limit=10):
results = {name: str(v) for name, column in RESULT_COLUMNS.items() if (v := getattr(row, column, None))}
if len(results) > len(found):
found = results
return found
def risk_assessment(pac_id: int, patient_risk, simulated: bool) -> dict:
"""The patient's current risk (`PatientRisk`) as a `RiskAssessment`."""
return risk.risk_assessment(pac_id, patient_risk, simulated, OUTCOMES, "cin2_mas")
"""The patient's current risk (`PatientRisk`) as a `RiskAssessment`, with the index cytology's results."""
resource = risk.risk_assessment(pac_id, patient_risk, simulated, OUTCOMES, "cin2_mas")
if results := index_results(pac_id, patient_risk.fecha_indice):
resource.setdefault("extension", []).append(
{"url": INDEX_RESULTS, "extension": [{"url": k, "valueString": v} for k, v in results.items()]})
return resource