Skip to content

Commit

Permalink
Check if values are not None
Browse files Browse the repository at this point in the history
  • Loading branch information
radioxoma committed Dec 9, 2024
1 parent c0674cf commit e45ccbe
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 25 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks/
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py3-plus]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black/
rev: 23.1.0
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8/
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8

Expand All @@ -35,7 +35,7 @@ repos:
args: [--convention=google, --add-ignore=D10]

- repo: https://github.com/pre-commit/mirrors-mypy/
rev: v1.1.1
rev: v1.13.0
hooks:
- id: mypy

Expand Down
24 changes: 6 additions & 18 deletions heval/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def __init__(self, parent):
self.parent = parent
x = self.parent.winfo_x()
y = self.parent.winfo_y()
self.geometry(f"+{x+50:.0f}+{y+100:.0f}")
self.geometry(f"+{x + 50:.0f}+{y + 100:.0f}")
self.title("Help")

# Mimic Label colors
Expand Down Expand Up @@ -557,7 +557,7 @@ def __init__(self, parent=None):
self.parent = parent
x = self.parent.winfo_x()
y = self.parent.winfo_y()
self.geometry(f"+{x+50:.0f}+{y+100:.0f}")
self.geometry(f"+{x + 50:.0f}+{y + 100:.0f}")
self.title("About v" + __version__)

abouttext = __about__ + " And remember: " + random.choice(__easter_text__)
Expand Down Expand Up @@ -825,9 +825,9 @@ def eval(self, event=None):
self.lbl_fluid_24h["text"] = round(self.human_model.nutrition.fluid_24h)
self.lbl_kcal_24h["text"] = round(self.human_model.nutrition.kcal_24h)
self.lbl_prot_24h["text"] = f"{self.human_model.nutrition.uurea_prot_24h:.1f}"
self.lbl_sbx_prot_g_kg_24h[
"text"
] = f"{self.human_model.nutrition.uures_prot_g_kg_24h:.2f}"
self.lbl_sbx_prot_g_kg_24h["text"] = (
f"{self.human_model.nutrition.uures_prot_g_kg_24h:.2f}"
)
# self.ctl_sbx_prot_g_kg_24h.delete(0, END)
# self.ctl_sbx_prot_g_kg_24h.insert(0, round(self.human_model.nutrition.uures_prot_g_kg_24h, 2)) # g/kg/24h
info = list()
Expand Down Expand Up @@ -1088,19 +1088,7 @@ def set_model_ctHb(self, event=None):

def eval(self, event=None):
self.lbl_hco3["text"] = round(self.human_model.blood.hco3p, 1)
info = ""
info += "Basic ABG assessment\n"
info += "====================\n"
info += "{}\n".format(self.human_model.blood.describe_abg())
info += "{}\n\n\n".format(self.human_model.blood.describe_sbe())
info += "Complex electrolyte assessment\n"
info += "==============================\n"
info += "{}\n\n".format(self.human_model.blood.describe_anion_gap())
info += "{}\n".format(self.human_model.blood.describe_electrolytes())
info += "{}\n\n".format(self.human_model.blood.describe_glucose())
info += "{}\n\n".format(self.human_model.blood.describe_albumin())
info += "{}\n".format(self.human_model.blood.describe_Hb())
self.TxtView.set_text(info)
self.TxtView.set_text(self.human_model.blood.describe_all())


class CalcGFR(ttk.Frame):
Expand Down
79 changes: 78 additions & 1 deletion heval/electrolytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ def describe_osmolarity(self):
dehydration (osmotic diuresis)
cGlu >30, mOsm >320, no acidosis and ketone bodies)
"""
info = ""
if not all(
v is not None
for v in (
self.cNa,
self.cGlu,
)
):
return info

info = "Osmolarity is "
if self.osmolarity > norm_mOsm[1]:
info += "high"
Expand All @@ -180,15 +190,27 @@ def describe_osmolarity(self):
# >330 mOsm/kg hyperosmolar hyperglycemic coma https://www.ncbi.nlm.nih.gov/pubmed/9387687
info += ", coma (>330 mOsm/kg)"

# Implies cNa, pCO2 available
if not all(
v is not None
for v in (
self.pH,
self.pCO2,
)
):
return info

# SBE>-18.4 - same as (pH>7.3 and hco3p>15 mEq/L) https://emedicine.medscape.com/article/1914705-overview
if all((self.osmolarity > 320, self.cGlu > 30, self.sbe > -18.4)):
# https://www.aafp.org/afp/2005/0501/p1723.html
# IV insulin drip and crystalloids
info += " Diabetes mellitus type 2 with hyperosmolar hyperglycemic state? Check for HAGMA and ketonuria to exclude DKA. Look for infection or another underlying illness that caused the hyperglycemic crisis."
return info

def describe_abg(self):
def describe_abg(self) -> str:
"""Describe pH and pCO2 - an old implementation considered stable."""
if not all(v is not None for v in (self.pH, self.pCO2)):
return ""
info = textwrap.dedent(
f"""\
pCO2 {self.pCO2:2.1f} kPa
Expand All @@ -202,6 +224,10 @@ def describe_abg(self):
return info

