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

references = [
 {"title": "Gomella's Neonatology: Management, Procedures, On-Call Problems, Diseases, and Drugs, Eighth Edition", "author": "Tricia Lacy Gomella, Fabien G. Eyal and Fayez Bany-Mohammed", "pages": [1124]},
 {"title": "Cover", "author": "Vitalsource Download", "pages": [6883]},
 {"title": "Kliegman R. Nelson Textbook of Pediatrics 2-Volume Set 22ed 2024", "author": None, "pages": [3317]},
 {"title": "Zitelli and Davis' Atlas of Pediatric Physical Diagnosis: Expert Consult - Online", "author": None, "pages": [570, 571, 585]},
 {"title": "Netters Pediatrics (Florin Т., Ludwig St.)", "author": None, "pages": [435]},
 {"title": "MedStudy Pediatrics Core 11th Edition 2024-2025", "author": None, "pages": [593]},
 {"title": "2021_Fleisher_&_Ludwig's_Textbook_of_Pediatric_Emergency_Medicine.epub", "author": None, "pages": []},
 {"title": "Pediatric Board Study Guide", "author": None, "pages": [835]},
]

short_md = """## In short

- Posterior urethral valves (PUVs) are obstructing tissue leaflets (folds) in the prostatic urethra just proximal to the external urethral sphincter, occurring almost exclusively in males; they are the most common cause of lower urinary tract obstruction and of childhood renal failure from obstructive uropathy.
- Reported incidence ranges widely: about 1 in 5,000, 1 in 8,000, or 1 in 25,000 live births depending on the source.
- About 30% of patients develop end-stage renal disease or chronic renal insufficiency; vesicoureteral reflux (VUR) occurs in about 50% of neonates with PUV, and about 20% of these have severe unilateral VUR with relative sparing of the other kidney - unilateral disease has a better long-term prognosis than bilateral disease.
- Most cases are now discovered prenatally, showing bilateral hydronephrosis, an enlarged/thick-walled bladder, and often oligohydramnios; severe obstruction in utero can cause renal dysplasia and pulmonary hypoplasia.
- Postnatal presentation varies widely: severe cases show pulmonary hypoplasia and renal failure or bladder distention with hydroureteronephrosis at birth; about a third are diagnosed by 1 week of age, but more than half go undetected for the first few months of life, presenting with vomiting, poor appetite, poor weight gain, or abdominal swelling. Older boys may present later with weak urinary stream, incontinence, urinary tract infection, or renal failure.
- Voiding cystourethrogram (VCUG) is the gold-standard/key diagnostic test, showing a dilated, elongated posterior urethra, thickened/trabeculated bladder wall, bladder neck hypertrophy, and often vesicoureteral reflux; classic exam findings can include an abdominal mass (hydronephrosis), hypertension, and urinary ascites.
- First-line treatment is endoscopic fulguration (ablation) of the valves as early as possible; cutaneous vesicostomy or another form of temporary urinary diversion may be needed, especially in very small infants.
- Serum creatinine and BUN can be markedly elevated at diagnosis; complications include urosepsis, electrolyte imbalance, and progression to chronic/end-stage renal failure despite successful relief of the obstruction, particularly when renal dysplasia has already occurred.
- Nephrectomy may be needed for a kidney with extremely poor function that fails to improve despite temporary nephrostomy, or with severe hypertension or recurrent infection.
"""

