attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment

Give me notes of this Make pdf and give me Explain wherever required like explain treatment

analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
Reading File
Running Command

mkdir -p /tmp/workspace/malaria-notes && ls /tmp/workspace/

Writing File

~/malaria-notes/generate_malaria_notes.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, KeepTogether
)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
from reportlab.platypus import ListFlowable, ListItem

OUTPUT = "/tmp/workspace/malaria-notes/Malaria_Notes.pdf"

doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    rightMargin=2*cm,
    leftMargin=2*cm,
    topMargin=2*cm,
    bottomMargin=2*cm,
    title="Malaria - Comprehensive Notes",
    author="Medical Notes"
)

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

# ── Color palette ──────────────────────────────────────────────
C_TITLE   = colors.HexColor("#1565C0")   # dark blue
C_HEAD    = colors.HexColor("#B71C1C")   # deep red
C_SUBHEAD = colors.HexColor("#1B5E20")   # dark green
C_BOX_BG  = colors.HexColor("#E3F2FD")   # light blue
C_BOX_BD  = colors.HexColor("#1565C0")
C_WARN_BG = colors.HexColor("#FFF3E0")   # light orange
C_WARN_BD = colors.HexColor("#E65100")
C_NOTE_BG = colors.HexColor("#F3E5F5")   # light purple
C_NOTE_BD = colors.HexColor("#6A1B9A")
C_RED_BG  = colors.HexColor("#FFEBEE")
C_RED_BD  = colors.HexColor("#C62828")
C_GREEN_BG= colors.HexColor("#E8F5E9")
C_GREEN_BD= colors.HexColor("#2E7D32")
C_TEXT    = colors.HexColor("#212121")
C_MUTED   = colors.HexColor("#555555")
C_LINE    = colors.HexColor("#BBDEFB")

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

def S(name, **kw):
    base = styles["Normal"] if name not in styles else styles[name]
    return ParagraphStyle(name+"_custom_"+str(id(kw)), parent=base, **kw)

title_style = S("title_main",
    fontSize=26, textColor=C_TITLE, alignment=TA_CENTER,
    fontName="Helvetica-Bold", spaceAfter=4)

subtitle_style = S("subtitle",
    fontSize=11, textColor=C_MUTED, alignment=TA_CENTER,
    fontName="Helvetica", spaceAfter=14)

section_style = S("section",
    fontSize=16, textColor=colors.white, fontName="Helvetica-Bold",
    spaceAfter=6, spaceBefore=18, leftIndent=0)

sub_style = S("sub",
    fontSize=13, textColor=C_HEAD, fontName="Helvetica-Bold",
    spaceAfter=4, spaceBefore=10)

sub2_style = S("sub2",
    fontSize=11, textColor=C_SUBHEAD, fontName="Helvetica-Bold",
    spaceAfter=3, spaceBefore=6)

body_style = S("body",
    fontSize=10, textColor=C_TEXT, fontName="Helvetica",
    spaceAfter=3, leading=15, alignment=TA_JUSTIFY)

bold_style = S("boldbody",
    fontSize=10, textColor=C_TEXT, fontName="Helvetica-Bold",
    spaceAfter=3, leading=15)

bullet_style = S("bullet",
    fontSize=10, textColor=C_TEXT, fontName="Helvetica",
    spaceAfter=2, leading=14, leftIndent=14, bulletIndent=4)

explain_style = S("explain",
    fontSize=9.5, textColor=colors.HexColor("#4A148C"), fontName="Helvetica-Oblique",
    spaceAfter=3, leading=14, leftIndent=6)

warn_style = S("warn",
    fontSize=9.5, textColor=colors.HexColor("#BF360C"), fontName="Helvetica-Bold",
    spaceAfter=2, leading=13)

table_header = S("th",
    fontSize=10, textColor=colors.white, fontName="Helvetica-Bold",
    alignment=TA_CENTER)

table_cell = S("tc",
    fontSize=9.5, textColor=C_TEXT, fontName="Helvetica",
    alignment=TA_CENTER, leading=13)

table_cell_left = S("tcl",
    fontSize=9.5, textColor=C_TEXT, fontName="Helvetica",
    alignment=TA_LEFT, leading=13)

story = []

# ── Helper builders ─────────────────────────────────────────────
def section_header(text, color=C_TITLE):
    """Full-width colored section banner."""
    data = [[Paragraph(text, ParagraphStyle("sh", fontSize=14, textColor=colors.white,
                fontName="Helvetica-Bold", alignment=TA_LEFT))]]
    t = Table(data, colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), color),
        ("TOPPADDING",   (0,0),(-1,-1), 7),
        ("BOTTOMPADDING",(0,0),(-1,-1), 7),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),
        ("RIGHTPADDING", (0,0),(-1,-1), 10),
        ("ROUNDEDCORNERS",(0,0),(-1,-1), 4),
    ]))
    return t

def info_box(title, content_paras, bg=C_BOX_BG, bd=C_BOX_BD):
    rows = []
    if title:
        rows.append([Paragraph(title, ParagraphStyle("ibt", fontSize=10, textColor=bd,
                        fontName="Helvetica-Bold"))])
    for p in content_paras:
        rows.append([p])
    t = Table(rows, colWidths=[W - 0.4*cm])
    t.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), bg),
        ("BOX",        (0,0), (-1,-1), 1.5, bd),
        ("TOPPADDING",   (0,0),(-1,-1), 5),
        ("BOTTOMPADDING",(0,0),(-1,-1), 5),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),
        ("RIGHTPADDING", (0,0),(-1,-1), 10),
    ]))
    return t

def bullet(text):
    return Paragraph(f"<bullet>&bull;</bullet> {text}", bullet_style)

def explain(text):
    return Paragraph(f"<i>&#9658; {text}</i>", explain_style)

def sp(n=6):
    return Spacer(1, n)

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

# ════════════════════════════════════════════════════════════════
# PAGE 1 – TITLE
# ════════════════════════════════════════════════════════════════
story.append(Spacer(1, 1.5*cm))
story.append(Paragraph("MALARIA", title_style))
story.append(Paragraph("Comprehensive Study Notes", subtitle_style))
story.append(HRFlowable(width="60%", thickness=2, color=C_TITLE, hAlign="CENTER"))
story.append(sp(8))

# Quick-reference overview table
overview_data = [
    [Paragraph("Feature", table_header), Paragraph("Details", table_header)],
    [Paragraph("Type", table_cell), Paragraph("Protozoal Infection", table_cell_left)],
    [Paragraph("Causative Agent", table_cell), Paragraph("Plasmodium spp. (falciparum, vivax, malariae, ovale, knowlesi)", table_cell_left)],
    [Paragraph("Vector", table_cell), Paragraph("Female Anopheles mosquito", table_cell_left)],
    [Paragraph("Host", table_cell), Paragraph("Humans", table_cell_left)],
    [Paragraph("Target Organs", table_cell), Paragraph("Liver (hepatocytes) & RBCs", table_cell_left)],
    [Paragraph("Most Dangerous", table_cell), Paragraph("P. falciparum (causes cerebral malaria)", table_cell_left)],
    [Paragraph("Most Common in India", table_cell), Paragraph("P. vivax", table_cell_left)],
]
ov_table = Table(overview_data, colWidths=[5.5*cm, W - 5.5*cm])
ov_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  C_TITLE),
    ("BACKGROUND",    (0,1), (-1,1),  C_BOX_BG),
    ("BACKGROUND",    (0,2), (-1,2),  colors.white),
    ("BACKGROUND",    (0,3), (-1,3),  C_BOX_BG),
    ("BACKGROUND",    (0,4), (-1,4),  colors.white),
    ("BACKGROUND",    (0,5), (-1,5),  C_BOX_BG),
    ("BACKGROUND",    (0,6), (-1,6),  colors.white),
    ("BACKGROUND",    (0,7), (-1,7),  C_BOX_BG),
    ("BOX",           (0,0), (-1,-1), 1, C_TITLE),
    ("INNERGRID",     (0,0), (-1,-1), 0.5, C_LINE),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(ov_table)
story.append(sp(10))

# ════════════════════════════════════════════════════════════════
# SECTION 1 – INTRODUCTION
# ════════════════════════════════════════════════════════════════
story.append(section_header("1.  INTRODUCTION"))
story.append(sp(6))
story.append(Paragraph(
    "Malaria is a <b>protozoal infection</b> caused by <b>Plasmodium parasites</b>, "
    "transmitted by the bite of an infected <b>female Anopheles mosquito</b>. It mainly "
    "infects and destroys <b>liver cells (hepatocytes)</b> and <b>RBCs</b>, causing "
    "fever, anemia, jaundice, and life-threatening complications.",
    body_style))
story.append(sp(4))

# Plasmodium species table
story.append(Paragraph("Plasmodium Species", sub_style))
sp_data = [
    [Paragraph("Species", table_header), Paragraph("Key Feature", table_header), Paragraph("RBCs Infected", table_header)],
    [Paragraph("P. falciparum", table_cell_left), Paragraph("Most dangerous; cerebral malaria; no hypnozoites", table_cell_left), Paragraph("All RBC types (multiple receptors)", table_cell_left)],
    [Paragraph("P. vivax", table_cell_left), Paragraph("Most common in India; causes relapses (hypnozoites); uses DARC receptor", table_cell_left), Paragraph("Immature RBCs (reticulocytes)", table_cell_left)],
    [Paragraph("P. malariae", table_cell_left), Paragraph("Mild, chronic; 72-hr fever cycle", table_cell_left), Paragraph("Old / mature RBCs", table_cell_left)],
    [Paragraph("P. ovale", table_cell_left), Paragraph("Rare; relapses like vivax (hypnozoites)", table_cell_left), Paragraph("Immature RBCs", table_cell_left)],
    [Paragraph("P. knowlesi", table_cell_left), Paragraph("Zoonotic (from macaques); infects all RBCs", table_cell_left), Paragraph("All RBC types", table_cell_left)],
]
sp_table = Table(sp_data, colWidths=[3.5*cm, 8.5*cm, W - 12*cm])
sp_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  C_HEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_RED_BG]),
    ("BOX",           (0,0), (-1,-1), 1, C_HEAD),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#FFCDD2")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(sp_table)
story.append(sp(4))
story.append(info_box("🔑 Key Point – Duffy Antigen (DARC)",
    [Paragraph("P. vivax uses Duffy Antigen Receptor (DARC) on RBCs to gain entry. "
               "Many West Africans naturally lack the Duffy antigen — so P. vivax <b>cannot infect them</b>. "
               "This is a classic example of genetic resistance to malaria.", body_style)],
    bg=C_NOTE_BG, bd=C_NOTE_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 2 – LIFE CYCLE
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("2.  LIFE CYCLE", color=C_HEAD))
story.append(sp(6))
story.append(Paragraph(
    "The malaria life cycle involves <b>two hosts</b>: the <b>female Anopheles mosquito</b> "
    "(definitive/sexual host) and <b>humans</b> (intermediate/asexual host). "
    "The cycle has five stages:", body_style))
story.append(sp(4))

# Stage 1
story.append(Paragraph("Stage 1 — Sporozoite Injection (Mosquito Bite)", sub2_style))
story.append(bullet("Infected female Anopheles mosquito injects <b>sporozoites</b> into human skin."))
story.append(bullet("Within <b>30 minutes</b>, sporozoites enter the bloodstream and travel to the <b>liver</b>."))
story.append(explain("Sporozoites are the infective form of the parasite. They are thin, elongated cells injected via mosquito saliva."))
story.append(sp(4))

# Stage 2
story.append(Paragraph("Stage 2 — Liver Stage (Hepatic Schizogony)", sub2_style))
story.append(bullet("Sporozoites enter <b>hepatocytes</b> (liver cells)."))
story.append(bullet("Each sporozoite undergoes <b>asexual replication</b>, forming <b>hepatic schizonts</b>."))
story.append(bullet("Schizonts rupture → release <b>thousands of merozoites</b> into the blood (over 1–2 weeks)."))
story.append(sp(3))
story.append(info_box("⚠ Hypnozoites (Dormant Liver Forms)",
    [Paragraph("<b>Only P. vivax and P. ovale</b> form hypnozoites — dormant parasite forms that stay "
               "hidden in liver cells for <b>weeks to years</b>. They reactivate later, causing <b>relapse fever</b>. "
               "This is why these two species require Primaquine to eliminate the liver reservoir.",
               body_style)],
    bg=C_WARN_BG, bd=C_WARN_BD))
story.append(sp(4))

# Stage 3
story.append(Paragraph("Stage 3 — Blood Stage (Erythrocytic Schizogony)", sub2_style))
story.append(bullet("Released merozoites immediately enter <b>RBCs</b>."))
story.append(bullet("Inside RBCs, the parasite matures through three forms:"))
story.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;<b>1. Ring form</b> (early trophozoite) — earliest intracellular stage", body_style))
story.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;<b>2. Trophozoite</b> — growing parasite, consumes hemoglobin", body_style))
story.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;<b>3. Schizont</b> — contains multiple nuclei; nearly ready to burst", body_style))
story.append(sp(3))
species_rbc_data = [
    [Paragraph("Species", table_header), Paragraph("RBC Preference", table_header), Paragraph("Microscopy Feature", table_header)],
    [Paragraph("P. falciparum", table_cell_left), Paragraph("All RBCs (most virulent)", table_cell_left), Paragraph("Delicate ring forms; crescent-shaped gametocytes", table_cell_left)],
    [Paragraph("P. vivax", table_cell_left), Paragraph("Reticulocytes (immature)", table_cell_left), Paragraph("Enlarged RBCs; Schuffner's dots", table_cell_left)],
    [Paragraph("P. malariae", table_cell_left), Paragraph("Old/senescent RBCs", table_cell_left), Paragraph("Band-shaped trophozoite", table_cell_left)],
    [Paragraph("P. ovale", table_cell_left), Paragraph("Reticulocytes", table_cell_left), Paragraph("Oval RBCs with fimbriated edges", table_cell_left)],
]
srbc_t = Table(species_rbc_data, colWidths=[3.5*cm, 5*cm, W - 8.5*cm])
srbc_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  C_SUBHEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_GREEN_BG]),
    ("BOX",           (0,0), (-1,-1), 1, C_SUBHEAD),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#C8E6C9")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(srbc_t)
