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

references = [
 {"title": "CURRENT Diagnosis and Treatment Pediatrics, Twenty-Fourth Edition", "author": "Hay, William W., Levin, Myron J., Deterding, Robin R., Abzug, Mark J.", "pages": [450]},
 {"title": "Pediatric Board Study Guide", "author": None, "pages": [874]},
 {"title": "Berkowitz's Pediatrics", "author": "Berkowitz, Carol D.;", "pages": [1048, 1050, 1051, 1052]},
 {"title": "Kliegman R. Nelson Textbook of Pediatrics 2-Volume Set 22ed 2024", "author": None, "pages": [4179]},
 {"title": "Cover", "author": "Vitalsource Download", "pages": [4995]},
 {"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": [100]},
 {"title": "SKIN Boad Review1.pptx", "author": None, "pages": []},
]

short_md = """## In short

- Hair loss (alopecia) is classified into four categories: congenital diffuse, congenital localized, acquired diffuse, and acquired localized; acquired localized hair loss is the most common type overall in childhood.
- About 60% hair loss in a single area is needed before hair loss becomes clinically detectable.
- Three conditions account for most acquired localized pediatric hair loss: alopecia areata, tinea capitis, and traumatic alopecia (traction alopecia/hair pulling/trichotillomania).
- Alopecia areata is the most common cause of hair loss in children overall, presents as complete hair loss in a round/oval patch (immune/T-cell mediated, with dense lymphocytic infiltration preceding loss), and is associated with nail pitting and conditions like Hashimoto thyroiditis, Addison disease, pernicious anemia, myasthenia gravis, and vitiligo; about 50% of children regrow hair completely within 12 months, though relapse is common; treatment includes topical or intradermal triamcinolone steroids.
- Telogen effluvium is the most common form of diffuse hair loss in children: sudden conversion of many anagen (growing) hairs to telogen (resting) phase, occurring about 2-4 months (6-16 weeks by one source) after a stressor (illness, surgery, childbirth, fever, medication change, severe diet, or emotional stress); losing more than 150 hairs/day is atypical, and complete regrowth usually occurs within 6-12 months once the trigger resolves.
- Anagen effluvium is loss of actively growing hairs from reduced hair shaft production during the anagen phase, most commonly from chemotherapy or radiation.
- Tinea capitis is a leading cause of acquired hair loss, from Trichophyton (mainly T. tonsurans in the US) or Microsporum species, presenting with patchy alopecia, broken hairs, and scalp scaling; severe inflammatory (kerion) forms can cause permanent scarring alopecia. T. tonsurans does not fluoresce under Wood lamp, while M. canis fluoresces yellow-green - so a negative Wood lamp exam does not rule out tinea capitis.
- Trichotillomania shows hair of varying lengths remaining in the affected area (crown, occipital, parietal), sometimes with scalp hemorrhage or crusting from pulling; it is OCD-related and managed with behavioral therapy plus medication such as clomipramine or N-acetylcysteine.
- Neonatal alopecia has distinct causes: telogen effluvium in the first 6 months of life, pressure-related alopecia from birth trauma (e.g., a halo of hair loss around caput succedaneum, or occipital hair loss from prolonged pressure), congenital triangular alopecia, aplasia cutis congenita, hypothyroidism, hypopituitarism, and rare genetic conditions.
"""

