CaMa: individual risk and population curves served, and the cycle estimates with any scenario in production
webapi/fhir/risk.py builds a patient's RiskAssessment for CaCu and CaMa; GET /cama/modelo/curvas serves the production version's survival curves; the cycle's estimator is generic by scenario; silver persona carries the date of death for CaMa; the import schema accepts it; the CaMa risk batches can be confirmed and voided.
This commit is contained in:
@@ -25,15 +25,16 @@ class Provenance:
|
||||
return {key: value for key, value in self.__dict__.items() if value}
|
||||
|
||||
|
||||
class Cin2LogisticEstimator:
|
||||
"""Scores CaCu's surveillance cohort with the `cacu-cin2_logistic` version in production (or `version`, to
|
||||
test a candidate). Offered by `live_estimators` only once that version exists, so `procedencia` always has
|
||||
something to report when `estimate` calls it."""
|
||||
class ScenarioEstimator:
|
||||
"""Scores a domain's cohort with the version of one scenario that is in production (or `version`, to test a
|
||||
candidate). Offered by `live_estimators` only once that version exists, so `procedencia` always has something to
|
||||
report when `estimate` calls it."""
|
||||
|
||||
def __init__(self, domain: str = "cacu", version: str | None = None):
|
||||
def __init__(self, domain: str, scenario: str, version: str | None = None):
|
||||
self.domain = domain
|
||||
self.scenario = scenario
|
||||
self.version = version
|
||||
self.desenlace = "cin2_mas"
|
||||
self.desenlace = ""
|
||||
self._provenance: Provenance | None = None
|
||||
|
||||
def estimar(self, columnas: list[str], filas: list[tuple]) -> list[tuple]:
|
||||
@@ -49,7 +50,7 @@ class Cin2LogisticEstimator:
|
||||
from models.steps.risks import risk_rows
|
||||
|
||||
repos = import_module(f"persistance.{self.domain}")
|
||||
scenario = Scenario.load(self.domain, "cin2_logistic")
|
||||
scenario = Scenario.load(self.domain, self.scenario)
|
||||
build_id = repos.cohort_repository.latest_build(scenario.cohort)
|
||||
resolved = registry.resolve(self.domain, scenario.scenario, self.version)
|
||||
frame = KitBuild(self.domain, build_id).frame()
|
||||
@@ -67,11 +68,39 @@ class Cin2LogisticEstimator:
|
||||
return self._provenance
|
||||
|
||||
|
||||
class Cin2LogisticEstimator(ScenarioEstimator):
|
||||
"""Scores CaCu's surveillance cohort with the `cacu-cin2_logistic` version in production (or `version`)."""
|
||||
|
||||
def __init__(self, domain: str = "cacu", version: str | None = None):
|
||||
super().__init__(domain, "cin2_logistic", version)
|
||||
self.desenlace = "cin2_mas"
|
||||
|
||||
|
||||
# The scenarios the cycle estimates with, per domain other than CaCu: each one that has a version in production
|
||||
# scores the cohort it names.
|
||||
LIVE_SCENARIOS = {"cama": ("survival",)}
|
||||
|
||||
|
||||
def _scenario_estimators(domain: str) -> dict[str, Any]:
|
||||
from models.dags.training import Scenario
|
||||
from models.io.registry import registry
|
||||
|
||||
found = {}
|
||||
for name in LIVE_SCENARIOS.get(domain, ()):
|
||||
scenario = Scenario.load(domain, name)
|
||||
try:
|
||||
registry.resolve(domain, name)
|
||||
except LookupError:
|
||||
continue
|
||||
found[scenario.cohort] = ScenarioEstimator(domain, name)
|
||||
return found
|
||||
|
||||
|
||||
def live_estimators(domain: str) -> dict[str, Any]:
|
||||
"""The estimators of a domain's cohorts whose model has a version in production, by cohort url. Empty where
|
||||
none is in production yet, the same as no estimator being configured: `estimate` then does nothing."""
|
||||
if domain != "cacu":
|
||||
return {}
|
||||
return _scenario_estimators(domain)
|
||||
from models.dags.training import Scenario
|
||||
from models.io.registry import registry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user