import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from lib import build_and_save

references = [
 {"title": "Zitelli and Davis' Atlas of Pediatric Physical Diagnosis: Expert Consult - Online", "author": None, "pages": [559, 560]},
 {"title": "Berkowitz's Pediatrics", "author": "Berkowitz, Carol D.;", "pages": [845]},
 {"title": "Update in Pediatrics", "author": None, "pages": [514]},
 {"title": "Cover", "author": "Vitalsource Download", "pages": [6760, 6769, 6792]},
 {"title": "CURRENT Diagnosis and Treatment Pediatrics, Twenty-Fourth Edition", "author": "Hay, William W., Levin, Myron J., Deterding, Robin R., Abzug, Mark J.", "pages": [765, 766]},
 {"title": "2021_Fleisher_&_Ludwig's_Textbook_of_Pediatric_Emergency_Medicine.epub", "author": None, "pages": []},
 {"title": "Pediatric Board Study Guide", "author": None, "pages": [801]},
 {"title": "MedStudy Pediatrics Core 11th Edition 2024-2025", "author": None, "pages": [565]},
]

short_md = """## In short

- Classic features of glomerulonephritis (nephritic syndrome): hematuria (often gross, coffee/tea/cola-colored), red blood cell casts on urine microscopy, hypertension, and edema; edema results from transient acute kidney injury with salt and fluid retention.
- Acute poststreptococcal glomerulonephritis (APSGN) is the most common cause of acute GN in children worldwide, following pharyngitis, otitis media, cellulitis, or pyoderma from one of about 10 nephritogenic group A beta-hemolytic streptococcal strains; only about 15% of infected children develop clinical nephritis.
- APSGN most often affects children 4-12 years old (rare before age 2), is more common in males, and shows low C3 with elevated antistreptolysin O (ASO) titers; it is typically self-limited with a good long-term prognosis, though microscopic hematuria can persist up to a year.
- In high-income countries, nonstreptococcal organisms (Staphylococcus species, Pneumococcus, Salmonella typhi, Klebsiella pneumoniae, E. coli) have emerged as leading causes of postinfectious GN; other triggers include varicella, CMV, EBV, hepatitis B/C, toxoplasmosis, ventriculoperitoneal shunt infection (shunt nephritis), and endocarditis, with hematuria onset 1-6 weeks after the preceding infection.
- Rapidly progressive glomerulonephritis (RPGN) is an important subset presenting with gross hematuria (50-85%), edema (13-80%), anemia (70%), and hypertension (63-85%); nephrotic syndrome is uncommon since rapid GFR decline causes AKI instead. Pulmonary hemorrhage suggests anti-GBM disease or ANCA vasculitis and can be fatal without prompt treatment.
- Membranoproliferative glomerulonephritis (MPGN) is the most common "chronic" GN in childhood but is itself uncommon; it is a biopsy diagnosis with GBM thickening and mesangial hypercellularity, subdivided into immune-complex-mediated MPGN and complement-mediated MPGN (C3 glomerulonephritis and dense deposit disease), usually with depressed C3.
- Recurrent painless macroscopic hematuria suggests IgA nephropathy, though this presentation is also fairly common in Alport syndrome in the first decade of life.
- Important chronic GN causes besides MPGN: lupus nephritis, ANCA-associated vasculitis, and anti-GBM glomerulonephritis; GN in the newborn period is extremely rare and usually reflects congenital infection.
- Management depends on cause: postinfectious GN is largely supportive (fluid/salt restriction, blood pressure management), with admission for renal insufficiency, oliguria, or acute hypertension; steroids are considered by some nephrologists for rapidly progressive APSGN, and immunosuppressive treatment is used for MPGN/C3 glomerulopathy, with response varying by underlying cause.
"""

