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

references = [
 {"title": "Kliegman R. Nelson Textbook of Pediatrics 2-Volume Set 22ed 2024", "author": None, "pages": [1404, 1764, 2571, 2572]},
 {"title": "2021_Fleisher_&_Ludwig's_Textbook_of_Pediatric_Emergency_Medicine.epub", "author": None, "pages": []},
 {"title": "Pediatric Clinical Practice Guidelines & Policies, 18th Edition", "author": "American Academy of Pediatrics", "pages": [382, 402, 405]},
 {"title": "Algorithms in Pediatrics", "author": None, "pages": [742]},
 {"title": "Pediatric Board Study Guide", "author": None, "pages": [606]},
 {"title": "Pediatric Otolaryngology (American Academy of Pediatrics) ( etc.)", "author": None, "pages": [422]},
 {"title": "Red_Book_2021_2024_Report_of_the_Comm_z_library_sk,_1lib_sk,", "author": None, "pages": [924]},
 {"title": "Pediatric Clinical Practice Guidelines and Policies", "author": "American Academy of Pediatrics (AAP);", "pages": [480, 503]},
]

short_md = """## In short

- Chronic sinusitis is defined as persistence of respiratory symptoms (cough, nasal discharge, or nasal congestion) for longer than 90 days (some sources say more than 12 weeks); this contrasts with acute sinusitis (under 30 days, or 7 days-4 weeks by another classification) and subacute sinusitis (1-3 months, or 4-12 weeks).
- Chronic rhinosinusitis is subdivided into CRS with nasal polyposis (CRSwNP) and CRS without nasal polyposis (CRSsNP); nasal polyposis in a child is a high-yield clue for cystic fibrosis.
- The ethmoid and maxillary sinuses are present at birth; the frontal sinus is not fully formed until 7-9 years of age, and the sphenoid sinus also develops later, in school-age children.
- Viral rhinosinusitis (a diffuse mucositis) predisposes to about 80% of bacterial sinus infections, while allergic inflammation predisposes to about 20%; children average 6-8 viral URIs per year, and roughly 5-13% of these may be complicated by secondary bacterial sinusitis.
- Predisposing conditions for chronic (possibly noninfectious) sinus disease include cystic fibrosis, primary ciliary dyskinesia, and immunoglobulin deficiencies; other risk factors include young age, recurrent URI, ciliary dysfunction, allergic rhinitis, GERD, and immune deficiency.
- Children with chronic sinusitis often have milder, more indolent symptoms than acute sinusitis - cough often worse when supine, and rhinorrhea - with fever less common and physical exam often normal.
- Chronic sinusitis lasting more than 1 year, or severe sinusitis requiring hospitalization, is often caused by S. aureus or anaerobes (Peptococcus, Peptostreptococcus, Bacteroides), as well as nontypeable H. influenzae and viridans streptococci - a different microbiology than typical acute bacterial sinusitis.
- Over-the-counter cold medications/decongestants (systemic or intranasal) are not recommended for children under 12; supportive therapy includes hydration, saline nasal rinses, and acetaminophen/ibuprofen.
- In recurrent acute or chronic sinusitis, empiric antimicrobial therapy is usually indicated; children who fail to improve should be referred to otolaryngology for endoscopic exam (with or without cultures), with adenoidectomy generally considered before CT imaging or sinus surgery in refractory cases.
"""

