I have never understood which anti-diabetics to give when means-whats the use of FBS vs PPBS vs RBS for drig management-OHA vs Insulin,I know driga but dont know when IPD vs OPD,before or after food.
| Test | What It Measures | Normal | Prediabetes | Diabetes |
|---|---|---|---|---|
| FBS (Fasting Blood Sugar, ≥8h fast) | Basal hepatic glucose output overnight | <100 mg/dL | 100-125 | ≥126 mg/dL |
| PPBS (2h post-meal) | Meal-related glucose spike | <140 mg/dL | 140-199 | ≥200 mg/dL |
| RBS (Random, any time) | Snapshot - useful only in symptomatic patients | - | - | ≥200 + symptoms = diagnosis |
| HbA1c | Average glucose over 8-12 weeks | <5.7% | 5.7-6.4% | ≥6.5% |
| Situation | Setting | Drug of Choice | Why |
|---|---|---|---|
| Stable T2DM, eating well | OPD | OHAs (metformin first-line ± add-ons) | Safe, oral, manageable |
| Newly diagnosed T2DM, HbA1c <10% | OPD | Metformin ± one other agent | Guideline-recommended start |
| Newly diagnosed T2DM, HbA1c >10% or FBS >300 | OPD or IPD | Start insulin, may de-escalate later | Need rapid control |
| Any DM patient admitted to hospital | IPD | Insulin only | OHAs are unsafe inpatient |
| ICU / post-op / NPO | IPD | IV regular insulin infusion | Precise titration needed |
| DKA / HHS | IPD emergency | IV regular insulin | Life-saving |
| Pregnancy | Any | Insulin (metformin sometimes used as adjunct) | Fetal safety |
| Insulin Type | Examples | Onset | Peak | Duration | When to Give |
|---|---|---|---|---|---|
| Rapid-acting | Aspart, Lispro, Glulisine | <15 min | 0.5-1.5h | 3-5h | Immediately BEFORE or WITH meals (bolus) |
| Short-acting | Regular (Actrapid) | 30-60 min | 2-3h | 4-8h | 30 min BEFORE meals |
| Intermediate | NPH | 2-4h | 4-10h | 10-16h | Twice daily (morning + bedtime) |
| Long-acting | Glargine, Detemir | 0.5-4h | No peak | 20-24h | Once daily at bedtime or fixed time (controls FBS) |
| Ultra-long | Degludec | 30-90 min | No peak | >42h | Once daily any time (consistent daily) |
New T2DM patient diagnosed in OPD
|
Is FBS >300 or HbA1c >10-12% or symptomatic (weight loss, polyuria)?
| |
YES NO
| |
Start Insulin Start Metformin (500mg OD with food,
(can de-escalate to titrate up to 2000mg/day)
OHA once controlled) |
Add 2nd agent if HbA1c not at target in 3 months:
- High PPBS? → Add glinide or AGI or DPP4i
- CVD/HF? → Add SGLT2i or GLP-1 RA
- Obese? → GLP-1 RA or SGLT2i
- Lean, young? → Sulfonylurea
|
Still not at target on 2-3 OHAs?
|
→ Start Basal Insulin (Glargine at bedtime)
Keep metformin, stop sulfonylurea
|
Still high PPBS despite basal insulin?
|
→ Add prandial (meal-time) rapid-acting insulin
| Drug | When to Give |
|---|---|
| Metformin | With or just after food (reduces nausea) |
| Glipizide, Glyburide | 30 min before meals |
| Glimepiride | With first meal of the day |
| Repaglinide/Nateglinide | Within 15 min before each meal; skip if skipping meal |
| Acarbose/Voglibose | With first bite of food |
| DPP-4i (sitagliptin etc.) | Any time, with or without food |
| SGLT2i | Morning, with or without food |
| GLP-1 RA (oral semaglutide) | 30 min before first meal, empty stomach |
| Rapid-acting insulin (Aspart, Lispro) | Immediately before or with meals |
| Regular insulin | 30 min before meals |
| Basal insulin (Glargine/Degludec) | Fixed time daily (bedtime preferred to control morning FBS) |
Create a pocket reference PDF with this drug selection flowchart
ls /home/daytona/workspace/ 2>/dev/null && echo "---" && python3 -c "import reportlab; print('reportlab ok')" && python3 -c "from reportlab.lib.pagesizes import A5; print('A5 ok')"
~/antidiabetic-pocket-ref/make_pdf.py
#!/usr/bin/env python3
"""Pocket Reference PDF – Anti-Diabetic Drug Selection
A5 landscape, 4 pages: cover, glucose targets/tests, OHA guide, insulin guide + flowchart
"""
from reportlab.lib.pagesizes import A5, landscape
from reportlab.lib import colors
from reportlab.lib.units import mm
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import (
SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
HRFlowable, KeepTogether
)
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_RIGHT
from reportlab.platypus.flowables import Flowable
from reportlab.pdfgen import canvas
import os
OUTPUT = "/home/daytona/workspace/antidiabetic-pocket-ref/Antidiabetic_Pocket_Reference.pdf"
W, H = landscape(A5) # 210 x 148 mm landscape => ~595 x 420 pt
# ── Colour palette ────────────────────────────────────────────────────────────
NAVY = colors.HexColor("#1a3a5c")
TEAL = colors.HexColor("#0a7e8c")
AMBER = colors.HexColor("#e07b00")
GREEN = colors.HexColor("#2e7d32")
RED = colors.HexColor("#c62828")
PURPLE = colors.HexColor("#6a1b9a")
LTBLUE = colors.HexColor("#e8f4f8")
LTGREEN = colors.HexColor("#e8f5e9")
LTAMBER = colors.HexColor("#fff8e1")
LTRED = colors.HexColor("#ffebee")
LTPURP = colors.HexColor("#f3e5f5")
WHITE = colors.white
LGREY = colors.HexColor("#f5f5f5")
DGREY = colors.HexColor("#424242")
MID = colors.HexColor("#78909c")
# ── Styles ────────────────────────────────────────────────────────────────────
def S(name, **kw):
return ParagraphStyle(name, **kw)
cover_title = S("ct", fontName="Helvetica-Bold", fontSize=22, textColor=WHITE, alignment=TA_CENTER, leading=28)
cover_sub = S("cs", fontName="Helvetica", fontSize=11, textColor=LTBLUE, alignment=TA_CENTER, leading=16)
cover_src = S("cr", fontName="Helvetica-Oblique", fontSize=7, textColor=MID, alignment=TA_CENTER)
section_hdr = S("sh", fontName="Helvetica-Bold", fontSize=9, textColor=WHITE, alignment=TA_LEFT, leading=12)
col_hdr = S("ch", fontName="Helvetica-Bold", fontSize=7.5,textColor=WHITE, alignment=TA_CENTER, leading=10)
body = S("bd", fontName="Helvetica", fontSize=7, textColor=DGREY, leading=10)
body_b = S("bdb", fontName="Helvetica-Bold", fontSize=7, textColor=DGREY, leading=10)
body_c = S("bdc", fontName="Helvetica", fontSize=7, textColor=DGREY, alignment=TA_CENTER, leading=10)
small = S("sm", fontName="Helvetica", fontSize=6, textColor=MID, leading=8)
small_b = S("smb", fontName="Helvetica-Bold", fontSize=6, textColor=DGREY, leading=8)
footnote = S("fn", fontName="Helvetica-Oblique", fontSize=5.5,textColor=MID, leading=7)
red_b = S("rb", fontName="Helvetica-Bold", fontSize=7, textColor=RED, leading=10)
green_b = S("gb", fontName="Helvetica-Bold", fontSize=7, textColor=GREEN, leading=10)
navy_b = S("nb", fontName="Helvetica-Bold", fontSize=7, textColor=NAVY, leading=10)
teal_b = S("tb", fontName="Helvetica-Bold", fontSize=7.5,textColor=TEAL, leading=10)
# ── Helper flowables ──────────────────────────────────────────────────────────
def SBanner(text, bg=NAVY, fg=WHITE, size=9):
data = [[Paragraph(text, S("bh", fontName="Helvetica-Bold", fontSize=size,
textColor=fg, leading=size+3))]]
t = Table(data, colWidths=[W - 24*mm])
t.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), bg),
("TOPPADDING", (0,0), (-1,-1), 4),
("BOTTOMPADDING",(0,0),(-1,-1), 4),
("LEFTPADDING", (0,0), (-1,-1), 6),
("RIGHTPADDING",(0,0), (-1,-1), 6),
]))
return t
def HR(col=TEAL):
return HRFlowable(width="100%", thickness=1, color=col, spaceAfter=3, spaceBefore=3)
def sp(h=4):
return Spacer(1, h)
def p(txt, style=body):
return Paragraph(txt, style)
# ── Page-number canvas ────────────────────────────────────────────────────────
class NumberedCanvas(canvas.Canvas):
def __init__(self, *a, **kw):
super().__init__(*a, **kw)
self._pages = []
def showPage(self):
self._pages.append(dict(self.__dict__))
self._startPage()
def save(self):
total = len(self._pages)
for i, page in enumerate(self._pages, 1):
self.__dict__.update(page)
self._draw_footer(i, total)
super().showPage()
super().save()
def _draw_footer(self, n, total):
self.saveState()
self.setFillColor(MID)
self.setFont("Helvetica", 6)
self.drawRightString(W - 10*mm, 5*mm, f"Page {n} / {total}")
self.drawString(10*mm, 5*mm, "Anti-Diabetic Pocket Reference | Harrison's 22e • Katzung 16e")
self.restoreState()
# ══════════════════════════════════════════════════════════════════════════════
# PAGE 1 – COVER
# ══════════════════════════════════════════════════════════════════════════════
def page_cover():
els = []
# Full-bleed banner via a table
banner_data = [[
Paragraph("💊 Anti-Diabetic Drug Selection", cover_title),
""
]]
banner = Table(banner_data, colWidths=[W - 24*mm, 0])
banner.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), NAVY),
("TOPPADDING", (0,0), (-1,-1), 18),
("BOTTOMPADDING",(0,0),(-1,-1), 18),
("LEFTPADDING", (0,0), (-1,-1), 12),
]))
els.append(banner)
els.append(sp(6))
els.append(p("Pocket Clinical Reference · OPD / IPD · OHA vs Insulin · Before / After Food", cover_sub))
els.append(sp(10))
# 3-column highlight cards
cards = [
(LTBLUE, TEAL, "DIAGNOSE", [
"FBS ≥ 126 mg/dL",
"2h PPBS ≥ 200 mg/dL",
"RBS ≥ 200 + symptoms",
"HbA1c ≥ 6.5%",
]),
(LTGREEN, GREEN, "CHOOSE DRUG", [
"FBS↑ → Basal control",
"PPBS↑ → Meal control",
"OPD stable → OHA",
"IPD / DKA → Insulin",
]),
(LTAMBER, AMBER, "TIMING", [
"Metformin: with food",
"Glipizide: 30 min before",
"Glinides: just before meal",
"Acarbose: with first bite",
]),
]
card_rows = []
for bg, hc, title, bullets in cards:
inner = [
Paragraph(title, S("ct2", fontName="Helvetica-Bold", fontSize=9,
textColor=hc, leading=12)),
] + [Paragraph(f"• {b}", body) for b in bullets]
cell_data = [[item] for item in inner]
cell_tbl = Table(cell_data, colWidths=[52*mm])
cell_tbl.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), bg),
("TOPPADDING", (0,0), (-1,-1), 3),
("BOTTOMPADDING",(0,0),(-1,-1), 3),
("LEFTPADDING", (0,0), (-1,-1), 5),
("RIGHTPADDING",(0,0), (-1,-1), 5),
("BOX", (0,0), (-1,-1), 1, hc),
]))
card_rows.append(cell_tbl)
card_table = Table([card_rows], colWidths=[54*mm, 54*mm, 54*mm], hAlign="CENTER")
card_table.setStyle(TableStyle([
("VALIGN", (0,0), (-1,-1), "TOP"),
("LEFTPADDING",(0,0),(-1,-1), 4),
("RIGHTPADDING",(0,0),(-1,-1), 4),
]))
els.append(card_table)
els.append(sp(8))
els.append(p("Sources: Harrison's Principles of Internal Medicine 22e · Katzung's Basic & Clinical Pharmacology 16e · ADA Standards of Care", footnote))
return els
# ══════════════════════════════════════════════════════════════════════════════
# PAGE 2 – GLUCOSE TESTS + DIAGNOSIS
# ══════════════════════════════════════════════════════════════════════════════
def page_glucose():
els = []
els.append(SBanner("📊 GLUCOSE TESTS — What Each One Tells You & What Drug It Points To", TEAL))
els.append(sp(5))
# Main diagnostic table
hdr = [
Paragraph("TEST", col_hdr),
Paragraph("CONDITION", col_hdr),
Paragraph("NORMAL", col_hdr),
Paragraph("PRE-DM", col_hdr),
Paragraph("DIABETES", col_hdr),
Paragraph("WHAT IT TELLS YOU", col_hdr),
Paragraph("DRUG TARGET", col_hdr),
]
rows = [
hdr,
[
p("FBS\n(≥8h fast)", body_b),
p("Basal hepatic\nglucose output", body),
p("< 100", body_c),
p("100–125\n(IFG)", body_c),
p("≥ 126 mg/dL", body_c),
p("Overnight glucose control;\nreflects liver output", body),
p("Metformin, Glargine,\nGlimepiride, SGLT2i", body),
],
[
p("PPBS\n(2h post-meal)", body_b),
p("Meal-related\nglucose spike", body),
p("< 140", body_c),
p("140–199\n(IGT)", body_c),
p("≥ 200 mg/dL", body_c),
p("Meal spike; reflects\nbeta-cell response", body),
p("Glinides, Acarbose,\nRapid insulin, GLP-1RA", body),
],
[
p("RBS\n(random)", body_b),
p("Snapshot any time", body),
p("—", body_c),
p("—", body_c),
p("≥ 200 + symptoms\n= diagnosis", body_c),
p("Acute hyperglycaemia;\nno additional test needed", body),
p("Start treatment immediately;\nusually needs insulin", body),
],
[
p("HbA1c", body_b),
p("Avg glucose\nlast 8–12 weeks", body),
p("< 5.7%", body_c),
p("5.7–6.4%", body_c),
p("≥ 6.5%", body_c),
p("Long-term control;\nguides therapy intensity", body),
p("OHA if < 10%;\nInsulin if ≥ 10–12%", body),
],
]
cws = [20*mm, 26*mm, 16*mm, 16*mm, 22*mm, 44*mm, 42*mm]
tbl = Table(rows, colWidths=cws, repeatRows=1)
tbl.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,0), TEAL),
("BACKGROUND", (0,1), (-1,1), LTBLUE),
("BACKGROUND", (0,2), (-1,2), LTGREEN),
("BACKGROUND", (0,3), (-1,3), LTRED),
("BACKGROUND", (0,4), (-1,4), LTAMBER),
("GRID", (0,0), (-1,-1), 0.4, colors.HexColor("#b0bec5")),
("VALIGN", (0,0), (-1,-1), "MIDDLE"),
("TOPPADDING", (0,0), (-1,-1), 4),
("BOTTOMPADDING", (0,0), (-1,-1), 4),
("LEFTPADDING", (0,0), (-1,-1), 4),
("RIGHTPADDING", (0,0), (-1,-1), 4),
("FONTNAME", (0,0), (-1,0), "Helvetica-Bold"),
]))
els.append(tbl)
els.append(sp(6))
els.append(HR(TEAL))
# Rule box
rule_data = [
[Paragraph("FBS HIGH → Fix basal glucose → Metformin / Basal Insulin / Glimepiride", green_b),
Paragraph("PPBS HIGH → Fix meal spike → Glinide / Acarbose / Rapid Insulin / GLP-1RA", teal_b)],
[Paragraph("BOTH HIGH → Combination OHA or Basal + Prandial Insulin", navy_b),
Paragraph("RBS ≥ 200 + symptoms → Start insulin; diagnose without further tests", red_b)],
]
rule_tbl = Table(rule_data, colWidths=[84*mm, 84*mm])
rule_tbl.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), LGREY),
("BOX", (0,0), (-1,-1), 1, TEAL),
("LINEAFTER", (0,0), (0,-1), 0.5, MID),
("TOPPADDING", (0,0), (-1,-1), 4),
("BOTTOMPADDING",(0,0),(-1,-1), 4),
("LEFTPADDING",(0,0), (-1,-1), 6),
("VALIGN", (0,0), (-1,-1), "MIDDLE"),
]))
els.append(rule_tbl)
return els
# ══════════════════════════════════════════════════════════════════════════════
# PAGE 3 – OHA GUIDE
# ══════════════════════════════════════════════════════════════════════════════
def page_oha():
els = []
els.append(SBanner("💊 ORAL HYPOGLYCAEMIC AGENTS — Drug · Target · Timing · Cautions", GREEN))
els.append(sp(4))
hdr = [
Paragraph("DRUG / CLASS", col_hdr),
Paragraph("GLUCOSE\nTARGET", col_hdr),
Paragraph("WHEN TO GIVE", col_hdr),
Paragraph("BEST FOR", col_hdr),
Paragraph("STOP WHEN / CAUTIONS", col_hdr),
]
oha_data = [
# (drug, target, timing, best-for, cautions, row-bg)
("Metformin\n(Biguanide)", "FBS ↓\nHepatic output", "WITH or just AFTER food\n(reduces GI side-effects)",
"1st-line T2DM\nObese patients", LTGREEN,
"Hospitalized (IPD)\nNPO / contrast dye\nGFR < 30\nLactic acidosis risk"),
("Glipizide / Glimepiride\n(Sulfonylurea)", "FBS + PPBS ↓\nInsulin secretagogue", "30 min BEFORE meal\n(glipizide); with 1st meal (glimepiride)",
"Lean T2DM\nDisease < 5 years", LTBLUE,
"Hypoglycaemia risk\nRenal / hepatic failure\nStop with fluoroquinolones\nWeight gain"),
("Repaglinide / Nateglinide\n(Glinides)", "PPBS ↓\nShort burst insulin", "Within 15 min BEFORE each meal\nSkip if skipping meal",
"High PPBS, normal FBS\nIrregular meals", LTAMBER,
"Hypoglycaemia if meal skipped\nRenal caution (repaglinide safer)\nExpensive"),
("Acarbose / Voglibose\n(Alpha-glucosidase inhibitor)", "PPBS ↓\nSlows carb absorption", "WITH first bite of food\n(must be with meal)",
"Post-meal spikes\nAsian diet (rice/roti)", LTPURP,
"Flatulence / diarrhoea\nIf hypoglycaemia occurs: give glucose (not sucrose)\nHepatic disease"),
("Sitagliptin / Vildagliptin\n(DPP-4 inhibitor)", "PPBS ↓\nGlucose-dep. insulin", "ANY time, with or without food",
"Elderly patients\nCKD (dose adjust)\nLow hypo risk", LTBLUE,
"Pancreatitis rare\nDose-reduce in CKD\nNasopharyngitis"),
("Empagliflozin / Dapagliflozin\n(SGLT2 inhibitor)", "FBS + PPBS ↓\nUrinary glucose excretion", "MORNING, with or without food\n(avoid nocturia)",
"T2DM + Heart Failure\nT2DM + CKD\nObese T2DM", LTGREEN,
"UTI / genital infections\nDKA risk (euglycaemic)\nGFR < 30–45 (class-dep.)\nStop before surgery"),
("Semaglutide / Liraglutide\n(GLP-1 receptor agonist)", "FBS + PPBS ↓\nWeight loss + CV protection", "SC injection: weekly (semaglutide) or daily (liraglutide)\nOral: 30 min before 1st meal, empty stomach",
"T2DM + obesity\nT2DM + ASCVD\nWeight loss needed", LTAMBER,
"Nausea / vomiting\nPancreatitis (rare)\nNot for T1DM alone\nSC injection site reactions"),
]
rows = [hdr]
for drug, target, timing, best, bg, cautions in oha_data:
rows.append([
p(drug, body_b),
p(target, body),
p(timing, body),
p(best, body),
p(cautions, small),
])
cws = [36*mm, 28*mm, 38*mm, 34*mm, 46*mm]
tbl = Table(rows, colWidths=cws, repeatRows=1)
style = [
("BACKGROUND", (0,0), (-1,0), GREEN),
("GRID", (0,0), (-1,-1), 0.4, colors.HexColor("#c8e6c9")),
("VALIGN", (0,0), (-1,-1), "TOP"),
("TOPPADDING", (0,0), (-1,-1), 4),
("BOTTOMPADDING",(0,0),(-1,-1), 4),
("LEFTPADDING",(0,0), (-1,-1), 4),
("RIGHTPADDING",(0,0),(-1,-1), 4),
]
bg_colors = [LTGREEN, LTBLUE, LTAMBER, LTPURP, LTBLUE, LTGREEN, LTAMBER]
for i, bg in enumerate(bg_colors, 1):
style.append(("BACKGROUND", (0,i), (-1,i), bg))
tbl.setStyle(TableStyle(style))
els.append(tbl)
els.append(sp(5))
els.append(p("* OPD = use OHAs for stable T2DM. IPD = STOP metformin and SGLT2i; use insulin instead.", footnote))
return els
# ══════════════════════════════════════════════════════════════════════════════
# PAGE 4 – INSULIN GUIDE + DECISION FLOWCHART
# ══════════════════════════════════════════════════════════════════════════════
def page_insulin():
els = []
els.append(SBanner("🩺 INSULIN TYPES + IPD vs OPD FLOWCHART — When to Give Insulin", AMBER))
els.append(sp(4))
# ── Insulin types table (left column) ──
ins_hdr = [
Paragraph("TYPE", col_hdr),
Paragraph("EXAMPLES", col_hdr),
Paragraph("ONSET", col_hdr),
Paragraph("PEAK", col_hdr),
Paragraph("DURATION", col_hdr),
Paragraph("GIVE", col_hdr),
]
ins_rows = [
ins_hdr,
[p("Rapid-acting", body_b), p("Aspart\nLispro\nGlulisine", small), p("<15 min",body_c),
p("0.5–1.5h",body_c), p("3–5h",body_c), p("Immediately BEFORE\nor WITH meal",body)],
[p("Short-acting\n(Regular)", body_b), p("Actrapid\nHumulin R", small), p("30–60 min",body_c),
p("2–3h",body_c), p("4–8h",body_c), p("30 min BEFORE\nmeal",body)],
[p("Intermediate\n(NPH)", body_b), p("Insulatard\nHumulin N", small), p("2–4h",body_c),
p("4–10h",body_c), p("10–16h",body_c), p("Twice daily:\nmorning + bedtime",body)],
[p("Long-acting", body_b), p("Glargine\nDetemir", small), p("0.5–4h",body_c),
p("No peak",body_c), p("20–24h",body_c), p("Once daily at\nBEDTIME (FBS control)",body)],
[p("Ultra-long", body_b), p("Degludec", small), p("30–90 min",body_c),
p("No peak",body_c), p("> 42h",body_c), p("Once daily,\nfixed time",body)],
[p("IV Infusion\n(ICU/DKA)", body_b), p("Regular IV", small), p("Immediate",body_c),
p("—",body_c), p("Titrated",body_c), p("Continuous IV in ICU,\nDKA, HHS, post-op",body)],
]
cws_ins = [22*mm, 22*mm, 16*mm, 14*mm, 18*mm, 30*mm]
ins_tbl = Table(ins_rows, colWidths=cws_ins, repeatRows=1)
ins_style = [
("BACKGROUND", (0,0), (-1,0), AMBER),
("BACKGROUND", (0,1), (-1,1), LTBLUE),
("BACKGROUND", (0,2), (-1,2), LTGREEN),
("BACKGROUND", (0,3), (-1,3), LTBLUE),
("BACKGROUND", (0,4), (-1,4), LTAMBER),
("BACKGROUND", (0,5), (-1,5), LTPURP),
("BACKGROUND", (0,6), (-1,6), LTRED),
("GRID", (0,0), (-1,-1), 0.4, colors.HexColor("#ffe0b2")),
("VALIGN", (0,0), (-1,-1), "MIDDLE"),
("TOPPADDING", (0,0), (-1,-1), 3),
("BOTTOMPADDING",(0,0),(-1,-1), 3),
("LEFTPADDING",(0,0), (-1,-1), 4),
("RIGHTPADDING",(0,0),(-1,-1), 4),
]
ins_tbl.setStyle(TableStyle(ins_style))
els.append(ins_tbl)
els.append(sp(5))
# ── Decision flowchart as a table ──
els.append(SBanner("⚡ OPD vs IPD DECISION FLOWCHART", NAVY, size=8))
els.append(sp(4))
def fc_cell(text, bg, tc=DGREY, bold=False):
fn = "Helvetica-Bold" if bold else "Helvetica"
return Paragraph(text, S("fc", fontName=fn, fontSize=7, textColor=tc,
leading=10, alignment=TA_CENTER))
ARROW = "▼"
fc_data = [
# Row 1: Start
[fc_cell("NEW DIABETIC PATIENT", NAVY, WHITE, True),
"", "", "", ""],
# Row 2: Question 1
[fc_cell(f"{ARROW}", LGREY, MID), "", "", "", ""],
[fc_cell("FBS > 300 OR HbA1c > 10–12%\nOR catabolic / symptomatic?", LTAMBER, DGREY, True),
"", "", "", ""],
# Row 3: Yes / No branches
[fc_cell("YES ▶", LTRED, RED, True),
fc_cell("→ START INSULIN\n(may step down to OHA later)", LTRED, RED, True),
fc_cell("",LGREY),
fc_cell("NO ▶", LTGREEN, GREEN, True),
fc_cell("→ Start METFORMIN\n500 mg OD with food; titrate", LTGREEN, GREEN, True)],
# Row 4: IPD
[fc_cell(f"{ARROW}", LGREY, MID),
fc_cell("", LGREY),
fc_cell("", LGREY),
fc_cell(f"{ARROW}", LGREY, MID),
fc_cell("", LGREY)],
[fc_cell("PATIENT ADMITTED (IPD)?", LTRED, RED, True),
fc_cell("", LGREY),
fc_cell("", LGREY),
fc_cell("Add 2nd agent if HbA1c not at target in 3 months", LTGREEN, DGREY),
fc_cell("", LGREY)],
[fc_cell("YES → STOP metformin & SGLT2i\nUse INSULIN only (SC or IV)", LTRED, RED, True),
fc_cell("", LGREY),
fc_cell("", LGREY),
fc_cell("High PPBS: Glinide / AGI / DPP4i\nCV disease: SGLT2i / GLP-1RA\nObese: GLP-1RA / SGLT2i\nLean/young: Sulfonylurea", LTGREEN, DGREY),
fc_cell("", LGREY)],
# Row 5: Not at target
[fc_cell("", LGREY), "", "", fc_cell(f"{ARROW}", LGREY, MID), ""],
[fc_cell("SPECIAL SITUATIONS", LTAMBER, AMBER, True),
fc_cell("", LGREY), fc_cell("", LGREY),
fc_cell("Still not at target on 2–3 OHAs?\n→ Add BASAL insulin (Glargine at bedtime)\n Keep metformin; stop sulfonylurea\nStill high PPBS?\n→ Add prandial rapid-acting insulin", LTAMBER, DGREY), ""],
[fc_cell("T1DM: Insulin ALWAYS\nPregnancy: Insulin (metformin adjunct only)\nDKA / HHS: IV Regular insulin\nPre-op/NPO: IV insulin infusion", LTPURP, PURPLE),
fc_cell("", LGREY), fc_cell("", LGREY),
fc_cell("", LGREY), fc_cell("", LGREY)],
]
cws_fc = [42*mm, 42*mm, 6*mm, 40*mm, 38*mm]
fc_tbl = Table(fc_data, colWidths=cws_fc)
fc_tbl.setStyle(TableStyle([
("SPAN", (0,0), (-1,0)),
("SPAN", (0,1), (-1,1)),
("SPAN", (0,2), (-1,2)),
("SPAN", (0,4), (1,4)),
("SPAN", (0,5), (1,5)),
("SPAN", (0,6), (1,6)),
("SPAN", (0,7), (1,7)),
("SPAN", (0,8), (1,8)),
("SPAN", (0,9), (1,9)),
("BACKGROUND", (0,0), (-1,0), NAVY),
("BACKGROUND", (0,1), (-1,1), LGREY),
("BACKGROUND", (0,2), (-1,2), LTAMBER),
("BACKGROUND", (0,7), (1,7), LGREY),
("VALIGN", (0,0), (-1,-1), "MIDDLE"),
("GRID", (0,0), (-1,-1), 0.3, colors.HexColor("#b0bec5")),
("TOPPADDING", (0,0), (-1,-1), 4),
("BOTTOMPADDING",(0,0),(-1,-1), 4),
("LEFTPADDING",(0,0), (-1,-1), 5),
("RIGHTPADDING",(0,0),(-1,-1), 5),
]))
els.append(fc_tbl)
return els
# ══════════════════════════════════════════════════════════════════════════════
# BUILD PDF
# ══════════════════════════════════════════════════════════════════════════════
def build():
os.makedirs(os.path.dirname(OUTPUT), exist_ok=True)
doc = SimpleDocTemplate(
OUTPUT,
pagesize=landscape(A5),
leftMargin=12*mm, rightMargin=12*mm,
topMargin=10*mm, bottomMargin=12*mm,
title="Anti-Diabetic Drug Selection – Pocket Reference",
author="Orris Clinical AI",
subject="Diabetes Management",
)
story = []
# Page 1
story.extend(page_cover())
from reportlab.platypus import PageBreak
story.append(PageBreak())
# Page 2
story.extend(page_glucose())
story.append(PageBreak())
# Page 3
story.extend(page_oha())
story.append(PageBreak())
# Page 4
story.extend(page_insulin())
doc.build(story, canvasmaker=NumberedCanvas)
print(f"PDF created: {OUTPUT}")
if __name__ == "__main__":
build()
cd /home/daytona/workspace/antidiabetic-pocket-ref && python3 make_pdf.py 2>&1
ls -lh /home/daytona/workspace/antidiabetic-pocket-ref/Antidiabetic_Pocket_Reference.pdf
Antidiabetic Pocket Reference
PDF Document · PDF