def describe_anion_gap(self):
if not all(
v is not None for v in (self.pH, self.pCO2, self.cNa, self.cCl, self.ctAlb)
):
return ""
info = "-- Anion gap ---------------------------------------\n"
desc = f"{self.anion_gap:.1f} ({norm_gap[0]:.0f}-{norm_gap[1]:.0f} mEq/L)"
if abg.abg_approach_stable(self.pH, self.pCO2)[1] == "metabolic_acidosis":
Expand Down Expand Up @@ -271,6 +297,8 @@ def describe_sbe(self):
* https://pubmed.ncbi.nlm.nih.gov/29910040/
* https://en.wikipedia.org/wiki/Metabolic_acidosis
"""
if not all(v is not None for v in (self.pH, self.pCO2)):
return ""
NaHCO3_threshold = -15 # was -9 mEq/L
info = ""
if self.sbe > norm_sbe[1]:
Expand Down Expand Up @@ -317,13 +345,25 @@ def describe_sbe(self):
return info

def describe_electrolytes(self):
if not all(
v is not None
for v in (
self.parent.weight,
self.cK,
self.cNa,
self.cCl,
self.cGlu,
)
):
return ""
info = [
"-- Electrolyte and osmolar abnormalities -----------",
self.describe_osmolarity(),
electrolyte_K(self.parent.weight, self.cK),
electrolyte_Na(self.parent.weight, self.cNa, self.cGlu, self.parent.debug),
electrolyte_Cl(self.cCl),
]

return "\n".join(info) + "\n"

def describe_glucose(self):
Expand All @@ -333,6 +373,14 @@ def describe_glucose(self):
https://en.wikipedia.org/wiki/Glycosuria
"""
info = ""
if not all(
v is not None
for v in (
self.parent.weight,
self.cGlu,
)
):
return info
if self.cGlu > norm_cGlu[1]:
if self.cGlu <= norm_cGlu_target[1]:
info += f"cGlu is above ideal {self.cGlu:.1f} (target {norm_cGlu_target[0]:.1f}-{norm_cGlu_target[1]:.1f} mmol/L), but acceptable"
Expand Down Expand Up @@ -362,6 +410,8 @@ def describe_glucose(self):

def describe_albumin(self):
"""Albumin as nutrition marker in adults."""
if self.ctAlb is None:
return ""
ctalb_range = f"{self.ctAlb} ({abg.norm_ctAlb[0]}-{abg.norm_ctAlb[1]} g/dL)"
if abg.norm_ctAlb[1] < self.ctAlb:
info = f"ctAlb is high {ctalb_range}. Dehydration?"
Expand All @@ -383,6 +433,16 @@ def describe_Hb(self):
[1] https://en.wikipedia.org/wiki/Hematocrit#cite_ref-3
[2] https://www.healthcare.uiowa.edu/path_handbook/appendix/heme/pediatric_normals.html
"""
info = ""
if not all(
v is not None
for v in (
self.parent.weight,
self.parent.sex,
self.ctHb,
)
):
return info
# Top hct value for free water deficit calculation.
if self.parent.sex == human.HumanSex.male:
hb_norm = hb_norm_male
Expand Down Expand Up @@ -418,6 +478,23 @@ def describe_Hb(self):
info += " \nNote that normal Hb and Hct values in children greatly dependent from age."
return info

def describe_all(self) -> str:
info = ""
info += "Basic ABG assessment\n"
info += "====================\n"
info += "{}\n".format(self.describe_abg())
info += "{}\n\n\n".format(self.describe_sbe())

info += "Complex electrolyte assessment\n"
info += "==============================\n"
info += "{}\n\n".format(self.describe_anion_gap())
info += "{}\n".format(self.describe_electrolytes())

info += "{}\n\n".format(self.describe_glucose())
info += "{}\n\n".format(self.describe_albumin())
info += "{}\n".format(self.describe_Hb())
return info


def solution_glucose(
glu_mass: float, body_weight: float, add_insuline: bool = True
Expand Down

0 comments on commit e45ccbe

Please sign in to comment.