story.append(sp(4))

# Stage 4
story.append(Paragraph("Stage 4 — RBC Rupture & Fever", sub2_style))
story.append(bullet("Schizonts rupture → <b>release new merozoites</b> → invade new RBCs."))
story.append(bullet("<b>Hemozoin pigment + parasite toxins</b> → stimulate cytokine release → cause classic malarial symptoms."))
story.append(sp(3))

fever_data = [
    [Paragraph("Species", table_header), Paragraph("Rupture Interval", table_header), Paragraph("Fever Pattern", table_header)],
    [Paragraph("P. vivax / ovale", table_cell), Paragraph("Every 48 hours", table_cell), Paragraph("Tertian fever (every 3rd day)", table_cell)],
    [Paragraph("P. malariae", table_cell), Paragraph("Every 72 hours", table_cell), Paragraph("Quartan fever (every 4th day)", table_cell)],
    [Paragraph("P. falciparum", table_cell), Paragraph("Asynchronous (all times)", table_cell), Paragraph("Continuous / irregular fever", table_cell)],
]
fever_t = Table(fever_data, colWidths=[4.5*cm, 4.5*cm, W - 9*cm])
fever_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  colors.HexColor("#E53935")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_RED_BG]),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#B71C1C")),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#FFCDD2")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(fever_t)
story.append(sp(3))
story.append(explain(
    "Why does P. falciparum cause continuous fever? Because it infects ALL types of RBCs and "
    "the rupture is asynchronous (RBCs burst at different times), so there is no clear 48- or 72-hr cycle. "
    "This makes falciparum harder to recognize clinically."))
story.append(sp(4))

# Stage 5
story.append(Paragraph("Stage 5 — Gametocyte Formation (Sexual Stage)", sub2_style))
story.append(bullet("Some merozoites convert into <b>gametocytes</b> (sexual forms)."))
story.append(bullet("<b>P. falciparum</b> gametocytes = <b>crescent-shaped</b> (banana-shaped) — diagnostic hallmark."))
story.append(bullet("Other species form <b>round-shaped</b> gametocytes."))
story.append(bullet("When a mosquito bites an infected human, it ingests gametocytes → sexual reproduction occurs inside the mosquito gut → new sporozoites form → cycle continues."))

# ════════════════════════════════════════════════════════════════
# SECTION 3 – SIGNS & SYMPTOMS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("3.  SIGNS & SYMPTOMS", color=colors.HexColor("#7B1FA2")))
story.append(sp(6))

story.append(Paragraph("Classic Malarial Paroxysm", sub_style))
story.append(info_box("Paroxysm Sequence (Occurs in 3 Phases)",
    [Paragraph(
        "<b>1. Cold stage (Chills)</b> — intense shivering, feeling cold, teeth chattering (lasts 15 min–1 hr)<br/>"
        "<b>2. Hot stage (High Fever)</b> — temperature spikes to 39–41°C, headache, body pain (lasts 2–6 hrs)<br/>"
        "<b>3. Sweating stage</b> — profuse sweating, temperature drops, patient feels exhausted (lasts 2–4 hrs)",
        body_style),
    Paragraph("This 3-phase cycle corresponds to the <b>synchronized rupture of RBCs</b> releasing hemozoin and parasite toxins.",
              explain_style)
    ], bg=C_BOX_BG, bd=C_BOX_BD))
story.append(sp(6))

story.append(Paragraph("Other General Symptoms", sub_style))
symp_list = ["Headache", "Body pain / myalgia", "Fatigue / weakness", "Nausea and vomiting",
             "Enlarged spleen (splenomegaly) — due to RBC destruction and immune activation",
             "Jaundice (in severe cases) — due to massive RBC hemolysis releasing bilirubin"]
for s in symp_list:
    story.append(bullet(s))
story.append(sp(6))

story.append(Paragraph("Severe Malaria (P. falciparum Only)", sub_style))
story.append(info_box("Why is P. falciparum uniquely dangerous?",
    [Paragraph(
        "P. falciparum produces a protein called <b>PfEMP-1 (Plasmodium falciparum Erythrocyte Membrane Protein-1)</b> "
        "on the surface of infected RBCs. This causes infected RBCs to <b>cytoadhere</b> (stick) to capillary walls and "
        "to each other (rosetting), blocking microcirculation in vital organs — especially the brain.",
        body_style)
    ], bg=C_RED_BG, bd=C_RED_BD))
story.append(sp(4))

severe_data = [
    [Paragraph("Complication", table_header), Paragraph("Explanation", table_header)],
    [Paragraph("1. Cerebral malaria", table_cell_left), Paragraph("PfEMP-1-mediated RBC sequestration blocks brain capillaries → confusion, seizures, coma, death if untreated", table_cell_left)],
    [Paragraph("2. Severe anemia", table_cell_left), Paragraph("Massive hemolysis of RBCs faster than bone marrow can replace them", table_cell_left)],
    [Paragraph("3. Renal failure (Blackwater fever)", table_cell_left), Paragraph("Massive hemolysis releases hemoglobin into urine → dark/black colored urine → acute kidney injury", table_cell_left)],
    [Paragraph("4. Respiratory distress", table_cell_left), Paragraph("Pulmonary edema from capillary leakage; metabolic acidosis from anaerobic metabolism", table_cell_left)],
    [Paragraph("5. Hypoglycemia", table_cell_left), Paragraph("Parasite consumes glucose + quinine treatment stimulates insulin release → dangerously low blood sugar", table_cell_left)],
    [Paragraph("6. Shock", table_cell_left), Paragraph("Circulatory collapse due to cytokine storm, severe anemia, and dehydration", table_cell_left)],
    [Paragraph("7. Multi-organ failure / Death", table_cell_left), Paragraph("If untreated — kidneys, liver, lungs, brain all fail simultaneously", table_cell_left)],
]
severe_t = Table(severe_data, colWidths=[5*cm, W - 5*cm])
severe_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  colors.HexColor("#C62828")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_RED_BG]),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#C62828")),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#FFCDD2")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(severe_t)

# ════════════════════════════════════════════════════════════════
# SECTION 4 – DIAGNOSIS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("4.  DIAGNOSIS", color=colors.HexColor("#00695C")))
story.append(sp(6))

story.append(Paragraph("1. Peripheral Blood Smear (Gold Standard)", sub2_style))
story.append(bullet("<b>Thick smear</b> — concentrates blood, better for <b>detecting</b> the parasite (high sensitivity)"))
story.append(bullet("<b>Thin smear</b> — single-layer of cells for <b>identifying the species</b> and staging"))
story.append(sp(4))

micro_data = [
    [Paragraph("Species", table_header), Paragraph("Microscopy Finding", table_header)],
    [Paragraph("P. falciparum", table_cell_left), Paragraph("Delicate ring forms (multiple rings/RBC), crescent/banana-shaped gametocytes", table_cell_left)],
    [Paragraph("P. vivax", table_cell_left), Paragraph("Enlarged RBCs, Schüffner's dots (red stippling on RBC membrane)", table_cell_left)],
    [Paragraph("P. malariae", table_cell_left), Paragraph("Band-shaped (rectangular) trophozoite across the RBC", table_cell_left)],
    [Paragraph("P. ovale", table_cell_left), Paragraph("Oval-shaped RBCs with fimbriated (jagged/ragged) edges", table_cell_left)],
]
micro_t = Table(micro_data, colWidths=[4*cm, W - 4*cm])
micro_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  colors.HexColor("#00796B")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, colors.HexColor("#E0F2F1")]),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#004D40")),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#B2DFDB")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(micro_t)
story.append(sp(6))

story.append(Paragraph("2. Rapid Diagnostic Test (RDT)", sub2_style))
story.append(bullet("Detects <b>specific parasite antigens</b> from a finger-prick blood sample"))
story.append(bullet("<b>HRP2 antigen</b> — specific for P. falciparum (Histidine-Rich Protein 2)"))
story.append(bullet("<b>pLDH (parasite Lactate Dehydrogenase)</b> — detects other Plasmodium species"))
story.append(explain("RDT is faster than microscopy, useful in field settings with no lab access. "
                     "However, it cannot quantify parasite load or identify species with as much detail."))
story.append(sp(6))

story.append(Paragraph("3. Other Investigations", sub2_style))
other_dx = [
    ("CBC", "Detects anemia (low Hb, low RBC count), thrombocytopenia (low platelets — very common in malaria)"),
    ("LFT (Liver Function Test)", "Elevated bilirubin (jaundice from hemolysis), elevated liver enzymes (hepatic involvement)"),
    ("RFT (Renal Function Test)", "Elevated creatinine/BUN in renal failure; hemoglobinuria in blackwater fever"),
    ("LDH (Lactate Dehydrogenase)", "Elevated — marker of hemolysis and tissue damage"),
    ("Blood glucose", "Hypoglycemia monitoring — especially in falciparum and during quinine treatment"),
]
for test, desc in other_dx:
    story.append(bullet(f"<b>{test}</b> — {desc}"))

# ════════════════════════════════════════════════════════════════
# SECTION 5 – TREATMENT
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("5.  TREATMENT", color=colors.HexColor("#E65100")))
story.append(sp(6))

story.append(info_box("Treatment Principle",
    [Paragraph(
        "Treatment targets <b>two goals</b>:<br/>"
        "1. <b>Kill the blood-stage parasites</b> — to stop fever and prevent complications<br/>"
        "2. <b>Kill liver-stage hypnozoites</b> (P. vivax & P. ovale only) — to prevent relapses",
        body_style)
    ], bg=C_WARN_BG, bd=C_WARN_BD))
story.append(sp(6))

# Uncomplicated
story.append(Paragraph("A. Uncomplicated Malaria", sub_style))
story.append(sp(3))

story.append(Paragraph("1) P. falciparum (No hypnozoites — blood stage only)", sub2_style))
story.append(Paragraph(
    "First-line: <b>Artemisinin-Based Combination Therapy (ACT)</b>",
    bold_style))
story.append(explain(
    "Why ACT? Artemisinins kill parasites VERY rapidly (within hours) by producing free radicals "
    "that damage parasite membranes. A partner drug (lumefantrine, mefloquine, piperaquine, SP) "
    "has a longer half-life to kill any remaining parasites and prevent resistance."))
story.append(sp(3))

act_data = [
    [Paragraph("ACT Regimen", table_header), Paragraph("Dosing", table_header), Paragraph("Notes", table_header)],
    [Paragraph("Artemether + Lumefantrine (AL)", table_cell_left), Paragraph("Twice daily for 3 days", table_cell_left), Paragraph("Most widely used; take with fatty food for absorption", table_cell_left)],
    [Paragraph("Artesunate + Sulfadoxine-Pyrimethamine (SP)", table_cell_left), Paragraph("Artesunate daily x3 days; SP single dose on Day 1", table_cell_left), Paragraph("Common in India (NVBDCP regimen)", table_cell_left)],
    [Paragraph("Artesunate + Mefloquine", table_cell_left), Paragraph("3 days", table_cell_left), Paragraph("Used in SE Asia", table_cell_left)],
    [Paragraph("Dihydroartemisinin + Piperaquine (DHP)", table_cell_left), Paragraph("Once daily for 3 days", table_cell_left), Paragraph("Convenient once-daily dosing", table_cell_left)],
]
act_t = Table(act_data, colWidths=[5.5*cm, 4.5*cm, W - 10*cm])
act_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  colors.HexColor("#E65100")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_WARN_BG]),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#BF360C")),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, colors.HexColor("#FFE0B2")),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(act_t)
story.append(sp(6))

story.append(Paragraph("2) P. vivax & P. ovale (Hypnozoites present — relapse prevention needed)", sub2_style))
story.append(bullet("Blood stage: <b>Chloroquine</b> (where sensitive) or ACT"))
story.append(bullet("<b>Primaquine for 14 days</b> — targets and kills hypnozoites in the liver to prevent relapse"))
story.append(info_box("Primaquine Contraindications",
    [Paragraph(
        "Primaquine is <b>CONTRAINDICATED</b> in:<br/>"
        "1. <b>G6PD deficiency</b> — Primaquine causes oxidative hemolysis (massive RBC destruction) in G6PD-deficient patients. Always test G6PD before giving primaquine.<br/>"
        "2. <b>Pregnancy</b> — Risk of hemolysis in the fetus (fetal RBCs have low G6PD activity)",
        body_style)
    ], bg=C_RED_BG, bd=C_RED_BD))
story.append(explain(
    "G6PD (Glucose-6-Phosphate Dehydrogenase) is an enzyme that protects RBCs from oxidative damage. "
    "Deficiency is X-linked and common in malaria-endemic regions. Without G6PD, primaquine causes "
    "the RBC membrane to rupture — causing acute hemolytic anemia."))
story.append(sp(6))

story.append(Paragraph("3) P. malariae & P. knowlesi", sub2_style))
story.append(bullet("<b>Chloroquine</b> — first-line treatment"))
story.append(bullet("<b>ACT</b> — used if chloroquine resistance is suspected"))
story.append(bullet("No hypnozoites → no primaquine needed"))
story.append(sp(6))

# Severe malaria
story.append(Paragraph("B. Severe Malaria", sub_style))
story.append(info_box("Severe Malaria Treatment Protocol",
    [Paragraph(
        "<b>Step 1:</b> IV Artesunate (first-line, injectable) — given immediately in hospital<br/>"
        "<b>Step 2:</b> Once patient is stable and can swallow → switch to oral ACT for 3 days<br/>"
        "<br/>"
        "<b>Why IV Artesunate?</b> In cerebral malaria or when the patient cannot swallow, oral drugs are "
        "not feasible. IV artesunate achieves therapeutic levels within minutes, killing parasites faster "
        "than quinine with fewer side effects. It is now preferred over IV quinine globally.",
        body_style)
    ], bg=C_RED_BG, bd=C_RED_BD))