long_md = """## Definition

Glomerulonephritis (GN) is a generic term for noninfectious inflammatory glomerular injury, typically presenting with the nephritic syndrome: hematuria, red blood cell casts, hypertension, and edema, reflecting renal inflammation. GN is classified as acute, chronic, or, in a small but important subset, rapidly progressive glomerulonephritis (RPGN); a causal classification scheme is now favored over the traditional histopathological approach as understanding of pathophysiology has advanced.

## Epidemiology

Acute poststreptococcal glomerulonephritis (APSGN) is the most common cause of acute GN in children worldwide. It most often affects children between 4 and 12 years of age, is rare before age 2, and is more common in males. GN is extremely rare in the newborn period, when it usually reflects congenital infection.

## Etiology

APSGN follows pharyngitis, otitis media, cellulitis, or pyoderma caused by one of about 10 nephritogenic strains of group A beta-hemolytic streptococcus, though only about 15% of children infected with these strains go on to develop clinical nephritis. In recent years, nonstreptococcal organisms - Staphylococcus species, Pneumococcus, Salmonella typhi, Klebsiella pneumoniae, and E. coli - have become the leading causes of postinfectious GN in high-income countries, alongside viral causes (varicella, cytomegalovirus, Epstein-Barr virus, hepatitis B and C) and parasitic causes (toxoplasmosis); hematuria typically begins 1-6 weeks after the preceding infection. Other postinfectious causes include ventriculoperitoneal shunt infection (shunt nephritis) and acute or subacute endocarditis. The majority of acute pediatric GN is postinfectious or due to IgA vasculitis (IgAV, formerly Henoch-Schonlein purpura). Important chronic GN entities include membranoproliferative glomerulonephritis (MPGN)/C3 glomerulopathy, lupus nephritis, ANCA-associated vasculitis, and anti-glomerular basement membrane (anti-GBM) disease. Both humoral (immune complex deposition with predilection for glomeruli) and cellular immune mechanisms are implicated in the pathogenesis of postinfectious GN generally.

## Pathophysiology

Immune activation in GN leads to downstream kidney injury through complement activation, coagulation cascade activation, and local cytokine release. MPGN is a biopsy diagnosis (not a single distinct disease) characterized by glomerular basement membrane thickening from immune complex deposition or mesangial cell interposition, together with hypercellularity from mesangial cell proliferation and leukocyte influx, producing a lobular appearance of the glomerular tuft. Recent reclassification recognizes two MPGN mechanisms: immune-complex-mediated MPGN (triggered by environmental or autologous antigens) and complement-mediated MPGN, arising from dysregulation and persistent activation of the alternative complement pathway, with two subtypes - C3 glomerulonephritis and dense deposit disease (formerly Type II MPGN).

## Clinical Features

Acute GN presents with sudden-onset painless, dark cola- or tea-colored urine, proteinuria, and cellular casts on urine microscopy; edema, hypertension, and renal insufficiency are common accompanying findings. Hematuria may be microscopic or gross. Edema results from transient acute kidney injury causing salt and fluid retention; hypertension can be severe and occasionally causes hypertensive seizures. Many patients with APSGN are actually asymptomatic and never come to medical attention. Most APSGN symptoms resolve within a few weeks, though microscopic hematuria can persist for up to a year; complete recovery of renal function is the rule, with only a minority progressing to renal failure. RPGN, a more severe subset, presents with gross hematuria (50-85% of cases), edema (13-80%), anemia (70%), and hypertension (63-85%); nephrotic syndrome is uncommon in RPGN because the rapid fall in glomerular filtration produces acute kidney injury rather than the typical nephrotic picture. Extrarenal manifestations can occur depending on etiology; pulmonary hemorrhage specifically suggests anti-GBM nephritis (Goodpasture syndrome) or ANCA vasculitis and can be fatal if treatment is delayed.

## Diagnostics

Urinalysis in acute GN shows an "active" sediment: hematuria, proteinuria, and cellular casts; red blood cell casts are almost always associated with glomerulonephritis or vasculitis and effectively exclude an extrarenal source of bleeding. Serum C3 level is a key branch point in evaluation: low C3 with elevated antistreptolysin O (ASO) titer supports APSGN, while low C3 also occurs in MPGN/C3 glomerulopathy, lupus nephritis, and shunt nephritis/endocarditis, whereas most other causes of GN (including IgA nephropathy, ANCA vasculitis, and anti-GBM disease) have a normal C3. Recurrent painless macroscopic hematuria suggests IgA nephropathy, though this pattern is also a fairly common presentation of Alport syndrome in the first decade of life. Age at onset is a useful additional clue since many glomerular diseases have characteristic age ranges. In children with nephrotic-range proteinuria and minimal hematuria/sediment abnormality (as in minimal change disease), the clinical picture is distinctly different from acute GN, helping distinguish nephrotic from nephritic presentations.

## Treatment

Management depends on the underlying cause. Postinfectious GN, including APSGN, is managed supportively with attention to fluid balance and blood pressure; admission may be needed for renal insufficiency, oliguria, or acute hypertension, the latter requiring aggressive management with fluid and salt restriction plus antihypertensive therapy. Some pediatric nephrologists consider steroid treatment in rare cases of APSGN with a rapidly progressive clinical course, since an aggressive course can progressively impair kidney function and lead to chronic kidney disease, often with crescents seen on biopsy. Immunosuppressive treatment is recommended for MPGN/C3 glomerulopathy, though response varies depending on the underlying etiology.

## Prognosis

Poststreptococcal GN is typically self-limited with a good prognosis for long-term renal function; most children recover fully, and only a few progress to renal failure. MPGN and other chronic GN entities carry a more variable course dependent on the specific underlying mechanism and response to treatment.
"""

