163 lines
9.3 KiB
Python
163 lines
9.3 KiB
Python
"""Captions and clinical synonyms used by the source documents, keyed by
|
|
the column they fill. Extend these tables when a new report format shows a
|
|
caption or a term the extractor doesn't know yet; no code changes are needed.
|
|
"""
|
|
import re
|
|
|
|
# Column -> captions printed before its value (accents/case don't matter).
|
|
LABELS: dict[str, tuple[str, ...]] = {
|
|
"pac_id_hospital": ("expediente", "no. expediente", "num. expediente", "número de expediente", "nss", "no. de afiliación", "afiliación", "registro", "folio del paciente"),
|
|
"pac_sexo": ("sexo", "género", "genero"),
|
|
"pac_fecha_nacimiento": ("fecha de nacimiento", "f. de nacimiento", "f. nacimiento", "fecha nac", "f. nac", "nacimiento", "fec. nac"),
|
|
"pac_codigo_postal": ("código postal", "c.p.", "cp"),
|
|
"pac_dependencia": ("dependencia",),
|
|
"pac_parentesco": ("parentesco",),
|
|
"ord_numero_hospital": ("número de orden", "no. de orden", "orden", "folio de orden", "solicitud"),
|
|
"ord_fecha_solicitud": ("fecha de solicitud", "solicitado el"),
|
|
"ord_fecha_resultado": ("fecha de resultado", "fecha del resultado"),
|
|
"ord_medico_solicitante": ("médico solicitante", "solicitante", "solicita"),
|
|
"ord_diagnostico": ("diagnóstico", "dx"),
|
|
"cit_fecha_toma": ("fecha de toma", "toma de muestra", "fecha toma", "fecha de muestra"),
|
|
"cit_fecha_reporte": ("fecha de reporte", "fecha del reporte", "fecha de informe", "reportado el"),
|
|
"cit_calidad_especimen": ("calidad de la muestra", "calidad del espécimen", "calidad de muestra", "muestra"),
|
|
"cit_celulas_escamosas": ("células escamosas", "celulas escamosas", "anormalidades en células escamosas", "interpretación", "resultado citológico"),
|
|
"cit_celulas_glandulares": ("células glandulares",),
|
|
"cit_dx_lesion": ("diagnóstico", "lesión"),
|
|
"cit_observaciones": ("observaciones", "comentarios", "notas"),
|
|
"cit_vph_resultado": ("resultado vph", "vph de alto riesgo", "vph alto riesgo", "virus del papiloma humano", "detección de vph", "vph", "hpv"),
|
|
"cit_vph_genotipo_16": ("genotipo 16", "vph 16", "hpv 16", "vph-16", "tipo 16"),
|
|
"cit_vph_genotipo_18": ("genotipo 18", "vph 18", "hpv 18", "vph-18", "tipo 18"),
|
|
"bx_fecha_solicitud": ("fecha de solicitud", "fecha de toma"),
|
|
"bx_fecha_reporte": ("fecha de reporte", "fecha del reporte", "fecha de informe"),
|
|
"bx_cin_grado": ("diagnóstico", "diagnóstico histopatológico", "resultado", "conclusión", "nic", "cin"),
|
|
"bx_grado_histologico": ("diagnóstico", "diagnóstico histopatológico", "resultado", "conclusión", "grado histológico"),
|
|
"bx_observaciones": ("observaciones", "descripción microscópica", "comentarios"),
|
|
"mast_birads": ("bi-rads", "birads", "categoría", "clasificación"),
|
|
"mast_fecha_toma": ("fecha de estudio", "fecha de toma", "fecha"),
|
|
"mast_interpretacion": ("interpretación", "impresión diagnóstica", "conclusión", "hallazgos"),
|
|
"nm_fecha": ("fecha", "fecha de consulta", "fecha de la nota"),
|
|
"nm_medico_tratante": ("médico tratante", "médico", "atendió"),
|
|
"nm_especialidad": ("especialidad", "servicio"),
|
|
"nm_motivo_consulta": ("motivo de consulta", "motivo"),
|
|
"nm_diagnostico_texto": ("diagnóstico", "impresión diagnóstica", "dx"),
|
|
"nm_cie_codigo": ("cie-10", "cie10", "cie"),
|
|
"nm_tratamiento_texto": ("tratamiento", "plan terapéutico"),
|
|
"nm_plan_estudios": ("plan", "estudios solicitados"),
|
|
"nm_pronostico": ("pronóstico",),
|
|
"nm_talla": ("talla", "estatura"),
|
|
"nm_masa_corporal": ("peso",),
|
|
"nm_imc_visita": ("imc", "índice de masa corporal"),
|
|
"nm_temperatura": ("temperatura", "temp"),
|
|
"nm_frecuencia_cardiaca": ("frecuencia cardiaca", "fc"),
|
|
"nm_frecuencia_respiratoria": ("frecuencia respiratoria", "fr"),
|
|
"hemoglobina_g_dl": ("hemoglobina", "hb", "hgb"),
|
|
"hematocrito_pct": ("hematocrito", "hto", "hct"),
|
|
"eritrocitos_mill_ul": ("eritrocitos", "glóbulos rojos", "rbc"),
|
|
"leucocitos_mil_ul": ("leucocitos", "glóbulos blancos", "wbc"),
|
|
"plaquetas_mil_ul": ("plaquetas", "plt"),
|
|
"neutrofilos_pct": ("neutrófilos",),
|
|
"linfocitos_pct": ("linfocitos",),
|
|
"monocitos_pct": ("monocitos",),
|
|
"eosinofilos_pct": ("eosinófilos",),
|
|
"basofilos_pct": ("basófilos",),
|
|
"bh_fecha": ("fecha", "fecha de toma"),
|
|
"eeg_id_registro_laboratorio": ("no. de estudio", "número de estudio", "folio", "no. de registro", "registro de laboratorio"),
|
|
"eeg_fecha_estudio": ("fecha de estudio", "fecha del estudio", "fecha de registro"),
|
|
"eeg_fecha_reporte": ("fecha de reporte", "fecha del reporte", "fecha de interpretación"),
|
|
"eeg_medico_interpreta": ("médico interpreta", "interpretado por", "médico que interpreta"),
|
|
"eeg_estado_registro": ("estado del registro", "estado"),
|
|
"eeg_calidad_tecnica": ("calidad técnica", "calidad del registro"),
|
|
"eeg_simetria": ("simetría", "simetria"),
|
|
"eeg_distribucion_anormalidad": ("distribución de la anormalidad", "localización de la anormalidad"),
|
|
"eeg_respuesta_fotoestimulacion": ("respuesta a fotoestimulación", "fotoestimulación"),
|
|
"eeg_conclusion_texto": ("conclusión", "impresión diagnóstica", "interpretación"),
|
|
"eeg_conclusion_categoria": ("conclusión", "categoría diagnóstica"),
|
|
}
|
|
|
|
# Free-text terms -> catalog value. Only what the source documents say
|
|
# differently from the catalog itself; the catalog values and their own
|
|
# aliases are added by whoever builds the FieldSpec.
|
|
CLINICAL_TERMS: dict[str, dict[str, object]] = {
|
|
"cit_vph_resultado": {
|
|
"POSITIVO": "POSITIVO",
|
|
"DETECTADO": "POSITIVO",
|
|
"NEGATIVO": "NEGATIVO",
|
|
"NO DETECTADO": "NEGATIVO",
|
|
"INDETERMINADO": "INDETERMINADO",
|
|
"INVALIDO": "INDETERMINADO",
|
|
"NO CONCLUYENTE": "INDETERMINADO",
|
|
},
|
|
"cit_vph_genotipo_16": {"POSITIVO": 1, "DETECTADO": 1, "PRESENTE": 1, "NEGATIVO": 0, "NO DETECTADO": 0, "AUSENTE": 0},
|
|
"cit_vph_genotipo_18": {"POSITIVO": 1, "DETECTADO": 1, "PRESENTE": 1, "NEGATIVO": 0, "NO DETECTADO": 0, "AUSENTE": 0},
|
|
"cit_celulas_escamosas": {
|
|
"ASCUS": "ASC-US",
|
|
"ASC US": "ASC-US",
|
|
"LSIL": "LIEBG",
|
|
"LIE BAJO GRADO": "LIEBG",
|
|
"LESION INTRAEPITELIAL ESCAMOSA DE BAJO GRADO": "LIEBG",
|
|
"HSIL": "LIEAG",
|
|
"LIE ALTO GRADO": "LIEAG",
|
|
"LESION INTRAEPITELIAL ESCAMOSA DE ALTO GRADO": "LIEAG",
|
|
"NEGATIVO PARA LESION INTRAEPITELIAL": "NORMAL",
|
|
"NEGATIVO PARA LESION INTRAEPITELIAL O MALIGNIDAD": "NORMAL",
|
|
},
|
|
"bx_cin_grado": {
|
|
"NIC I": "LIEBG", "NIC 1": "LIEBG", "CIN I": "LIEBG", "CIN 1": "LIEBG", "DISPLASIA LEVE": "LIEBG",
|
|
"NIC II": "LIEAG", "NIC 2": "LIEAG", "CIN II": "LIEAG", "CIN 2": "LIEAG", "DISPLASIA MODERADA": "LIEAG",
|
|
"NIC III": "LIEAG", "NIC 3": "LIEAG", "CIN III": "LIEAG", "CIN 3": "LIEAG", "DISPLASIA SEVERA": "LIEAG",
|
|
"LESION INTRAEPITELIAL DE BAJO GRADO": "LIEBG", "LESION INTRAEPITELIAL ESCAMOSA DE BAJO GRADO": "LIEBG",
|
|
"LESION INTRAEPITELIAL DE ALTO GRADO": "LIEAG", "LESION INTRAEPITELIAL ESCAMOSA DE ALTO GRADO": "LIEAG",
|
|
"CARCINOMA IN SITU": "CIS",
|
|
"CARCINOMA EPIDERMOIDE INVASOR": "CARCINOMA", "CARCINOMA INVASOR": "CARCINOMA", "CARCINOMA EPIDERMOIDE": "CARCINOMA",
|
|
"ADENOCARCINOMA": "CARCINOMA",
|
|
"CERVICITIS CRONICA": "NORMAL", "SIN ALTERACIONES": "NORMAL", "NEGATIVO PARA DISPLASIA": "NORMAL",
|
|
"NEGATIVO PARA MALIGNIDAD": "NORMAL",
|
|
},
|
|
"bx_grado_histologico": {
|
|
"CARCINOMA DUCTAL INFILTRANTE": "CARCINOMA_INVASOR",
|
|
"CARCINOMA LOBULILLAR INFILTRANTE": "CARCINOMA_INVASOR",
|
|
"CARCINOMA DUCTAL INVASOR": "CARCINOMA_INVASOR",
|
|
"CARCINOMA INVASOR": "CARCINOMA_INVASOR",
|
|
"CARCINOMA INFILTRANTE": "CARCINOMA_INVASOR",
|
|
"CARCINOMA DUCTAL IN SITU": "CARCINOMA_IN_SITU",
|
|
"CARCINOMA LOBULILLAR IN SITU": "CARCINOMA_IN_SITU",
|
|
"CARCINOMA IN SITU": "CARCINOMA_IN_SITU",
|
|
"CDIS": "CARCINOMA_IN_SITU",
|
|
"FIBROADENOMA": "BENIGNO",
|
|
"MASTOPATIA FIBROQUISTICA": "BENIGNO",
|
|
"CAMBIOS FIBROQUISTICOS": "BENIGNO",
|
|
"HIPERPLASIA DUCTAL USUAL": "BENIGNO",
|
|
"BENIGNO": "BENIGNO",
|
|
"NEGATIVO PARA MALIGNIDAD": "BENIGNO",
|
|
},
|
|
"mast_birads": {f"BI-RADS {n}": str(n) for n in ("0", "1", "2", "3", "4", "4A", "4B", "4C", "5", "6")},
|
|
}
|
|
|
|
# Columns worth looking for anywhere in the narrative, not only after a caption.
|
|
FREE_TEXT_FIELDS = frozenset(
|
|
{"cit_vph_resultado", "cit_celulas_escamosas", "bx_cin_grado", "bx_grado_histologico", "mast_birads", "nm_cie_codigo"}
|
|
)
|
|
|
|
# Shape of a valid value.
|
|
PATTERNS: dict[str, str] = {
|
|
"pac_codigo_postal": r"(?<!\d)\d{5}(?!\d)",
|
|
"nm_cie_codigo": r"\b[A-TV-Z][0-9]{2}(?:\.[0-9A-Z]{1,2})?\b",
|
|
}
|
|
|
|
_DOMAIN_PREFIX = re.compile(r"^(pac|ord|cit|bx|mast|nm|bh|eeg|psi|pea|amg|pn)_")
|
|
|
|
|
|
def labels_for(column: str, description: str | None = None) -> tuple[str, ...]:
|
|
"""Known captions, plus the column name itself in words
|
|
(`pac_fecha_nacimiento` -> "fecha nacimiento") and a short
|
|
description when the schema has one."""
|
|
labels = list(LABELS.get(column, ()))
|
|
words = _DOMAIN_PREFIX.sub("", column).replace("_", " ").strip()
|
|
if words and words not in labels and not words.isdigit():
|
|
labels.append(words)
|
|
if description:
|
|
short = description.split("—")[0].split("(")[0].strip()
|
|
if short and len(short.split()) <= 5 and short.lower() not in (label.lower() for label in labels):
|
|
labels.append(short)
|
|
return tuple(labels)
|