story.append(sp(3))
story.append(bullet("Monitor blood glucose closely (hypoglycemia risk)"))
story.append(bullet("Manage cerebral edema, seizures (anti-epileptics), respiratory support as needed"))
story.append(bullet("Exchange blood transfusion considered if parasitemia >10% (hyperparasitemia)"))

# ════════════════════════════════════════════════════════════════
# SECTION 6 – PREVENTION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("6.  PREVENTION", color=C_SUBHEAD))
story.append(sp(6))

story.append(Paragraph("A. Personal Protection", sub2_style))
prev_personal = [
    ("Mosquito nets (ITNs)", "Insecticide-Treated Nets — physical barrier + insecticide kills mosquitoes"),
    ("Insect repellents", "DEET-based repellents applied to skin; reduce mosquito bites"),
    ("Protective clothing", "Wearing long sleeves and pants, especially at dusk and dawn (peak Anopheles biting time)"),
    ("Prevent water stagnation", "Empty stagnant water containers — Anopheles mosquitoes breed in still water"),
]
for measure, expl in prev_personal:
    story.append(bullet(f"<b>{measure}</b> — {expl}"))
story.append(sp(6))

story.append(Paragraph("B. Community Prevention", sub2_style))
prev_community = [
    ("Fogging", "Aerial/ground insecticide spraying to kill adult mosquitoes in an area"),
    ("Larvicidal sprays", "Chemicals (e.g., temephos, Bacillus thuringiensis israelensis) applied to water bodies to kill mosquito larvae"),
    ("Indoor Residual Spraying (IRS)", "Spraying insecticide on walls/ceilings inside homes — mosquitoes rest on surfaces after feeding"),
    ("Environmental sanitation", "Draining swamps, proper waste disposal, removing breeding sites"),
]
for measure, expl in prev_community:
    story.append(bullet(f"<b>{measure}</b> — {expl}"))
story.append(sp(6))

story.append(Paragraph("C. Chemoprophylaxis (For Travelers)", sub2_style))
story.append(info_box("Drug Prophylaxis for Travelers",
    [Paragraph(
        "Travelers visiting malaria-endemic regions (Africa, SE Asia, South Asia) should take preventive medication:<br/><br/>"
        "<b>Chloroquine</b> — used in areas with chloroquine-sensitive malaria; taken weekly<br/>"
        "<b>Mefloquine</b> — used in chloroquine-resistant areas (most of Africa, SE Asia); taken weekly<br/>"
        "<b>Atovaquone-Proguanil (Malarone)</b> — daily; preferred for short trips; fewer side effects<br/>"
        "<b>Doxycycline</b> — daily; cheap alternative; causes photosensitivity<br/><br/>"
        "Prophylaxis should begin <b>1–2 weeks before travel</b> and continue for <b>4 weeks after return</b>.",
        body_style)
    ], bg=C_GREEN_BG, bd=C_GREEN_BD))

# ════════════════════════════════════════════════════════════════
# QUICK REVISION TABLE
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("7.  QUICK REVISION — KEY FACTS", color=colors.HexColor("#283593")))
story.append(sp(6))

qr_data = [
    [Paragraph("Topic", table_header), Paragraph("Key Fact", table_header)],
    [Paragraph("Vector", table_cell_left), Paragraph("Female Anopheles mosquito", table_cell_left)],
    [Paragraph("Most dangerous species", table_cell_left), Paragraph("P. falciparum — cerebral malaria, continuous fever, no hypnozoites", table_cell_left)],
    [Paragraph("Most common in India", table_cell_left), Paragraph("P. vivax — uses DARC, relapses, 48-hr fever", table_cell_left)],
    [Paragraph("Hypnozoites", table_cell_left), Paragraph("P. vivax & P. ovale only — cause relapses", table_cell_left)],
    [Paragraph("Falciparum gametocyte shape", table_cell_left), Paragraph("Crescent/banana-shaped (diagnostic)", table_cell_left)],
    [Paragraph("Gold standard diagnosis", table_cell_left), Paragraph("Peripheral blood smear (thick + thin)", table_cell_left)],
    [Paragraph("RDT antigen for falciparum", table_cell_left), Paragraph("HRP2", table_cell_left)],
    [Paragraph("Treatment: falciparum", table_cell_left), Paragraph("ACT (e.g., Artemether-Lumefantrine) x 3 days", table_cell_left)],
    [Paragraph("Relapse prevention", table_cell_left), Paragraph("Primaquine 14 days (check G6PD first!)", table_cell_left)],
    [Paragraph("Severe malaria Rx", table_cell_left), Paragraph("IV Artesunate → oral ACT once stable", table_cell_left)],
    [Paragraph("Blackwater fever", table_cell_left), Paragraph("Massive hemolysis → hemoglobinuria → dark/black urine → AKI", table_cell_left)],
    [Paragraph("Africans resistant to vivax?", table_cell_left), Paragraph("Yes — lack Duffy antigen (DARC); P. vivax cannot enter RBCs", table_cell_left)],
    [Paragraph("P. malariae fever cycle", table_cell_left), Paragraph("Every 72 hours (quartan)", table_cell_left)],
]
qr_t = Table(qr_data, colWidths=[5*cm, W - 5*cm])
qr_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  colors.HexColor("#283593")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BOX_BG]),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#1A237E")),
    ("INNERGRID",     (0,0), (-1,-1), 0.4, C_LINE),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
]))
story.append(qr_t)
story.append(sp(14))
story.append(HRFlowable(width="100%", thickness=1, color=C_LINE))
story.append(sp(4))
story.append(Paragraph("— End of Malaria Notes —", subtitle_style))

# BUILD
doc.build(story)
print(f"PDF saved to {OUTPUT}")
Running Command

cd /tmp/workspace/malaria-notes && python generate_malaria_notes.py 2>&1

Running Command

ls -lh /tmp/workspace/malaria-notes/Malaria_Notes.pdf

Your PDF is ready! Download it here:

Malaria Notes

PDF Document · PDF


Here's what's covered in the notes (with full explanations):

MALARIA — Complete Notes Summary

1. Introduction

  • Protozoal infection caused by Plasmodium spp., transmitted by female Anopheles mosquito
  • Destroys hepatocytes + RBCs → fever, anemia, jaundice
5 Plasmodium species table with RBC preference for each

2. Life Cycle (5 Stages)

StageWhat Happens
Stage 1Mosquito injects sporozoites → liver within 30 min
Stage 2Liver stage — hepatic schizogony → thousands of merozoites released (1–2 weeks)
Stage 3Blood stage — merozoites enter RBCs → Ring → Trophozoite → Schizont
Stage 4RBC rupture → hemozoin + toxins → fever (48h vivax, 72h malariae, continuous falciparum)
Stage 5Gametocyte formation → mosquito picks them up → sexual cycle
Hypnozoites (P. vivax + P. ovale only) — dormant liver forms causing relapses

3. Signs & Symptoms

  • Classic Paroxysm: Chills → High Fever → Sweating (matches RBC rupture)
  • Other: headache, body pain, fatigue, splenomegaly, jaundice
Severe malaria (P. falciparum) — 7 complications explained (cerebral malaria via PfEMP-1, blackwater fever, hypoglycemia, shock, multi-organ failure)

4. Diagnosis

TestPurpose
Thick smearDetects parasite
Thin smearIdentifies species
RDT (HRP2)Quick falciparum detection
RDT (pLDH)Other species
CBC / LFT / RFTAnemia, complications

5. Treatment (Fully Explained)

  • P. falciparum → ACT (Artemether-Lumefantrine, Artesunate+SP, DHP) x 3 days — why ACT explained
  • P. vivax / ovale → Chloroquine + Primaquine 14 days (kills hypnozoites) — G6PD warning explained
  • P. malariae / knowlesi → Chloroquine first-line
  • Severe malariaIV Artesunate → oral ACT once stable

6. Prevention

  • Personal: mosquito nets, repellents, long sleeves, no stagnant water
  • Community: fogging, larvicidal sprays, IRS
  • Chemoprophylaxis: Chloroquine / Mefloquine / Malarone depending on region

7. Quick Revision Table — 14 key exam facts in one place

attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment

Similarly do pdf for this and give Pathology give in flow chart form

Writing File

~/malaria-notes/generate_typhoid_notes.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, KeepTogether
)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY

OUTPUT = "/tmp/workspace/malaria-notes/Typhoid_Fever_Notes.pdf"

doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    rightMargin=2*cm,
    leftMargin=2*cm,
    topMargin=2*cm,
    bottomMargin=2*cm,
    title="Typhoid Fever - Comprehensive Notes",
    author="Medical Notes"
)

W = A4[0] - 4*cm

# ── Colors ──────────────────────────────────────────────────────
C_TITLE   = colors.HexColor("#4A148C")   # deep purple
C_HEAD    = colors.HexColor("#0277BD")   # blue
C_SUBHEAD = colors.HexColor("#1B5E20")   # dark green
C_ORANGE  = colors.HexColor("#E65100")
C_RED     = colors.HexColor("#B71C1C")
C_TEAL    = colors.HexColor("#00695C")
C_BOX_BG  = colors.HexColor("#EDE7F6")
C_BOX_BD  = colors.HexColor("#4A148C")
C_WARN_BG = colors.HexColor("#FFF3E0")
C_WARN_BD = colors.HexColor("#E65100")
C_RED_BG  = colors.HexColor("#FFEBEE")
C_RED_BD  = colors.HexColor("#C62828")
C_GREEN_BG= colors.HexColor("#E8F5E9")
C_GREEN_BD= colors.HexColor("#2E7D32")
C_BLUE_BG = colors.HexColor("#E3F2FD")
C_BLUE_BD = colors.HexColor("#1565C0")
C_TEXT    = colors.HexColor("#212121")
C_MUTED   = colors.HexColor("#555555")
C_LINE    = colors.HexColor("#CE93D8")
C_FLOW_BG = colors.HexColor("#F3E5F5")
C_FLOW_BD = colors.HexColor("#7B1FA2")
C_FLOW_ARR= colors.HexColor("#7B1FA2")
C_ARROW   = colors.HexColor("#6A1B9A")

# ── Styles ───────────────────────────────────────────────────────
def S(base_name, **kw):
    styles = getSampleStyleSheet()
    base = styles["Normal"] if base_name not in styles else styles[base_name]
    return ParagraphStyle("s_" + base_name + str(id(kw)), parent=base, **kw)

title_style   = S("Normal", fontSize=28, textColor=C_TITLE, alignment=TA_CENTER, fontName="Helvetica-Bold", spaceAfter=4)
subtitle_style= S("Normal", fontSize=11, textColor=C_MUTED, alignment=TA_CENTER, fontName="Helvetica", spaceAfter=14)
body_style    = S("Normal", fontSize=10, textColor=C_TEXT, fontName="Helvetica", spaceAfter=3, leading=15, alignment=TA_JUSTIFY)
bold_style    = S("Normal", fontSize=10, textColor=C_TEXT, fontName="Helvetica-Bold", spaceAfter=3, leading=15)
bullet_style  = S("Normal", fontSize=10, textColor=C_TEXT, fontName="Helvetica", spaceAfter=2, leading=14, leftIndent=14, bulletIndent=4)
sub_style     = S("Normal", fontSize=13, textColor=C_RED, fontName="Helvetica-Bold", spaceAfter=4, spaceBefore=10)
sub2_style    = S("Normal", fontSize=11, textColor=C_TEAL, fontName="Helvetica-Bold", spaceAfter=3, spaceBefore=6)
explain_style = S("Normal", fontSize=9.5, textColor=colors.HexColor("#4A148C"), fontName="Helvetica-Oblique", spaceAfter=3, leading=14, leftIndent=6)
table_header  = S("Normal", fontSize=10, textColor=colors.white, fontName="Helvetica-Bold", alignment=TA_CENTER)
table_cell    = S("Normal", fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", alignment=TA_CENTER, leading=13)
table_cell_l  = S("Normal", fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", alignment=TA_LEFT, leading=13)
flow_title    = S("Normal", fontSize=10, textColor=colors.white, fontName="Helvetica-Bold", alignment=TA_CENTER, leading=14)
flow_body     = S("Normal", fontSize=9,  textColor=C_TEXT, fontName="Helvetica", alignment=TA_CENTER, leading=13)
flow_arrow    = S("Normal", fontSize=16, textColor=C_ARROW, fontName="Helvetica-Bold", alignment=TA_CENTER)

story = []

# ── helpers ──────────────────────────────────────────────────────
def section_header(text, color=C_TITLE):
    data = [[Paragraph(text, S("Normal", fontSize=14, textColor=colors.white, fontName="Helvetica-Bold", alignment=TA_LEFT))]]
    t = Table(data, colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(-1,-1), color),
        ("TOPPADDING",   (0,0),(-1,-1), 7),
        ("BOTTOMPADDING",(0,0),(-1,-1), 7),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),
        ("RIGHTPADDING", (0,0),(-1,-1), 10),
    ]))
    return t

def info_box(title, paras, bg=C_BOX_BG, bd=C_BOX_BD):
    rows = []
    if title:
        rows.append([Paragraph(title, S("Normal", fontSize=10, textColor=bd, fontName="Helvetica-Bold"))])
    for p in paras:
        rows.append([p])
    t = Table(rows, colWidths=[W - 0.4*cm])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(-1,-1), bg),
        ("BOX",          (0,0),(-1,-1), 1.5, bd),
        ("TOPPADDING",   (0,0),(-1,-1), 6),
        ("BOTTOMPADDING",(0,0),(-1,-1), 6),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),
        ("RIGHTPADDING", (0,0),(-1,-1), 10),
    ]))
    return t

def bullet(text):
    return Paragraph(f"<bullet>&bull;</bullet> {text}", bullet_style)

def explain(text):
    return Paragraph(f"<i>&#9658; {text}</i>", explain_style)

def sp(n=6):
    return Spacer(1, n)

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