long_md = """## Definition

Posterior urethral valves (PUVs) are aberrant, obstructing folds (leaflets) of tissue in the male urethra, fanning distally from the region of the verumontanum/prostatic urethra to just proximal to the external urethral sphincter, typically separated by a slit-like opening. They cause bladder outlet obstruction and consequent lower urinary tract dysfunction, and are almost exclusive to males.

## Epidemiology

PUV is the most common cause of severe obstructive uropathy and of lower urinary tract obstruction (LUTO) in male infants, and the most common cause of childhood renal failure secondary to LUTO (followed by urethral atresia and anterior urethral valves). Reported incidence varies by source, ranging from about 1 in 5,000 to 1 in 25,000 live births (most commonly cited around 1 in 8,000).

## Etiology

The embryologic origin of PUV remains disputed. The posterior urethra develops from the cloaca and urogenital sinus, lined by transitional epithelium; one theory proposes that abnormal integration of the Wolffian ducts into the posterior urethra leads to formation of a congenital obstructing posterior urethral membrane (COPUM), and that the valve-like leaflets seen on imaging may actually result from perforation of this membrane by an advancing catheter during imaging or catheterization.

## Pathophysiology

Obstruction causes the prostatic urethra to dilate and the bladder muscle to undergo hypertrophy, producing a thick-walled, trabeculated "valve bladder" with reduced compliance. Vesicoureteral reflux occurs in about 50% of neonates with PUV; about 20% of these have severe unilateral reflux with relative sparing of the contralateral kidney, a pattern (sometimes called the VURD, or valves-unilateral-reflux-dysplasia, phenomenon) associated with a better long-term prognosis than bilateral disease. Distal ureteral obstruction can also result from a chronically distended bladder or bladder muscle hypertrophy. Renal changes range from mild hydronephrosis to severe renal dysplasia, with severity depending on the degree of obstruction and its timing during fetal development. As with other causes of significant fetal urinary obstruction, severe cases can produce oligohydramnios and secondary pulmonary hypoplasia.

## Clinical Features

Presentation is highly variable, ranging from mild bladder outlet obstruction to severe obstructive uropathy, renal insufficiency, and pulmonary hypoplasia. Most cases are now discovered prenatally, showing bilateral hydronephrosis and an enlarged, sometimes thick-walled, bladder, with or without oligohydramnios. Postnatally, severely affected neonates may present with severe pulmonary hypoplasia and renal failure, or with bladder distention and hydroureteronephrosis; associated findings can include hypertension, an abdominal mass from hydronephrosis, and urinary ascites. Only about one-third of cases are diagnosed by 1 week of age; more than half go undetected for the first few months of life, when parents may report vomiting, poor appetite, inadequate weight gain, or visible abdominal swelling, sometimes with a weak urinary stream noted on careful review of systems. Older boys with previously unrecognized PUV may present with a diminished urinary stream (though few are actually brought for evaluation for this symptom alone), dribbling, incontinence, recurrent urinary tract infection, or renal failure/uremia. Serum creatinine and BUN can be markedly elevated at diagnosis in significant cases.

## Diagnostics

Voiding cystourethrography (VCUG) is the gold-standard and key diagnostic study, classically showing a dilated and elongated posterior urethra, a thickened and trabeculated bladder wall, bladder neck hypertrophy, decreased urethral caliber distal to the point of obstruction, and often vesicoureteral reflux. Suprapubic ultrasound can demonstrate the dilated posterior urethra and bladder, and prenatal ultrasound typically shows bilateral hydroureteronephrosis with or without a thick-walled bladder and oligohydramnios. Diagnosis made radiologically is generally confirmed endoscopically (cystoscopy) at the time of treatment.

## Differential Diagnosis

Bilateral hydronephrosis identified in a male infant requires urgent investigation specifically to exclude posterior urethral valves. Other causes of neonatal bladder outlet obstruction to consider include urethral atresia and anterior urethral valves, though these are less common than PUV.

## Treatment

Endoscopic fulguration (ablation) of the valves is performed as early as possible in most cases and is usually successful in achieving urinary drainage. In some cases, particularly in very small infants where endoscopic instrumentation is not feasible, cutaneous vesicostomy or another form of temporary urinary diversion may be indicated instead. Prophylactic antibiotics are often used for associated vesicoureteral reflux, individualized based on reflux grade and patient/physician preference given the potential side effects of prolonged antibiotic use; most clinicians still use prophylaxis for grade 3-5 VUR in infants and young children. Nephrectomy may be required for a kidney with extremely poor function that does not improve despite temporary nephrostomy drainage, or in the setting of severe hypertension or recurrent urinary infection referable to that kidney.

## Complications

Despite successful surgical relief of the obstruction, associated renal dysplasia may still progress to chronic or end-stage renal failure during infancy or childhood in a substantial proportion of patients (about 30% overall). Urosepsis, electrolyte imbalance, and ongoing valve-bladder dysfunction (impaired bladder compliance and emptying) are recognized complications even after valve ablation.
"""

clinical_md = """## Recognizing and Confirming PUV

Treat bilateral hydronephrosis in a male infant, whether identified prenatally or postnatally, as an urgent indication to exclude posterior urethral valves. In a neonate with a palpable abdominal mass, hypertension, urinary ascites, or unexplained renal failure, include PUV in the differential and obtain a voiding cystourethrogram, the key diagnostic study, looking for a dilated/elongated posterior urethra, thickened trabeculated bladder, bladder neck hypertrophy, and vesicoureteral reflux. Do not rely on parental report of a weak urinary stream to trigger evaluation, since most children with PUV are not brought in for this symptom specifically - maintain suspicion based on the broader clinical picture (vomiting, poor weight gain, abdominal distention, recurrent UTI) since more than half of cases are not diagnosed until several months of age. In an older boy with incontinence, recurrent UTI, or unexplained renal impairment, consider previously unrecognized PUV as part of the work-up.

## Managing PUV and Its Renal Consequences

Arrange endoscopic fulguration of the valves as early as feasible once the diagnosis is confirmed; reserve cutaneous vesicostomy or another temporary diversion for very small infants in whom endoscopic treatment is not practical. Check renal function (creatinine, BUN) and electrolytes at diagnosis, and evaluate for vesicoureteral reflux, since about half of neonates with PUV have VUR - consider prophylactic antibiotics for higher-grade (3-5) reflux in infants and young children, weighing this against the risks of prolonged antibiotic exposure. Set expectations with families that unilateral disease with contralateral renal sparing carries a better prognosis than bilateral involvement, and that even after technically successful valve ablation, about 30% of patients progress to chronic or end-stage renal disease because of underlying renal dysplasia established before birth - so long-term nephrology follow-up is needed regardless of surgical success. Consider nephrectomy for a kidney with severely impaired function that does not improve with temporary nephrostomy, or that is a source of severe hypertension or recurrent infection.
"""

build_and_save(
    topic="Posterior Urethral Valves",
    slug="posterior-urethral-valves",
    category_id=15912,
    summary="Posterior urethral valves: presentation across the diagnostic spectrum from prenatal hydronephrosis to delayed childhood UTI, VCUG-based diagnosis, endoscopic ablation, and long-term renal prognosis by VUR pattern.",
    references=references,
    short_md=short_md,
    long_md=long_md,
    clinical_md=clinical_md,
)
