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.

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
I now have all the information I need to give a complete, clinically practical answer. Let me compile this into a well-organized response.
Here is a practical, step-by-step guide to using blood glucose values for drug decisions in diabetes - exactly the kind of clinical reasoning framework that textbooks often scatter across chapters.

Using Blood Glucose Values to Choose & Adjust Anti-Diabetic Drugs

1. Why Different Glucose Tests Tell You Different Things

TestWhat It MeasuresNormalPrediabetesDiabetes
FBS (Fasting Blood Sugar, ≥8h fast)Basal hepatic glucose output overnight<100 mg/dL100-125≥126 mg/dL
PPBS (2h post-meal)Meal-related glucose spike<140 mg/dL140-199≥200 mg/dL
RBS (Random, any time)Snapshot - useful only in symptomatic patients--≥200 + symptoms = diagnosis
HbA1cAverage glucose over 8-12 weeks<5.7%5.7-6.4%≥6.5%
Clinical rule of thumb:
  • High FBS = problem with basal/overnight glucose production → address with drugs that control fasting glucose (metformin, long-acting insulin, SGLT2i, glimepiride)
  • High PPBS with normal/near-normal FBS = problem with meal spikes → address with drugs that blunt post-meal glucose (glinides, alpha-glucosidase inhibitors, short-acting insulin, GLP-1 agonists)
  • Both high = both issues → combination therapy or insulin
(Katzung: "A fasting plasma glucose ≥126 mg/dL is diagnostic... Symptoms and random glucose >200 mg/dL are diagnostic and there is no need for additional testing.")

2. OHA vs Insulin - When to Use Which

Use OHAs (Oral Hypoglycemic Agents) when:

  • Type 2 DM, patient is stable and not in crisis
  • HbA1c <10% at diagnosis (mild-moderate hyperglycemia)
  • Patient can eat orally, is conscious, hemodynamically stable
  • Outpatient / OPD setting

Use Insulin when (mandatory):

  • Type 1 DM - always, no exceptions
  • Type 2 DM with any of the following:
    • FBS >300 mg/dL or HbA1c >10-12% at presentation
    • Diabetic ketoacidosis (DKA) or Hyperosmolar Hyperglycemic State (HHS)
    • Hospitalized (IPD) patient - metformin must be stopped; insulin is the standard
    • Patient NPO (nothing by mouth) - pre-op, post-op, ICU
    • Pregnancy (gestational DM or pre-existing DM) - OHAs not approved in most cases
    • Severe renal/hepatic failure (most OHAs are contraindicated)
    • Catabolic state: infection, surgery, MI, stroke
    • OHA failure - on max dose OHAs but HbA1c still >7-8%