# ────────────────────────────────────────────────────────────────
# FLOWCHART HELPER — builds a visual box-arrow-box chain
# ────────────────────────────────────────────────────────────────
def flowchart_box(header_text, body_lines, header_color):
    """Single flowchart box."""
    body_text = "<br/>".join(body_lines)
    data = [
        [Paragraph(header_text, flow_title)],
        [Paragraph(body_text, flow_body)],
    ]
    t = Table(data, colWidths=[W * 0.82])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(0,0), header_color),
        ("BACKGROUND",   (0,1),(0,1), C_FLOW_BG),
        ("BOX",          (0,0),(-1,-1), 1.5, header_color),
        ("TOPPADDING",   (0,0),(-1,-1), 6),
        ("BOTTOMPADDING",(0,0),(-1,-1), 6),
        ("LEFTPADDING",  (0,0),(-1,-1), 8),
        ("RIGHTPADDING", (0,0),(-1,-1), 8),
        ("ALIGN",        (0,0),(-1,-1), "CENTER"),
    ]))
    # Center the table on the page
    wrapper = Table([[t]], colWidths=[W])
    wrapper.setStyle(TableStyle([
        ("ALIGN",  (0,0),(-1,-1), "CENTER"),
        ("LEFTPADDING",  (0,0),(-1,-1), 0),
        ("RIGHTPADDING", (0,0),(-1,-1), 0),
        ("TOPPADDING",   (0,0),(-1,-1), 0),
        ("BOTTOMPADDING",(0,0),(-1,-1), 0),
    ]))
    return wrapper

def arrow():
    return Paragraph("&#x25BC;", S("Normal", fontSize=18, textColor=C_ARROW,
                                    fontName="Helvetica-Bold", alignment=TA_CENTER, spaceAfter=0))

# ════════════════════════════════════════════════════════════════
# PAGE 1 — TITLE + OVERVIEW
# ════════════════════════════════════════════════════════════════
story.append(Spacer(1, 1.2*cm))
story.append(Paragraph("TYPHOID FEVER", title_style))
story.append(Paragraph("(Enteric Fever) — Comprehensive Study Notes", subtitle_style))
story.append(HRFlowable(width="60%", thickness=2, color=C_TITLE, hAlign="CENTER"))
story.append(sp(10))

overview_data = [
    [Paragraph("Feature", table_header), Paragraph("Details", table_header)],
    [Paragraph("Other name",   table_cell), Paragraph("Enteric Fever", table_cell_l)],
    [Paragraph("Causative agent", table_cell), Paragraph("Salmonella Typhi (bacterium)", table_cell_l)],
    [Paragraph("Mode of transmission", table_cell), Paragraph("Fecal-oral route / urine-oral route", table_cell_l)],
    [Paragraph("Site of infection", table_cell), Paragraph("Small intestine (Peyer's patches)", table_cell_l)],
    [Paragraph("Incubation period", table_cell), Paragraph("10–14 days", table_cell_l)],
    [Paragraph("Most affected", table_cell), Paragraph("Children; endemic in SE Asia, Africa", table_cell_l)],
    [Paragraph("Paratyphoid", table_cell), Paragraph("Salmonella Paratyphi — milder form", table_cell_l)],
]
ov_t = Table(overview_data, colWidths=[5*cm, W - 5*cm])
ov_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_TITLE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [C_BOX_BG, colors.white]),
    ("BOX",           (0,0),(-1,-1), 1, C_TITLE),
    ("INNERGRID",     (0,0),(-1,-1), 0.5, C_LINE),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 8),
    ("VALIGN",        (0,0),(-1,-1), "MIDDLE"),
]))
story.append(ov_t)
story.append(sp(8))

# ════════════════════════════════════════════════════════════════
# SECTION 1 — INTRODUCTION
# ════════════════════════════════════════════════════════════════
story.append(section_header("1.  INTRODUCTION"))
story.append(sp(6))
story.append(Paragraph(
    "Typhoid fever (enteric fever) is a <b>systemic bacterial infection</b> caused by "
    "<b><i>Salmonella enterica</i> serovar Typhi</b>. The bacteria live in the <b>bloodstream and "
    "intestines</b> of infected people and spread through contaminated food and water.",
    body_style))
story.append(sp(4))

key_pts = [
    "Highly contagious — spread via fecal-oral route",
    "Common in <b>developing countries</b> (SE Asia, Africa, South Asia) — rare in US, Canada, Japan, W. Europe, Australia",
    "<b>Children</b> are more affected than adults",
    "<b>Paratyphoid fever</b> (caused by <i>S. Paratyphi</i>) is similar but milder",
    "<b>Salmonellosis</b> is different — it is food poisoning caused by non-typhoidal Salmonella",
]
for k in key_pts:
    story.append(bullet(k))

story.append(sp(4))
story.append(info_box("Salmonella Typhi vs Salmonellosis — Key Difference",
    [Paragraph(
        "<b>Typhoid fever (S. Typhi):</b> Systemic infection — bacteria enter blood (bacteremia), spread to liver, spleen, bone marrow. "
        "Causes prolonged high fever, rose spots, relative bradycardia.<br/>"
        "<b>Salmonellosis (non-typhoidal Salmonella):</b> Localized gut infection — causes self-limiting gastroenteritis "
        "(diarrhea, vomiting) lasting 3–7 days. Does NOT cause sustained bacteremia.",
        body_style)
    ], bg=C_BOX_BG, bd=C_BOX_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 2 — CAUSE & TRANSMISSION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("2.  CAUSE & ROUTE OF TRANSMISSION", color=C_HEAD))
story.append(sp(6))

story.append(Paragraph("Causative Organism", sub_style))
story.append(bullet("<b><i>Salmonella Typhi</i></b> — Gram-negative, motile, rod-shaped (bacillus) bacterium"))
story.append(bullet("Lives in <b>bloodstream and intestines</b> of infected individuals"))
story.append(bullet("Can contaminate food and water sources"))
story.append(sp(6))

story.append(Paragraph("Mode of Transmission", sub_style))
trans_data = [
    [Paragraph("Route", table_header), Paragraph("How it happens", table_header)],
    [Paragraph("Fecal-oral (main)", table_cell_l), Paragraph("Eating food/water contaminated with feces of infected person", table_cell_l)],
    [Paragraph("Urine-oral (less common)", table_cell_l), Paragraph("Contamination via urine of infected/carrier person", table_cell_l)],
    [Paragraph("Unpasteurized milk/juice", table_cell_l), Paragraph("Dairy or juice not heat-treated can harbor S. Typhi", table_cell_l)],
    [Paragraph("Poor hand hygiene", table_cell_l), Paragraph("Not washing hands after toilet, before cooking/eating", table_cell_l)],
    [Paragraph("Poor sanitation", table_cell_l), Paragraph("Open defecation, untreated sewage contaminating water supply", table_cell_l)],
]
trans_t = Table(trans_data, colWidths=[4.5*cm, W - 4.5*cm])
trans_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_HEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BLUE_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_HEAD),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#BBDEFB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6),
    ("VALIGN",        (0,0),(-1,-1), "TOP"),
]))
story.append(trans_t)
story.append(sp(4))

