~/ra-project/generate_ra_pdf.py
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.lib import colors
from reportlab.platypus import (
SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
HRFlowable, PageBreak, KeepTogether
)
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_JUSTIFY
from reportlab.platypus import ListFlowable, ListItem
# ── Output path ──────────────────────────────────────────────────────────────
OUTPUT = "/tmp/workspace/ra-project/Rheumatoid_Arthritis_Project.pdf"
# ── Document ──────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
OUTPUT,
pagesize=A4,
leftMargin=2.5*cm, rightMargin=2.5*cm,
topMargin=2.5*cm, bottomMargin=2.5*cm,
title="Rheumatoid Arthritis – Comprehensive Project Report",
author="Orris Medical AI"
)
W = A4[0] - 5*cm # usable text width
# ── Styles ────────────────────────────────────────────────────────────────────
styles = getSampleStyleSheet()
TITLE = ParagraphStyle("TITLE", parent=styles["Title"],
fontSize=22, textColor=colors.HexColor("#1a3a5c"),
spaceAfter=6, alignment=TA_CENTER, fontName="Helvetica-Bold")
SUBTITLE = ParagraphStyle("SUBTITLE", parent=styles["Normal"],
fontSize=11, textColor=colors.HexColor("#4a6a8a"),
spaceAfter=12, alignment=TA_CENTER)
H1 = ParagraphStyle("H1", parent=styles["Heading1"],
fontSize=14, textColor=colors.HexColor("#1a3a5c"),
spaceBefore=14, spaceAfter=4, fontName="Helvetica-Bold",
borderPad=2)
H2 = ParagraphStyle("H2", parent=styles["Heading2"],
fontSize=12, textColor=colors.HexColor("#2c5f8a"),
spaceBefore=10, spaceAfter=3, fontName="Helvetica-Bold")
H3 = ParagraphStyle("H3", parent=styles["Heading3"],
fontSize=10.5, textColor=colors.HexColor("#3d7ab5"),
spaceBefore=8, spaceAfter=2, fontName="Helvetica-BoldOblique")
BODY = ParagraphStyle("BODY", parent=styles["Normal"],
fontSize=9.5, leading=14, spaceAfter=5, alignment=TA_JUSTIFY)
BULLET = ParagraphStyle("BULLET", parent=styles["Normal"],
fontSize=9.5, leading=13, spaceAfter=3,
leftIndent=14, bulletIndent=0)
SOURCE = ParagraphStyle("SOURCE", parent=styles["Normal"],
fontSize=8, textColor=colors.HexColor("#666666"),
leftIndent=10, spaceAfter=2, fontName="Helvetica-Oblique")
def h(level, text):
s = {1: H1, 2: H2, 3: H3}[level]
return Paragraph(text, s)
def p(text):
return Paragraph(text, BODY)
def b(text):
return Paragraph(f"• {text}", BULLET)
def hr():
return HRFlowable(width="100%", thickness=0.5,
color=colors.HexColor("#2c5f8a"), spaceAfter=6)
def table(headers, rows, col_widths=None):
data = [headers] + rows
if col_widths is None:
n = len(headers)
col_widths = [W / n] * n
t = Table(data, colWidths=col_widths, repeatRows=1)
t.setStyle(TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.HexColor("#1a3a5c")),
("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
("FONTSIZE", (0, 0), (-1, -1), 8.5),
("ROWBACKGROUNDS", (0, 1), (-1, -1),
[colors.HexColor("#eaf0f8"), colors.white]),
("GRID", (0, 0), (-1, -1), 0.4, colors.HexColor("#aac0d8")),
("VALIGN", (0, 0), (-1, -1), "TOP"),
("TOPPADDING", (0, 0), (-1, -1), 4),
("BOTTOMPADDING",(0, 0),(-1, -1), 4),
("LEFTPADDING", (0, 0), (-1, -1), 5),
("WORDWRAP", (0, 0), (-1, -1), True),
]))
return t
# ── Content ───────────────────────────────────────────────────────────────────
story = []
# ── Cover ─────────────────────────────────────────────────────────────────────
story += [
Spacer(1, 1.5*cm),
Paragraph("RHEUMATOID ARTHRITIS", TITLE),
Paragraph("Comprehensive Project Report", SUBTITLE),
Paragraph("A complete review of epidemiology, pathophysiology, clinical features,<br/>"
"diagnosis, treatment, complications and prognosis", SUBTITLE),
Spacer(1, 0.5*cm),
HRFlowable(width="80%", thickness=2, color=colors.HexColor("#1a3a5c"),
hAlign="CENTER", spaceAfter=8),
Spacer(1, 0.4*cm),
Paragraph("Sources: Firestein & Kelley's Textbook of Rheumatology • Goldman-Cecil Medicine<br/>"
"Katzung's Basic and Clinical Pharmacology 16th Ed • Campbell's Operative Orthopaedics 2026<br/>"
"Murray & Nadel's Respiratory Medicine • Bradley and Daroff's Neurology", SUBTITLE),
Spacer(1, 0.3*cm),
Paragraph("Date: July 2026", SUBTITLE),
PageBreak(),
]
# ── 1. Definition ─────────────────────────────────────────────────────────────
story += [
h(1, "1. Definition"),
hr(),
p("Rheumatoid arthritis (RA) is a <b>chronic, systemic, autoimmune inflammatory disease</b> "
"characterized by destructive, <b>symmetric polyarthritis</b> associated with autoantibodies "
"directed against citrullinated proteins. It is the most common idiopathic inflammatory "
"arthritis, affecting approximately <b>0.8% of the global population</b>."),
p("The hallmark pathology is <b>hypertrophic synovitis</b> that leads to joint laxity from "
"soft-tissue attenuation, progressive cartilage destruction, joint subluxation, and dislocation. "
"RA is not merely an articular disease — it is a systemic illness with extra-articular "
"manifestations involving virtually every organ system."),
Spacer(1, 0.3*cm),
]
# ── 2. Epidemiology ───────────────────────────────────────────────────────────
story += [
h(1, "2. Epidemiology"),
hr(),
table(
[Paragraph("<b>Feature</b>", BODY), Paragraph("<b>Data</b>", BODY)],
[
[p("Global prevalence"), p("~0.8% of the population")],
[p("Sex ratio"), p("2–4× more common in women than men")],
[p("Peak onset age"), p("4th–6th decade (though any age is possible)")],
[p("Genetic risk"), p("HLA-DRB1 'shared epitope' alleles")],
[p("Environmental triggers"), p("Smoking, periodontitis, gut microbiome dysbiosis")],
],
col_widths=[W*0.4, W*0.6]
),
Spacer(1, 0.3*cm),
h(2, "Key Epidemiological Points"),
b("<b>Smoking</b> increases citrullinated peptides in the alveolar compartment (57% vs 7% "
"in non-smokers; P<0.05) and upregulates PAD2 enzymes."),
b("<b>Periodontitis</b> is a significant risk factor — Porphyromonas gingivalis produces "
"PAD enzymes that generate citrullinated proteins, potentially triggering autoimmunity."),
b("<b>Gut microbiome:</b> enrichment of Prevotella copri has been demonstrated in patients "
"with positive autoantibodies and in new-onset untreated RA."),
b("Risk factors act additively in genetically predisposed individuals; the pre-clinical "
"phase (positive autoantibodies without joint inflammation) can precede clinical disease "
"by years."),
Spacer(1, 0.3*cm),
]
# ── 3. Pathophysiology ────────────────────────────────────────────────────────
story += [
h(1, "3. Pathophysiology"),
hr(),
h(2, "3.1 Citrullination and Autoantibodies"),
p("The central molecular mechanism involves <b>citrullination</b> — a post-translational "
"modification in which positively charged <i>arginine</i> is converted to neutral "
"<i>citrulline</i> by calcium-dependent <b>peptidyl-arginine deiminase (PAD)</b> enzymes. "
"In genetically predisposed individuals (particularly HLA-DRB1 shared epitope carriers), "
"this normally physiological process triggers autoimmunity against citrullinated antigens."),
p("Several citrullinated autoantigens have been identified: collagen type II, fibrinogen, "
"vimentin, and alpha-enolase. Smoking, periodontal disease, and HLA-DRB1 polymorphisms "
"interact to drive ACPA production."),
Spacer(1, 0.2*cm),
table(
[Paragraph("<b>Autoantibody</b>", BODY), Paragraph("<b>Prevalence</b>", BODY),
Paragraph("<b>Specificity</b>", BODY), Paragraph("<b>Clinical Significance</b>", BODY)],
[
[p("Anti-CCP / ACPA"), p("~70%"), p("93–98%"),
p("Highly specific; may precede symptoms by years; predicts aggressive erosive disease")],
[p("Rheumatoid Factor (RF)"), p("~75%"), p("Moderate"),
p("Associated with severe disease and extra-articular features; non-specific (also positive in SLE, Sjögren's, infections)")],
[p("Anti-carbamylated protein (anti-CarP)"), p("~40%"), p("High"),
p("Emerging biomarker; relevant in seronegative patients")],
[p("ANA"), p("~30%"), p("Low"), p("Non-specific; overlap features")],
[p("pANCA"), p("~30%"), p("Low"), p("Non-specific")],
],
col_widths=[W*0.22, W*0.13, W*0.13, W*0.52]
),
Spacer(1, 0.3*cm),
h(2, "3.2 Synovial Inflammation — Cellular Events"),
p("The sequence of events within the inflamed RA joint involves a complex interplay of "
"innate and adaptive immune cells:"),
b("<b>Neutrophil influx:</b> Neutrophils flood inflamed joints, especially early synovial "
"effusions. They overexpress PAD2 and PAD4 enzymes."),
b("<b>NETosis:</b> Neutrophils form Neutrophil Extracellular Traps (NETs), releasing "
"citrullinated autoantigens, active PAD isoforms, and NET-derived elastase. NET "
"complexes correlate with ACPA levels and systemic inflammatory markers."),
b("<b>Fibroblast-Like Synoviocyte (FLS) activation:</b> NETs activate FLS → release of "
"pro-inflammatory cytokines (IL-1, IL-6, TNF), chemokines, and adhesion molecules. "
"FLS also upregulate MHC class II and present NET-derived peptides to CD4+ T cells."),
b("<b>T and B cell responses:</b> CD4+ T cells drive antigen-specific adaptive responses "
"and further ACPA production. B cells produce autoantibodies that form immune complexes."),
b("<b>Pannus formation:</b> The inflamed, hyperplastic synovium (pannus) invades and "
"destroys adjacent bone and cartilage via activated FLS, macrophages, and osteoclasts."),
b("<b>Platelets:</b> Thrombocytosis is frequent in active RA (driven by IL-1, IL-6, TNF). "
"Platelet microparticles harboring CLEC-2 are increased in RA blood."),
Spacer(1, 0.2*cm),
h(2, "3.3 Key Cytokines in RA"),
table(
[Paragraph("<b>Cytokine</b>", BODY), Paragraph("<b>Role in RA</b>", BODY)],
[
[p("TNF-α"), p("Central mediator of synovial inflammation and joint destruction; target of TNF inhibitors")],
[p("IL-1"), p("Drives bone erosion and cartilage degradation")],
[p("IL-6"), p("Systemic inflammation, anemia of chronic disease, thrombocytosis, acute phase response; target of tocilizumab")],
[p("IL-17"), p("Osteoclast activation, bone destruction; produced by Th17 cells")],
[p("IL-12 / IL-23"), p("T-helper cell polarization toward Th1 and Th17 phenotypes")],
[p("GM-CSF"), p("Macrophage activation and survival in the synovium")],
],
col_widths=[W*0.2, W*0.8]
),
Spacer(1, 0.3*cm),
]
# ── 4. Clinical Features ──────────────────────────────────────────────────────
story += [
h(1, "4. Clinical Features"),
hr(),
h(2, "4.1 Articular Manifestations"),
p("The <b>distribution of involved joints</b> is the most important diagnostic clue. "
"Symptoms typically begin in the small joints of the hands (PIP and MCP joints) and "
"the toes (MTP joints). RA <b>characteristically spares the DIP joints</b>, "
"distinguishing it from osteoarthritis and psoriatic arthritis. Larger joints (wrists, "
"knees, elbows, ankles, hips, shoulders) are involved later."),
Spacer(1, 0.2*cm),
table(
[Paragraph("<b>Feature</b>", BODY), Paragraph("<b>Description</b>", BODY)],
[
[p("Pattern"), p("Symmetric polyarthritis")],
[p("Small joints first"), p("PIPs, MCPs of hands; MTPs of feet")],
[p("DIP joints"), p("Usually SPARED")],
[p("Morning stiffness"), p(">1 hour — a hallmark; proportional to inflammation")],
[p("Systemic symptoms"), p("Fatigue, weight loss, low-grade fever, malaise")],
[p("Onset"), p("Usually insidious over weeks to months; rarely acute")],
],
col_widths=[W*0.35, W*0.65]
),
Spacer(1, 0.2*cm),
h(3, "Classic Hand Deformities"),
b("<b>Ulnar deviation</b> with MCP palmar subluxation/dislocation — most characteristic deformity"),
b("<b>Swan-neck deformity</b> — PIP hyperextension with DIP flexion"),
b("<b>Boutonnière deformity</b> — PIP flexion with DIP hyperextension"),
b("<b>Mallet deformity</b> — distal interphalangeal hyperflexion (capsular disruption)"),
b("<b>Attritional tendon rupture</b> — extensor or flexor tendons"),
b("<b>Z-deformity of thumb</b> — MCP flexion, IP hyperextension"),
Spacer(1, 0.2*cm),
h(2, "4.2 Extra-Articular Manifestations"),
p("RA is a <b>systemic disease</b>. Extra-articular features are more common in seropositive "
"(RF/ACPA positive) patients with long-standing, poorly controlled disease."),
table(
[Paragraph("<b>System</b>", BODY), Paragraph("<b>Manifestation</b>", BODY)],
[
[p("Skin"), p("Rheumatoid nodules (20–35%; subcutaneous, over bony prominences), rheumatoid vasculitis, pyoderma gangrenosum")],
[p("Lung"), p("Interstitial lung disease (ILD), pleural effusions, pulmonary nodules (Caplan syndrome in miners), pulmonary hypertension")],
[p("Heart"), p("Pericarditis, accelerated atherosclerosis, increased MI/stroke risk, conduction abnormalities")],
[p("Eyes"), p("Keratoconjunctivitis sicca (Sjögren overlap), scleritis, episcleritis, peripheral ulcerative keratitis")],
[p("Nervous system"), p("Peripheral neuropathy, cervical myelopathy (atlantoaxial instability), carpal tunnel syndrome, mononeuritis multiplex")],
[p("Haematological"), p("Normochromic normocytic anaemia of chronic disease; thrombocytosis (active); Felty's syndrome (RA + splenomegaly + neutropenia)")],
[p("Kidney"), p("Secondary AA amyloidosis (long-standing disease); drug-related nephrotoxicity")],
[p("Endocrine"), p("Associated with hypothyroidism — check TSH routinely")],
],
col_widths=[W*0.2, W*0.8]
),
Spacer(1, 0.3*cm),
]
# ── 5. Diagnosis ──────────────────────────────────────────────────────────────
story += [
h(1, "5. Diagnosis"),
hr(),
h(2, "5.1 2010 ACR/EULAR Classification Criteria"),
p("The 2010 ACR/EULAR criteria replaced the older 1987 ARA criteria, with emphasis on "
"<b>early diagnosis</b>. A score of <b>≥6 out of 10</b> is required to classify RA. "
"Entry requirement: at least 1 swollen joint not better explained by another disease."),
p("If <b>typical RA erosions</b> are present on X-ray, the patient is classified as RA "
"without needing to score criteria."),
Spacer(1, 0.2*cm),
table(
[Paragraph("<b>Domain</b>", BODY), Paragraph("<b>Criterion</b>", BODY),
Paragraph("<b>Score</b>", BODY)],
[
[p("Joint involvement"), p("1 large joint"), p("0")],
[p(""), p("2–10 large joints"), p("1")],
[p(""), p("1–3 small joints"), p("2")],
[p(""), p("4–10 small joints"), p("3")],
[p(""), p(">10 joints (including ≥1 small joint)"), p("5")],
[p("Serology (RF/ACPA)"), p("Both negative"), p("0")],
[p(""), p("Low positive (≤3× ULN)"), p("2")],
[p(""), p("High positive (>3× ULN)"), p("3")],
[p("Acute-phase reactants"), p("Normal CRP and ESR"), p("0")],
[p(""), p("Abnormal CRP or ESR"), p("1")],
[p("Symptom duration"), p("<6 weeks"), p("0")],
[p(""), p("≥6 weeks"), p("1")],
[p(""), p("<b>MAXIMUM TOTAL</b>"), p("<b>10</b>")],
],
col_widths=[W*0.3, W*0.55, W*0.15]
),
Spacer(1, 0.3*cm),
h(2, "5.2 Laboratory Investigations"),
table(
[Paragraph("<b>Test</b>", BODY), Paragraph("<b>Significance</b>", BODY)],
[
[p("Rheumatoid Factor (RF)"), p("Present in ~75%; associated with severe disease; non-specific (positive in SLE, Sjögren's, viral infections, etc.)")],
[p("Anti-CCP / ACPA"), p("Present in ~70%; HIGHLY SPECIFIC (93–98%); may precede symptoms by years; predicts aggressive erosive disease")],
[p("ESR / CRP"), p("Elevated in active disease; used to monitor treatment response")],
[p("CBC"), p("Normochromic normocytic anaemia (chronic disease); thrombocytosis in active disease; cytopenia in Felty's")],
[p("ANA / pANCA"), p("Each positive in ~30%; non-specific; check for overlap syndromes")],
[p("Synovial fluid analysis"), p("Inflammatory fluid: WBC 2,000–50,000/μL (predominantly PMNs), low viscosity, high protein")],
[p("X-ray"), p("Periarticular osteopenia → symmetric joint space narrowing → marginal erosions → deformity/subluxation")],
[p("Ultrasound"), p("Detects synovitis, tenosynovitis, power Doppler signal — more sensitive than clinical exam in early disease")],
[p("MRI"), p("Most sensitive for early bone marrow edema, erosions, tenosynovitis; useful when X-ray is normal")],
],
col_widths=[W*0.3, W*0.7]
),
Spacer(1, 0.2*cm),
p("<i>Note: Approximately 15% of RA patients are <b>seronegative</b> (negative for both RF and ACPA). "
"These patients generally have milder disease but require exclusion of other diagnoses.</i>"),
Spacer(1, 0.3*cm),
h(2, "5.3 Differential Diagnosis"),
table(
[Paragraph("<b>Condition</b>", BODY), Paragraph("<b>Key Distinguishing Features</b>", BODY)],
[
[p("Viral arthritis (Hep B/C, parvovirus, rubella)"), p("Self-limited (2–3 weeks), specific serology, prodromal viral illness")],
[p("Systemic Lupus Erythematosus (SLE)"), p("Malar rash, renal disease, ANA+, anti-dsDNA+, photosensitivity, oral ulcers")],
[p("Psoriatic arthritis"), p("Skin/nail changes, DIP involvement, dactylitis, HLA-B27")],
[p("Reactive arthritis"), p("Urethritis, conjunctivitis, oral ulcers, HLA-B27, preceding infection")],
[p("Osteoarthritis"), p("DIP involvement, Heberden's/Bouchard's nodes, non-inflammatory synovial fluid, no systemic features")],
[p("Chronic tophaceous gout"), p("Urate crystals in fluid, tophi, asymmetric, males, hyperuricaemia")],
[p("Polymyalgia rheumatica"), p("Elderly, shoulder/hip girdle aching, no synovitis on exam, dramatic response to steroids")],
[p("Primary Sjögren's syndrome"), p("Sicca symptoms, anti-Ro/La+, less destructive arthritis")],
[p("RS3PE syndrome"), p("Elderly, seronegative, pitting oedema, abrupt onset — rule out paraneoplastic")],
],
col_widths=[W*0.35, W*0.65]
),
Spacer(1, 0.3*cm),
]
# ── 6. Treatment ──────────────────────────────────────────────────────────────
story += [
PageBreak(),
h(1, "6. Treatment & Management"),
hr(),
p("Treatment follows a <b>Treat-to-Target (T2T)</b> strategy. The goal is <b>clinical "
"remission</b> (or at minimum low disease activity), assessed using validated scores "
"(DAS28 <2.6, SDAI ≤3.3, or Boolean remission). Early aggressive therapy prevents "
"irreversible joint damage."),
Spacer(1, 0.2*cm),
h(2, "6.1 Non-Pharmacological Management"),
b("Patient education on disease course, medication adherence, and self-management"),
b("Physical therapy (range of motion, strengthening exercises) and occupational therapy"),
b("Splinting and assistive devices to reduce joint stress and maintain function"),
b("Aerobic exercise and resistance training — safe and beneficial in all stages"),
b("Smoking cessation — modifies both disease risk and severity"),
b("Dental hygiene — periodontal disease management reduces inflammatory burden"),
b("Psychological support — depression and anxiety are significant comorbidities"),
b("Multidisciplinary team: rheumatologist, physiotherapist, occupational therapist, surgeon, "
"nurse specialist, dietitian, psychologist"),
Spacer(1, 0.2*cm),
h(2, "6.2 Pharmacological Treatment"),
h(3, "Step 1 — Symptomatic Relief (NSAIDs & Glucocorticoids)"),
table(
[Paragraph("<b>Drug Class</b>", BODY), Paragraph("<b>Examples & Doses</b>", BODY),
Paragraph("<b>Notes</b>", BODY)],
[
[p("NSAIDs"), p("Ibuprofen 400 mg QID; Naproxen 500 mg BD; Celecoxib 100 mg BD; Diclofenac/misoprostol"),
p("Symptomatic relief only — do NOT modify disease. Use with GI protection. Caution in CV/renal disease.")],
[p("Glucocorticoids"), p("Prednisone ≤10 mg/day PO; Intra-articular triamcinolone"),
p("'Bridging' therapy while waiting for DMARD effect. Avoid long-term systemic use — osteoporosis, infection, metabolic risks.")],
],
col_widths=[W*0.2, W*0.42, W*0.38]
),
Spacer(1, 0.2*cm),
h(3, "Step 2 — Conventional Synthetic DMARDs (csDMARDs)"),
p("<b>Methotrexate (MTX)</b> is the anchor drug and first-line DMARD. Always start here "
"unless contraindicated. Add folic acid (5 mg/week) to reduce toxicity. "
"Adjust dose upward to 20–25 mg/week PO or SQ for maximum efficacy."),
table(
[Paragraph("<b>Drug</b>", BODY), Paragraph("<b>Dose</b>", BODY),
Paragraph("<b>Key Points / Monitoring</b>", BODY)],
[
[p("Methotrexate"), p("7.5–25 mg WEEKLY (PO or SQ)"),
p("Anchor drug. Monitor: LFTs, CBC, creatinine. Teratogenic — contraindicate in pregnancy. Avoid alcohol.")],
[p("Hydroxychloroquine (HCQ)"), p("200–400 mg/day (5 mg/kg)"),
p("Mild disease; used in triple therapy. Annual ophthalmology review for retinal toxicity.")],
[p("Sulfasalazine"), p("500 mg OD → 2 g/day (divided doses)"),
p("Effective alone or in triple therapy. Monitor: CBC, LFTs. Avoid in sulfa allergy.")],
[p("Leflunomide"), p("10–20 mg OD"),
p("Alternative to MTX. Very teratogenic — contraindicate in pregnancy/breastfeeding. Long half-life.")],
[p("Azathioprine"), p("1–2.5 mg/kg/day"),
p("Alternative when MTX intolerant. Check TPMT before use. Monitor CBC.")],
],
col_widths=[W*0.22, W*0.28, W*0.5]
),
Spacer(1, 0.15*cm),
p("<i><b>Triple therapy</b> (MTX + HCQ + sulfasalazine) is as effective as biologics in "
"selected patients and is a valid, cost-effective escalation step.</i>"),
Spacer(1, 0.2*cm),
h(3, "Step 3 — Biologic DMARDs (bDMARDs)"),
p("Used when csDMARDs fail to achieve adequate disease control. Nearly always combined "
"with methotrexate to prevent immunogenicity. <b>TNF inhibitors are the preferred "
"first-choice biologics.</b>"),
Spacer(1, 0.1*cm),
p("<b>TNF Inhibitors:</b>"),
table(
[Paragraph("<b>Drug</b>", BODY), Paragraph("<b>Mechanism</b>", BODY),
Paragraph("<b>Dose</b>", BODY), Paragraph("<b>Notes</b>", BODY)],
[
[p("Etanercept"), p("Soluble TNF receptor fusion protein (p75 + IgG Fc); binds TNF and lymphotoxin"),
p("50 mg SQ weekly"), p("May be used as monotherapy")],
[p("Adalimumab"), p("Fully human anti-TNF monoclonal antibody"),
p("40 mg SQ every 2 weeks"), p("Most widely used TNF inhibitor worldwide")],
[p("Infliximab"), p("Chimeric (75% human) anti-TNF monoclonal antibody"),
p("3–5 mg/kg IV at 0, 2, 6 wks → every 4–8 wks"), p("MUST use with MTX to prevent immunogenicity")],
[p("Certolizumab"), p("PEGylated anti-TNF Fab fragment (no Fc region)"),
p("400 mg SQ at wks 0,2,4 → 200 mg every 2 wks"), p("Safe in pregnancy (minimal placental transfer)")],
[p("Golimumab"), p("Fully human anti-TNF monoclonal antibody"),
p("50 mg SQ monthly"), p("Or 2 mg/kg IV at wks 0, 4, then every 8 wks")],
],
col_widths=[W*0.17, W*0.33, W*0.27, W*0.23]
),
Spacer(1, 0.15*cm),
p("<b>Non-TNF Biologics (for TNF failure or specific indications):</b>"),
table(
[Paragraph("<b>Drug</b>", BODY), Paragraph("<b>Target / Mechanism</b>", BODY),
Paragraph("<b>Dose</b>", BODY)],
[
[p("Tocilizumab"), p("IL-6 receptor antagonist"), p("4–8 mg/kg IV every 4 weeks; or SQ 162 mg weekly/biweekly")],
[p("Abatacept"), p("T-cell co-stimulation blocker (CTLA4-Ig; blocks CD28–B7 interaction)"),
p("500–1000 mg IV at 0, 2, 4 wks → every 4 wks")],
[p("Rituximab"), p("Anti-CD20 monoclonal antibody → B-cell depletion"),
p("Two 1000 mg IV infusions 2 wks apart → every 16–24 wks (with MTX)")],
[p("Sarilumab"), p("IL-6 receptor antagonist (anti-IL-6R)"),
p("150–200 mg SQ every 2 weeks")],
],
col_widths=[W*0.2, W*0.5, W*0.3]
),
Spacer(1, 0.2*cm),
h(3, "Step 4 — Targeted Synthetic DMARDs (tsDMARDs) — JAK Inhibitors"),
p("JAK inhibitors are <b>oral</b> targeted agents that block Janus kinase signalling. "
"They are an alternative to biologics, particularly where injection-related barriers "
"or specific disease characteristics apply."),
table(
[Paragraph("<b>Drug</b>", BODY), Paragraph("<b>JAK Selectivity</b>", BODY),
Paragraph("<b>Dose</b>", BODY), Paragraph("<b>Special Notes</b>", BODY)],
[
[p("Tofacitinib"), p("JAK1/3"), p("5 mg PO BD"), p("First approved JAK inhibitor for RA")],
[p("Baricitinib"), p("JAK1/2"), p("2 or 4 mg PO OD"), p("Once-daily dosing; also approved for alopecia areata")],
[p("Upadacitinib"), p("Selective JAK1"), p("15 mg PO OD"), p("Higher selectivity; also used in PsA, AS, AD, UC")],
[p("Filgotinib"), p("Selective JAK1"), p("200 mg PO OD"), p("Approved in EU; not in US")],
],
col_widths=[W*0.22, W*0.2, W*0.2, W*0.38]
),
Spacer(1, 0.1*cm),
p("<i><b>Boxed Warning for JAK inhibitors:</b> Increased risk of serious infections, "
"malignancy, major adverse cardiovascular events (MACE), and venous thromboembolism (VTE), "
"particularly in patients >50 years with cardiovascular risk factors. Screen and treat "
"latent TB before initiating.</i>"),
Spacer(1, 0.3*cm),
h(2, "6.3 ACR Treatment Algorithm Summary"),
table(
[Paragraph("<b>Stage</b>", BODY), Paragraph("<b>Recommendation</b>", BODY)],
[
[p("Step 1 (early/low disease activity)"), p("MTX monotherapy (target dose 20–25 mg/week)")],
[p("Step 2 (inadequate response at 3 months)"), p("Escalate to triple csDMARD therapy OR add TNF inhibitor/non-TNF biologic/JAK inhibitor")],
[p("Step 3 (biologic failure)"), p("Switch to different biologic class or JAK inhibitor")],
[p("Remission achieved"), p("Consider cautious tapering (reduce dose, then extend interval) — do not abruptly stop")],
[p("Poor prognostic features"), p("More aggressive early treatment warranted; consider biologic earlier")],
],
col_widths=[W*0.38, W*0.62]
),
Spacer(1, 0.3*cm),
]
# ── 7. Disease Activity Monitoring ───────────────────────────────────────────
story += [
h(1, "7. Monitoring Disease Activity"),
hr(),
table(
[Paragraph("<b>Tool</b>", BODY), Paragraph("<b>Description</b>", BODY),
Paragraph("<b>Remission Threshold</b>", BODY)],
[
[p("DAS28"), p("Disease Activity Score using 28 joints + ESR or CRP + patient global"), p("<2.6")],
[p("CDAI"), p("Clinical Disease Activity Index — no laboratory values"), p("≤2.8")],
[p("SDAI"), p("Simplified Disease Activity Index — includes CRP"), p("≤3.3")],
[p("Boolean remission"), p("Tender joints ≤1, swollen joints ≤1, CRP ≤1 mg/dL, patient global ≤1"), p("All criteria met")],
[p("HAQ-DI"), p("Health Assessment Questionnaire — measures functional disability (0–3 scale)"), p("<0.5 = minimal disability")],
[p("Sharp/van der Heijde score"), p("Annual X-ray hands/feet — quantifies erosion and joint space narrowing progression"), p("No change = good")],
],
col_widths=[W*0.2, W*0.55, W*0.25]
),
Spacer(1, 0.2*cm),
p("Laboratory monitoring should include CBC, LFTs, creatinine, CRP/ESR every 4–8 weeks "
"initially, then every 3 months when stable. Screen for latent TB and hepatitis B/C "
"before initiating biologics or JAK inhibitors."),
Spacer(1, 0.3*cm),
]
# ── 8. Surgical Management ────────────────────────────────────────────────────
story += [
h(1, "8. Surgical Management"),
hr(),
p("The advent of DMARDs and biologics has <b>significantly reduced</b> the need for "
"rheumatoid hand surgery. However, surgery remains an important component of "
"comprehensive disease management when medical therapy is insufficient."),
Spacer(1, 0.2*cm),
h(2, "Indications for Surgery"),
b("Severe joint destruction with pain unresponsive to medical therapy"),
b("Attritional tendon rupture requiring repair/reconstruction"),
b("Significant functional impairment affecting activities of daily living"),
b("Cervical myelopathy from atlantoaxial (C1–C2) instability"),
b("Nerve compression (e.g., carpal tunnel syndrome unresponsive to splinting)"),
Spacer(1, 0.2*cm),
table(
[Paragraph("<b>Procedure</b>", BODY), Paragraph("<b>Indication</b>", BODY)],
[
[p("Synovectomy"), p("Early disease with persistent synovitis, limited erosions, failed medical therapy")],
[p("Tendon repair/transfer"), p("Attritional extensor or flexor tendon ruptures")],
[p("Total hip arthroplasty (THA)"), p("End-stage hip RA with pain and functional loss")],
[p("Total knee arthroplasty (TKA)"), p("End-stage knee RA; PCL-retaining or PCL-substituting designs used")],
[p("Shoulder/elbow arthroplasty"), p("End-stage glenohumeral or elbow RA")],
[p("MCP joint arthroplasty (silicone)"), p("Severe ulnar deviation, palmar subluxation, pain")],
[p("Wrist arthrodesis"), p("Severe wrist destruction; sacrifices motion for pain relief and stability")],
[p("MTP resection arthroplasty"), p("Forefoot RA with painful metatarsal head subluxation")],
[p("Cervical spine fusion (C1–C2)"), p("Atlantoaxial instability with myelopathy or high risk of cord injury")],
],
col_widths=[W*0.38, W*0.62]
),
Spacer(1, 0.3*cm),
]
# ── 9. Complications & Prognosis ──────────────────────────────────────────────
story += [
h(1, "9. Complications & Prognosis"),
hr(),
h(2, "9.1 Articular Complications"),
b("Progressive joint destruction, deformity, and disability"),
b("Atlantoaxial subluxation (C1–C2 instability) → risk of sudden cervical myelopathy"),
b("Joint ankylosis"),
Spacer(1, 0.2*cm),
h(2, "9.2 Systemic / Extra-Articular Complications"),
table(
[Paragraph("<b>Complication</b>", BODY), Paragraph("<b>Details</b>", BODY)],
[
[p("Cardiovascular disease"), p("RA doubles the risk of MI and stroke; equivalent to type 2 DM as a CV risk factor. Main cause of excess mortality.")],
[p("Interstitial Lung Disease (ILD)"), p("A leading cause of RA mortality; UIP and NSIP patterns most common. More common in seropositive, male smokers.")],
[p("Infections"), p("Increased susceptibility (disease + immunosuppressive therapy). TB reactivation risk with biologics/JAK inhibitors — screen before use.")],
[p("Malignancy"), p("Slightly increased risk of Non-Hodgkin lymphoma (proportional to disease activity, not treatment). Reduced solid tumour risk with MTX.")],
[p("Osteoporosis"), p("From systemic inflammation + corticosteroid use → fragility fracture risk. Screen DEXA; prescribe calcium, vitamin D, bisphosphonates.")],
[p("Secondary AA Amyloidosis"), p("Rare; from long-standing uncontrolled inflammation. Presents with proteinuria, nephrotic syndrome, renal failure.")],
[p("Drug toxicity"), p("MTX: hepatotoxicity, pneumonitis; HCQ: retinal toxicity; NSAIDs: GI/renal/CV; Biologics: serious infections, demyelination, CHF.")],
],
col_widths=[W*0.28, W*0.72]
),
Spacer(1, 0.2*cm),
h(2, "9.3 Prognostic Factors"),
p("<b>Poor prognostic indicators</b> warrant more aggressive early treatment:"),
table(
[Paragraph("<b>Poor Prognostic Feature</b>", BODY), Paragraph("<b>Favourable Feature</b>", BODY)],
[
[p("High-titer RF and/or ACPA positivity"), p("Seronegative disease")],
[p("Early radiographic erosions (<2 years)"), p("No erosions on X-ray")],
[p("High disease activity at presentation (DAS28 >5.1)"), p("Low initial disease activity")],
[p("Elevated CRP/ESR"), p("Normal inflammatory markers")],
[p("Extra-articular features present"), p("Purely articular disease")],
[p("HLA-DRB1 shared epitope positive"), p("No shared epitope")],
[p("Female sex"), p("Male sex")],
[p("Smoking (current or past)"), p("Non-smoker")],
[p("Low functional status (high HAQ)"), p("Good functional status")],
],
col_widths=[W*0.5, W*0.5]
),
Spacer(1, 0.2*cm),
p("With modern treat-to-target strategies and early aggressive therapy, <b>remission is "
"achievable</b> in a significant proportion of patients. Sustained remission may allow "
"medication tapering. Life expectancy is reduced by approximately <b>5–10 years</b> in "
"poorly controlled RA, primarily due to cardiovascular disease."),
Spacer(1, 0.3*cm),
]
# ── 10. Special Forms ─────────────────────────────────────────────────────────
story += [
h(1, "10. Special Forms of Rheumatoid Arthritis"),
hr(),
h(2, "10.1 Juvenile Idiopathic Arthritis (JIA) — Formerly 'Juvenile RA'"),
b("Onset before age 16; arthritis persisting >6 weeks"),
b("Diagnosis by exclusion of other arthritis forms"),
b("Subtypes: oligoarticular, polyarticular (RF+ or RF–), systemic (Still's disease)"),
b("Chronic anterior uveitis is a major extra-articular complication — regular slit-lamp screening required"),
b("Growth disturbances and leg-length discrepancy can occur"),
Spacer(1, 0.2*cm),
h(2, "10.2 Felty's Syndrome"),
b("Classic triad: Seropositive RA + Splenomegaly + Neutropenia"),
b("Rare; occurs in long-standing seropositive RA"),
b("Risk of recurrent life-threatening bacterial infections"),
b("Splenomegaly causes enhanced platelet clearance, but haemorrhage is rare (platelets usually remain >50,000/μL)"),
b("Large granular lymphocyte (LGL) syndrome can co-occur"),
Spacer(1, 0.2*cm),
h(2, "10.3 Seronegative RA"),
b("~15% of RA patients are negative for both RF and ACPA"),
b("Generally milder articular disease with fewer extra-articular features"),
b("Requires exclusion of other seronegative arthropathies (psoriatic, reactive, SpA)"),
Spacer(1, 0.3*cm),
]
# ── 11. Summary Table ─────────────────────────────────────────────────────────
story += [
h(1, "11. Summary — Quick Reference Table"),
hr(),
table(
[Paragraph("<b>Feature</b>", BODY), Paragraph("<b>Rheumatoid Arthritis</b>", BODY)],
[
[p("Type"), p("Chronic systemic autoimmune inflammatory arthritis")],
[p("Prevalence"), p("~0.8% globally; F:M = 2–4:1")],
[p("Key autoantibodies"), p("RF (~75%), ACPA/anti-CCP (~70%)")],
[p("Central mechanism"), p("Citrullination → ACPA generation → synovitis → pannus")],
[p("Joint pattern"), p("Symmetric, small joints (MCPs, PIPs, MTPs); spares DIPs")],
[p("Hallmark symptom"), p("Morning stiffness >1 hour")],
[p("Classic deformity"), p("Ulnar deviation, swan-neck, boutonnière")],
[p("Diagnosis criteria"), p("2010 ACR/EULAR — score ≥6/10")],
[p("Anchor drug"), p("Methotrexate (weekly dosing)")],
[p("1st-line biologic"), p("TNF inhibitors")],
[p("Oral targeted therapy"), p("JAK inhibitors (tofacitinib, baricitinib, upadacitinib)")],
[p("Treatment target"), p("Clinical remission (DAS28 <2.6)")],
[p("Main cause of death"), p("Cardiovascular disease; interstitial lung disease")],
[p("Life expectancy impact"), p("Reduced by ~5–10 years if poorly controlled")],
],
col_widths=[W*0.35, W*0.65]
),
Spacer(1, 0.5*cm),
]
# ── Sources ───────────────────────────────────────────────────────────────────
story += [
h(1, "References & Sources"),
hr(),
Paragraph("All content sourced from authoritative medical textbooks:", SOURCE),
Paragraph("1. Firestein GS & Kelley WN. <i>Firestein & Kelley's Textbook of Rheumatology</i>, "
"2-Volume Set. Elsevier.", SOURCE),
Paragraph("2. Goldman L & Schafer AI. <i>Goldman-Cecil Medicine International Edition</i>, "
"2 Volume Set, Chapter 243. Elsevier.", SOURCE),
Paragraph("3. Katzung BG. <i>Basic and Clinical Pharmacology</i>, 16th Edition, Chapter 36. "
"McGraw-Hill.", SOURCE),
Paragraph("4. Azar FM et al. <i>Campbell's Operative Orthopaedics</i>, 15th Ed 2026. Elsevier.", SOURCE),
Paragraph("5. Broaddus VC et al. <i>Murray & Nadel's Textbook of Respiratory Medicine</i>, "
"2-Volume Set. Elsevier.", SOURCE),
Paragraph("6. Daroff RB et al. <i>Bradley and Daroff's Neurology in Clinical Practice</i>. Elsevier.", SOURCE),
Paragraph("7. Hochberg MC et al. <i>Rheumatology</i>, 2-Volume Set (2022). Elsevier.", SOURCE),
Spacer(1, 1*cm),
Paragraph("Report generated by Orris Medical AI | July 2026", SUBTITLE),
]
# ── Build ──────────────────────────────────────────────────────────────────────
doc.build(story)
from pypdf import PdfReader
reader = PdfReader(OUTPUT)
print(f"PAGES: {len(reader.pages)}")
print(f"FILE: {OUTPUT}")