(Harrison's 22e: "Insulin is sometimes the initial glucose-lowering agent in type 2 DM if there is severe hyperglycemia or the patient is catabolic." Also: "Metformin should be discontinued in hospitalized patients, in patients who can take nothing orally, and in those receiving radiographic contrast material.")

3. IPD (Inpatient) vs OPD (Outpatient) - The Core Difference

SituationSettingDrug of ChoiceWhy
Stable T2DM, eating wellOPDOHAs (metformin first-line ± add-ons)Safe, oral, manageable
Newly diagnosed T2DM, HbA1c <10%OPDMetformin ± one other agentGuideline-recommended start
Newly diagnosed T2DM, HbA1c >10% or FBS >300OPD or IPDStart insulin, may de-escalate laterNeed rapid control
Any DM patient admitted to hospitalIPDInsulin onlyOHAs are unsafe inpatient
ICU / post-op / NPOIPDIV regular insulin infusionPrecise titration needed
DKA / HHSIPD emergencyIV regular insulinLife-saving
PregnancyAnyInsulin (metformin sometimes used as adjunct)Fetal safety

4. Drug-by-Drug: What It Targets & When to Give It

Metformin (Biguanide)

  • Targets: High FBS - reduces hepatic glucose output
  • Give: With or just after food (reduces GI side effects)
  • Best for: Obese T2DM, first-line OPD
  • Stop when: Hospitalized, NPO, contrast dye, GFR <30, acidosis, severe infection, surgery

Sulfonylureas - Glimepiride, Glipizide, Glyburide

  • Targets: Both FBS and PPBS - stimulate insulin from pancreas
  • Give: 30 minutes BEFORE meals (especially glipizide); glimepiride can be once daily with first meal
  • Best for: Lean T2DM with residual beta cell function, disease <5 years
  • Watch: Hypoglycemia risk - dangerous in elderly, skipped meals, renal failure

Glinides - Repaglinide, Nateglinide

  • Targets: Post-meal spikes (PPBS) specifically
  • Give: Immediately BEFORE each meal - within 15 minutes
  • Best for: Patients with high PPBS but near-normal FBS; irregular meal timings
  • Note: Skip dose if skipping meal

Alpha-Glucosidase Inhibitors - Acarbose, Voglibose

  • Targets: PPBS - slow carbohydrate absorption
  • Give: With the first bite of food (must be given WITH food)
  • Best for: High post-meal spikes, especially in Asian diet (rice/roti heavy)
  • Note: Flatulence is common; hypoglycemia treated with glucose (not sucrose)

SGLT2 Inhibitors - Dapagliflozin, Empagliflozin, Canagliflozin

  • Targets: Both FBS and PPBS - urinary glucose excretion
  • Give: Morning, before or with breakfast (morning timing to avoid nocturia)
  • Best for: T2DM + heart failure, T2DM + CKD (empagliflozin/dapagliflozin have proven organ protection), obese T2DM
  • Stop: If GFR <45 (canagliflozin) or <30 (empagliflozin/dapagliflozin), major surgery, IPD

DPP-4 Inhibitors - Sitagliptin, Vildagliptin, Saxagliptin

  • Targets: Mainly PPBS - glucose-dependent insulin enhancement
  • Give: Can be taken any time with or without food
  • Best for: Elderly T2DM (very low hypoglycemia risk), CKD (dose adjust, but can be used)
  • Note: Safe inpatient? Technically yes, but insulin preferred in acute illness

GLP-1 Receptor Agonists - Semaglutide, Liraglutide, Dulaglutide

  • Targets: Both FBS and PPBS + weight loss + CV protection
  • Give: Subcutaneous injection, timing varies (liraglutide any time daily; semaglutide weekly); oral semaglutide 30 min before first meal on empty stomach
  • Best for: T2DM + obesity + ASCVD risk
  • No hypoglycemia unless combined with sulfonylurea/insulin

Insulin (Types and Timing)

Insulin TypeExamplesOnsetPeakDurationWhen to Give
Rapid-actingAspart, Lispro, Glulisine<15 min0.5-1.5h3-5hImmediately BEFORE or WITH meals (bolus)
Short-actingRegular (Actrapid)30-60 min2-3h4-8h30 min BEFORE meals
IntermediateNPH2-4h4-10h10-16hTwice daily (morning + bedtime)
Long-actingGlargine, Detemir0.5-4hNo peak20-24hOnce daily at bedtime or fixed time (controls FBS)
Ultra-longDegludec30-90 minNo peak>42hOnce daily any time (consistent daily)
(Harrison's 22e: "Insulin is delivered subcutaneously via multiple daily injections (MDIs)... Insulin is used to mimic physiologic insulin secretion.") (Katzung 16e: "Glargine is usually given once daily... provides a low, continuous level of circulating insulin.")

5. The Practical Decision Tree

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

6. Quick Rule: Before Food vs After Food

DrugWhen to Give
MetforminWith or just after food (reduces nausea)
Glipizide, Glyburide30 min before meals
GlimepirideWith first meal of the day
Repaglinide/NateglinideWithin 15 min before each meal; skip if skipping meal
Acarbose/VogliboseWith first bite of food
DPP-4i (sitagliptin etc.)Any time, with or without food
SGLT2iMorning, 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 insulin30 min before meals
Basal insulin (Glargine/Degludec)Fixed time daily (bedtime preferred to control morning FBS)

Summary in One Line Each

  • FBS high → fix basal glucose → metformin, basal insulin, glimepiride
  • PPBS high → fix meal spike → glinides, AGI, short/rapid insulin, GLP-1
  • IPD/hospital → insulin always, stop metformin and SGLT2i
  • OPD, stable T2DM → OHAs first, insulin if targets not met
  • Type 1 DM → insulin always, no OHAs (except occasional metformin adjunct)
  • Pregnant → insulin (metformin as adjunct only)
  • Pre/post-op, NPO → IV regular insulin infusion
Sources: Harrison's Principles of Internal Medicine 22e, pp. 3254-3260; Katzung's Basic and Clinical Pharmacology 16e, pp. 1174-1200.

Create a pocket reference PDF with this drug selection flowchart

Reading File
Running Command

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')"

Writing File

~/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()
Running Command

cd /home/daytona/workspace/antidiabetic-pocket-ref && python3 make_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/antidiabetic-pocket-ref/Antidiabetic_Pocket_Reference.pdf

Your pocket reference PDF is ready for download:

Antidiabetic Pocket Reference

PDF Document · PDF


What's inside (4 pages, A5 landscape - prints as a folded A4 booklet):
Page 1 - Cover Three quick-reference cards: Diagnose / Choose Drug / Timing at a glance.
Page 2 - Glucose Tests Full table of FBS vs PPBS vs RBS vs HbA1c with normal ranges, diagnostic cutoffs, and which drug class each test points to. Color-coded rule box at the bottom.
Page 3 - OHA Guide All 7 oral/injectable non-insulin agents (metformin, sulfonylureas, glinides, AGI, DPP-4i, SGLT2i, GLP-1RA) with: glucose target, exact timing (before/with/after food), best patient type, and when to stop.
Page 4 - Insulin Types + Decision Flowchart Insulin table (rapid → ultra-long, onset/peak/duration/timing) plus the full OPD vs IPD decision tree as a visual flow showing exactly when to start OHA vs insulin, when to escalate, and special situations (T1DM, pregnancy, DKA, pre-op).
This is a shared conversation. Sign in to Orris to start your own chat.