How to calculate insulin dose
how to calculate insulin dose basal bolus weight-based formula
"insulin dosing" AND algorithm
Create a quick reference PDF with insulin dosing formulas and calculations
mkdir -p /tmp/workspace/insulin-dosing-reference && ls -la /tmp/workspace/
~/insulin-dosing-reference/build_pdf.py
#!/usr/bin/env python3
"""Build an Insulin Dosing Quick Reference PDF."""
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from reportlab.lib import colors
from reportlab.platypus import (
SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
ListFlowable, ListItem, HRFlowable, PageBreak
)
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_LEFT
styles = getSampleStyleSheet()
title_style = ParagraphStyle(
"TitleStyle", parent=styles["Title"], fontSize=18, textColor=colors.HexColor("#1a3a5c"),
spaceAfter=2, alignment=TA_CENTER
)
subtitle_style = ParagraphStyle(
"SubtitleStyle", parent=styles["Normal"], fontSize=9.5, textColor=colors.HexColor("#555555"),
alignment=TA_CENTER, spaceAfter=12
)
h1_style = ParagraphStyle(
"H1", parent=styles["Heading1"], fontSize=13, textColor=colors.white,
backColor=colors.HexColor("#1a3a5c"), spaceBefore=10, spaceAfter=8,
leftIndent=6, borderPadding=(4, 4, 4, 4)
)
h2_style = ParagraphStyle(
"H2", parent=styles["Heading2"], fontSize=11, textColor=colors.HexColor("#1a3a5c"),
spaceBefore=8, spaceAfter=4
)
body_style = ParagraphStyle(
"Body", parent=styles["Normal"], fontSize=9.5, leading=13, spaceAfter=4
)
formula_style = ParagraphStyle(
"Formula", parent=styles["Normal"], fontSize=10.5, leading=14, spaceAfter=4,
textColor=colors.HexColor("#7a1f1f"), fontName="Helvetica-Bold",
backColor=colors.HexColor("#f7f0f0"), borderPadding=(6, 6, 6, 6),
leftIndent=4, rightIndent=4
)
example_style = ParagraphStyle(
"Example", parent=styles["Normal"], fontSize=9, leading=12.5, spaceAfter=4,
textColor=colors.HexColor("#2d5a2d"), fontName="Helvetica-Oblique",
leftIndent=8
)
caution_style = ParagraphStyle(
"Caution", parent=styles["Normal"], fontSize=8.8, leading=12, spaceAfter=4,
textColor=colors.HexColor("#7a1f1f")
)
source_style = ParagraphStyle(
"Source", parent=styles["Normal"], fontSize=7.3, leading=9.5, textColor=colors.HexColor("#888888")
)
footer_style = ParagraphStyle(
"Footer", parent=styles["Normal"], fontSize=7.5, textColor=colors.HexColor("#999999"),
alignment=TA_CENTER
)
def table_default_style(header_bg="#1a3a5c"):
return TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.HexColor(header_bg)),
("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
("FONTSIZE", (0, 0), (-1, -1), 8.7),
("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.white, colors.HexColor("#f2f2f2")]),
("GRID", (0, 0), (-1, -1), 0.5, colors.HexColor("#cccccc")),
("VALIGN", (0, 0), (-1, -1), "TOP"),
("LEFTPADDING", (0, 0), (-1, -1), 5),
("RIGHTPADDING", (0, 0), (-1, -1), 5),
("TOPPADDING", (0, 0), (-1, -1), 4),
("BOTTOMPADDING", (0, 0), (-1, -1), 4),
])
story = []
# ---- Title ----
story.append(Paragraph("Insulin Dosing Quick Reference", title_style))
story.append(Paragraph(
"Formulas & worked calculations for basal-bolus insulin dosing • Adult, non-critical-care setting",
subtitle_style
))
story.append(HRFlowable(width="100%", thickness=1, color=colors.HexColor("#1a3a5c")))
story.append(Spacer(1, 8))
# ---- Caution box up top ----
story.append(Paragraph(
"⚠ These are standard teaching formulas for STARTING doses only. Always individualize based on "
"renal/hepatic function, age, hypoglycemia history, and clinical judgment. Titrate using home glucose "
"monitoring / CGM data, not a single reading.",
caution_style
))
story.append(Spacer(1, 6))
# ---- Section 1: TDD ----
story.append(Paragraph("1. Total Daily Dose (TDD)", h1_style))
story.append(Paragraph(
"TDD is the foundation for all subsequent calculations. It is weight-based and depends on diabetes type "
"and insulin sensitivity.", body_style
))
tdd_data = [
["Population / Context", "Typical TDD (units/kg/day)"],
["Type 1 DM (metabolically stable, starting dose)", "0.4 - 1.0 (commonly ~0.5)"],
["Type 1 DM - simple estimate", "Weight (kg) x 0.5 - 0.7"],
["Type 2 DM, insulin-naive (starting basal only)", "0.1 - 0.2 (or flat 10 units/day)"],
["Insulin-resistant (obesity, steroids, infection, T2DM advanced)", "up to 1.0 - 1.5+"],
["Insulin-sensitive (renal impairment, elderly, lean)", "0.3 - 0.5 (use lower end)"],
]
t = Table(tdd_data, colWidths=[3.5*inch, 2.6*inch])
t.setStyle(table_default_style())
story.append(t)
story.append(Spacer(1, 6))
story.append(Paragraph("TDD = Weight (kg) × units/kg/day (from table above)", formula_style))
story.append(Paragraph(
"Example: 70 kg patient, T1DM → 70 kg × 0.5-0.7 units/kg ≈ <b>35-49 units/day</b>",
example_style
))
story.append(Paragraph(
"Source: Textbook of Family Medicine 9e, p.989; Tintinalli's Emergency Medicine; Goldman-Cecil Medicine; "
"Washington Manual of Medical Therapeutics", source_style
))
# ---- Section 2: Basal / Bolus split ----
story.append(Paragraph("2. Basal / Bolus Split", h1_style))
story.append(Paragraph(
"Once TDD is known, split it roughly evenly between basal (background) and bolus (prandial/meal) insulin.",
body_style
))
split_data = [
["Component", "% of TDD", "Notes"],
["Basal (glargine, detemir, degludec, or pump basal rate)", "40 - 50%", "Given once daily (or pump-continuous); controls fasting/overnight glucose"],
["Bolus / Prandial (rapid-acting: lispro, aspart, glulisine)", "50 - 60%", "Divided across meals, proportional to carb content"],
]
t2 = Table(split_data, colWidths=[3.0*inch, 1.0*inch, 2.1*inch])
t2.setStyle(table_default_style())
story.append(t2)
story.append(Spacer(1, 6))
story.append(Paragraph("Basal dose = 50% × TDD | Bolus dose (total/day) = 50% × TDD", formula_style))
story.append(Paragraph(
"Example: TDD = 40 units → Basal = 20 units (once daily) + Bolus = 20 units total, split "
"≈ 6-7 units per meal across 3 meals",
example_style
))
story.append(Paragraph(
"Some patients need a 40/60 split favoring bolus. Titrate basal by ~1-2 units (or 10-20%) every "
"few days based on fasting glucose trend until fasting BG <100-130 mg/dL.", body_style
))
story.append(Paragraph(
"Source: Fuster & Hurst's The Heart, 15th ed.; Goodman & Gilman's Pharmacological Basis of "
"Therapeutics; Textbook of Family Medicine 9e, p.989-990", source_style
))
story.append(PageBreak())
# ---- Section 3: Insulin-to-Carb Ratio ----
story.append(Paragraph("3. Meal (Bolus) Dose: Insulin-to-Carb Ratio (ICR)", h1_style))
story.append(Paragraph(
"ICR = grams of carbohydrate covered by 1 unit of rapid-acting insulin. Estimate a starting ratio "
"with the <b>500 Rule</b>, then adjust from actual postprandial responses.", body_style
))
story.append(Paragraph("ICR (starting estimate) = 500 ÷ TDD", formula_style))
story.append(Paragraph(
"Example: TDD = 50 units → 500 ÷ 50 = ICR of 1:10 (1 unit covers 10 g carbohydrate)",
example_style
))
story.append(Paragraph(
"Typical adult range: 1 unit per 10-15 g carbohydrate (Harrison's Principles of Internal Medicine, "
"22nd ed., p.1090).", body_style
))
story.append(Paragraph("Meal bolus dose = Grams of carbohydrate in meal ÷ ICR", formula_style))
story.append(Paragraph(
"Example: ICR = 1:10, meal has 60 g carbs → 60 ÷ 10 = <b>6 units</b> before the meal",
example_style
))
# ---- Section 4: Correction Factor ----
story.append(Paragraph("4. Correction (Sliding-Scale) Dose: Correction Factor (CF)", h1_style))
story.append(Paragraph(
"CF (a.k.a. insulin sensitivity factor) = mg/dL drop in blood glucose per 1 unit of rapid-acting insulin.",
body_style
))
story.append(Paragraph("CF (starting estimate) = 1800 ÷ TDD (rapid-acting) | 1500 ÷ TDD (regular insulin)", formula_style))
story.append(Paragraph(
"Example: TDD = 50 units, rapid-acting → 1800 ÷ 50 = CF of 36 (1 unit lowers glucose ≈36 mg/dL)",
example_style
))
story.append(Paragraph("Correction dose = (Current BG − Target BG) ÷ CF", formula_style))
story.append(Paragraph(
"Example: Current BG = 250 mg/dL, target = 130 mg/dL, CF = 36 → (250−130) ÷ 36 "
"= 120 ÷ 36 ≈ <b>3.3 → 3 units</b>",
example_style
))
story.append(Paragraph(
"Total mealtime dose = Carb-coverage dose + Correction dose (only add correction if BG is above target). "
"Do not stack corrections - account for insulin already on board before correcting again.", body_style
))
story.append(Paragraph(
"Source: Endocrine & Diabetes Plus Clinic patient education materials; Harriet Lane Handbook, "
"23rd ed.; standard ADA patient-education formulas (500/1800/1500 rules)", source_style
))
# ---- Section 5: Worked full example ----
story.append(Paragraph("5. Full Worked Example", h1_style))
example_data = [
["Step", "Calculation", "Result"],
["Patient", "70 kg adult, T1DM", "-"],
["1. TDD", "70 kg x 0.6 units/kg", "42 units/day"],
["2. Basal (50%)", "42 x 0.5", "21 units (once daily)"],
["2. Bolus total (50%)", "42 x 0.5", "21 units/day (~7/meal)"],
["3. ICR", "500 / 42", "1:12 (1 unit per 12 g carb)"],
["3. Meal dose (60 g carb lunch)", "60 / 12", "5 units"],
["4. CF", "1800 / 42", "43 mg/dL per unit"],
["4. Correction (BG 220, target 120)", "(220-120) / 43", "2.3 -> 2 units"],
["Total lunch dose", "5 units (carb) + 2 units (correction)", "7 units"],
]
t3 = Table(example_data, colWidths=[2.0*inch, 2.6*inch, 1.5*inch])
t3.setStyle(table_default_style("#2d5a2d"))
story.append(t3)
story.append(Spacer(1, 8))
# ---- Section 6: Special populations ----
story.append(Paragraph("6. Special Situations", h1_style))
special_items = [
"<b>Pregnancy:</b> insulin needs rise progressively; bolus insulin may reach ~75% of TDD by late 3rd trimester (vs ~50% pre-pregnancy). - Creasy & Resnik's Maternal-Fetal Medicine",
"<b>Pediatrics:</b> same 3 components (basal rate, ICR, correction factor) but doses scaled to body size and titrated more often. - Harriet Lane Handbook, 23rd ed.",
"<b>Perioperative/Inpatient:</b> verify ICR, CF, basal regimen, and glucose targets preoperatively; often reduce bolus doses for fasting patients. - Barash's Clinical Anesthesia, 9th ed.",
"<b>DKA / IV insulin:</b> uses separate weight-based infusion protocols (typically 0.1 unit/kg/hr) - NOT the subcutaneous TDD method on this sheet.",
"<b>Renal/hepatic impairment or elderly:</b> use lower end of TDD range (0.3-0.5 units/kg/day) to reduce hypoglycemia risk.",
]
story.append(ListFlowable(
[ListItem(Paragraph(item, body_style), bulletColor=colors.HexColor("#1a3a5c")) for item in special_items],
bulletType="bullet", start="circle", leftIndent=14
))
story.append(Spacer(1, 10))
story.append(HRFlowable(width="100%", thickness=0.75, color=colors.HexColor("#cccccc")))
story.append(Spacer(1, 4))
story.append(Paragraph(
"For educational/clinical reference use only. Not a substitute for individualized medical judgment. "
"Compiled from: Harrison's Principles of Internal Medicine 22e; Goldman-Cecil Medicine; Tintinalli's "
"Emergency Medicine; Textbook of Family Medicine 9e; Washington Manual of Medical Therapeutics; "
"Fuster & Hurst's The Heart 15e; Goodman & Gilman's Pharmacological Basis of Therapeutics; "
"Harriet Lane Handbook 23e; Creasy & Resnik's Maternal-Fetal Medicine; Barash's Clinical Anesthesia 9e.",
footer_style
))
doc = SimpleDocTemplate(
"/tmp/workspace/insulin-dosing-reference/Insulin_Dosing_Quick_Reference.pdf",
pagesize=letter,
topMargin=0.55*inch, bottomMargin=0.55*inch,
leftMargin=0.6*inch, rightMargin=0.6*inch,
title="Insulin Dosing Quick Reference"
)
doc.build(story)
print("PDF created successfully.")
cd /tmp/workspace/insulin-dosing-reference && python3 build_pdf.py
cd /tmp/workspace/insulin-dosing-reference && ls -la && python3 -c " from pypdf import PdfReader r = PdfReader('Insulin_Dosing_Quick_Reference.pdf') print('Pages:', len(r.pages)) "
Insulin Dosing Quick Reference
PDF Document · PDF