Dm type 1

Reading File
Finding Sources
Searching PubMed

"type 1 diabetes mellitus"[MeSH Terms] AND management

Reading File
Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Loading Image
I now have comprehensive information to give a thorough answer on Type 1 Diabetes Mellitus. Let me compile the full response.

Type 1 Diabetes Mellitus (T1DM)


Definition & Epidemiology

Type 1 DM accounts for 5-10% of all diabetes cases. It results from cellular-mediated autoimmune destruction of pancreatic β-cells, leading to absolute or near-absolute insulin deficiency. Though most patients are diagnosed before age 30, onset can occur at any age. The highest incidence is in people from northern Europe and Sardinia. Only 10-15% of patients have a positive family history despite a clear genetic susceptibility.
  • Textbook of Family Medicine 9e, p. 985
  • Katzung's Basic and Clinical Pharmacology, 16th Ed, p. 1174

Classification

SubtypeDescription
Type 1a (Immune-mediated)Most common; autoantibodies present; associated with HLA-DR3/DR4
Type 1b (Idiopathic)Antibody-negative; more common in African and Asian ancestry; classified as "near-complete insulin deficiency"
LADA (Latent Autoimmune Diabetes in Adults)Slow-progressing autoimmune form; initially appears as T2DM; up to 10-15% of apparent "T2DM" patients in northern Europeans

Pathogenesis

The autoimmune process destroys β-cells through T-cell mediated mechanisms. Key autoantibodies (present in 85-90% at the time of initial fasting hyperglycemia):
  • ICA - Islet cell autoantibodies
  • IAA - Insulin autoantibodies
  • GAD65 - Glutamic acid decarboxylase antibodies (most commonly tested)
  • IA-2 / ICA512 - Tyrosine phosphatase antibodies
  • ZnT8 - Zinc transporter 8 antibodies
The rate of β-cell destruction varies:
  • Children/infants: rapid destruction → acute DKA at presentation
  • Adults: prolonged prodromal phase → LADA
Proinsulin is processed in the β-cell ER into insulin (A chain + B chain linked by disulfide bonds) and C-peptide (released in equimolar amounts). C-peptide levels serve as a marker of residual β-cell function; T1DM patients are deficient in C-peptide.
Structure of human insulin showing A chain (yellow), B chain (yellow), and connecting C-peptide (blue)
Figure: Human proinsulin structure. The C-peptide (blue) is cleaved, leaving A and B chains connected by disulfide bonds. Normal C-peptide: 0.5-2.0 ng/mL; deficient in T1DM.

Clinical Features

FeatureDescription
Classic triadPolyuria, polydipsia, polyphagia
Weight lossDue to catabolism from insulin deficiency
Fatigue
DKAMay be first presentation in children; life-threatening
Blurred visionDue to osmotic lens changes
Associated autoimmune conditions:
  • Autoimmune thyroid disease: 15-30% (screen with TPO antibodies)
  • Celiac disease: 4-9% (screen with anti-tTG)
  • Addison's disease: 0.5% (screen with 21-hydroxylase antibodies)
  • ~33% of T1DM patients screen positive for at least one additional organ-specific autoantibody at diagnosis

Diagnosis

Standard criteria (same as other DM types):
  • Fasting plasma glucose ≥126 mg/dL (7.0 mmol/L)
  • 2-hour OGTT glucose ≥200 mg/dL
  • Random glucose ≥200 mg/dL + symptoms
  • HbA1c ≥6.5%
Distinguishing features from T2DM: positive autoantibodies, low/absent C-peptide, younger lean patients, tendency to ketosis.

Staging (T1DM Staging)

StageFeatures
Stage 1≥2 positive autoantibodies; normoglycemia; asymptomatic
Stage 2≥2 positive antibodies + dysglycemia (impaired glucose tolerance); asymptomatic
Stage 3Overt clinical T1DM with symptoms and hyperglycemia

Treatment

1. Insulin Therapy

The cornerstone of T1DM management is insulin replacement mimicking physiologic secretion (basal + bolus).
Insulin Preparations (Harrison's 22E, p. 3253):
PreparationOnsetPeakDuration
Rapid-acting (Aspart, Glulisine, Lispro)<15 min0.5-1.5 h3-5 h
Short-acting (Regular)0.5-1 h2-3 h4-8 h
Inhaled insulin<15 min1-2 h3 h
Intermediate (NPH)2-4 h4-10 h10-16 h
Long-acting (Degludec, Glargine)1-9 hMinimal peak>24 h
Delivery systems:
  • MDI (Multiple Daily Injections) - standard approach; basal + bolus regimen
  • CSII (Continuous Subcutaneous Insulin Infusion / Insulin Pump) - programmable basal rates + bolus
  • Sensor-augmented pump - CGM + pump; auto-suspends at low glucose
  • AID (Automated Insulin Delivery) - CGM + pump + algorithm; adjusts basal in real-time; some deliver correction boluses. This is a rapidly evolving area including DIY approaches

2. Glycemic Monitoring

  • CGM (Continuous Glucose Monitoring) is strongly encouraged, especially in newly diagnosed patients
  • HbA1c target: generally <7% (individualized)

3. New Disease-Modifying Therapy

Teplizumab-mzwv (approved 2022):
  • A humanized anti-CD3 monoclonal antibody
  • Targets the T-cell receptor CD3 complex to modulate autoimmune response
  • Indicated for Stage 2 T1DM (2+ antibodies + impaired glucose tolerance) in patients ≥8 years
  • Given as 14-day IV infusion
  • Delays onset of Stage 3 (overt) T1DM by approximately 25 months
  • Side effects: transient leukopenia/lymphopenia, rash, headache

Complications

Acute

  • DKA (Diabetic Ketoacidosis) - most serious acute complication; absent insulin → lipolysis → ketogenesis → metabolic acidosis
  • Hypoglycemia - especially with intensive insulin therapy

Chronic (Microvascular)

  • Diabetic retinopathy - leading cause of new blindness in working-age adults
  • Diabetic nephropathy - leading cause of end-stage renal disease
  • Diabetic neuropathy - most common complication

Chronic (Macrovascular)

  • Coronary artery disease, stroke, peripheral vascular disease
Intensive insulin therapy (targeting near-normal glycemia) significantly reduces microvascular complications, as demonstrated by the landmark DCCT trial.

Benefits of Intensive Insulin Therapy

  • Reduced acute metabolic complications
  • Reduced chronic microvascular complications
  • Better sense of well-being and patient autonomy
  • Greater flexibility in meals and exercise
  • Reduced risk of fetal malformations when used during pregnancy

Sources:
  • Harrison's Principles of Internal Medicine, 22nd Edition (2025), Chapter 416
  • Katzung's Basic and Clinical Pharmacology, 16th Edition, Chapter on Pancreatic Hormones
  • Textbook of Family Medicine, 9th Edition, Chapter 34

Create a T1DM management reference guide (PDF)

Reading File
Running Command

mkdir -p /home/daytona/workspace/t1dm-guide && ls /home/daytona/workspace/t1dm-g…

Writing File

~/t1dm-guide/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm, mm
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
    HRFlowable, KeepTogether, PageBreak
)
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_JUSTIFY
from reportlab.platypus import Flowable
from reportlab.lib.colors import HexColor
import os