long_md = """## Definition

Alopecia is partial or complete hair loss, classified as nonscarring or scarring (the latter rare in children, most often from prolonged or untreated inflammatory conditions such as pyoderma or tinea capitis). Hair loss in childhood is further divided into four categories: congenital diffuse, congenital localized, acquired diffuse, and acquired localized - with acquired localized hair loss being the most common type overall. Related terms: hypertrichosis is excessive hair growth in inappropriate locations; hirsutism is androgen-dependent male-pattern hair growth in women; hypotrichosis is deficient hair growth.

## Epidemiology

About 60% hair loss within a single area is required before hair loss becomes clinically apparent. Three conditions predominate among causes of acquired localized pediatric hair loss: traumatic alopecia (traction alopecia/hair pulling/trichotillomania), alopecia areata, and tinea capitis. Alopecia areata is the single most common cause of hair loss in children overall. Telogen effluvium is the most common cause of diffuse hair loss in children.

## Etiology

True alopecia is rarely congenital; it more often relates to an inflammatory dermatosis, mechanical factors, drug ingestion, infection, endocrinopathy (particularly hypothyroidism), nutritional disturbance, or disturbance of the normal hair growth cycle. Alopecia areata is thought to have an immunologic (T-cell-mediated autoimmune) pathogenic mechanism, with dense lymphocytic infiltration preceding hair loss, and is associated with atopy, nail pitting, and other autoimmune conditions including Hashimoto thyroiditis, Addison disease, pernicious anemia, myasthenia gravis, and vitiligo. Telogen effluvium results from abrupt conversion of numerous scalp hairs from the anagen (growth) phase into the telogen (resting) phase, triggered by events such as pregnancy, childbirth, discontinuation of oral contraceptives or steroids, severe febrile illness, medication change, severe dieting/sudden weight loss, acute blood loss, or significant emotional/psychiatric stress; hair loss appears roughly 2-4 months (variably cited as 6-16 weeks) after the trigger. Anagen effluvium results from reduced hair shaft production during the growth phase itself, most commonly from chemotherapy or radiation. Tinea capitis, a fungal scalp infection most often from Trichophyton tonsurans (or Microsporum species, especially with pet exposure), is among the most common causes of acquired hair loss, affecting mainly school-age children (3-7 years); prevalence is estimated at 3-13% of the pediatric population, with Black children having the highest infection rates. Neonatal causes include telogen effluvium in the first 6 months of life (from hormone level drop, high fever, or stress - the same mechanism causing normal newborn hair shedding), pressure-related alopecia from birth trauma (a halo of hair loss around caput succedaneum, or occipital hair loss from prolonged pressure over the occiput), congenital triangular alopecia, congenital nevi, aplasia cutis congenita, underlying cystic/meningocele lesions, complex developmental disorders (e.g., Kabuki syndrome), hypothyroidism, hypopituitarism, and rare genetic hair-shaft disorders (monilethrix, pili annulati, pili torti, trichorrhexis invaginata/bamboo hair) and rare conditions like atrichia with papular lesions and vitamin D-resistant rickets.

## Clinical Features

Alopecia areata presents as complete hair loss in a well-defined round or oval patch; about 50% of affected children regrow hair completely within 12 months, though relapse is common. Telogen effluvium presents as diffuse thinning with smooth, typically non-erythematous underlying scalp skin; nail pitting can be seen; losing more than 150 hairs per day is considered atypical, though patients often report losing several hundred hairs daily while clinically apparent baldness remains rare (individuals typically need to lose about 25% of scalp hair before thinning becomes visually apparent). Tinea capitis presents with patchy alopecia, broken-off hairs (sometimes appearing as black dots, especially with T. tonsurans), and scalp scaling; extent ranges from localized patches to severe inflammatory kerion formation, which can rarely cause permanent scarring alopecia. Trichotillomania (hair-pulling) shows hair loss with strands of variable length remaining in affected areas (commonly crown, occipital, and parietal regions), sometimes with scalp hemorrhage or crusting; it is related to obsessive-compulsive spectrum behavior, often with tension before pulling and gratification or tension release afterward.

## Diagnostics

Evaluation begins with the scalp exam to determine whether hair loss is diffuse or circumscribed, and whether inflammation, scale, or infiltrative change is present; gently pulling hair assesses whether it is easily removable. Microscopic examination of plucked hairs (mounted in Permount on a glass slide) evaluates for breakage, structural shaft defects, and whether growing or resting hairs are being shed. A Wood lamp exam of the scalp can support a diagnosis of tinea capitis if positive (Microsporum canis fluoresces yellow-green), but a negative result does not exclude infection, since T. tonsurans - the most common US cause of tinea capitis - does not fluoresce. History should account for the child's age, since certain causes cluster at particular ages, and should also cover recent illness, medications, stressors, and family history; examination should also note adenopathy, nail changes, and hair loss elsewhere on the body.

## Treatment

Alopecia areata is managed with topical or intradermal (triamcinolone) corticosteroids; spontaneous resolution over 6-12 months is common, and expectant management with reassurance is reasonable given this natural history. Telogen effluvium requires only reassurance, since regrowth typically occurs over months once the inciting trigger resolves or is removed. Trichotillomania management combines behavioral therapy (cognitive behavioral therapy) with medication such as clomipramine or N-acetylcysteine, built on a strong physician-patient-parent relationship since treatment can be difficult. Tinea capitis requires systemic (not topical) antifungal therapy given the depth of the infection within the hair shaft/follicle. Any underlying inflammatory scalp condition (such as atopic or seborrheic dermatitis) causing partial alopecia typically allows hair regrowth once treated successfully, provided the follicle has not been permanently damaged.
"""

clinical_md = """## Working Up a Child with Hair Loss

Start by classifying the pattern: diffuse versus circumscribed, and congenital versus acquired, since this framework (congenital diffuse, congenital localized, acquired diffuse, acquired localized) narrows the differential substantially. For circumscribed acquired hair loss, examine closely for the three leading causes: a smooth, well-demarcated bald patch suggests alopecia areata; scaling with broken hairs (sometimes black dots) suggests tinea capitis; and hairs of variable, uneven length with an irregular pattern (crown, occipital, parietal areas), sometimes with scalp crusting, suggests trichotillomania. Perform a Wood lamp exam if tinea capitis is suspected, but do not let a negative result exclude the diagnosis, since T. tonsurans - the dominant US cause - does not fluoresce; proceed to fungal culture/microscopy if suspicion remains. For diffuse hair loss, ask specifically about events 2-4 months prior (illness, surgery, childbirth, high fever, new medication, crash dieting, or major stress), since this history points to telogen effluvium, and reassure that regrowth is expected over 6-12 months. Consider anagen effluvium in any child on chemotherapy or radiation who develops hair loss.

## Treating Common Pediatric Alopecias

For alopecia areata, offer topical or intradermal triamcinolone and counsel that about half of children regrow hair fully within a year, though relapse can occur - also screen for associated autoimmune conditions (thyroid disease, vitiligo) and check for nail pitting on exam. For telogen effluvium, reassurance alone is usually sufficient once the inciting stressor is identified and addressed. For tinea capitis, start systemic antifungal therapy rather than topical treatment, since topical agents cannot penetrate the hair shaft; treat kerion-type presentations the same way, since most respond well without incision. For trichotillomania, build a strong therapeutic alliance with the child and family, initiate cognitive behavioral therapy, and consider adjunct medication (clomipramine or N-acetylcysteine) for refractory cases, recognizing the OCD-spectrum nature of the behavior.
"""

build_and_save(
    topic="Hair Loss",
    slug="hair-loss",
    category_id=15274,
    summary="Pediatric alopecia: distinguishing alopecia areata, telogen effluvium, tinea capitis, and trichotillomania by pattern and history, plus neonatal causes and Wood-lamp diagnostic pitfalls.",
    references=references,
    short_md=short_md,
    long_md=long_md,
    clinical_md=clinical_md,
)