story.append(info_box("Chronic Carrier — Important Concept",
    [Paragraph(
        "A person can continue to spread typhoid even when <b>asymptomatic or apparently recovered</b>. "
        "The bacteria persist in the <b>gallbladder</b> (biliary carrier). They shed S. Typhi in feces for months-years.<br/>"
        "<b>Famous example:</b> 'Typhoid Mary' — an asymptomatic cook who infected 51 people.<br/>"
        "<b>Clinical implication:</b> Always test stool culture after recovery. Carriers need prolonged antibiotic treatment.",
        body_style)
    ], bg=C_WARN_BG, bd=C_WARN_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 3 — PATHOLOGY FLOWCHART
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("3.  PATHOLOGY — STEP-BY-STEP FLOWCHART", color=colors.HexColor("#6A1B9A")))
story.append(sp(8))

story.append(Paragraph(
    "The pathology of typhoid fever follows a stepwise progression from ingestion to systemic disease:",
    body_style))
story.append(sp(8))

# ── flowchart boxes ──────────────────────────────────────────────
STEP_COLORS = [
    colors.HexColor("#6A1B9A"),  # 1 dark purple
    colors.HexColor("#1565C0"),  # 2 dark blue
    colors.HexColor("#00695C"),  # 3 dark teal
    colors.HexColor("#E65100"),  # 4 dark orange
    colors.HexColor("#B71C1C"),  # 5 dark red
    colors.HexColor("#4527A0"),  # 6 deep purple
    colors.HexColor("#283593"),  # 7 indigo
    colors.HexColor("#1B5E20"),  # 8 dark green
]

steps = [
    (
        "STEP 1 — Ingestion of S. Typhi",
        [
            "Person ingests food/water contaminated with Salmonella Typhi",
            "Infective dose: ~10³ – 10⁶ organisms needed",
            "Bacteria survive stomach acid (acid-tolerant)"
        ]
    ),
    (
        "STEP 2 — Invasion of Small Intestine (Ileum)",
        [
            "S. Typhi reaches the distal ileum (terminal ileum)",
            "Bacteria attach to and penetrate the intestinal epithelium",
            "They target M cells (microfold cells) overlying Peyer's patches",
            "Peyer's patches = lymphoid tissue in the gut wall"
        ]
    ),
    (
        "STEP 3 — Entry into Lymphoid Tissue",
        [
            "Bacteria replicate inside macrophages in Peyer's patches",
            "Cause characteristic swelling/hypertrophy of Peyer's patches",
            "Local inflammation → lymphadenopathy of mesenteric lymph nodes",
        ]
    ),
    (
        "STEP 4 — Primary Bacteremia (1st Week)",
        [
            "Bacteria escape from lymph nodes into the thoracic duct",
            "Enter the bloodstream → PRIMARY BACTEREMIA",
            "Spread to liver, spleen, bone marrow, gallbladder",
            "Patient develops high fever, malaise — incubation phase ends"
        ]
    ),
    (
        "STEP 5 — Intracellular Multiplication in Organs (1–2nd Week)",
        [
            "S. Typhi multiplies inside macrophages in liver (Kupffer cells),",
            "spleen, bone marrow — evading immune detection",
            "Hepatosplenomegaly develops",
            "Bacteria re-enter bloodstream → SECONDARY BACTEREMIA (larger)",
            "This causes the sustained high fever of typhoid"
        ]
    ),
    (
        "STEP 6 — Re-infection of Gut via Bile",
        [
            "Bacteria excreted in bile from gallbladder → back into intestine",
            "Re-infect already sensitized Peyer's patches",
            "Hypersensitivity reaction → NECROSIS of Peyer's patches",
            "Necrotic patches slough off → ulcers form in the intestinal wall"
        ]
    ),
    (
        "STEP 7 — Intestinal Ulceration & Complications (2nd–3rd Week)",
        [
            "Ulcers in terminal ileum can cause:",
            "• Intestinal hemorrhage (bleeding from ulcers → bloody stools)",
            "• Intestinal perforation (hole in gut wall) → life-threatening peritonitis",
            "Rose spots (salmon-colored skin rash) appear on trunk",
            "— caused by bacteria in skin capillaries + immune response"
        ]
    ),
    (
        "STEP 8 — Resolution OR Complications (3rd–4th Week)",
        [
            "With treatment: fever subsides, ulcers heal, recovery in 3–4 weeks",
            "Without treatment / resistant strains:",
            "• Sepsis → multi-organ failure",
            "• Mental status changes (toxic encephalopathy)",
            "• Carrier state — bacteria persist in gallbladder for months–years"
        ]
    ),
]

for i, (header, lines) in enumerate(steps):
    story.append(flowchart_box(header, lines, STEP_COLORS[i % len(STEP_COLORS)]))
    if i < len(steps) - 1:
        story.append(sp(2))
        story.append(arrow())
        story.append(sp(2))

story.append(sp(8))

# Outcome box
outcome_data = [[
    Paragraph("RECOVERY\n(with treatment)", S("Normal", fontSize=9, textColor=C_SUBHEAD,
              fontName="Helvetica-Bold", alignment=TA_CENTER)),
    Paragraph("OR", S("Normal", fontSize=12, textColor=C_TEXT,
              fontName="Helvetica-Bold", alignment=TA_CENTER)),
    Paragraph("COMPLICATIONS\n(untreated/resistant)", S("Normal", fontSize=9, textColor=C_RED,
              fontName="Helvetica-Bold", alignment=TA_CENTER)),
]]
out_t = Table(outcome_data, colWidths=[W*0.42, W*0.1, W*0.42])
out_t.setStyle(TableStyle([
    ("BACKGROUND",   (0,0),(0,0), C_GREEN_BG),
    ("BACKGROUND",   (2,0),(2,0), C_RED_BG),
    ("BOX",          (0,0),(0,0), 1.5, C_GREEN_BD),
    ("BOX",          (2,0),(2,0), 1.5, C_RED_BD),
    ("TOPPADDING",   (0,0),(-1,-1), 10),
    ("BOTTOMPADDING",(0,0),(-1,-1), 10),
    ("LEFTPADDING",  (0,0),(-1,-1), 6),
    ("VALIGN",       (0,0),(-1,-1), "MIDDLE"),
]))
story.append(out_t)

# ════════════════════════════════════════════════════════════════
# SECTION 4 — SIGNS & SYMPTOMS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("4.  SIGNS & SYMPTOMS", color=colors.HexColor("#7B1FA2")))
story.append(sp(6))

story.append(Paragraph(
    "<b>Incubation period: 10–14 days</b> (range 6–30 days depending on inoculum size)",
    bold_style))
story.append(sp(4))

symp_data = [
    [Paragraph("SYMPTOMS", table_header), Paragraph("COMPLICATIONS (if untreated)", table_header)],
    [Paragraph(
        "• High fever (stepladder pattern — rises daily)\n"
        "• Chills\n"
        "• Headache\n"
        "• Weakness\n"
        "• Fatigue and muscle ache\n"
        "• Stomach pain\n"
        "• Diarrhea OR constipation\n"
        "• Loss of appetite and sweating\n"
        "• Skin rash (rose spots on trunk)\n"
        "• Cough (due to bacteremia)",
        S("Normal", fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", leading=15)),
     Paragraph(
        "• Severe stomach pain\n"
        "• Swollen abdomen\n"
        "• Intestinal bleeding & perforation\n"
        "• Spread of infection to other organs\n"
        "• Sepsis (life-threatening)\n"
        "• Mental status changes\n  (confusion, delirium — 'typhoid state')",
        S("Normal", fontSize=9.5, textColor=C_RED, fontName="Helvetica", leading=15)),
    ]
]
symp_t = Table(symp_data, colWidths=[W/2, W/2])
symp_t.setStyle(TableStyle([
    ("BACKGROUND",   (0,0),(-1,0), colors.HexColor("#7B1FA2")),
    ("BACKGROUND",   (0,1),(0,1),  C_BLUE_BG),
    ("BACKGROUND",   (1,1),(1,1),  C_RED_BG),
    ("BOX",          (0,0),(-1,-1), 1, colors.HexColor("#4A148C")),
    ("LINEAFTER",    (0,0),(0,-1),  1, colors.HexColor("#CE93D8")),
    ("TOPPADDING",   (0,0),(-1,-1), 7),
    ("BOTTOMPADDING",(0,0),(-1,-1), 7),
    ("LEFTPADDING",  (0,0),(-1,-1), 8),
    ("VALIGN",       (0,0),(-1,-1), "TOP"),
]))
story.append(symp_t)
story.append(sp(4))

story.append(info_box("Stepladder Fever Pattern",
    [Paragraph(
        "Typhoid fever is classically described as having a <b>'stepladder' fever pattern</b> — temperature rises "
        "progressively by ~0.5°C each day during the 1st week, peaking at 39–40°C, then remaining high. "
        "This corresponds to the waves of bacteremia as bacteria multiply in organs and re-enter blood.",
        body_style)
    ], bg=C_WARN_BG, bd=C_WARN_BD))
story.append(sp(3))
story.append(info_box("Rose Spots",
    [Paragraph(
        "<b>Rose spots</b> — salmon-pink, slightly raised, blanching macules (2–4mm) found on the <b>trunk and abdomen</b>. "
        "They appear in 20–30% of patients during the 1st–2nd week and are caused by bacterial emboli in skin capillaries. "
        "They are pathognomonic (characteristic) of typhoid fever.",
        body_style)
    ], bg=C_BOX_BG, bd=C_BOX_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 5 — DIAGNOSIS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("5.  DIAGNOSTIC TESTS", color=C_TEAL))
story.append(sp(6))

diag_data = [
    [Paragraph("Test", table_header), Paragraph("What it does", table_header), Paragraph("Notes", table_header)],
    [Paragraph("Blood Culture", table_cell_l),
     Paragraph("Gold standard — grows S. Typhi from blood", table_cell_l),
     Paragraph("Most positive in Week 1 (bacteremia phase); sensitivity ~60–80%", table_cell_l)],
    [Paragraph("Stool Culture", table_cell_l),
     Paragraph("Grows S. Typhi from stool", table_cell_l),
     Paragraph("Best in Week 2–3; useful for detecting carriers", table_cell_l)],
    [Paragraph("Widal Test", table_cell_l),
     Paragraph("Rapid blood test — detects antibodies (agglutinins) against S. Typhi antigens (O and H)", table_cell_l),
     Paragraph("Most common rapid test; UNRELIABLE — cross-reacts with other infections, vaccinations; gives false positives", table_cell_l)],
    [Paragraph("IgM Test (Typhidot)", table_cell_l),
     Paragraph("Detects IgM antibodies specific to S. Typhi outer membrane protein (OMP)", table_cell_l),
     Paragraph("More specific than Widal; positive from Day 4–5 of illness", table_cell_l)],
    [Paragraph("Real-time PCR", table_cell_l),
     Paragraph("Detects S. Typhi DNA directly in blood", table_cell_l),
     Paragraph("Highly sensitive and specific; rapid; expensive; available in reference labs", table_cell_l)],
    [Paragraph("CBC", table_cell_l),
     Paragraph("Blood count", table_cell_l),
     Paragraph("Leukopenia (low WBCs) — characteristic of typhoid; also anemia, thrombocytopenia", table_cell_l)],
]
diag_t = Table(diag_data, colWidths=[3.5*cm, 6*cm, W - 9.5*cm])
diag_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_TEAL),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, colors.HexColor("#E0F2F1")]),
    ("BOX",           (0,0),(-1,-1), 1, C_TEAL),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#B2DFDB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6),
    ("VALIGN",        (0,0),(-1,-1), "TOP"),
]))
story.append(diag_t)
story.append(sp(4))
story.append(info_box("Why is the Widal test unreliable?",
    [Paragraph(
        "The Widal test measures agglutinating antibodies against S. Typhi <b>O antigen</b> (somatic) and <b>H antigen</b> (flagellar). "
        "Problems: <br/>"
        "1. <b>Cross-reactivity</b> — antibodies from other Salmonella infections, malaria, dengue, liver disease can give false positives<br/>"
        "2. <b>Prior vaccination</b> — typhoid vaccine raises H antibody titers, causing false positives<br/>"
        "3. <b>Early disease</b> — antibodies not yet formed in first 5–7 days (false negative)<br/>"
        "Despite this, it remains widely used in resource-limited settings due to low cost.",
        body_style)
    ], bg=C_WARN_BG, bd=C_WARN_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 6 — TREATMENT
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("6.  MEDICAL TREATMENT", color=C_ORANGE))
story.append(sp(6))

story.append(Paragraph(
    "Treatment is with <b>antibiotics</b>. The choice depends on local resistance patterns. "
    "Antibiotic resistance (including multidrug-resistant/MDR typhoid) is a major global concern.",
    body_style))
story.append(sp(6))

abx_data = [
    [Paragraph("Antibiotic Class", table_header), Paragraph("Example", table_header),
     Paragraph("Mechanism", table_header), Paragraph("Notes", table_header)],
    [Paragraph("Fluoroquinolones\n(1st choice)", table_cell_l),
     Paragraph("Ciprofloxacin\nOfloxacin", table_cell_l),
     Paragraph("Inhibit DNA gyrase (topoisomerase II/IV) → stop bacterial DNA replication and cell division", table_cell_l),
     Paragraph("First choice for uncomplicated typhoid; resistance increasing (especially in Asia)", table_cell_l)],
    [Paragraph("3rd-Gen Cephalosporins", table_cell_l),
     Paragraph("Ceftriaxone\nCefixime", table_cell_l),
     Paragraph("Inhibit penicillin-binding proteins → block bacterial cell wall (peptidoglycan) synthesis → cell lysis", table_cell_l),
     Paragraph("IV Ceftriaxone for severe/MDR typhoid; Cefixime oral for uncomplicated", table_cell_l)],
    [Paragraph("Macrolides", table_cell_l),
     Paragraph("Azithromycin", table_cell_l),
     Paragraph("Bind 50S ribosomal subunit → inhibit translocation → stop bacterial protein synthesis", table_cell_l),
     Paragraph("Useful for uncomplicated typhoid, esp. resistant cases; concentrates inside cells (useful for intracellular S. Typhi)", table_cell_l)],
    [Paragraph("Carbapenems\n(last resort)", table_cell_l),
     Paragraph("Imipenem\nMeropenem", table_cell_l),
     Paragraph("Beta-lactam — prevent bacterial cell wall cross-linking; resistant to beta-lactamase enzymes", table_cell_l),
     Paragraph("Reserved for extensively drug-resistant (XDR) typhoid; IV only", table_cell_l)],
]
abx_t = Table(abx_data, colWidths=[3.5*cm, 3*cm, 6*cm, W - 12.5*cm])
abx_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_ORANGE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_WARN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_ORANGE),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#FFE0B2")),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6),
    ("VALIGN",        (0,0),(-1,-1), "TOP"),
]))
story.append(abx_t)
story.append(sp(4))

story.append(Paragraph("Supportive Treatment", sub2_style))
support = [
    "Adequate <b>hydration</b> — IV fluids if dehydrated",
    "Antipyretics (paracetamol) for fever control",
    "<b>Dexamethasone</b> (corticosteroid) in severe typhoid with altered consciousness or shock — reduces mortality",
    "Surgical intervention for intestinal perforation (emergency surgery)",
    "Dietary: soft, easily digestible food; avoid high-fiber to reduce risk of perforation",
]
for s in support:
    story.append(bullet(s))

# ════════════════════════════════════════════════════════════════
# SECTION 7 — PREVENTION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("7.  PREVENTION", color=C_SUBHEAD))
story.append(sp(6))

story.append(Paragraph("A. Vaccines Against S. Typhi", sub_style))
story.append(sp(3))

vax_data = [
    [Paragraph("Vaccine", table_header), Paragraph("Type", table_header),
     Paragraph("Dosing", table_header), Paragraph("Age", table_header), Paragraph("Duration", table_header)],
    [Paragraph("Inactivated typhoid vaccine (Vi-PS)", table_cell_l),
     Paragraph("Injectable\n(killed bacteria)", table_cell),
     Paragraph("Single IM dose; booster every 2 years", table_cell),
     Paragraph("≥2 years", table_cell),
     Paragraph("2–3 years", table_cell)],
    [Paragraph("Live attenuated typhoid vaccine (Ty21a)", table_cell_l),
     Paragraph("Oral\n(live weakened)", table_cell),
     Paragraph("4 doses over 1 week (Day 1,3,5,7)", table_cell),
     Paragraph("≥6 years", table_cell),
     Paragraph("~5 years", table_cell)],
    [Paragraph("Tybar-TCV (Typhoid Conjugate Vaccine)", table_cell_l),
     Paragraph("Injectable\n(conjugate)", table_cell),
     Paragraph("Single 0.5 ml IM dose; booster after 5 years", table_cell),
     Paragraph("≥6 months", table_cell),
     Paragraph("Long-term", table_cell)],
]
vax_t = Table(vax_data, colWidths=[4*cm, 2.8*cm, 4*cm, 2*cm, W - 12.8*cm])
vax_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_SUBHEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_GREEN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_SUBHEAD),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#C8E6C9")),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6),
    ("VALIGN",        (0,0),(-1,-1), "MIDDLE"),
]))
story.append(vax_t)
story.append(sp(4))

story.append(info_box("Tybar-TCV — Important (India Focus)",
    [Paragraph(
        "<b>Tybar-TCV</b> (by Bharat Biotech) is a <b>Vi-polysaccharide conjugated to tetanus toxoid</b>. "
        "Because it is conjugated, it produces T-cell dependent immunity — providing <b>long-lasting protection even in infants</b> "
        "(unlike the older Vi-PS vaccine which only works in children ≥2 years). "
        "It can be given from <b>6 months of age</b> as a <b>single 0.5 ml IM injection</b>. "
        "It is being rolled out in India's National Immunization Schedule.",
        body_style)
    ], bg=C_GREEN_BG, bd=C_GREEN_BD))
story.append(sp(4))

story.append(Paragraph("B. Non-Vaccine Prevention", sub_style))
non_vax = [
    "<b>Hand washing</b> — with soap and water before eating/cooking and after toilet use",
    "Drink <b>safe/treated water</b> — boil or use purified water in endemic areas",
    "Eat <b>properly cooked food</b> — avoid raw vegetables, street food in endemic areas",
    "Avoid unpasteurized milk or juice",
    "Proper sewage treatment and waste disposal",
    "Screen and treat <b>chronic carriers</b> — do not allow them to handle food professionally until culture-negative",
]
for n in non_vax:
    story.append(bullet(n))

# ════════════════════════════════════════════════════════════════
# SECTION 8 — QUICK REVISION TABLE
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(section_header("8.  QUICK REVISION — KEY FACTS", color=colors.HexColor("#283593")))
story.append(sp(6))

qr_data = [
    [Paragraph("Topic", table_header), Paragraph("Key Fact", table_header)],
    [Paragraph("Causative organism", table_cell_l), Paragraph("Salmonella Typhi (Gram-negative rod)", table_cell_l)],
    [Paragraph("Mode of transmission", table_cell_l), Paragraph("Fecal-oral route (contaminated food/water)", table_cell_l)],
    [Paragraph("Incubation period", table_cell_l), Paragraph("10–14 days", table_cell_l)],
    [Paragraph("Pathology key step", table_cell_l), Paragraph("S. Typhi invades M cells → Peyer's patches → bacteremia → organs", table_cell_l)],
    [Paragraph("Characteristic fever pattern", table_cell_l), Paragraph("Stepladder fever rising each day", table_cell_l)],
    [Paragraph("Skin finding", table_cell_l), Paragraph("Rose spots (salmon-pink macules on trunk)", table_cell_l)],
    [Paragraph("CBC finding", table_cell_l), Paragraph("Leukopenia (low WBC) — characteristic", table_cell_l)],
    [Paragraph("Gold standard diagnosis", table_cell_l), Paragraph("Blood culture (Week 1)", table_cell_l)],
    [Paragraph("Widal test limitation", table_cell_l), Paragraph("Cross-reacts with other infections — not reliable alone", table_cell_l)],
    [Paragraph("1st-line antibiotic", table_cell_l), Paragraph("Fluoroquinolones (Ciprofloxacin)", table_cell_l)],
    [Paragraph("MDR typhoid treatment", table_cell_l), Paragraph("Ceftriaxone IV or Azithromycin oral", table_cell_l)],
    [Paragraph("XDR typhoid treatment", table_cell_l), Paragraph("Carbapenems (Meropenem)", table_cell_l)],
    [Paragraph("Chronic carrier site", table_cell_l), Paragraph("Gallbladder — bacteria persist here", table_cell_l)],
    [Paragraph("Best vaccine for infants", table_cell_l), Paragraph("Tybar-TCV (Vi-conjugate) — from 6 months", table_cell_l)],
    [Paragraph("Serious complication", table_cell_l), Paragraph("Intestinal perforation → peritonitis → sepsis", table_cell_l)],
]
qr_t = Table(qr_data, colWidths=[5*cm, W - 5*cm])
qr_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  colors.HexColor("#283593")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BLUE_BG]),
    ("BOX",           (0,0),(-1,-1), 1, colors.HexColor("#1A237E")),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#BBDEFB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 8),
    ("VALIGN",        (0,0),(-1,-1), "TOP"),
]))
story.append(qr_t)

