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": [341]},
 {"title": "Red Book Atlas of Pediatric Infectious Diseases", "author": "American Academy of Pediatrics,Carol J. Baker, MD, FAAP", "pages": [463, 526]},
 {"title": "Red Book 2018", "author": "Kimberlin, David W.; Long, Sarah S.; Brady, Michael T.", "pages": [686]},
 {"title": "Pediatric Board Study Guide", "author": None, "pages": [1113]},
 {"title": "CURRENT Diagnosis and Treatment Pediatrics, Twenty-Fourth Edition", "author": "Hay, William W., Levin, Myron J., Deterding, Robin R., Abzug, Mark J.", "pages": [443]},
 {"title": "Red Book Atlas 4th Ed.indb", "author": "American Academy of Pediatrics;Carol J. Baker, MD, FAAP;", "pages": [528]},
 {"title": "Red_Book_2021_2024_Report_of_the_Comm_z_library_sk,_1lib_sk,", "author": None, "pages": [640]},
 {"title": "Cover", "author": "Vitalsource Download", "pages": [4218, 5049]},
]

short_md = """## In short

- Tinea versicolor (now more accurately termed pityriasis versicolor) is a common, benign superficial fungal skin infection caused by Malassezia species (M. furfur, M. globosa, M. restricta, M. sympodialis - also known by the older names Pityrosporum ovale/orbiculare), part of normal skin flora in 90-100% of people.
- Infection occurs when Malassezia converts from its yeast phase to its mycelial (hyphal) phase, favored by heat, humidity, sweating, and skin occlusion; individual susceptibility and immunosuppression may also play a role.
- Classic distribution is the upper trunk, neck, and proximal upper extremities in adolescents/young adults, in a guttate ("raindrop") pattern of oval scaly macules/patches 1-3 cm in diameter; infants and children more often show facial involvement, particularly the bilateral temples, and lesions can also affect the scalp, genital area, and thighs.
- Lesion color varies even within the same patient - white, pink, tan, or brown, with fine ("dusty") scale; lighter skin tends toward reddish-brown lesions, darker skin toward hypo- or hyperpigmented lesions.
- The name "versicolor" reflects that lesions fail to tan with sun exposure and appear relatively darker than surrounding skin in winter, but lighter (hypopigmented) after summer sun exposure, since surrounding uninvolved skin tans normally; the fungal product azelaic acid inhibits dopatyrosinase, impairing melanin synthesis in affected skin.
- Most patients are asymptomatic, though some report pruritus; a papulopustular perifollicular variant can occur on the back, chest, and extremities.
- Wood lamp exam typically shows yellowish-brown fluorescence; KOH preparation of skin scrapings classically shows short, stubby hyphae with clusters of spores - the "spaghetti and meatballs" pattern.
- First-line treatment: selenium sulfide 2.5% suspension or zinc pyrithione shampoo applied to the whole body and left on overnight, repeated in 1 week then monthly thereafter (can be irritating); topical antifungals applied twice daily for 1-2 weeks are an alternative; a single 400 mg dose of fluconazole may also be used. Recurrence is common regardless of treatment.
- Differential diagnosis includes pityriasis alba, vitiligo, seborrheic dermatitis, pityriasis rosea, progressive macular hypopigmentation, pityriasis lichenoides, secondary syphilis, and (rare) dyschromatosis universalis hereditaria.
"""

