import json, pathlib

sources = json.loads(pathlib.Path("/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/articles/syncope.sources.json").read_text())

article = {
    "topic": "Syncope",
    "slug": "syncope",
    "category_id": 15072,
    "summary": "Transient loss of consciousness and postural tone from cerebral hypoperfusion in children, usually benign vasovagal syncope, but requiring a focused history, exam, and ECG to exclude the uncommon cardiac causes.",
    "written_by": "claude-sonnet",
    "references": sources["references"],
    "short": [{
        "title": "In short",
        "content": """- Syncope is a sudden, brief loss of consciousness and postural tone from transient global cerebral hypoperfusion, with spontaneous, rapid, complete recovery and no neurologic sequelae; presyncope/near-syncope is the same prodrome without actual loss of consciousness.
- It is common: about 15-25% (one source: 30-50%) of children experience syncope by age 18, it accounts for roughly 3% of pediatric ED visits (or about 126 per 100,000 children), incidence peaks in the second decade, and girls are affected more than boys.
- Autonomic (vasovagal/neurocardiogenic/reflex) syncope is the most common cause, accounting for about 80% of pediatric cases; it is triggered by prolonged standing, a hot/crowded environment, brisk exercise in heat, pain, medical procedures, or emotional distress, and classically has a prodrome of diaphoresis, warmth, pallor, or lightheadedness.
- Vasovagal syncope has three physiologic patterns: vasodepressor (hypotension-predominant), cardioinhibitory (bradycardia-predominant), or mixed hypotension plus bradycardia.
- Situational syncope is a related reflex type triggered by micturition, defecation, hair grooming, coughing, or sneezing.
- About 10% of pediatric syncope has an underlying cardiac cause — the one category that can be life-threatening — so history should specifically probe for syncope during exercise or while recumbent, associated chest pain or palpitations, known heart disease, or a family history of unexplained death, drowning, hypertrophic cardiomyopathy, long QT syndrome/other arrhythmias, or pacemaker placement.
- High-risk red flags warranting cardiac evaluation: exercise-induced syncope, syncope without a prodrome, an abnormal cardiac exam, early sudden cardiac death in the family, known/suspected heart disease, congenital cardiac abnormality, or an abnormal ECG.
- Evaluation centers on a detailed history, physical exam, and 12-lead ECG; routine blood testing and imaging add little and are not recommended routinely, given the overall low diagnostic yield of broad testing.
- A syncopal episode is usually distinguishable from a seizure by its story: the child is upright, feels lightheaded or nauseated, becomes pale, and slumps, with brief recovery and no postictal sleepiness (though brief seizure-like movements can occur); post-syncope, signs of increased vagal tone — pallor, clammy skin, dilated pupils, relative bradycardia — are common.
- Because recurrence is common, education and reassurance are an important part of management for benign syncope, and most patients can be discharged home after a careful ED evaluation."""
    }],
    "long": [
        {"title": "Definition",
         "content": "Syncope is a sudden, brief loss of consciousness and postural tone caused by transient global cerebral hypoperfusion, with spontaneous, rapid, and complete recovery and no neurologic sequelae. Presyncope (or near-syncope) describes the same prodromal sensory and postural changes without actual loss of consciousness — in some individuals, the complete loss of consciousness phase is skipped entirely, leaving only the prodrome and recovery."},
        {"title": "Epidemiology",
         "content": "Syncope is common in childhood, reported to occur at least once in 15-25% of children by age 18 (another source cites 30-50% by the end of adolescence). It accounts for roughly 3% of pediatric emergency department visits, or approximately 126 per 100,000 children presenting for medical attention. Incidence peaks during the second decade of life, and girls are more commonly affected than boys."},
        {"title": "Etiology",
         "content": "Autonomic (neurally mediated, reflex) syncope — encompassing vasovagal/neurocardiogenic syncope and situational syncope — is the most common cause in children and adolescents, accounting for almost 80% of cases. It results from a brief inability of the autonomic nervous system to maintain blood pressure and, sometimes, heart rate at the level needed for cerebral perfusion. Vasovagal syncope is triggered by prolonged standing, a crowded or poorly ventilated environment, brisk exercise in a warm setting, severe anxiety, pain (real or anticipated), fear, acute position change, or a specific event such as a medical procedure or emotional distress; it takes one of three forms — vasodepressor (predominant hypotension), cardioinhibitory (predominant bradycardia), or a mixed pattern with both. Situational syncope occurs after micturition, defecation, hair grooming, coughing, or sneezing. In children, symptoms of vasovagal syncope can overlap with postural orthostatic tachycardia syndrome (POTS), defined by a positional heart rate increase of 40 beats per minute or more with normal blood pressure. About 10% of children with syncope have an underlying cardiac cause, which is the category most likely to be life-threatening; other diseases, some serious, can also present as syncope."},
        {"title": "Clinical features",
         "content": "Vasovagal syncope classically has a prodrome of diaphoresis, warmth, pallor, or lightheadedness before the event; a syncopal episode itself is typically brief, with the child upright beforehand, developing lightheadedness or nausea, becoming pale, and slumping to the ground, sometimes with brief seizure-like movements. Recovery is rapid, distinguishing it from a seizure's postictal sleepiness. After the event, signs of increased vagal tone — pallor, clammy skin, dilated pupils, and relative bradycardia — are often present. Reflex/vasovagal syncope is more likely when there is a preceding prodrome, and is often associated with a recent position change, poor hydration or nutrition, or a warm environment; syncope without a prodrome should raise concern for a more serious cause."},
        {"title": "Diagnostics",
         "content": "Evaluation is guided primarily by a comprehensive medical and family history, a thorough physical examination, and a 12-lead ECG, which together identify most patients with life-threatening causes. Routine blood testing and imaging add little diagnostic yield and are not recommended routinely. Worrisome historical features include syncope occurring while recumbent or associated with exercise, chest pain, or palpitations; a personal history of repaired or unrepaired heart disease; or a family history of unexplained death, drowning, hypertrophic cardiomyopathy, long QT syndrome or other arrhythmias, or pacemaker placement. An abnormal cardiac examination should prompt urgent cardiac referral."},
        {"title": "Differential diagnosis",
         "content": "When a cause of pediatric syncope is identified, it is usually benign neurocardiogenic (vasovagal) syncope, but the differential diagnosis is broad and includes many conditions, some life-threatening, that can present as a syncopal episode. Syncope can usually be distinguished from a seizure by its history — an upright child with a prodrome of lightheadedness or nausea, pallor, and slumping, with rapid and complete recovery without postictal sleepiness — though brief seizure-like movements can accompany syncope. Narcolepsy is a separate cause of sudden alteration in alertness, involving uncontrollable daytime sleep episodes rather than loss of postural tone from hypoperfusion."},
        {"title": "Treatment",
         "content": "Because most pediatric syncope is benign, a minimal ED evaluation with parental education and reassurance is appropriate once high-risk features have been excluded. Since recurrence is common, patient and family education about triggers and prodromal symptoms is an important part of management. High-risk features — early sudden cardiac death in the family, known or suspected heart disease, congenital cardiac abnormality, exercise-induced syncope, syncope without prodrome, or an abnormal ECG — should prompt cardiac evaluation for the underlying cause rather than reassurance alone. Most syncope patients can be discharged home after a careful and thorough ED evaluation."},
    ],
    "clinical": [
        {"title": "Bedside history and examination",
         "content": "Evaluate every child with syncope with a comprehensive medical and family history, thorough physical examination, and a 12-lead ECG — this combination identifies most patients with a life-threatening cause, while routine blood testing and imaging add little and are not recommended routinely. Specifically ask about syncope occurring while recumbent or during exercise, associated chest pain or palpitations, personal history of repaired or unrepaired heart disease, and family history of unexplained death, drowning, hypertrophic cardiomyopathy, long QT syndrome or other arrhythmias, or pacemaker placement. Note whether there was a typical vasovagal prodrome (diaphoresis, warmth, pallor, lightheadedness) and a recognizable trigger (prolonged standing, heat, crowding, pain, emotional distress, position change) — syncope without a prodrome is a concerning feature. Refer any child with an abnormal cardiac exam for urgent cardiac evaluation."},
        {"title": "Deciding on further workup and disposition",
         "content": "Reserve cardiac evaluation (echocardiography, further rhythm monitoring, specialist referral) for children with high-risk features: early sudden cardiac death in the family, known or suspected heart disease, congenital cardiac abnormality, exercise-induced syncope, syncope without a prodrome, or an abnormal ECG. In their absence, and with a history consistent with reflex (vasovagal/situational) syncope, observation until the patient returns to baseline, followed by education and reassurance, is appropriate, since recurrence is common but the overall prognosis is benign. Most patients can be discharged home after this evaluation without further testing."},
    ],
}

for v in ("short", "long", "clinical"):
    for s in article[v]:
        assert s["title"].strip() and s["content"].strip()

out = pathlib.Path("/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/articles/syncope.article.json")
out.write_text(json.dumps(article, indent=1))
print(out)