story.append(sp(14))
story.append(HRFlowable(width="100%", thickness=1, color=C_LINE))
story.append(sp(4))
story.append(Paragraph("— End of Typhoid Fever Notes —",
    S("Normal", fontSize=11, textColor=C_MUTED, alignment=TA_CENTER, fontName="Helvetica")))

# BUILD
doc.build(story)
print(f"PDF saved to {OUTPUT}")
Running Command

cd /tmp/workspace/malaria-notes && python generate_typhoid_notes.py 2>&1

Running Command

ls -lh /tmp/workspace/malaria-notes/Typhoid_Fever_Notes.pdf

Your Typhoid Fever PDF is ready! Download it here:

Typhoid Fever Notes

PDF Document · PDF


Here's what the PDF contains across 8 sections:

1. Introduction

  • S. Typhi vs Salmonellosis — key difference explained
  • Endemic regions, paratyphoid comparison

2. Cause & Transmission

  • Fecal-oral/urine-oral routes in a color table
  • Chronic Carrier concept explained (Typhoid Mary, gallbladder reservoir)

3. Pathology — 8-Step Flowchart (box → arrow → box)

StepWhat Happens
1Ingestion of S. Typhi (survives stomach acid)
2Invades ileum via M cells over Peyer's patches
3Replicates in lymphoid tissue → mesenteric lymphadenopathy
4Primary bacteremia (Week 1) → liver, spleen, bone marrow
5Intracellular multiplication in Kupffer cells → secondary bacteremia
6Bacteria re-enter gut via bile → re-infect Peyer's patches → necrosis
7Ulcers form → hemorrhage or perforation → rose spots
8Resolution (with Rx) OR sepsis/carrier state (without Rx)

4. Signs & Symptoms

  • Stepladder fever pattern explained
  • Rose spots explained
  • Complications side-by-side table

5. Diagnostic Tests

  • Blood culture (gold standard, Week 1)
  • Widal test limitations fully explained
  • IgM Typhidot, PCR, Stool culture

6. Treatment — Antibiotics Explained

DrugMechanismUse
Fluoroquinolones (Cipro)Inhibit DNA gyrase1st choice
CeftriaxoneBlock cell wall synthesisMDR typhoid
AzithromycinInhibit protein synthesisResistant cases
CarbapenemsCell wall (beta-lactamase resistant)XDR typhoid

7. Prevention — Vaccines Table

  • Inactivated (Vi-PS), Live oral (Ty21a), Tybar-TCV (from 6 months) fully explained

8. Quick Revision — 15 Key Facts Table

attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment

Make pdf for this as u did for above Pathophysiology in flow chart form

Writing File

~/malaria-notes/generate_influenza_notes.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
)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY

OUTPUT = "/tmp/workspace/malaria-notes/Influenza_Notes.pdf"

doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    rightMargin=2*cm, leftMargin=2*cm,
    topMargin=2*cm, bottomMargin=2*cm,
    title="Influenza (Flu) - Comprehensive Notes"
)

W = A4[0] - 4*cm

# ── Colors ──────────────────────────────────────────────────────
C_TITLE   = colors.HexColor("#4A148C")   # deep purple
C_HEAD    = colors.HexColor("#1565C0")   # dark blue
C_SUBHEAD = colors.HexColor("#1B5E20")   # dark green
C_ORANGE  = colors.HexColor("#E65100")
C_RED     = colors.HexColor("#B71C1C")
C_TEAL    = colors.HexColor("#00695C")
C_INDIGO  = colors.HexColor("#283593")
C_BOX_BG  = colors.HexColor("#EDE7F6")
C_BOX_BD  = colors.HexColor("#4A148C")
C_WARN_BG = colors.HexColor("#FFF3E0")
C_WARN_BD = colors.HexColor("#E65100")
C_RED_BG  = colors.HexColor("#FFEBEE")
C_RED_BD  = colors.HexColor("#C62828")
C_GREEN_BG= colors.HexColor("#E8F5E9")
C_GREEN_BD= colors.HexColor("#2E7D32")
C_BLUE_BG = colors.HexColor("#E3F2FD")
C_BLUE_BD = colors.HexColor("#1565C0")
C_TEXT    = colors.HexColor("#212121")
C_MUTED   = colors.HexColor("#555555")
C_LINE    = colors.HexColor("#B39DDB")

# flowchart step colors
FLOW_COLORS = [
    colors.HexColor("#4527A0"),  # step 1 – entry
    colors.HexColor("#1565C0"),  # step 2 – attachment
    colors.HexColor("#006064"),  # step 3 – replication
    colors.HexColor("#00695C"),  # step 4 – release
    colors.HexColor("#E65100"),  # step 5 – inflammation
    colors.HexColor("#B71C1C"),  # step 6 – epithelial death
    colors.HexColor("#4E342E"),  # step 7 – secondary infection
]

# ── Style factory ────────────────────────────────────────────────
_styles = getSampleStyleSheet()
def S(**kw):
    return ParagraphStyle("_" + str(id(kw)), parent=_styles["Normal"], **kw)

title_s  = S(fontSize=28, textColor=C_TITLE, alignment=TA_CENTER, fontName="Helvetica-Bold", spaceAfter=4)
sub_s    = S(fontSize=11, textColor=C_MUTED, alignment=TA_CENTER, fontName="Helvetica", spaceAfter=14)
body_s   = S(fontSize=10, textColor=C_TEXT,  fontName="Helvetica", spaceAfter=3, leading=15, alignment=TA_JUSTIFY)
bold_s   = S(fontSize=10, textColor=C_TEXT,  fontName="Helvetica-Bold", spaceAfter=3, leading=15)
bul_s    = S(fontSize=10, textColor=C_TEXT,  fontName="Helvetica", spaceAfter=2, leading=14, leftIndent=14, bulletIndent=4)
sec_s    = S(fontSize=13, textColor=C_RED,   fontName="Helvetica-Bold", spaceAfter=4, spaceBefore=10)
sub2_s   = S(fontSize=11, textColor=C_TEAL,  fontName="Helvetica-Bold", spaceAfter=3, spaceBefore=6)
exp_s    = S(fontSize=9.5, textColor=colors.HexColor("#4A148C"), fontName="Helvetica-Oblique",
             spaceAfter=3, leading=14, leftIndent=6)
th_s     = S(fontSize=10, textColor=colors.white, fontName="Helvetica-Bold", alignment=TA_CENTER)
tc_s     = S(fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", alignment=TA_CENTER, leading=13)
tcl_s    = S(fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", alignment=TA_LEFT,   leading=13)
flow_h_s = S(fontSize=10,  textColor=colors.white, fontName="Helvetica-Bold", alignment=TA_CENTER, leading=14)
flow_b_s = S(fontSize=9.5, textColor=C_TEXT,       fontName="Helvetica",      alignment=TA_LEFT,   leading=14)
arrow_s  = S(fontSize=18,  textColor=colors.HexColor("#6A1B9A"), fontName="Helvetica-Bold", alignment=TA_CENTER, spaceAfter=0)

story = []

# ── Helpers ──────────────────────────────────────────────────────
def sec_hdr(text, color=C_TITLE):
    t = Table([[Paragraph(text, S(fontSize=14, textColor=colors.white,
               fontName="Helvetica-Bold", alignment=TA_LEFT))]], colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(-1,-1), color),
        ("TOPPADDING",   (0,0),(-1,-1), 7), ("BOTTOMPADDING",(0,0),(-1,-1), 7),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),("RIGHTPADDING", (0,0),(-1,-1), 10),
    ]))
    return t

def info_box(title, paras, bg=C_BOX_BG, bd=C_BOX_BD):
    rows = []
    if title:
        rows.append([Paragraph(title, S(fontSize=10, textColor=bd, fontName="Helvetica-Bold"))])
    for p in paras: rows.append([p])
    t = Table(rows, colWidths=[W-0.4*cm])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(-1,-1), bg),
        ("BOX",          (0,0),(-1,-1), 1.5, bd),
        ("TOPPADDING",   (0,0),(-1,-1), 6), ("BOTTOMPADDING",(0,0),(-1,-1), 6),
        ("LEFTPADDING",  (0,0),(-1,-1), 10),("RIGHTPADDING", (0,0),(-1,-1), 10),
    ]))
    return t

def bul(text): return Paragraph(f"<bullet>&bull;</bullet> {text}", bul_s)
def exp(text): return Paragraph(f"<i>&#9658; {text}</i>", exp_s)
def sp(n=6):   return Spacer(1, n)
def hr():      return HRFlowable(width="100%", thickness=0.8, color=C_LINE, spaceAfter=4, spaceBefore=4)
def arrow():   return Paragraph("&#x25BC;", arrow_s)

def flow_box(header, lines, color):
    """Single flowchart box — header bar + body."""
    body_html = "<br/>".join(lines)
    data = [
        [Paragraph(header, flow_h_s)],
        [Paragraph(body_html, flow_b_s)],
    ]
    inner = Table(data, colWidths=[W*0.84])
    inner.setStyle(TableStyle([
        ("BACKGROUND",   (0,0),(0,0), color),
        ("BACKGROUND",   (0,1),(0,1), colors.HexColor("#F3E5F5")),
        ("BOX",          (0,0),(-1,-1), 1.5, 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),
        ("ALIGN",        (0,0),(-1,-1), "CENTER"),
    ]))
    wrap = Table([[inner]], colWidths=[W])
    wrap.setStyle(TableStyle([
        ("ALIGN",        (0,0),(-1,-1), "CENTER"),
        ("LEFTPADDING",  (0,0),(-1,-1), 0),("RIGHTPADDING", (0,0),(-1,-1), 0),
        ("TOPPADDING",   (0,0),(-1,-1), 0),("BOTTOMPADDING",(0,0),(-1,-1), 0),
    ]))
    return wrap

# ════════════════════════════════════════════════════════════════
# TITLE
# ════════════════════════════════════════════════════════════════
story.append(Spacer(1, 1.2*cm))
story.append(Paragraph("INFLUENZA (FLU)", title_s))
story.append(Paragraph("Comprehensive Study Notes", sub_s))
story.append(HRFlowable(width="60%", thickness=2, color=C_TITLE, hAlign="CENTER"))
story.append(sp(10))

# Quick overview table
ov_data = [
    [Paragraph("Feature", th_s),        Paragraph("Details", th_s)],
    [Paragraph("Disease type", tc_s),   Paragraph("Acute viral respiratory infection", tcl_s)],
    [Paragraph("Causative agent", tc_s),Paragraph("Influenza virus (family Orthomyxoviridae) — single-stranded RNA virus", tcl_s)],
    [Paragraph("Types", tc_s),          Paragraph("A (most severe), B (seasonal), C (mild), D (animals only)", tcl_s)],
    [Paragraph("Reservoir", tc_s),      Paragraph("Humans (main); Birds & pigs (for Influenza A — pandemic source)", tcl_s)],
    [Paragraph("Transmission", tc_s),   Paragraph("Respiratory droplets, direct contact, fomites", tcl_s)],
    [Paragraph("Incubation period", tc_s), Paragraph("1–4 days (average 2 days)", tcl_s)],
    [Paragraph("Season", tc_s),         Paragraph("Predominantly winter (cold, dry air + indoor crowding)", tcl_s)],
]
ov_t = Table(ov_data, colWidths=[5*cm, W-5*cm])
ov_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_TITLE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [C_BOX_BG, colors.white]),
    ("BOX",           (0,0),(-1,-1), 1, C_TITLE),
    ("INNERGRID",     (0,0),(-1,-1), 0.5, C_LINE),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 8), ("VALIGN",(0,0),(-1,-1),"MIDDLE"),
]))
story.append(ov_t)
story.append(sp(8))

# ════════════════════════════════════════════════════════════════
# SECTION 1 – INTRODUCTION
# ════════════════════════════════════════════════════════════════
story.append(sec_hdr("1.  INTRODUCTION"))
story.append(sp(6))
story.append(Paragraph(
    "Influenza (flu) is an <b>acute viral respiratory infection</b> caused by the <b>influenza virus</b> "
    "(family <i>Orthomyxoviridae</i>), a <b>single-stranded negative-sense RNA virus</b>. "
    "It infects the upper and lower respiratory tract, causing sudden fever, body aches, cough, and fatigue. "
    "It spreads easily in communities (highly contagious), especially in winters.", body_s))
story.append(sp(6))

# Influenza types table
story.append(Paragraph("Influenza Virus Types", sec_s))
type_data = [
    [Paragraph("Type", th_s), Paragraph("Severity", th_s), Paragraph("Key Features", th_s)],
    [Paragraph("Type A", tcl_s), Paragraph("Most severe", tc_s),
     Paragraph("Causes epidemics AND pandemics. Infects humans, birds, pigs. Subtypes named by surface proteins: H (Hemagglutinin 1–18) and N (Neuraminidase 1–11). E.g., H1N1, H3N2, H5N1.", tcl_s)],
    [Paragraph("Type B", tcl_s), Paragraph("Moderate", tc_s),
     Paragraph("Causes seasonal outbreaks only. Milder than Type A. Infects humans only (no animal reservoir). Two lineages: Victoria and Yamagata.", tcl_s)],
    [Paragraph("Type C", tcl_s), Paragraph("Mild", tc_s),
     Paragraph("Causes mild respiratory illness. No epidemics. Often in childhood — not included in seasonal flu vaccine.", tcl_s)],
    [Paragraph("Type D", tcl_s), Paragraph("N/A (animals)", tc_s),
     Paragraph("Affects cattle and pigs only. Does NOT cause disease in humans.", tcl_s)],
]
type_t = Table(type_data, colWidths=[2.2*cm, 2.5*cm, W-4.7*cm])
type_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_TITLE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BLUE_BG, colors.white, C_BLUE_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_TITLE),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, C_LINE),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(type_t)
story.append(sp(4))