OUTPUT_PATH = "/home/daytona/workspace/t1dm-guide/T1DM_Management_Reference_Guide.pdf"

# ── Colour palette ──────────────────────────────────────────────────────────
NAVY      = HexColor("#1B3A6B")
TEAL      = HexColor("#0D7A8A")
LIGHT_BLU = HexColor("#E8F4F8")
ORANGE    = HexColor("#E05A1C")
GOLD      = HexColor("#F0A500")
LIGHT_GRY = HexColor("#F5F5F5")
MID_GRY   = HexColor("#CCCCCC")
WHITE     = colors.white
BLACK     = colors.black
RED_ALERT = HexColor("#C0392B")
GREEN_OK  = HexColor("#1A7A4A")

# ── Document setup ───────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT_PATH,
    pagesize=A4,
    leftMargin=1.8*cm, rightMargin=1.8*cm,
    topMargin=2*cm,    bottomMargin=2*cm,
    title="T1DM Management Reference Guide",
    author="Orris Medical Reference",
    subject="Type 1 Diabetes Mellitus Clinical Management"
)

W = A4[0] - 3.6*cm  # usable page width

# ── Styles ───────────────────────────────────────────────────────────────────
styles = getSampleStyleSheet()

def make_style(name, **kw):
    return ParagraphStyle(name, **kw)

cover_title = make_style("CoverTitle",
    fontName="Helvetica-Bold", fontSize=28, textColor=WHITE,
    alignment=TA_CENTER, leading=34, spaceAfter=6)

cover_sub = make_style("CoverSub",
    fontName="Helvetica", fontSize=13, textColor=HexColor("#D0E8F0"),
    alignment=TA_CENTER, leading=18)

cover_badge = make_style("CoverBadge",
    fontName="Helvetica-Bold", fontSize=10, textColor=GOLD,
    alignment=TA_CENTER, spaceAfter=4)

section_hdr = make_style("SectionHdr",
    fontName="Helvetica-Bold", fontSize=13, textColor=WHITE,
    backColor=NAVY, leading=18, spaceBefore=14, spaceAfter=6,
    leftIndent=-4, rightIndent=-4, borderPadding=(5,8,5,8))

sub_hdr = make_style("SubHdr",
    fontName="Helvetica-Bold", fontSize=11, textColor=TEAL,
    spaceBefore=10, spaceAfter=4, leading=14)

body = make_style("Body",
    fontName="Helvetica", fontSize=9, textColor=BLACK,
    leading=13, spaceAfter=4, alignment=TA_JUSTIFY)

bullet_style = make_style("Bullet",
    fontName="Helvetica", fontSize=9, textColor=BLACK,
    leading=13, leftIndent=14, spaceAfter=2,
    bulletIndent=4, bulletText="\u2022")

small_note = make_style("SmallNote",
    fontName="Helvetica-Oblique", fontSize=7.5, textColor=HexColor("#555555"),
    leading=10, spaceAfter=2)

alert_red = make_style("AlertRed",
    fontName="Helvetica-Bold", fontSize=9, textColor=RED_ALERT,
    leading=12, spaceAfter=3, leftIndent=6)

alert_green = make_style("AlertGreen",
    fontName="Helvetica-Bold", fontSize=9, textColor=GREEN_OK,
    leading=12, spaceAfter=3, leftIndent=6)

footer_style = make_style("Footer",
    fontName="Helvetica-Oblique", fontSize=7, textColor=HexColor("#888888"),
    alignment=TA_CENTER)

tbl_hdr_style = make_style("TblHdr",
    fontName="Helvetica-Bold", fontSize=8.5, textColor=WHITE,
    alignment=TA_CENTER, leading=11)

tbl_cell = make_style("TblCell",
    fontName="Helvetica", fontSize=8.5, textColor=BLACK,
    leading=11, alignment=TA_LEFT)

tbl_cell_c = make_style("TblCellC",
    fontName="Helvetica", fontSize=8.5, textColor=BLACK,
    leading=11, alignment=TA_CENTER)

# ── Helper: coloured section header block ───────────────────────────────────
def sec(title, color=NAVY):
    data = [[Paragraph(f"  {title}", make_style("_sh",
        fontName="Helvetica-Bold", fontSize=11.5, textColor=WHITE,
        leading=16))]]
    t = Table(data, colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), color),
        ("TOPPADDING",    (0,0), (-1,-1), 6),
        ("BOTTOMPADDING", (0,0), (-1,-1), 6),
        ("LEFTPADDING",   (0,0), (-1,-1), 10),
        ("RIGHTPADDING",  (0,0), (-1,-1), 10),
        ("ROUNDEDCORNERS", [4]),
    ]))
    return t

def subsec(title):
    return Paragraph(title, sub_hdr)

def hr(color=TEAL, thickness=0.8):
    return HRFlowable(width="100%", thickness=thickness, color=color, spaceAfter=4, spaceBefore=2)

def para(text):
    return Paragraph(text, body)

def bul(text):
    return Paragraph(f"\u2022  {text}", bullet_style)

def note(text):
    return Paragraph(f"<i>{text}</i>", small_note)