long_md = """## Definition

Sinusitis is inflammation of the paranasal sinuses (or, more broadly, of the lining of the nose and sinuses, since the two are often affected together as rhinosinusitis). By duration, acute sinusitis lasts under 30 days (one classification specifies 7 days to 4 weeks), subacute sinusitis 1-3 months (or 4-12 weeks), and chronic sinusitis is defined as persistence of symptoms for longer than 90 days (some sources specify more than 12 weeks). Chronic rhinosinusitis (CRS) is further divided into CRS with nasal polyposis (CRSwNP) and CRS without nasal polyposis (CRSsNP); in children, nasal polyposis is strongly associated with cystic fibrosis.

## Epidemiology

Sinusitis is common in childhood and adolescence. The ethmoid and maxillary sinuses are present at birth, while the frontal sinus is not fully formed until 7-9 years of age and the sphenoid sinus likewise develops later, in school-age children. Children have an average of 6-8 viral upper respiratory infections per year, and approximately 5-13% of these are complicated by secondary bacterial sinus infection (one source cites 6-7%). Viral rhinosinusitis (a diffuse mucositis) predisposes to roughly 80% of bacterial sinus infections, while allergic inflammation accounts for the remaining 20%. Children are also at increased risk of sinusitis-related complications compared with adults, attributed to lower immunity as well as the thinner bone of the lamina papyracea and fovea ethmoidalis.

## Etiology

Acute bacterial sinusitis in children shares causative organisms with acute otitis media: Streptococcus pneumoniae, nontypeable Haemophilus influenzae, Moraxella, and group A streptococcus; H. influenzae has become an especially important, likely now the most common, cause since routine pneumococcal vaccination. Chronic sinusitis lasting more than a year, or severe sinusitis requiring hospitalization, is more often caused by Staphylococcus aureus or anaerobes (Peptococcus, Peptostreptococcus, Bacteroides), with nontypeable H. influenzae and viridans group streptococci also frequently recovered - a distinct microbiology from typical acute disease. Fungal sinusitis is rare in immunocompetent children. Predisposing conditions for chronic, sometimes noninfectious, sinus disease include cystic fibrosis, primary ciliary dyskinesia, and immunoglobulin deficiencies. Additional risk factors for chronic rhinosinusitis include young age (developing immune system), recurrent URI, ciliary dysfunction, allergic rhinitis, gastroesophageal reflux disease, and immune deficiency.

## Clinical Features

Chronic rhinosinusitis symptoms include nasal congestion, facial pressure, nasal obstruction, rhinorrhea/postnasal drip, and altered sense of smell. Compared with acute sinusitis, children with chronic sinusitis tend to have milder, more indolent symptoms, notably a cough that is often worse when the child is supine, along with rhinorrhea; fever is less common, and the physical examination is often normal. Chronic sinonasal illness - whether from recurrent viral URI, recurrent acute sinusitis, chronic sinusitis, or allergic rhinitis - can present as a moist, productive cough from constant postnasal drip; in most children, chronic cough of sinonasal origin results from back-to-back viral illnesses with only brief windows of improvement. Chronic sinusitis and gastroesophageal reflux are both important, often under-recognized, causes of chronic cough that can mimic or worsen asthma, and children with chronic sinusitis frequently do not report classic localized sinus pressure or tenderness, making diagnosis challenging.

## Diagnostics

Because chronic sinusitis symptoms overlap with recurrent viral illness, it is important to establish whether the child's rhinorrhea and cough ever improve within the typical 10-14 day course of a viral illness; failure to do so supports a sinonasal diagnosis. Acute bacterial sinusitis (as distinct from chronic) is defined by one of three patterns: persistent URI symptoms (nasal discharge and/or daytime cough) beyond 10 days without improvement; a "double sickening" pattern of sudden worsening or new symptoms after initial improvement; or severe onset with fever of at least 39C (102F) and purulent nasal discharge for 3-4 consecutive days - bacteria are recovered from maxillary sinus aspirates in about 70% of children meeting these criteria. Existing clinical criteria are limited in distinguishing bacterial from viral acute rhinosinusitis, a limitation shared by AAP and IDSA guidelines. Imaging findings (sinus opacification, mucosal thickening, air-fluid levels) are also seen with the common cold and do not reliably distinguish it from sinusitis, so are not routinely used for diagnosis of uncomplicated disease.

## Treatment

Supportive therapy for sinusitis includes hydration, saline nasal rinses/irrigation, and acetaminophen or ibuprofen; over-the-counter cold medications and decongestants (systemic or intranasal) are not recommended in children under 12 years. For uncomplicated acute sinusitis, amoxicillin is acceptable first-line therapy, with amoxicillin-clavulanate reserved for those who fail to improve; a 10-day course is generally sufficient. For recurrent acute or chronic sinusitis, a course of empiric antimicrobial therapy is usually indicated as well. Children who fail to improve should be referred to an otolaryngologist for endoscopic examination, with or without cultures; in most refractory cases, adenoidectomy is considered before CT imaging of the sinuses or sinus surgery. Hospitalization for parenteral therapy is rarely required and is usually reserved for suspected progression to orbital cellulitis or another serious complication.

## Complications

Complications of sinusitis include orbital cellulitis, brain abscess, epidural or subdural empyema, and cavernous sinus thrombosis - orbital, intracranial, and local complication categories that occur more often in children than adults.
"""

clinical_md = """## Distinguishing Chronic Sinusitis from Recurrent Viral Illness

In a child with persistent cough (often worse lying supine) and rhinorrhea, first determine whether symptoms have ever fully resolved within the typical 10-14 day course of a viral URI - if symptoms have persisted beyond 90 days (or 12 weeks) without a clear symptom-free interval, favor chronic sinusitis or chronic rhinosinusitis over a string of separate viral illnesses. Expect chronic sinusitis to look milder than acute bacterial sinusitis: fever is uncommon and the exam is often normal, so a lack of classic sinus tenderness or fever does not exclude the diagnosis. Screen for predisposing conditions - cystic fibrosis (especially with nasal polyps), primary ciliary dyskinesia, immunoglobulin deficiency, allergic rhinitis, and GERD - since these change management and prognosis. Do not rely on sinus imaging (plain films or CT) to make the diagnosis in uncomplicated cases, since opacification, mucosal thickening, and air-fluid levels are also seen with the common cold.

## Treating Chronic or Recurrent Sinusitis

Start with supportive care - saline nasal irrigation, hydration, and acetaminophen or ibuprofen for discomfort - and avoid over-the-counter cold medications or decongestants in children under 12. Because chronic sinusitis (especially lasting beyond a year) has a different microbiology than typical acute disease, including S. aureus and anaerobes alongside nontypeable H. influenzae and viridans streptococci, initiate empiric antimicrobial therapy for recurrent acute or chronic sinusitis, and reassess if there is no improvement. Refer to otolaryngology for endoscopic examination (with or without cultures) when a child fails to improve on empiric therapy; in most refractory cases, adenoidectomy is considered as a next step before CT scanning of the sinuses or sinus surgery are pursued. Watch for and urgently evaluate any signs suggesting orbital or intracranial extension - periorbital swelling, visual change, severe headache, or altered mental status - since sinusitis complications (orbital cellulitis, brain abscess, epidural/subdural empyema, cavernous sinus thrombosis) occur more often in children than in adults and require prompt escalation of care.
"""

build_and_save(
    topic="Chronic Sinusitis",
    slug="chronic-sinusitis",
    category_id=15310,
    summary="Pediatric chronic sinusitis: the 90-day threshold distinguishing it from acute/subacute disease, its milder presentation and distinct microbiology, and the empiric-antibiotic-then-ENT-referral treatment pathway.",
    references=references,
    short_md=short_md,
    long_md=long_md,
    clinical_md=clinical_md,
)