story.append(info_box("Key Surface Proteins — Hemagglutinin (H) & Neuraminidase (N)",
    [Paragraph(
        "<b>Hemagglutinin (H):</b> Allows the virus to ATTACH to host respiratory epithelial cells (binds sialic acid receptors). "
        "Target of neutralizing antibodies — basis of vaccine protection.<br/>"
        "<b>Neuraminidase (N):</b> Allows newly formed viruses to ESCAPE (cleave sialic acid bonds) from infected cells and spread to new cells. "
        "Target of antiviral drugs — Oseltamivir (Tamiflu) and Zanamivir inhibit neuraminidase.",
        body_s)
    ], bg=C_BOX_BG, bd=C_BOX_BD))
story.append(sp(4))

story.append(info_box("Why Annual Flu Vaccine?",
    [Paragraph(
        "Influenza virus undergoes two types of genetic change:<br/>"
        "<b>Antigenic Drift</b> — small, gradual mutations in H and N surface proteins each season → old vaccine becomes less effective.<br/>"
        "<b>Antigenic Shift</b> — sudden, major reassortment of gene segments (usually from animal reservoirs) → entirely new H/N combination → "
        "pandemic potential (e.g., H1N1 'Swine Flu' 2009, H5N1 'Bird Flu'). "
        "This is why the flu vaccine is reformulated EVERY YEAR.",
        body_s)
    ], bg=C_WARN_BG, bd=C_WARN_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 2 – TRANSMISSION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("2.  MODE OF TRANSMISSION", color=C_HEAD))
story.append(sp(6))

trans_data = [
    [Paragraph("Route", th_s), Paragraph("How it occurs", th_s), Paragraph("Range/Details", th_s)],
    [Paragraph("Respiratory droplets\n(main route)", tcl_s),
     Paragraph("Coughing, sneezing, talking release virus-laden droplets (>5 µm)", tcl_s),
     Paragraph("Short range: ~1–2 metres; land directly on mucosa of nearby person", tcl_s)],
    [Paragraph("Direct contact", tcl_s),
     Paragraph("Touching infected person's secretions (e.g., handshake, then touching face)", tcl_s),
     Paragraph("Virus survives on hands for ~5 minutes", tcl_s)],
    [Paragraph("Fomites\n(indirect contact)", tcl_s),
     Paragraph("Contaminated surfaces (doorknobs, phones) → hands → nose/mouth", tcl_s),
     Paragraph("Virus survives on hard surfaces up to 24 hours", tcl_s)],
    [Paragraph("Airborne (minor)", tcl_s),
     Paragraph("Small aerosols (<5 µm) can remain suspended in air; more relevant in enclosed spaces", tcl_s),
     Paragraph("Important in healthcare settings", tcl_s)],
]
trans_t = Table(trans_data, colWidths=[3.5*cm, 6*cm, W-9.5*cm])
trans_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_HEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BLUE_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_HEAD),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#BBDEFB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(trans_t)
story.append(sp(4))
story.append(info_box("Incubation Period",
    [Paragraph(
        "<b>1–4 days (average 2 days)</b>. "
        "Adults are infectious from <b>1 day before</b> symptoms appear to <b>5–7 days after</b>. "
        "Children and immunocompromised can shed virus for longer (up to 10+ days). "
        "This means people spread flu BEFORE they know they are sick — making containment difficult.",
        body_s)
    ], bg=C_BLUE_BG, bd=C_BLUE_BD))

# ════════════════════════════════════════════════════════════════
# SECTION 3 – PATHOPHYSIOLOGY FLOWCHART
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("3.  PATHOPHYSIOLOGY — STEP-BY-STEP FLOWCHART", color=colors.HexColor("#6A1B9A")))
story.append(sp(6))
story.append(Paragraph(
    "The pathophysiology of influenza follows a precise molecular sequence from viral entry to clinical symptoms:",
    body_s))
story.append(sp(8))

steps = [
    (
        "STEP 1 — Viral Entry via Respiratory Tract",
        [
            "Influenza virus is inhaled via respiratory droplets or aerosols",
            "Virus reaches the respiratory epithelium (nose, throat, trachea, bronchi)",
            "In severe disease (especially H5N1, H1N1): virus also reaches alveoli (lower airways)",
        ],
        FLOW_COLORS[0]
    ),
    (
        "STEP 2 — Attachment Using Hemagglutinin (H)",
        [
            "Hemagglutinin (H) on viral surface BINDS to sialic acid receptors on respiratory epithelial cells",
            "Human influenza A/B: binds alpha-2,6-linked sialic acid (found in upper airways of humans)",
            "Avian influenza (H5N1): binds alpha-2,3-linked sialic acid (found deep in lungs — explains severity)",
            "After binding → virus is endocytosed (taken into cell)",
        ],
        FLOW_COLORS[1]
    ),
    (
        "STEP 3 — Viral Replication Inside Epithelial Cells",
        [
            "Inside the host cell, the viral RNA genome is released into the nucleus",
            "Viral RNA polymerase replicates the genome and transcribes viral mRNA",
            "Host ribosomes translate viral proteins (H, N, nucleoprotein, polymerase subunits)",
            "New viral particles are assembled at the cell membrane",
        ],
        FLOW_COLORS[2]
    ),
    (
        "STEP 4 — Viral Release Using Neuraminidase (N)",
        [
            "Neuraminidase (N) cleaves sialic acid bonds — releasing new virions from the cell surface",
            "Without neuraminidase, newly formed viruses would remain stuck to the cell",
            "Released virions spread to infect neighboring epithelial cells",
            "This is the TARGET of antiviral drugs (Oseltamivir, Zanamivir) — they BLOCK neuraminidase",
        ],
        FLOW_COLORS[3]
    ),
    (
        "STEP 5 — Immune Response & Cytokine Release → Symptoms",
        [
            "Host innate immune system detects viral RNA via toll-like receptors (TLR-3, TLR-7)",
            "Infected cells release interferons (IFN-alpha, IFN-beta) — activate neighboring cells' defenses",
            "Pro-inflammatory cytokines (IL-6, TNF-alpha, IL-1beta) are released — CYTOKINE STORM",
            "Cytokines cause: SUDDEN HIGH FEVER, severe myalgia (body aches), headache, extreme fatigue",
            "Local inflammation of airways → sore throat, runny nose, dry cough",
        ],
        FLOW_COLORS[4]
    ),
    (
        "STEP 6 — Epithelial Cell Death & Ciliary Destruction",
        [
            "Infected epithelial cells undergo apoptosis (programmed death) or necrosis",
            "Cilia are destroyed — loss of mucociliary clearance (the normal protective escalator of the airway)",
            "Mucus and pathogens can no longer be cleared effectively from the airways",
            "Airway becomes denuded (stripped of protective lining) → exposed, raw epithelium",
        ],
        FLOW_COLORS[5]
    ),
    (
        "STEP 7 — Risk of Secondary Bacterial Infection",
        [
            "Destroyed cilia + denuded epithelium = ideal environment for bacterial colonization",
            "Common secondary pathogens: Streptococcus pneumoniae, Staphylococcus aureus, H. influenzae",
            "Can cause: bacterial pneumonia (most dangerous complication), otitis media (in children)",
            "Without treatment: leads to respiratory failure, ARDS, multi-organ failure, death",
        ],
        FLOW_COLORS[6]
    ),
]

for i, (header, lines, color) in enumerate(steps):
    story.append(flow_box(header, lines, color))
    if i < len(steps) - 1:
        story.append(sp(2))
        story.append(arrow())
        story.append(sp(2))

story.append(sp(8))

# Outcome
out_data = [[
    Paragraph("RECOVERY\n(7–10 days with rest + antivirals)",
              S(fontSize=9, textColor=C_SUBHEAD, fontName="Helvetica-Bold", alignment=TA_CENTER)),
    Paragraph("OR", S(fontSize=12, textColor=C_TEXT, fontName="Helvetica-Bold", alignment=TA_CENTER)),
    Paragraph("COMPLICATIONS\n(high-risk groups, secondary infection)",
              S(fontSize=9, textColor=C_RED, fontName="Helvetica-Bold", alignment=TA_CENTER)),
]]
out_t = Table(out_data, colWidths=[W*0.44, W*0.08, W*0.44])
out_t.setStyle(TableStyle([
    ("BACKGROUND",   (0,0),(0,0), C_GREEN_BG), ("BACKGROUND",(2,0),(2,0), C_RED_BG),
    ("BOX",          (0,0),(0,0), 1.5, C_GREEN_BD), ("BOX",(2,0),(2,0), 1.5, C_RED_BD),
    ("TOPPADDING",   (0,0),(-1,-1), 10), ("BOTTOMPADDING",(0,0),(-1,-1), 10),
    ("LEFTPADDING",  (0,0),(-1,-1), 6),  ("VALIGN",(0,0),(-1,-1),"MIDDLE"),
]))
story.append(out_t)

# ════════════════════════════════════════════════════════════════
# SECTION 4 – HIGH RISK GROUPS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("4.  HIGH RISK GROUPS", color=C_ORANGE))
story.append(sp(6))

risk_data = [
    [Paragraph("High Risk Group", th_s), Paragraph("Why they are at higher risk", th_s)],
    [Paragraph("Elderly >65 years", tcl_s),
     Paragraph("Immune senescence (aging immune system) — weaker T-cell and antibody responses; comorbidities", tcl_s)],
    [Paragraph("Children <5 years", tcl_s),
     Paragraph("Immature immune system; narrow airways (higher risk of croup); no prior immunity", tcl_s)],
    [Paragraph("Pregnant women", tcl_s),
     Paragraph("Physiological immune suppression during pregnancy; increased cardiac and respiratory demand; risk to fetus", tcl_s)],
    [Paragraph("Chronic diseases\n(asthma, COPD, diabetes, heart disease)", tcl_s),
     Paragraph("Underlying lung/heart compromise → flu worsens underlying disease; hyperglycemia in diabetics impairs immune function", tcl_s)],
    [Paragraph("Immunocompromised\n(HIV, chemotherapy, transplant)", tcl_s),
     Paragraph("Cannot mount effective adaptive immune response → prolonged viral shedding, higher complication rate", tcl_s)],
    [Paragraph("Healthcare workers", tcl_s),
     Paragraph("High exposure risk; can transmit to vulnerable patients — hence annual flu vaccination is mandatory for HCWs", tcl_s)],
]
risk_t = Table(risk_data, colWidths=[4.5*cm, W-4.5*cm])
risk_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_ORANGE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_WARN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_ORANGE),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#FFE0B2")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(risk_t)

# ════════════════════════════════════════════════════════════════
# SECTION 5 – SIGNS & SYMPTOMS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("5.  SIGNS & SYMPTOMS", color=colors.HexColor("#7B1FA2")))
story.append(sp(6))

story.append(info_box("Flu vs Common Cold — Key Distinction",
    [Paragraph(
        "Influenza starts <b>SUDDENLY</b> (within hours) with high fever and severe systemic symptoms. "
        "The common cold (rhinovirus) starts gradually with mild nasal symptoms. "
        "The severity of <b>myalgia (body aches)</b> and <b>extreme fatigue</b> is the hallmark that distinguishes flu from a cold.",
        body_s)
    ], bg=C_BOX_BG, bd=C_BOX_BD))
story.append(sp(6))