def spacer(h=0.3):
    return Spacer(1, h*cm)

# ── Generic table builder ────────────────────────────────────────────────────
def build_table(headers, rows, col_widths=None, zebra=True, hdr_color=TEAL):
    header_row = [Paragraph(h, tbl_hdr_style) for h in headers]
    data = [header_row]
    for row in rows:
        data.append([Paragraph(str(c), tbl_cell) for c in row])

    if col_widths is None:
        col_widths = [W / len(headers)] * len(headers)

    t = Table(data, colWidths=col_widths, repeatRows=1)
    style_cmds = [
        ("BACKGROUND",    (0,0), (-1,0),  hdr_color),
        ("TEXTCOLOR",     (0,0), (-1,0),  WHITE),
        ("FONTNAME",      (0,0), (-1,0),  "Helvetica-Bold"),
        ("FONTSIZE",      (0,0), (-1,-1), 8.5),
        ("ROWBACKGROUNDS",(0,1), (-1,-1), [WHITE, LIGHT_GRY] if zebra else [WHITE]),
        ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING",   (0,0), (-1,-1), 6),
        ("RIGHTPADDING",  (0,0), (-1,-1), 6),
        ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
    ]
    t.setStyle(TableStyle(style_cmds))
    return t

# ── Cover page ───────────────────────────────────────────────────────────────
def cover_page():
    elems = []

    # big navy banner
    banner_data = [[
        Paragraph("TYPE 1 DIABETES MELLITUS", cover_title),
    ]]
    banner = Table(banner_data, colWidths=[W])
    banner.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), NAVY),
        ("TOPPADDING",    (0,0), (-1,-1), 30),
        ("BOTTOMPADDING", (0,0), (-1,-1), 8),
        ("LEFTPADDING",   (0,0), (-1,-1), 16),
        ("RIGHTPADDING",  (0,0), (-1,-1), 16),
    ]))
    elems.append(banner)

    sub_data = [[Paragraph("Clinical Management Reference Guide", cover_sub)]]
    sub_tbl = Table(sub_data, colWidths=[W])
    sub_tbl.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), TEAL),
        ("TOPPADDING",    (0,0), (-1,-1), 10),
        ("BOTTOMPADDING", (0,0), (-1,-1), 16),
    ]))
    elems.append(sub_tbl)
    elems.append(spacer(0.7))

    # badges row
    badges = [
        ("PATHOGENESIS", NAVY),
        ("DIAGNOSIS", TEAL),
        ("INSULIN Rx", ORANGE),
        ("MONITORING", GREEN_OK),
        ("COMPLICATIONS", RED_ALERT),
    ]
    badge_cells = []
    for label, col in badges:
        cell_data = [[Paragraph(label, make_style("_b",
            fontName="Helvetica-Bold", fontSize=8, textColor=WHITE,
            alignment=TA_CENTER, leading=11))]]
        ct = Table(cell_data, colWidths=[W/len(badges)-3])
        ct.setStyle(TableStyle([
            ("BACKGROUND",    (0,0), (-1,-1), col),
            ("TOPPADDING",    (0,0), (-1,-1), 6),
            ("BOTTOMPADDING", (0,0), (-1,-1), 6),
            ("ROUNDEDCORNERS", [3]),
        ]))
        badge_cells.append(ct)

    badge_row = Table([badge_cells], colWidths=[W/len(badges)]*len(badges))
    badge_row.setStyle(TableStyle([
        ("LEFTPADDING",   (0,0), (-1,-1), 2),
        ("RIGHTPADDING",  (0,0), (-1,-1), 2),
    ]))
    elems.append(badge_row)
    elems.append(spacer(0.6))

    # quick-ref box
    qr_items = [
        ("Prevalence", "5-10% of all diabetes cases"),
        ("Mechanism", "Autoimmune β-cell destruction → absolute insulin deficiency"),
        ("Peak onset", "< 30 years (can occur at any age)"),
        ("Key antibodies", "GAD65, IA-2, IAA, ICA, ZnT8"),
        ("Treatment cornerstone", "Basal-bolus insulin therapy + CGM"),
        ("HbA1c target", "< 7.0% (individualised)"),
        ("Disease modifier", "Teplizumab (approved for Stage 2 T1DM, age ≥ 8)"),
    ]
    qr_data = [[Paragraph(k, make_style("_k", fontName="Helvetica-Bold", fontSize=9,
                                         textColor=NAVY, leading=12)),
                Paragraph(v, make_style("_v", fontName="Helvetica", fontSize=9,
                                         textColor=BLACK, leading=12))]
               for k, v in qr_items]
    qr_tbl = Table(qr_data, colWidths=[W*0.36, W*0.64])
    qr_tbl.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), LIGHT_BLU),
        ("ROWBACKGROUNDS",(0,0), (-1,-1), [LIGHT_BLU, WHITE]),
        ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
        ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
    ]))
    elems.append(qr_tbl)
    elems.append(spacer(0.8))
    elems.append(para(
        "<font color='#555555' size='8'>"
        "Sources: Harrison's Principles of Internal Medicine 22E (2025) · "
        "Katzung's Basic &amp; Clinical Pharmacology 16E · "
        "Textbook of Family Medicine 9E · ADA Standards of Care"
        "</font>"))
    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 1 – Pathogenesis & Classification
