Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fecf7c9d12 | |||
| 1c42d2dc21 | |||
| 1ba00f5c3d | |||
| 21b76ed95e | |||
| 7ddb3df4d9 | |||
| adf66161e1 |
+4
-1
@@ -32,12 +32,14 @@ from fhir_checks import follow_up, pages, served, unscored, validate
|
|||||||
from test_conectar import ok, wait_for
|
from test_conectar import ok, wait_for
|
||||||
|
|
||||||
from conftest import put_concept_map
|
from conftest import put_concept_map
|
||||||
|
from core.cacu import visibility
|
||||||
|
|
||||||
ROOT = Path(__file__).parents[2]
|
ROOT = Path(__file__).parents[2]
|
||||||
HOSPITAL = ROOT / "tests" / "fixtures" / "hospital"
|
HOSPITAL = ROOT / "tests" / "fixtures" / "hospital"
|
||||||
REFERENCE = ROOT / "tests" / "fixtures" / "reference" / "cacu"
|
REFERENCE = ROOT / "tests" / "fixtures" / "reference" / "cacu"
|
||||||
PIPELINE = ROOT / "tests" / "fixtures" / "pipelines" / "hospital_cacu.json"
|
PIPELINE = ROOT / "tests" / "fixtures" / "pipelines" / "hospital_cacu.json"
|
||||||
REFERENCE_CUTOFF = "2026-11-23" # the current platform's cohort cut-off (follow-up ends)
|
REFERENCE_CUTOFF = "2026-11-23" # the current platform's cohort cut-off (follow-up ends)
|
||||||
|
|
||||||
CAPTURED_ON = "2026-11-25" # the day the indicators were captured: durations counted to it
|
CAPTURED_ON = "2026-11-25" # the day the indicators were captured: durations counted to it
|
||||||
PERIODS = [f"{y}-S{s}" for y in range(2021, 2027) for s in (1, 2)]
|
PERIODS = [f"{y}-S{s}" for y in range(2021, 2027) for s in (1, 2)]
|
||||||
COHORTS = {
|
COHORTS = {
|
||||||
@@ -189,7 +191,8 @@ def test_cacu_from_the_hospital_to_indicators_and_risks(api, platform, tmp_path)
|
|||||||
# none is promoted without the clinical validation.
|
# none is promoted without the clinical validation.
|
||||||
wait_for(api, ok(api.post("/models/cacu/train", json={"as_of": REFERENCE_CUTOFF}))["run_id"])
|
wait_for(api, ok(api.post("/models/cacu/train", json={"as_of": REFERENCE_CUTOFF}))["run_id"])
|
||||||
names = [m["name"] for m in ok(api.get("/models/cacu"))]
|
names = [m["name"] for m in ok(api.get("/models/cacu"))]
|
||||||
assert set(names) == set(current)
|
# the hidden models (core.models.HIDDEN) are neither trained nor listed
|
||||||
|
assert set(names) == {n for n in current if visibility.model(f"cacu.{n}")}
|
||||||
for name in names:
|
for name in names:
|
||||||
(version,) = ok(api.get(f"/models/cacu/{name}/versions"))
|
(version,) = ok(api.get(f"/models/cacu/{name}/versions"))
|
||||||
assert version["reports"] == ["interpretability", "technical_validation"]
|
assert version["reports"] == ["interpretability", "technical_validation"]
|
||||||
|
|||||||
+8
-37
@@ -20,7 +20,7 @@ from fhir.resources.R4B.resource import Resource
|
|||||||
from core import catalog, models
|
from core import catalog, models
|
||||||
from core import fhir as f
|
from core import fhir as f
|
||||||
from core import measures as m
|
from core import measures as m
|
||||||
from core.cacu import currency, risk_series
|
from core.cacu import currency, risk_series, visibility
|
||||||
from core.cacu import reference_risk as reference
|
from core.cacu import reference_risk as reference
|
||||||
from core.domains import Domain, measures, part
|
from core.domains import Domain, measures, part
|
||||||
from core.follow_up import window_start
|
from core.follow_up import window_start
|
||||||
@@ -83,7 +83,7 @@ def _risks(domain: Domain, persons: list[str], cutoff: date) -> list[dict]:
|
|||||||
rows = [
|
rows = [
|
||||||
r
|
r
|
||||||
for r in reads.rows(domain.value, "risk", persons=persons)
|
for r in reads.rows(domain.value, "risk", persons=persons)
|
||||||
if r["model"] not in models.DEVELOPMENT
|
if r["model"] not in models.DEVELOPMENT and visibility.model(r["model"])
|
||||||
]
|
]
|
||||||
history = _history(domain, persons)
|
history = _history(domain, persons)
|
||||||
gone = {person: currency.withheld(found, cutoff) for person, found in history.items()}
|
gone = {person: currency.withheld(found, cutoff) for person, found in history.items()}
|
||||||
@@ -189,6 +189,7 @@ def _reference_facts(domain: Domain, id: str, cutoff: date | None) -> tuple[dict
|
|||||||
"biopsies": reads.rows(domain.value, "reference_biopsies", **one),
|
"biopsies": reads.rows(domain.value, "reference_biopsies", **one),
|
||||||
"events": reads.rows(domain.value, "reference_events", **one),
|
"events": reads.rows(domain.value, "reference_events", **one),
|
||||||
"requirements": reads.rows(domain.value, "reference_requirements", **one),
|
"requirements": reads.rows(domain.value, "reference_requirements", **one),
|
||||||
|
"master": reads.rows(domain.value, "reference_master"),
|
||||||
}
|
}
|
||||||
return facts, _cutoff(domain, cutoff)
|
return facts, _cutoff(domain, cutoff)
|
||||||
|
|
||||||
@@ -200,40 +201,10 @@ def reference_risk(
|
|||||||
cutoff: date | None = Query(None, description="Only what was reported by this day"),
|
cutoff: date | None = Query(None, description="Only what was reported by this day"),
|
||||||
sample: date | None = Query(None, description="The cytology's sample day"),
|
sample: date | None = Query(None, description="The cytology's sample day"),
|
||||||
) -> Response:
|
) -> Response:
|
||||||
"""EXPERIMENTAL, off unless CACU_NCI_REFERENCE=1. The NCI/ASCCP CIN3+ reference risk of one
|
"""Disabled. The NCI series, the master table's included, are in `$risk-series`."""
|
||||||
patient's cytology by a cut-off, how it was resolved and, beside it, the institutional models'
|
if domain != Domain.CACU or os.environ.get(NCI_REFERENCE) != "1":
|
||||||
risks when they measure the same thing. Research only: not validated, not a recommendation."""
|
raise HTTPException(404, "the NCI reference comparison is not enabled")
|
||||||
facts, day = _reference_facts(domain, id, cutoff)
|
raise HTTPException(503, "$reference-risk is disabled; the NCI series are in $risk-series")
|
||||||
resolution = reference.resolve(facts, day, sample)
|
|
||||||
latest: dict[str, dict] = {} # each model's latest assessment by the cut-off
|
|
||||||
for r in _risks(domain, [id], day):
|
|
||||||
index = str(r["index_date"])[:10]
|
|
||||||
if index > day.isoformat():
|
|
||||||
continue
|
|
||||||
found = latest.setdefault(
|
|
||||||
r["model"],
|
|
||||||
{
|
|
||||||
"model": r["model"],
|
|
||||||
"index_date": index,
|
|
||||||
"title": models.title(r["model"]),
|
|
||||||
"predictions": [],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if index > found["index_date"]:
|
|
||||||
found.update(index_date=index, predictions=[])
|
|
||||||
if index == found["index_date"]:
|
|
||||||
found["predictions"].append(
|
|
||||||
{
|
|
||||||
"years": int(r["horizon_years"]),
|
|
||||||
"p": r["probability"],
|
|
||||||
"low": r["ci_low"],
|
|
||||||
"high": r["ci_high"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
comparison = (
|
|
||||||
reference.compare(resolution, list(latest.values())) if resolution["horizons"] else []
|
|
||||||
)
|
|
||||||
return fhir(f.reference_risk(resolution, comparison, reference.tables()))
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/Patient/{id}/$risk-series", responses=_OK, response_class=Response)
|
@router.get("/Patient/{id}/$risk-series", responses=_OK, response_class=Response)
|
||||||
@@ -247,7 +218,7 @@ def cacu_risk_series(
|
|||||||
draw: institutional models and NCI tables, by outcome, with the published intervals."""
|
draw: institutional models and NCI tables, by outcome, with the published intervals."""
|
||||||
facts, day = _reference_facts(domain, id, cutoff)
|
facts, day = _reference_facts(domain, id, cutoff)
|
||||||
resolution = reference.resolve(facts, day, sample)
|
resolution = reference.resolve(facts, day, sample)
|
||||||
found = risk_series.series(facts, resolution, _risks(domain, [id], day), day, models.title)
|
found = risk_series.series(resolution, _risks(domain, [id], day), day, models.title)
|
||||||
return fhir(f.risk_series(found, id, day))
|
return fhir(f.risk_series(found, id, day))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -9,6 +9,7 @@ from fastapi import APIRouter, Depends, HTTPException, UploadFile
|
|||||||
from fastapi.responses import Response
|
from fastapi.responses import Response
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from core.cacu import visibility
|
||||||
from core.domains import Domain
|
from core.domains import Domain
|
||||||
from core.models import title
|
from core.models import title
|
||||||
from persistance import registry
|
from persistance import registry
|
||||||
@@ -35,7 +36,11 @@ class Model(BaseModel):
|
|||||||
def models(domain: Domain) -> list[Model]:
|
def models(domain: Domain) -> list[Model]:
|
||||||
"""The domain's registered models, with their names on screen."""
|
"""The domain's registered models, with their names on screen."""
|
||||||
prefix = f"{domain.value}."
|
prefix = f"{domain.value}."
|
||||||
return [Model(name=n.removeprefix(prefix), title=title(n)) for n in registry.names(prefix)]
|
return [
|
||||||
|
Model(name=n.removeprefix(prefix), title=title(n))
|
||||||
|
for n in registry.names(prefix)
|
||||||
|
if visibility.model(n)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{domain}/{name}/versions")
|
@router.get("/{domain}/{name}/versions")
|
||||||
|
|||||||
Reference in New Issue
Block a user