symp_data = [
    [Paragraph("TYPICAL SYMPTOMS", th_s), Paragraph("SYMPTOMS IN CHILDREN", th_s)],
    [Paragraph(
        "• Sudden high fever (38–40°C)\n"
        "• Chills\n"
        "• Headache\n"
        "• Myalgia — severe body aches\n"
        "• Dry cough\n"
        "• Sore throat\n"
        "• Runny or stuffy nose\n"
        "• Extreme fatigue\n"
        "• Loss of appetite",
        S(fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", leading=15)),
     Paragraph(
        "• All adult symptoms PLUS:\n"
        "• Vomiting\n"
        "• Diarrhea\n"
        "• Febrile seizures (from high fever)\n"
        "• Croup (barky cough from inflamed larynx)\n"
        "• Otitis media (ear infection)\n"
        "• More prone to dehydration",
        S(fontSize=9.5, textColor=C_TEXT, fontName="Helvetica", leading=15)),
    ]
]
symp_t = Table(symp_data, colWidths=[W/2, W/2])
symp_t.setStyle(TableStyle([
    ("BACKGROUND",   (0,0),(-1,0), colors.HexColor("#7B1FA2")),
    ("BACKGROUND",   (0,1),(0,1),  C_BLUE_BG),
    ("BACKGROUND",   (1,1),(1,1),  C_WARN_BG),
    ("BOX",          (0,0),(-1,-1), 1, colors.HexColor("#4A148C")),
    ("LINEAFTER",    (0,0),(0,-1),  1, C_LINE),
    ("TOPPADDING",   (0,0),(-1,-1), 7), ("BOTTOMPADDING",(0,0),(-1,-1), 7),
    ("LEFTPADDING",  (0,0),(-1,-1), 8), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(symp_t)

# ════════════════════════════════════════════════════════════════
# SECTION 6 – COMPLICATIONS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("6.  COMPLICATIONS", color=C_SUBHEAD))
story.append(sp(6))

comp_data = [
    [Paragraph("Complication", th_s), Paragraph("Explanation", th_s)],
    [Paragraph("Viral pneumonia", tcl_s),
     Paragraph("Direct invasion of lung parenchyma by influenza virus → bilateral interstitial pneumonia → ARDS. Most severe in high-risk groups. Can be rapidly fatal.", tcl_s)],
    [Paragraph("Bacterial pneumonia\n(secondary)", tcl_s),
     Paragraph("Most common serious complication. Destroyed cilia allow Strep. pneumoniae, Staph. aureus, H. influenzae to colonize. Staph. aureus pneumonia post-flu is particularly severe (necrotizing).", tcl_s)],
    [Paragraph("Otitis media\n(children)", tcl_s),
     Paragraph("Virus spreads via eustachian tube to middle ear. Causes ear pain, hearing loss, fever. Common cause of antibiotic use in children post-flu.", tcl_s)],
    [Paragraph("COPD/Asthma exacerbation", tcl_s),
     Paragraph("Respiratory inflammation + bronchoconstriction triggered by viral infection — can precipitate life-threatening airflow obstruction in COPD/asthma patients.", tcl_s)],
    [Paragraph("Myocarditis", tcl_s),
     Paragraph("Viral or immune-mediated inflammation of heart muscle → arrhythmias, cardiac failure. Can occur even in previously healthy patients.", tcl_s)],
    [Paragraph("Encephalitis", tcl_s),
     Paragraph("Rare but serious. Direct viral invasion or immune-mediated inflammation of brain tissue → confusion, seizures, coma. More common in children.", tcl_s)],
    [Paragraph("Death", tcl_s),
     Paragraph("From respiratory failure (viral/bacterial pneumonia + ARDS), multi-organ failure, or cardiac complications. Most deaths occur in elderly >65.", tcl_s)],
]
comp_t = Table(comp_data, colWidths=[4.5*cm, W-4.5*cm])
comp_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_SUBHEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_GREEN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_SUBHEAD),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#C8E6C9")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(comp_t)

# ════════════════════════════════════════════════════════════════
# SECTION 7 – DIAGNOSIS
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("7.  DIAGNOSIS", color=C_TEAL))
story.append(sp(6))

diag_data = [
    [Paragraph("Test", th_s), Paragraph("Method / Details", th_s), Paragraph("Notes", th_s)],
    [Paragraph("Clinical diagnosis", tcl_s),
     Paragraph("Sudden high fever + body aches + cough during flu season", tcl_s),
     Paragraph("Sufficient for most uncomplicated cases; start treatment empirically", tcl_s)],
    [Paragraph("Rapid Influenza Diagnostic Test (RIDT)", tcl_s),
     Paragraph("Detects influenza antigens (H protein) from nasopharyngeal swab in 10–15 min", tcl_s),
     Paragraph("Sensitivity 50–70% (misses many cases); specificity high. Useful for quick triage but negative result does not rule out flu.", tcl_s)],
    [Paragraph("RT-PCR (Gold Standard)", tcl_s),
     Paragraph("Detects influenza RNA via reverse transcriptase polymerase chain reaction from nasopharyngeal/throat swab", tcl_s),
     Paragraph("Highly sensitive (>95%) and specific; identifies type (A/B) and subtype; used in hospitalized cases, outbreaks, and public health surveillance.", tcl_s)],
    [Paragraph("Viral culture", tcl_s),
     Paragraph("Growing virus from specimen in cell culture", tcl_s),
     Paragraph("Research and surveillance only; takes days; not for clinical management.", tcl_s)],
    [Paragraph("CBC", tcl_s),
     Paragraph("Blood count", tcl_s),
     Paragraph("Leukopenia or leukocytosis (if secondary bacterial infection). Lymphopenia in severe flu.", tcl_s)],
]
diag_t = Table(diag_data, colWidths=[3.5*cm, 6*cm, W-9.5*cm])
diag_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_TEAL),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, colors.HexColor("#E0F2F1")]),
    ("BOX",           (0,0),(-1,-1), 1, C_TEAL),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#B2DFDB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(diag_t)

# ════════════════════════════════════════════════════════════════
# SECTION 8 – TREATMENT & PREVENTION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("8.  TREATMENT & PREVENTION", color=C_ORANGE))
story.append(sp(6))

story.append(Paragraph("A. Antiviral Drugs", sec_s))
story.append(info_box("Critical Timing: Antivirals work best within 48 hours of symptom onset",
    [Paragraph(
        "Starting antivirals early (within 48 hrs) reduces: duration of illness by ~1–2 days, "
        "severity of symptoms, risk of hospitalization and death, and duration of viral shedding. "
        "In high-risk patients or severe illness, start antivirals even after 48 hrs.",
        body_s)
    ], bg=C_WARN_BG, bd=C_WARN_BD))
story.append(sp(4))

antiviral_data = [
    [Paragraph("Drug", th_s), Paragraph("Class / Route", th_s), Paragraph("Mechanism", th_s), Paragraph("Notes", th_s)],
    [Paragraph("Oseltamivir\n(Tamiflu)", tcl_s),
     Paragraph("Neuraminidase inhibitor\nOral capsule/liquid", tcl_s),
     Paragraph("Inhibits neuraminidase → prevents newly formed virus from being released from host cells → stops spread", tcl_s),
     Paragraph("Most widely used. 75 mg twice daily x 5 days. Used in all ages, pregnancy safe. First-line for hospitalized.", tcl_s)],
    [Paragraph("Zanamivir\n(Relenza)", tcl_s),
     Paragraph("Neuraminidase inhibitor\nInhaled powder", tcl_s),
     Paragraph("Same as oseltamivir — inhibits neuraminidase", tcl_s),
     Paragraph("Inhaled — not suitable for patients with asthma/COPD (risk of bronchospasm). Alternative to oseltamivir.", tcl_s)],
    [Paragraph("Baloxavir marboxil\n(Xofluza)", tcl_s),
     Paragraph("Cap-dependent endonuclease inhibitor\nOral", tcl_s),
     Paragraph("Blocks viral RNA polymerase (cap-snatching mechanism) → prevents viral mRNA transcription → stops replication entirely", tcl_s),
     Paragraph("Single dose. Newer drug. Effective against both A and B. Useful in oseltamivir-resistant strains.", tcl_s)],
]
antiviral_t = Table(antiviral_data, colWidths=[3*cm, 3*cm, 5.5*cm, W-11.5*cm])
antiviral_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_ORANGE),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_WARN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_ORANGE),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#FFE0B2")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(antiviral_t)
story.append(sp(6))

story.append(Paragraph("B. Supportive Care", sec_s))
support = [
    "<b>Fever/pain:</b> Paracetamol (acetaminophen) — preferred; ibuprofen as alternative",
    "<b>AVOID ASPIRIN in children</b> — risk of <b>Reye's syndrome</b> (acute liver failure + encephalopathy; can be fatal)",
    "<b>Hydration:</b> Adequate oral fluids; IV fluids if dehydrated or unable to drink",
    "<b>Rest</b> — helps immune recovery",
    "<b>Oxygen therapy</b> if O2 saturation drops (SpO2 <94%); mechanical ventilation in ARDS",
    "Antibiotics ONLY if secondary bacterial infection is confirmed or strongly suspected",
]
for s in support: story.append(bul(s))
story.append(sp(6))

story.append(Paragraph("C. Prevention", sec_s))
prev_data = [
    [Paragraph("Prevention Measure", th_s), Paragraph("Details", th_s)],
    [Paragraph("Annual influenza vaccination\n(most effective)", tcl_s),
     Paragraph("Updated every year to match circulating strains. Two forms: inactivated (injectable — IM, all ages) and live attenuated (nasal spray — ages 2–49, not pregnant/immunocompromised). "
               "Quadrivalent vaccine covers 2 A strains + 2 B strains. Efficacy 40–60% (varies by match).", tcl_s)],
    [Paragraph("Hand hygiene", tcl_s),
     Paragraph("Wash hands frequently with soap for 20 seconds; use alcohol-based hand rub (60%+ alcohol)", tcl_s)],
    [Paragraph("Mask use during outbreaks", tcl_s),
     Paragraph("Surgical masks reduce droplet transmission; N95 respirators for healthcare settings", tcl_s)],
    [Paragraph("Cough etiquette", tcl_s),
     Paragraph("Cover cough/sneeze with elbow (not hand); dispose of tissues immediately", tcl_s)],
    [Paragraph("Isolation of infected patients", tcl_s),
     Paragraph("Stay home for at least 24 hours after fever-free without antipyretics; isolate for 5–7 days from symptom onset", tcl_s)],
    [Paragraph("Ventilation", tcl_s),
     Paragraph("Improve air circulation in indoor spaces; avoid crowded enclosed areas during flu season", tcl_s)],
]
prev_t = Table(prev_data, colWidths=[4.5*cm, W-4.5*cm])
prev_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_SUBHEAD),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_GREEN_BG]),
    ("BOX",           (0,0),(-1,-1), 1, C_SUBHEAD),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#C8E6C9")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 6), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(prev_t)

# ════════════════════════════════════════════════════════════════
# SECTION 9 – QUICK REVISION
# ════════════════════════════════════════════════════════════════
story.append(sp(10))
story.append(sec_hdr("9.  QUICK REVISION — KEY FACTS", color=C_INDIGO))
story.append(sp(6))

qr_data = [
    [Paragraph("Topic", th_s), Paragraph("Key Fact", th_s)],
    [Paragraph("Causative agent", tcl_s),     Paragraph("Influenza virus — ssRNA, family Orthomyxoviridae", tcl_s)],
    [Paragraph("Most severe type", tcl_s),    Paragraph("Type A — causes pandemics (H1N1, H3N2, H5N1)", tcl_s)],
    [Paragraph("Seasonal type", tcl_s),       Paragraph("Type B — seasonal outbreaks, no animal reservoir", tcl_s)],
    [Paragraph("Incubation", tcl_s),          Paragraph("1–4 days (average 2 days)", tcl_s)],
    [Paragraph("Main transmission", tcl_s),   Paragraph("Respiratory droplets", tcl_s)],
    [Paragraph("H protein function", tcl_s),  Paragraph("Attachment to host cells (binds sialic acid)", tcl_s)],
    [Paragraph("N protein function", tcl_s),  Paragraph("Release of new virions from host cells", tcl_s)],
    [Paragraph("Antiviral target", tcl_s),    Paragraph("Neuraminidase (N) — Oseltamivir, Zanamivir", tcl_s)],
    [Paragraph("Baloxavir target", tcl_s),    Paragraph("Cap-dependent endonuclease (viral RNA polymerase)", tcl_s)],
    [Paragraph("Antiviral timing", tcl_s),    Paragraph("Most effective within 48 hours of symptoms", tcl_s)],
    [Paragraph("AVOID in children", tcl_s),   Paragraph("Aspirin — causes Reye's syndrome (liver failure + encephalopathy)", tcl_s)],
    [Paragraph("Why annual vaccine?", tcl_s), Paragraph("Antigenic drift (gradual) and shift (sudden reassortment) change virus each year", tcl_s)],
    [Paragraph("Pandemic cause", tcl_s),      Paragraph("Antigenic shift in Type A (gene segments from bird/pig viruses)", tcl_s)],
    [Paragraph("Gold standard diagnosis", tcl_s), Paragraph("RT-PCR from nasopharyngeal swab", tcl_s)],
    [Paragraph("Dangerous complication", tcl_s),  Paragraph("Bacterial pneumonia (Staph aureus, Strep pneumoniae) due to destroyed cilia", tcl_s)],
]
qr_t = Table(qr_data, colWidths=[5*cm, W-5*cm])
qr_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0),  C_INDIGO),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, C_BLUE_BG]),
    ("BOX",           (0,0),(-1,-1), 1, colors.HexColor("#1A237E")),
    ("INNERGRID",     (0,0),(-1,-1), 0.4, colors.HexColor("#BBDEFB")),
    ("TOPPADDING",    (0,0),(-1,-1), 5), ("BOTTOMPADDING",(0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 8), ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(qr_t)

story.append(sp(14))
story.append(HRFlowable(width="100%", thickness=1, color=C_LINE))
story.append(sp(4))
story.append(Paragraph("— End of Influenza (Flu) Notes —",
    S(fontSize=11, textColor=C_MUTED, alignment=TA_CENTER, fontName="Helvetica")))

doc.build(story)
print(f"PDF saved to {OUTPUT}")
Running Command

cd /tmp/workspace/malaria-notes && python generate_influenza_notes.py 2>&1

Running Command

ls -lh /tmp/workspace/malaria-notes/Influenza_Notes.pdf

Your Influenza PDF is ready! Download it here:

Influenza Notes

PDF Document · PDF


Here's what's inside across 9 sections:

1. Introduction

  • ssRNA virus, family Orthomyxoviridae
  • Types A/B/C/D with key differences in a color table
  • H (Hemagglutinin) and N (Neuraminidase) proteins explained
  • Antigenic Drift vs Antigenic Shift — why annual vaccine is needed

2. Mode of Transmission

  • Droplets, direct contact, fomites, airborne — full table with range/details
  • Infectious 1 day BEFORE symptoms (explains rapid spread)

3. Pathophysiology — 7-Step Flowchart

StepWhat Happens
1Virus enters via respiratory tract
2Hemagglutinin (H) attaches to sialic acid receptors
3Viral replication inside epithelial cells
4Neuraminidase (N) releases new virions — drug target
5Cytokine storm → sudden fever, myalgia, fatigue
6Epithelial death + cilia destroyed → mucociliary clearance lost
7Secondary bacterial infection (Staph/Strep) → pneumonia

4. High Risk Groups

  • Elderly, children <5, pregnant, COPD/asthma/diabetes, immunocompromised, HCWs — all explained with reasoning

5. Signs & Symptoms

  • Adult vs children symptoms side-by-side

6. Complications

  • Viral/bacterial pneumonia, otitis media, COPD exacerbation, myocarditis, encephalitis — all explained

7. Diagnosis

  • RIDT (rapid, low sensitivity), RT-PCR (gold standard), clinical diagnosis

8. Treatment & Prevention

  • Oseltamivir (mechanism explained), Zanamivir, Baloxavir (different mechanism - RNA polymerase)
  • Aspirin avoided in children — Reye's syndrome explained
  • Supportive care + full prevention table including annual vaccine

9. Quick Revision — 15 Key Facts Table

This is a shared conversation. Sign in to Orris to start your own chat.