Menu

Implementing Cockcroft-Gault in Code: Units, Weight Choice and Test Cases
📰

Implementing Cockcroft-Gault in Code: Units, Weight Choice and Test Cases

DEV Community: python·EtsyOptima·1 day ago
#Ju330gSc
#devtopython#devto#dev#weight#female
Reading 0:00
15s threshold

The Cockcroft-Gault equation looks like a one-liner, which is exactly why it gets implemented carelessly. The arithmetic is trivial. The bugs live in the inputs: creatinine units, which body weight to use, and missing range checks. Here is how I would build and sanity-check it.

Not medical advice. This is a programming walkthrough. Clinical decisions belong to qualified professionals using current prescribing information and local protocols.

The formula

CrCl (mL/min) = ((140 − age) × weight in kg) / (72 × serum creatinine in mg/dL), multiplied by 0.85 for females.

A minimal implementation

SCR_UMOL_PER_MGDL = 88.4

def ideal_body_weight ( height_cm , female ) : # Devine: 50 kg (men) / 45.5 kg (women) + 2.3 kg per inch over 60 in return ( 45.5 if female else 50.0 ) + 2.3 * ( height_cm / 2.54 - 60 )

def dosing_weight ( actual_kg , height_cm , female ) : ibw = ideal_body_weight ( height_cm , female ) bmi = actual_kg / ( height_cm / 100 ) ** 2 if actual_kg < ibw : return actual_kg , "actual" if bmi >= 30 or…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.