long_md = """## Definition

Tinea versicolor, now more precisely termed pityriasis versicolor, is a common, benign superficial fungal infection of the skin caused by Malassezia, a lipid-dependent, dimorphic yeast that is part of normal human skin flora in 90-100% of individuals. It is the prototypic skin disease associated with Malassezia.

## Etiology

The causative organisms are Malassezia species - M. globosa, M. restricta, M. sympodialis, and M. furfur (also known historically as Pityrosporum ovale or Pityrosporum orbiculare, depending on the yeast-phase form) - which are lipophilic and normally colonize skin rich in sebaceous glands. Infection develops when the organism transforms from its yeast phase to its mycelial (hyphal) phase, a transition favored by heat, humidity, sweating, and skin occlusion; individual host susceptibility and immunosuppression may also contribute. Although most cases occur in the postpubertal period, tinea versicolor can occasionally occur in prepubertal children and even infants.

## Epidemiology

Tinea versicolor classically occurs in adolescents and young adults, though it can occur at any age. Warm, moist climates, pregnancy, immunodeficiency, and genetic factors predispose to infection.

## Clinical Features

Lesions localize to skin areas rich in sebaceous glands: the chest, back, neck, and proximal upper extremities are classic sites, with lesions often beginning in a perifollicular location and enlarging to merge into confluent patches. In infants and children, facial involvement (particularly the bilateral temples) is more common than in adults; other possible sites include the scalp, genital area, thighs, forearms, and dorsum of the hands. Lesions are typically oval, discrete or coalescing macules/patches, 1-3 cm in diameter, often arranged in a guttate ("raindrop") pattern, with fine, faint "dusty" scale. Color varies widely, even within the same patient: white, pink, tan, or brown, with lighter skin tending toward reddish-brown lesions and darker skin toward hypopigmented or hyperpigmented lesions. The name "versicolor" reflects a characteristic pattern: affected areas fail to tan with sun exposure and appear relatively darker than the surrounding skin in winter, but appear lighter (hypopigmented) than the tanned surrounding skin in summer, since only the uninvolved skin tans normally - hypopigmentation itself is attributed to azelaic acid, a fungal product that inhibits dopatyrosinase, an enzyme in the melanin synthesis pathway. Most patients are asymptomatic, though some experience pruritus. A papulopustular perifollicular variant, with monomorphic pustules, can occur on the back, chest, and sometimes the extremities. Recurrent infection is common.

## Diagnostics

Diagnosis is usually clinical, supported by Wood lamp examination, which typically shows yellowish-brown fluorescence of affected areas, and confirmed by potassium hydroxide (KOH) preparation of skin scrapings, which classically shows short, stubby hyphae together with large clusters of spores - the characteristic "spaghetti and meatballs" appearance.

## Differential Diagnosis

Conditions commonly confused with tinea versicolor include pityriasis alba, vitiligo, seborrheic dermatitis, pityriasis rosea, progressive macular hypopigmentation, pityriasis lichenoides, secondary syphilis, and the rare dyschromatosis universalis hereditaria. Folliculitis can also occur as a related Malassezia-associated condition, particularly in immunocompromised patients.

## Treatment

First-line treatment includes selenium sulfide 2.5% suspension or zinc pyrithione shampoo, applied to the whole body and left on overnight, repeated again in 1 week and then monthly thereafter; these agents can be irritating, and patients should be warned about this. Topical antifungals applied twice daily for 1-2 weeks are an effective alternative. A single 400 mg dose of oral fluconazole may also be used. Recurrent infection is common regardless of the treatment chosen, and patients should be counseled that pigmentary changes can take weeks to months to normalize even after the infection is successfully treated.
"""

clinical_md = """## Recognizing Tinea Versicolor Across Ages

In an adolescent or young adult with oval, scaly, variably colored (white, pink, tan, or brown) macules or patches in a guttate pattern on the chest, back, neck, or upper arms - especially if lesions fail to tan with sun exposure and look relatively lighter in summer, darker in winter - diagnose tinea versicolor clinically and confirm, if needed, with Wood lamp exam (yellowish-brown fluorescence) or KOH prep (short stubby hyphae with spore clusters, "spaghetti and meatballs"). In an infant or young child, expect facial involvement, particularly the bilateral temples, rather than the classic trunk-predominant adult pattern, and still consider tinea versicolor even outside the typical postpubertal age range. Distinguish it from mimickers based on distribution and morphology: pityriasis alba (typically facial, in younger children, less scaly), vitiligo (depigmented rather than hypopigmented, no scale), seborrheic dermatitis (greasy scale in sebaceous areas), pityriasis rosea (herald patch, lesions along skin cleavage lines), and, when clinically indicated, secondary syphilis.

## Treating and Counseling on Recurrence

Start with selenium sulfide 2.5% suspension or zinc pyrithione shampoo applied to the entire body and left on overnight, repeating at 1 week and then monthly, and warn patients about skin irritation from this regimen; offer a topical antifungal cream twice daily for 1-2 weeks as an alternative, or a single 400 mg dose of fluconazole for a simpler regimen. Counsel families that recurrence is common regardless of treatment choice, and that the characteristic pigmentary change (hypo- or hyperpigmentation) can persist for weeks to months after the fungal infection itself has cleared, since it reflects a temporary disruption of melanin synthesis rather than ongoing active infection - reassurance on this point prevents unnecessary repeat treatment courses for lingering discoloration alone.
"""

build_and_save(
    topic="Tinea Versicolor",
    slug="tinea-versicolor",
    category_id=15900,
    summary="Tinea/pityriasis versicolor: the Malassezia yeast-to-mycelial transition, age-dependent distribution (facial in children, truncal in adolescents), the 'spaghetti and meatballs' KOH finding, and treatment with selenium sulfide or topical/oral antifungals.",
    references=references,
    short_md=short_md,
    long_md=long_md,
    clinical_md=clinical_md,
)