clinical_md = """## Evaluating a Child with Suspected Glomerulonephritis

In a child with dark (cola- or tea-colored) urine, check for the full nephritic picture - hematuria with red blood cell casts, proteinuria, hypertension, and edema - on urinalysis and exam; RBC casts essentially confirm a glomerular/vasculitic source and exclude extrarenal bleeding. Check serum C3 as an early branch point: low C3 with elevated ASO/streptozyme supports APSGN (the most likely diagnosis in a 4-12-year-old with a preceding pharyngitis, otitis media, or skin infection 1-6 weeks earlier), while a normal C3 shifts the differential toward IgA nephropathy, ANCA vasculitis, or anti-GBM disease. Ask specifically about recurrent painless macroscopic hematuria, which points to IgA nephropathy but can also be an early presentation of Alport syndrome in the first decade of life. Admit for renal insufficiency, oliguria, or acute hypertension, managing the latter aggressively with fluid/salt restriction and antihypertensive therapy; reassure families that typical APSGN has an excellent prognosis, with most children recovering fully even though microscopic hematuria can linger for up to a year.

## Recognizing Rapidly Progressive Disease

Escalate urgently when a child with GN shows a rapidly progressive course - worsening renal function, especially with anemia, marked hypertension, and edema out of proportion to a typical self-limited postinfectious picture - since this raises concern for RPGN or a crescentic process requiring biopsy and consideration of immunosuppression. Treat pulmonary hemorrhage in a child with glomerulonephritis as a medical emergency suggesting anti-GBM disease (Goodpasture syndrome) or ANCA vasculitis, since delayed treatment can be fatal. For a child with biopsy-proven MPGN/C3 glomerulopathy or another chronic GN, coordinate with pediatric nephrology for immunosuppressive treatment, counseling families that response varies by the specific underlying mechanism rather than following one predictable course.
"""

build_and_save(
    topic="Glomerulonephritis",
    slug="glomerulonephritis",
    category_id=15084,
    summary="Pediatric glomerulonephritis: the nephritic syndrome, APSGN as the dominant acute cause versus RPGN and chronic MPGN, and the C3-guided diagnostic approach.",
    references=references,
    short_md=short_md,
    long_md=long_md,
    clinical_md=clinical_md,
)
