Compare commits

...

1 Commits

2 changed files with 12 additions and 2 deletions
+9
View File
@@ -125,6 +125,15 @@ def test_the_menu_offers_the_scenarios_with_a_summary_row_and_enough_patients(li
assert live_client.get("/cama/modelo/escenarios?paciente=500").status_code == 422
def test_a_patient_in_no_drawable_scenario_gets_no_default(live_client):
"""Pins down: a patient who belongs to none of the scenarios on the menu (patient 150 is outside `< 45 años`) gets
`predeterminado: null` while the menu is still offered. Fails if the default falls back to the first scenario and the dashboard
draws another subgroup's curve on her record."""
menu = live_client.get("/cama/modelo/escenarios?paciente=150").get_json()
assert menu["predeterminado"] is None and menu["escenarios"] == [{"nombre": "< 45 años", "n": 100}]
def test_a_scenarios_figure_comes_with_its_risk_factors_and_the_answer_is_kept(live_client):
"""Pins down: `POST /cama/modelo/curvas/consulta` returns the figure of the named scenario with its summary row (the risk-factor
label) and the version that scored it, and the same scenario a second time is answered without computing again; a scenario with
+3 -2
View File
@@ -100,7 +100,7 @@ def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint:
def scenarios_menu():
"""The clinical scenarios the menu offers: those with a row in the version's summary and enough patients over the data
ingested so far to draw, in the pipeline's order, with their patients; `?paciente=<pac_id>` also names the one she
belongs to first as the default. 404 while there is no version in production."""
belongs to first as the default (`null` when she is in none). 404 while there is no version in production."""
from models.cama.survival import live
try:
@@ -117,7 +117,8 @@ def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint:
mine = live.patient_scenarios(labelled, int(paciente))
except live.QueryError as error:
return jsonify({"error": str(error)}), 422
default = next((m["nombre"] for m in menu if m["nombre"] in mine), default)
# Belonging to no drawable scenario leaves no default: showing another subgroup's curve would misdescribe her.
default = next((m["nombre"] for m in menu if m["nombre"] in mine), None)
return jsonify({"modelo": {"nombre": f"{domain}-{scenario}", "version": str(version)}, "escenarios": menu, "predeterminado": default})
@blueprint.post("/modelo/curvas/consulta")