# ══════════════════════════════════════════════════════════════════════════════
def section_pathogenesis():
    elems = []
    elems.append(sec("1.  PATHOGENESIS & CLASSIFICATION", NAVY))
    elems.append(spacer(0.3))

    elems.append(subsec("1.1  Aetiology"))
    elems.append(para(
        "T1DM results from <b>T-cell mediated autoimmune destruction of pancreatic β-cells</b>, "
        "leading to absolute or near-absolute insulin deficiency. Genetic susceptibility involves "
        "HLA class II alleles (especially DR3-DQ2 and DR4-DQ8), but only 10-15% of patients have "
        "a positive family history. The highest incidence is in people of northern European and "
        "Sardinian descent."))
    elems.append(spacer(0.2))

    elems.append(subsec("1.2  Subtypes"))
    subtypes = [
        ["Subtype", "Features", "Notes"],
        ["Type 1a\n(Immune-mediated)", "Autoantibodies positive\nHLA-DR3/DR4 associated",
         "Most common form; all ethnicities"],
        ["Type 1b\n(Idiopathic)", "Antibody-negative\nAbsolute insulin deficiency",
         "More common in African & Asian ancestry"],
        ["LADA", "Slow autoimmune progression\nInitially resembles T2DM",
         "Up to 10-15% of apparent 'T2DM'\nin northern Europeans"],
    ]
    elems.append(build_table(subtypes[0], subtypes[1:],
                              col_widths=[W*0.22, W*0.40, W*0.38]))
    elems.append(spacer(0.3))

    elems.append(subsec("1.3  Key Autoantibodies"))
    elems.append(para("Present in <b>85-90%</b> of patients at the time of initial fasting hyperglycaemia:"))
    ab_rows = [
        ["GAD65", "Glutamic acid decarboxylase 65", "Most commonly tested clinically"],
        ["IA-2 / ICA512", "Tyrosine phosphatase", "High specificity for T1DM"],
        ["IAA", "Insulin autoantibody", "Especially useful in children < 2 years"],
        ["ICA", "Islet cell autoantibody", "Broadest marker; older assay"],
        ["ZnT8", "Zinc transporter 8", "Positive in ~60-80%; adds sensitivity"],
    ]
    elems.append(build_table(["Antibody", "Full Name", "Clinical Note"], ab_rows,
                              col_widths=[W*0.15, W*0.42, W*0.43], hdr_color=NAVY))
    elems.append(spacer(0.3))

    elems.append(subsec("1.4  T1DM Staging (ADA)"))
    stage_rows = [
        ["Stage 1", "≥2 positive autoantibodies", "Normoglycaemia", "Asymptomatic"],
        ["Stage 2", "≥2 positive autoantibodies", "Dysglycaemia (IFG/IGT)",
         "Asymptomatic – <b>Teplizumab eligible</b>"],
        ["Stage 3", "±Autoantibodies", "Frank hyperglycaemia", "Symptomatic T1DM"],
    ]
    elems.append(build_table(["Stage","Immunology","Glucose","Clinical"],
                              stage_rows,
                              col_widths=[W*0.12, W*0.28, W*0.25, W*0.35]))
    elems.append(spacer(0.2))
    elems.append(note("Stage 2 → Stage 3 progression occurs in ~70% within 10 years without intervention."))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 2 – Clinical Features & Diagnosis
# ══════════════════════════════════════════════════════════════════════════════
def section_diagnosis():
    elems = []
    elems.append(sec("2.  CLINICAL FEATURES & DIAGNOSIS", TEAL))
    elems.append(spacer(0.3))

    elems.append(subsec("2.1  Presenting Symptoms"))
    sx_data = [
        ["Classic Triad", "Polyuria, polydipsia, polyphagia"],
        ["Weight loss", "Catabolism from insulin deficiency"],
        ["Fatigue & weakness", "Cellular glucose starvation"],
        ["Blurred vision", "Osmotic lens changes"],
        ["DKA", "May be first presentation; more common in children"],
        ["Candidiasis", "Genital/oral; due to glucosuria"],
    ]
    for label, detail in sx_data:
        elems.append(bul(f"<b>{label}:</b> {detail}"))
    elems.append(spacer(0.3))

    elems.append(subsec("2.2  Diagnostic Criteria (ADA)"))
    diag_rows = [
        ["Fasting plasma glucose", "≥ 126 mg/dL (7.0 mmol/L)", "No caloric intake ≥ 8 h"],
        ["2-h OGTT glucose", "≥ 200 mg/dL (11.1 mmol/L)", "75 g glucose load"],
        ["Random plasma glucose", "≥ 200 mg/dL + symptoms", "Classic hyperglycaemia symptoms"],
        ["HbA1c", "≥ 6.5% (48 mmol/mol)", "Standardised NGSP/DCCT assay"],
    ]
    elems.append(build_table(["Test","Threshold","Condition"],
                              diag_rows, col_widths=[W*0.30, W*0.35, W*0.35]))
    elems.append(note("Confirm with repeat testing on a separate day unless unequivocal hyperglycaemia with symptoms."))
    elems.append(spacer(0.3))

    elems.append(subsec("2.3  T1DM vs T2DM – Key Differentiators"))
    diff_rows = [
        ["Age at onset", "Usually < 30 yrs", "Usually > 40 yrs (but rising in youth)"],
        ["Body habitus", "Lean / normal weight", "Often overweight / obese"],
        ["Onset", "Acute (days-weeks)", "Insidious (months-years)"],
        ["Ketonuria/DKA", "Common", "Uncommon (except HHS)"],
        ["C-peptide", "Low / absent", "Normal / elevated"],
        ["Autoantibodies", "Positive (85-90%)", "Negative"],
        ["Initial Rx", "Insulin mandatory", "Lifestyle + oral agents"],
    ]
    elems.append(build_table(["Feature","T1DM","T2DM"],
                              diff_rows, col_widths=[W*0.26, W*0.37, W*0.37]))
    elems.append(spacer(0.3))

    elems.append(subsec("2.4  Associated Autoimmune Conditions"))
    assoc_rows = [
        ["Autoimmune thyroid disease", "15-30%", "TPO antibodies"],
        ["Coeliac disease", "4-9%", "Anti-tTG / anti-EMA"],
        ["Addison's disease", "0.5%", "21-hydroxylase antibodies"],
        ["Vitiligo", "Variable", "Clinical diagnosis"],
        ["Pernicious anaemia", "Uncommon", "Anti-parietal cell / anti-IF antibodies"],
    ]
    elems.append(build_table(["Condition","Prevalence in T1DM","Screening Test"],
                              assoc_rows, col_widths=[W*0.38, W*0.25, W*0.37], hdr_color=NAVY))
    elems.append(note("~33% of T1DM patients screen positive for ≥1 additional organ-specific autoantibody at diagnosis."))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 3 – Insulin Therapy
