Skip to content

Instantly share code, notes, and snippets.

@halcwb
halcwb / CalcNaDeficit.vb
Created July 27, 2023 21:29
Calculates total body water.
Sub Main
Console.WriteLine(CalcNaDeficit("", 5, 0, 25, 110))
Console.WriteLine(CalcNaDeficit("male", 57, 184, 78, 110))
End Sub
' Calculates total body water. Returns -1 if calculation not possible.
' For adults, total body water (TBW) is calculated using the Watson equation:
' Men: TBW, liters = 2.447 – 0.09516 × age, years + 0.1074 × height, cm + 0.3362 × weight, kg
' Women: TBW, liters = -2.097 + 0.1069 × height, cm + 0.2466 × weight, kg
@halcwb
halcwb / CalcTBW.vb
Created July 27, 2023 21:20
Calculates total body water
Sub Main
Console.WriteLine(CalcTBW("", 5, 0, 25))
Console.WriteLine(CalcTBW("male", 57, 184, 78))
End Sub
' Calculates total body water. Returns -1 if calculation not possible.
' For adults, total body water (TBW) is calculated using the Watson equation:
' Men: TBW, liters = 2.447 – 0.09516 × age, years + 0.1074 × height, cm + 0.3362 × weight, kg
' Women: TBW, liters = -2.097 + 0.1069 × height, cm + 0.2466 × weight, kg
@halcwb
halcwb / CalcGlucNaCorrection.vb
Created July 27, 2023 20:57
Calculated glucose corrected serum Na
Sub Main
Console.WriteLine(CalcGlucNaCorrection(140, 5))
End Sub
' Calculated glucose corrected serum Na
' Returns -1 if calculation not possible.
' Measured sodium + 0.024 * (Serum glucose - 100)
Function CalcGlucNaCorrection(dblNa As Double, dblGluc As Double) As Double
Dim dblCor As Double = dblNa
dblGluc = dblGluc * 18
@halcwb
halcwb / CalcExpectedCO2.vb
Created July 27, 2023 20:45
Calculate the expected pCO2 according to bicarbonate using Winter's formula
Sub Main
Console.WriteLine(CalcExpectedCO2(10))
End Sub
' Calculate expected pCO2 according to Winters formula
' Returns a tuple with Item1 = low and Item2 = high
' Expected pCO₂ = 1.5 x HCO3- + 8 ± 2
Function CalcExpectedCO2(dblBic As Double) As System.Tuple(Of Double, Double)
Dim dblLow As Double = -1
Dim dblHigh As Double = -1
@halcwb
halcwb / CalcOsmolality.vb
Created July 27, 2023 20:17
Calculate serum osmolality
Sub Main
Console.WriteLine(CalcOsmolality(150, 3.5, 20, 0))
Console.WriteLine(CalcOsmolality(150, 0, 20, 10))
End Sub
' Calculate osmolality with either K (dblK) or ureu (dblUr)
' Returns -1 if calculation not possible.
' Serum osmolality (mOsm/kg) = (serum Na [mEq/L] + K [mEq/L]) × 2 + Glucose mmol/L
' Calculated Sosm = (2 x Serum [Na]) + [Glucose] + [Urea]
Function CalcOsmolality(dblNa As Double, dblK As Double, dblGluc As Double, dblUr As Double) As Double
@halcwb
halcwb / CalcFEUrea.vb
Created July 27, 2023 10:19
Fractional Excretion of Urea
Sub Main
Console.WriteLine(CalcFEUrea(60, 10, 4000, 200))
End Sub
' Fractional Excretion of Urea (FEUrea) = (SerumCr * UUrea) / (SerumUrea x UCr) %
' Prerenal Intrinsic renal Postrenal
' FEUrea ≤ 35% >50% N/A
Function CalcFEUrea(dblScreat As Double, dblSurea As Double, dbluCreat As Double, dblUurea As Double) As Double
Dim dblFEurea As Double = -1
@halcwb
halcwb / CalcFENa.vb
Created July 27, 2023 10:18
Fractional Excretion of Sodium
Sub Main
Console.WriteLine(CalcFENa(70, 150, 4000, 50))
End Sub
' Fractional Excretion of Sodium (FENa), % = 100 × (SCr × UNa ) / (SNa × UCr)
' FENa is a measure of tubular resorption of Na.
' Pre-Renal Intrinsic Post-Renal
' FENa <1%> 1% >4%
Function CalcFENa (dblScreat As Double, dblSNa As Double, dblUcreat As Double, dblUNa As Double) As Double
@halcwb
halcwb / CalcAnionGap.vb
Created July 27, 2023 10:16
Calculate the anion gap and the delta ratio
Sub Main
Console.WriteLine(CalcAnionGap(140, 120, 20, 0))
Console.WriteLine(CalcAnionGap(140, 120, 20, 20))
End Sub
' Calculate the anion gap and the delta ratio
' Uses albumin correction if available (albumin in gram/L!)
' Returns a Tuple with Item1 = anin gap and Item2 = ratio
'
' Anion gap, mEq/L = sodium, mEq/L - (chloride, mEq/L+ bicarbonate, mEq/L)
@halcwb
halcwb / CalcCorrectedCalcium.vb
Created July 27, 2023 10:15
Calculate corrected calcium.
Sub Main
Console.WriteLine(CalcCorrectedCalcium(50, 2, 0))
End Sub
' Calculate corrected calcium.
' dblAlb and dblNorm in g/L!
' Returns -1 if cannot be calculated
' Corrected Calcium = total [Ca](mmol/L) + 0.02 (40 - [albumin](g/L))
Function CalcCorrectedCalcium(dblAlb As Double, dblCa As Double, dblNorm As Double) As Double
Dim dblCorr As Double = -1
@halcwb
halcwb / CalcFreeWaterDeficit.vb
Created July 27, 2023 10:13
Calculate free water deficit
Sub Main
' Child 0.7 L
Console.WriteLine(CalcFreeWaterDeficit("", 0, 20, 160))
' adult female 60 4.3 L
Console.WriteLine(CalcFreeWaterDeficit("female", 20, 60, 160))
End Sub
'Calulate Free Water Deficit in Hypernatremia