feat(tea): EEG analysis before the silver load, and its verdict, quality checks and baselines through silver and FHIR
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
- an order is an `orden` of the study it asks for (`ord_tipo_estudio`, in Core's code or one of its aliases);
|
||||
- the M-CHAT is a `toma`, the ADOS-2 and the neuropediatrics note are `encuentro`s, the EEG is a `toma`; each
|
||||
hangs from its order when it has one;
|
||||
- an EEG metric is a result of its EEG's recording, not a procedure; a metric's electrode value is a `parte` of the
|
||||
EEG (`codigo_fuente` the electrode) with the metric's result. Both find their EEG through the metric's row.
|
||||
- what the EEG analysis writes: the EEG's verdict and study-wide quality checks (`eeg_criterio` without an
|
||||
electrode) and each metric with its deviation from the age baseline are results of the EEG's recording, not
|
||||
procedures; a bad channel (`eeg_criterio` with an electrode) and a metric's value at an electrode are `parte`s of
|
||||
the EEG, `codigo_fuente` the electrode. The metric rows find their EEG through the metric.
|
||||
"""
|
||||
|
||||
from core.tea.enums import (
|
||||
@@ -18,6 +20,7 @@ from core.tea.models import (
|
||||
ADOS2_ITEMS,
|
||||
Ados2,
|
||||
Eeg,
|
||||
EegCriterio,
|
||||
EegMetrica,
|
||||
EegMetricaElectrodo,
|
||||
EvaluacionNeuropediatrica,
|
||||
@@ -50,7 +53,20 @@ def _metrica(f) -> str | None:
|
||||
return None if codigo is None else codigo.lower()
|
||||
|
||||
|
||||
def _criterio(f) -> str | None:
|
||||
"""A quality check's results in the catalog: `calidad_` and its code in snake case (`clean-windows` ->
|
||||
`calidad_clean_windows`)."""
|
||||
codigo = texto_limpio(f.cri_codigo)
|
||||
return None if codigo is None else "calidad_" + codigo.lower().replace("-", "_")
|
||||
|
||||
|
||||
def _valor_de_criterio(f):
|
||||
return f.cri_valor if f.cri_valor is not None else texto_limpio(f.cri_valor_texto)
|
||||
|
||||
|
||||
SU_EEG = Padre(estudio_id="eeg", clase="toma", fuente_id="met_eeg_id", tabla=EEG)
|
||||
EEG_DEL_CRITERIO = Padre(estudio_id="eeg", clase="toma", fuente_id="cri_eeg_id", tabla=EEG)
|
||||
DEVIATION = ("z", "fuera", "p5", "mediana", "p95")
|
||||
|
||||
|
||||
DESDE_STAGING = (
|
||||
@@ -95,26 +111,42 @@ DESDE_STAGING = (
|
||||
Eeg, "eeg_id", "toma", estudio_id="eeg", fecha="eeg_fecha_estudio", paciente="eeg_pac_id",
|
||||
padres=(_su_orden("eeg", "eeg_ord_id"),), columnas={"id_hospital": "eeg_id_registro_laboratorio"},
|
||||
resultados={
|
||||
"eeg_valido": "eeg.valido",
|
||||
"eeg_nivel": "eeg.nivel",
|
||||
"eeg_fraccion_limpia": "eeg.fraccion_limpia",
|
||||
"eeg_canales_malos": "eeg.canales_malos",
|
||||
"eeg_edad_meses": "eeg.edad_meses",
|
||||
"eeg_con_sueno": "eeg.con_sueno",
|
||||
"eeg_canales": "eeg.canales",
|
||||
"eeg_duracion_min": "eeg.duracion_min",
|
||||
"eeg_canales_amplitud": "eeg.calidad_amplitud",
|
||||
"eeg_canales_alta_frecuencia": "eeg.calidad_alta_frecuencia",
|
||||
"eeg_canales_correlacion": "eeg.calidad_correlacion",
|
||||
"eeg_canales_sin_senal": "eeg.calidad_sin_senal",
|
||||
"eeg_ruido_linea_db": "eeg.calidad_linea",
|
||||
"eeg_ruido_linea_db": "eeg.ruido_linea",
|
||||
},
|
||||
),
|
||||
DeStaging(
|
||||
EegCriterio, "cri_id", "toma", estudio_id="eeg", paciente=None, observa_en=EEG_DEL_CRITERIO,
|
||||
solo_si=lambda f: f.cri_electrodo is None,
|
||||
derivadas={"criterio": _criterio, "valor": _valor_de_criterio},
|
||||
resultados={"valor": "eeg.{criterio}", "cri_anormal": "eeg.{criterio}_anormal",
|
||||
"cri_decisivo": "eeg.{criterio}_decisivo", "cri_bajo": "eeg.{criterio}_bajo",
|
||||
"cri_alto": "eeg.{criterio}_alto"},
|
||||
),
|
||||
DeStaging(
|
||||
EegCriterio, "cri_id", "parte", estudio_id="eeg", paciente=None, padres=(EEG_DEL_CRITERIO,),
|
||||
solo_si=lambda f: f.cri_electrodo is not None,
|
||||
derivadas={"criterio": _criterio, "valor": _valor_de_criterio},
|
||||
columnas={"codigo_fuente": "cri_electrodo"},
|
||||
resultados={"valor": "eeg.{criterio}"},
|
||||
),
|
||||
DeStaging(
|
||||
EegMetrica, "met_id", "toma", estudio_id="eeg", paciente=None, observa_en=SU_EEG,
|
||||
derivadas={"metrica": _metrica},
|
||||
resultados={"met_valor": "eeg.{metrica}"},
|
||||
resultados={"met_valor": "eeg.{metrica}", **{f"met_{d}": f"eeg.{{metrica}}_{d}" for d in DEVIATION}},
|
||||
),
|
||||
DeStaging(
|
||||
EegMetricaElectrodo, "mel_id", "parte", estudio_id="eeg", paciente=None,
|
||||
juntas=(Junta(EegMetrica, "met_id", "mel_met_id"),), padres=(SU_EEG,),
|
||||
derivadas={"metrica": _metrica},
|
||||
columnas={"codigo_fuente": "mel_electrodo"},
|
||||
resultados={"mel_valor": "eeg.{metrica}"},
|
||||
resultados={"mel_valor": "eeg.{metrica}", "mel_z": "eeg.{metrica}_z"},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user