# ══════════════════════════════════════════════════════════════════════════════
def section_insulin():
    elems = []
    elems.append(sec("3.  INSULIN THERAPY", ORANGE))
    elems.append(spacer(0.3))

    elems.append(subsec("3.1  Insulin Preparations"))
    ins_rows = [
        ["RAPID-ACTING (injected)", "", "", ""],
        ["Aspart (NovoLog)", "< 15 min", "0.5 – 1.5 h", "3 – 5 h"],
        ["Glulisine (Apidra)", "< 15 min", "0.5 – 1.5 h", "3 – 5 h"],
        ["Lispro (Humalog)", "< 15 min", "0.5 – 1.5 h", "3 – 5 h"],
        ["RAPID-ACTING (inhaled)", "", "", ""],
        ["Inhaled human insulin (Afrezza)", "< 15 min", "1 – 2 h", "~ 3 h"],
        ["SHORT-ACTING (injected)", "", "", ""],
        ["Regular (Humulin R)", "0.5 – 1.0 h", "2 – 3 h", "4 – 8 h"],
        ["INTERMEDIATE-ACTING", "", "", ""],
        ["NPH (Humulin N)", "2 – 4 h", "4 – 10 h", "10 – 16 h"],
        ["LONG-ACTING / ULTRALONG", "", "", ""],
        ["Glargine (Lantus / Toujeo)", "2 – 4 h", "Flat / minimal", "20 – 24 h (U300: > 24 h)"],
        ["Detemir (Levemir)", "1 – 3 h", "6 – 8 h", "6 – 23 h (dose-dependent)"],
        ["Degludec (Tresiba)", "1 – 9 h", "Flat / minimal", "> 42 h (ultralong)"],
    ]
    # build with category rows highlighted
    hdr = ["Preparation", "Onset", "Peak", "Duration"]
    hdr_p = [Paragraph(h, tbl_hdr_style) for h in hdr]
    data = [hdr_p]
    cat_indices = []
    for i, row in enumerate(ins_rows):
        if row[1] == "":
            cat_indices.append(i+1)
            data.append([Paragraph(f"  {row[0]}", make_style("_cat",
                fontName="Helvetica-Bold", fontSize=8.5, textColor=WHITE,
                leading=11))] + [Paragraph("", tbl_cell)]*3)
        else:
            data.append([Paragraph(f"  {row[0]}", tbl_cell)] +
                        [Paragraph(row[j], tbl_cell_c) for j in range(1,4)])

    t = Table(data, colWidths=[W*0.40, W*0.18, W*0.18, W*0.24], repeatRows=1)
    ts = [
        ("BACKGROUND",    (0,0), (-1,0),  TEAL),
        ("TEXTCOLOR",     (0,0), (-1,0),  WHITE),
        ("FONTNAME",      (0,0), (-1,0),  "Helvetica-Bold"),
        ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
        ("TOPPADDING",    (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING",   (0,0), (-1,-1), 5),
        ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
        ("ROWBACKGROUNDS",(0,1), (-1,-1), [WHITE, LIGHT_GRY]),
    ]
    for ci in cat_indices:
        ts.append(("BACKGROUND", (0, ci), (-1, ci), NAVY))
        ts.append(("SPAN",       (0, ci), (-1, ci)))
    t.setStyle(TableStyle(ts))
    elems.append(t)
    elems.append(spacer(0.3))

    elems.append(subsec("3.2  Delivery Systems"))
    del_rows = [
        ["MDI\n(Multiple Daily Injections)",
         "≥3-4 injections/day; basal (long-acting) + bolus (rapid-acting) before meals",
         "Standard first-line approach"],
        ["CSII\n(Insulin Pump)",
         "Continuous subcutaneous infusion; programmable basal rates + manual bolus",
         "Good glycaemic control; requires patient engagement"],
        ["Sensor-Augmented Pump",
         "CSII + CGM; auto-suspends infusion when glucose low or predicted low within 30 min",
         "Reduces nocturnal hypoglycaemia"],
        ["AID\n(Automated Insulin Delivery)",
         "CGM + pump + algorithm; adjusts basal in real-time; some deliver auto correction bolus",
         "\"Hybrid closed-loop\"; best glycaemic outcomes; rapidly evolving"],
    ]
    elems.append(build_table(["System","Description","Notes"],
                              del_rows, col_widths=[W*0.20, W*0.48, W*0.32], hdr_color=ORANGE))
    elems.append(note(
        "AID systems are not fully closed-loop — carbohydrate intake and exercise data must still "
        "be entered manually. FDA-approved and DIY community-based approaches both exist."))
    elems.append(spacer(0.3))

    elems.append(subsec("3.3  Typical Basal-Bolus Regimen"))
    bb_rows = [
        ["Basal insulin", "Long-acting analogue (glargine / detemir / degludec)",
         "40-50% of total daily dose\nOnce daily (or twice for detemir)"],
        ["Bolus insulin", "Rapid-acting analogue (aspart / lispro / glulisine)",
         "50-60% of TDD split across 3 meals\nAdjust for carbohydrate count + ISF"],
        ["Correction dose", "Same rapid-acting insulin",
         "Based on insulin sensitivity factor (ISF)\nISF ≈ 1800 ÷ TDD (mg/dL per unit)"],
    ]
    elems.append(build_table(["Component","Insulin Type","Dosing Principle"],
                              bb_rows, col_widths=[W*0.20, W*0.42, W*0.38]))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 4 – Glycaemic Targets & Monitoring
# ══════════════════════════════════════════════════════════════════════════════
def section_monitoring():
    elems = []
    elems.append(sec("4.  GLYCAEMIC TARGETS & MONITORING", HexColor("#1A7A4A")))
    elems.append(spacer(0.3))

    elems.append(subsec("4.1  Glycaemic Targets (ADA 2024)"))
    tgt_rows = [
        ["HbA1c", "< 7.0%", "< 7.5% in children; < 8.0% in elderly/complex"],
        ["Fasting / pre-meal glucose", "80 – 130 mg/dL", "4.4 – 7.2 mmol/L"],
        ["Post-meal glucose (1-2 h)", "< 180 mg/dL", "< 10.0 mmol/L"],
        ["Time-in-Range (TIR)", "> 70% of readings", "70 – 180 mg/dL (3.9 – 10 mmol/L)"],
        ["Time Below Range (TBR)", "< 4%", "< 70 mg/dL (< 3.9 mmol/L)"],
        ["Time Above Range (TAR)", "< 25%", "> 180 mg/dL"],
    ]
    elems.append(build_table(["Parameter","Target","Notes / Range"],
                              tgt_rows, col_widths=[W*0.30, W*0.25, W*0.45], hdr_color=GREEN_OK))
    elems.append(spacer(0.3))

    elems.append(subsec("4.2  Monitoring Methods"))
    mon_rows = [
        ["SMBG\n(Self-Monitoring Blood Glucose)",
         "Fingerstick glucometer before meals, at bedtime, and with symptoms",
         "Minimum if CGM not available"],
        ["CGM\n(Continuous Glucose Monitor)",
         "Sensor measures interstitial glucose every 1-5 min; alerts for highs/lows",
         "Strongly recommended; improves TIR, reduces DKA and hypoglycaemia"],
        ["HbA1c",
         "Lab test; reflects average glucose over ~90 days",
         "Every 3 months until at target, then every 6 months"],
        ["Fructosamine / GMI",
         "2-3 week average; useful when HbA1c unreliable",
         "Haemoglobinopathy, haemolysis, pregnancy"],
    ]
    elems.append(build_table(["Method","Principle","Clinical Use"],
                              mon_rows, col_widths=[W*0.22, W*0.45, W*0.33]))
    elems.append(spacer(0.3))

    elems.append(subsec("4.3  Benefits of Intensive Management"))
    benefits = [
        "Reduced microvascular complications (retinopathy, nephropathy, neuropathy) — DCCT trial",
        "Reduced macrovascular risk with long-term normalised glycaemia (\"legacy effect\")",
        "Reduced DKA admissions",
        "Improved well-being, flexibility in meals and activity",
        "Lower risk of fetal malformations when maintained during pregnancy",
    ]
    for b in benefits:
        elems.append(bul(b))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 5 – Disease-Modifying Therapy & Adjuncts
# ══════════════════════════════════════════════════════════════════════════════
def section_adjuncts():
    elems = []
    elems.append(sec("5.  DISEASE-MODIFYING THERAPY & ADJUNCTS", NAVY))
    elems.append(spacer(0.3))

    elems.append(subsec("5.1  Teplizumab (Tzield) — Disease Modifier"))
    tep_data = [
        ["Mechanism", "Humanised anti-CD3 monoclonal antibody → modulates T-cell autoimmune response"],
        ["Indication", "Stage 2 T1DM (≥2 autoantibodies + impaired glucose tolerance), age ≥ 8 years"],
        ["Administration", "IV infusion once daily × 14 days"],
        ["Efficacy", "Delays onset of Stage 3 (overt) T1DM by ~25 months"],
        ["Side Effects", "Transient leukopenia/lymphopenia, rash, headache, cytokine release syndrome"],
        ["Monitoring", "CBC before and during infusion; pre-treat to reduce infusion reactions"],
    ]
    for k, v in tep_data:
        t = Table([[Paragraph(k, make_style("_k2", fontName="Helvetica-Bold",
                              fontSize=9, textColor=NAVY, leading=12)),
                    Paragraph(v, body)]],
                  colWidths=[W*0.25, W*0.75])
        t.setStyle(TableStyle([
            ("BACKGROUND",    (0,0), (0,0), LIGHT_BLU),
            ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
            ("TOPPADDING",    (0,0), (-1,-1), 5),
            ("BOTTOMPADDING", (0,0), (-1,-1), 5),
            ("LEFTPADDING",   (0,0), (-1,-1), 7),
            ("VALIGN",        (0,0), (-1,-1), "TOP"),
        ]))
        elems.append(t)
    elems.append(spacer(0.3))

    elems.append(subsec("5.2  Adjunct Non-Insulin Agents"))
    elems.append(para(
        "The following are used <b>in addition to insulin</b>, not as replacements, "
        "for selected patients with T1DM:"))
    adj_rows = [
        ["Pramlintide\n(Symlin)", "Amylin analogue", "Reduces post-meal glucose spikes; weight loss;\n"
         "increases hypoglycaemia risk — reduce mealtime insulin by 50%"],
        ["SGLT-2 inhibitors\n(off-label)", "Glucosuria", "Modest HbA1c reduction; weight loss; "
         "caution: euglycaemic DKA risk"],
        ["GLP-1 RAs\n(off-label)", "Incretin effect", "Weight reduction; may reduce insulin requirements"],
    ]
    elems.append(build_table(["Agent","Mechanism","Notes / Cautions"],
                              adj_rows, col_widths=[W*0.22, W*0.20, W*0.58]))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 6 – Complications
# ══════════════════════════════════════════════════════════════════════════════
def section_complications():
    elems = []
    elems.append(sec("6.  COMPLICATIONS", RED_ALERT))
    elems.append(spacer(0.3))

    elems.append(subsec("6.1  Acute Complications"))

    # DKA box
    dka_items = [
        ["Trigger", "Insulin omission, infection, MI, pancreatitis, new-onset T1DM"],
        ["Triad", "Hyperglycaemia (>250 mg/dL) + ketonuria/ketonaemia + anion gap metabolic acidosis"],
        ["Symptoms", "Nausea/vomiting, abdominal pain, Kussmaul breathing, altered consciousness"],
        ["Key labs", "pH < 7.3, bicarbonate < 15 mEq/L, glucose > 250 mg/dL, elevated ketones"],
        ["Management", "IV fluids (0.9% NaCl) → insulin infusion (0.1 U/kg/h) → K⁺ replacement → glucose when BG < 200"],
    ]
    dka_data = [[Paragraph("<b>DKA</b> — Diabetic Ketoacidosis",
                             make_style("_dka_hdr", fontName="Helvetica-Bold",
                                        fontSize=10, textColor=WHITE,
                                        leading=14, alignment=TA_LEFT)),
                 Paragraph("", tbl_cell)]]
    for k, v in dka_items:
        dka_data.append([
            Paragraph(k, make_style("_dk", fontName="Helvetica-Bold",
                                     fontSize=8.5, textColor=RED_ALERT, leading=12)),
            Paragraph(v, body)
        ])
    dka_tbl = Table(dka_data, colWidths=[W*0.20, W*0.80])
    dka_tbl.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,0), RED_ALERT),
        ("SPAN",          (0,0), (-1,0)),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
        ("ROWBACKGROUNDS",(0,1), (-1,-1), [LIGHT_GRY, WHITE]),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]))
    elems.append(dka_tbl)
    elems.append(spacer(0.3))

    # Hypoglycaemia box
    hypo_rows = [
        ["Level 1 (Alert)", "BG < 70 mg/dL (3.9)", "Treat with 15 g fast-acting carb; recheck in 15 min"],
        ["Level 2 (Clinically significant)", "BG < 54 mg/dL (3.0)", "Requires immediate treatment; adjust insulin regimen"],
        ["Level 3 (Severe)", "Altered cognition / unconsciousness", "Glucagon 1 mg IM/SC or IN; IV dextrose in hospital"],
    ]
    elems.append(build_table(["Hypoglycaemia Level","Glucose Threshold","Management"],
                              hypo_rows, col_widths=[W*0.28, W*0.28, W*0.44], hdr_color=GOLD))
    elems.append(note("Rule of 15: 15 g carbohydrate → wait 15 min → recheck; repeat if still < 70 mg/dL."))
    elems.append(spacer(0.3))

    elems.append(subsec("6.2  Chronic Complications"))
    chronic_rows = [
        ["MICROVASCULAR", "", "", ""],
        ["Retinopathy", "Retinal microaneurysms → proliferative DR",
         "Annual dilated fundus exam", "Laser photocoagulation; anti-VEGF (PDR)"],
        ["Nephropathy", "Mesangial expansion → proteinuria → ESRD",
         "Annual urine ACR + eGFR",
         "ACE-inhibitor/ARB; tight glycaemic & BP control"],
        ["Neuropathy", "Distal symmetric polyneuropathy; autonomic neuropathy",
         "Annual foot exam; monofilament test",
         "Pregabalin, duloxetine, TCAs for pain"],
        ["MACROVASCULAR", "", "", ""],
        ["CAD / MI", "Accelerated atherosclerosis",
         "Lipid panel, BP, ECG",
         "Statin; antiplatelet if indicated; BP < 130/80"],
        ["Stroke", "2-4× increased risk",
         "Carotid auscultation / imaging if symptomatic",
         "Risk factor modification"],
        ["PAD", "Claudication; foot ischaemia",
         "ABI; foot pulses",
         "Revascularisation; wound care"],
    ]
    hdr2 = ["Complication","Pathology","Screening","Management"]
    hdr2_p = [Paragraph(h, tbl_hdr_style) for h in hdr2]
    data2 = [hdr2_p]
    cat2 = []
    for i, row in enumerate(chronic_rows):
        if row[1] == "":
            cat2.append(i+1)
            data2.append([Paragraph(f"  {row[0]}", make_style("_c2", fontName="Helvetica-Bold",
                fontName2="Helvetica-Bold", fontSize=8.5, textColor=WHITE, leading=11))] +
                [Paragraph("", tbl_cell)]*3)
        else:
            data2.append([Paragraph(r, tbl_cell) for r in row])

    t2 = Table(data2, colWidths=[W*0.20, W*0.28, W*0.26, W*0.26], repeatRows=1)
    ts2 = [
        ("BACKGROUND",    (0,0), (-1,0), RED_ALERT),
        ("TEXTCOLOR",     (0,0), (-1,0), WHITE),
        ("FONTNAME",      (0,0), (-1,0), "Helvetica-Bold"),
        ("GRID",          (0,0), (-1,-1), 0.4, MID_GRY),
        ("TOPPADDING",    (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING",   (0,0), (-1,-1), 5),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
        ("ROWBACKGROUNDS",(0,1), (-1,-1), [WHITE, LIGHT_GRY]),
    ]
    for ci in cat2:
        ts2.append(("BACKGROUND", (0,ci), (-1,ci), NAVY))
        ts2.append(("SPAN",       (0,ci), (-1,ci)))
        ts2.append(("TEXTCOLOR",  (0,ci), (-1,ci), WHITE))
    t2.setStyle(TableStyle(ts2))
    elems.append(t2)

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 7 – Special Situations
# ══════════════════════════════════════════════════════════════════════════════
def section_special():
    elems = []
    elems.append(sec("7.  SPECIAL SITUATIONS", TEAL))
    elems.append(spacer(0.3))

    elems.append(subsec("7.1  T1DM in Pregnancy"))
    preg = [
        "HbA1c target < 6.5% pre-conception; < 7.0% during pregnancy (to minimise hypoglycaemia risk)",
        "Intensive insulin therapy reduces risk of congenital malformations, preeclampsia, and macrosomia",
        "CGM strongly recommended throughout pregnancy",
        "Insulin requirements typically increase in 2nd and 3rd trimesters",
        "Avoid oral antidiabetic agents (metformin acceptable by some guidelines only)",
        "Screen for diabetic nephropathy and retinopathy pre-conception and at each trimester",
    ]
    for p in preg:
        elems.append(bul(p))
    elems.append(spacer(0.3))

    elems.append(subsec("7.2  Sick Day Rules"))
    sick = [
        "<b>Never stop insulin</b> — illness causes insulin resistance; requirements often increase",
        "Test blood glucose every 2-4 hours",
        "Test for ketones when BG > 240 mg/dL",
        "Maintain adequate hydration (clear fluids if not eating)",
        "If moderate-large ketones or vomiting persists → seek emergency care",
        "May need supplemental rapid-acting insulin (\"correction dose\") every 4 hours",
    ]
    for s in sick:
        elems.append(bul(s))
    elems.append(spacer(0.3))

    elems.append(subsec("7.3  Exercise Guidelines"))
    ex_rows = [
        ["Before exercise", "Check BG; target 126-180 mg/dL before starting"],
        ["During exercise", "Check BG every 30 min for prolonged activity"],
        ["Aerobic exercise", "May cause hypoglycaemia — reduce bolus by 20-50%; have carbs available"],
        ["Anaerobic / HIIT", "May cause transient hyperglycaemia — small correction dose may be needed"],
        ["Post-exercise", "Risk of delayed hypoglycaemia for 24-48 h; reduce overnight basal"],
    ]
    for k, v in ex_rows:
        elems.append(bul(f"<b>{k}:</b> {v}"))
    elems.append(spacer(0.3))

    elems.append(subsec("7.4  Perioperative Management"))
    periop = [
        "Continue long-acting basal insulin at 75-80% of usual dose the night before surgery",
        "Hold rapid-acting insulin if patient is fasting (NPO)",
        "Monitor blood glucose every 1-2 hours intraoperatively",
        "Target intraoperative BG: 140-180 mg/dL",
        "IV insulin infusion preferred for major/prolonged surgery",
        "Resume usual regimen once oral intake re-established",
    ]
    for p in periop:
        elems.append(bul(p))

    elems.append(PageBreak())
    return elems

# ══════════════════════════════════════════════════════════════════════════════
# SECTION 8 – Routine Monitoring Schedule
# ══════════════════════════════════════════════════════════════════════════════
def section_schedule():
    elems = []
    elems.append(sec("8.  ROUTINE MONITORING SCHEDULE", NAVY))
    elems.append(spacer(0.3))

    sched_rows = [
        ["Every visit", "Blood glucose review / CGM download; BP; weight; foot inspection; hypoglycaemia review; injection sites"],
        ["Every 3 months", "HbA1c; insulin dose review; nutrition / carb-counting review"],
        ["Annually", "Dilated fundus exam; urine ACR; eGFR; foot monofilament test; lipid panel; thyroid function (TSH); BP; dental check"],
        ["At diagnosis", "Autoantibody panel; C-peptide; thyroid antibodies (TPO/TG); anti-tTG (coeliac); 21-OH antibodies (Addison); ECG if > 35 yrs"],
        ["Pregnancy", "Pre-conception: ophthalmology + nephrology review; monthly HbA1c; CGM throughout"],
    ]
    elems.append(build_table(["Frequency","Actions"],
                              sched_rows, col_widths=[W*0.20, W*0.80], hdr_color=TEAL))
    elems.append(spacer(0.4))

    elems.append(subsec("Key Referrals"))
    refs = [
        ("Endocrinology / Diabetes specialist", "At diagnosis; poorly controlled; AID/pump initiation"),
        ("Ophthalmology", "Annual; earlier if visual symptoms"),
        ("Nephrology", "eGFR < 60 mL/min/1.73m² or progressive albuminuria"),
        ("Podiatry", "Peripheral neuropathy or foot deformity"),
        ("Dietitian / Diabetes educator", "At diagnosis and periodically"),
        ("Mental health", "Diabetes distress, depression, disordered eating"),
    ]
    ref_rows = [[k, v] for k, v in refs]
    elems.append(build_table(["Specialty","Indication"],
                              ref_rows, col_widths=[W*0.38, W*0.62]))
    elems.append(spacer(0.4))

    # Footer note
    elems.append(hr())
    elems.append(para(
        "<font size='8' color='#444444'>"
        "<b>Sources:</b> Harrison's Principles of Internal Medicine, 22nd Ed (McGraw-Hill, 2025) · "
        "Katzung's Basic &amp; Clinical Pharmacology, 16th Ed · "
        "Textbook of Family Medicine, 9th Ed · "
        "ADA Standards of Medical Care in Diabetes 2024. "
        "This guide is intended as a clinical reference aid and does not replace individualised medical judgement."
        "</font>"))

    return elems

# ══════════════════════════════════════════════════════════════════════════════
# Page numbering
# ══════════════════════════════════════════════════════════════════════════════
PAGE_NUM = [0]

def on_page(canvas, doc):
    PAGE_NUM[0] += 1
    canvas.saveState()
    if PAGE_NUM[0] > 1:
        canvas.setFont("Helvetica", 7)
        canvas.setFillColor(HexColor("#888888"))
        canvas.drawCentredString(
            A4[0]/2, 1.2*cm,
            f"T1DM Management Reference Guide  |  Page {PAGE_NUM[0]}"
        )
        canvas.setStrokeColor(MID_GRY)
        canvas.setLineWidth(0.5)
        canvas.line(1.8*cm, 1.5*cm, A4[0]-1.8*cm, 1.5*cm)
    canvas.restoreState()

# ══════════════════════════════════════════════════════════════════════════════
# Build
# ══════════════════════════════════════════════════════════════════════════════
story = []
story += cover_page()
story += section_pathogenesis()
story += section_diagnosis()
story += section_insulin()
story += section_monitoring()
story += section_adjuncts()
story += section_complications()
story += section_special()
story += section_schedule()

doc.build(story, onFirstPage=on_page, onLaterPages=on_page)
print(f"PDF created: {OUTPUT_PATH}")
Running Command

cd /home/daytona/workspace/t1dm-guide && python generate_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/t1dm-guide/T1DM_Management_Reference_Guide.pdf

Your T1DM Management Reference Guide PDF is ready:

T1DM Management Reference Guide

PDF Document · PDF


The guide is an 8-section colour-coded clinical reference document covering:
SectionContent
CoverQuick-reference summary card with key facts at a glance
1. Pathogenesis & ClassificationType 1a/1b/LADA subtypes, autoantibody table, ADA staging (Stages 1-3)
2. Clinical Features & DiagnosisADA diagnostic criteria, T1DM vs T2DM differentiator table, associated autoimmune conditions
3. Insulin TherapyFull insulin preparations table (rapid/short/intermediate/long/ultralong), delivery systems (MDI, CSII, AID), basal-bolus dosing principles
4. Glycaemic Targets & MonitoringHbA1c/TIR/TBR/TAR targets, CGM vs SMBG, DCCT benefits
5. Disease-Modifying TherapyTeplizumab (mechanism, indication, efficacy), adjunct agents (pramlintide, SGLT-2i)
6. ComplicationsDKA management box, hypoglycaemia levels + Rule of 15, microvascular/macrovascular chronic complication table
7. Special SituationsPregnancy, sick day rules, exercise guidelines, perioperative management
8. Monitoring ScheduleFrequency-based screening checklist + referral indications
Sources: Harrison's 22E (2025), Katzung's 16E, Textbook of Family Medicine 9E, ADA Standards of Care 2024.
This is a shared conversation. Sign in to Orris to start your own chat.