import json, pathlib

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

article = {
    "topic": "Irritable Bowel Syndrome",
    "slug": "irritable-bowel-syndrome",
    "category_id": 15021,
    "summary": "A functional gut-brain disorder causing recurrent abdominal pain and altered bowel habits in children, its Rome-criteria subtypes, red flags that argue against it, and supportive management.",
    "written_by": "claude-sonnet",
    "references": sources["references"],
    "short": [{
        "title": "In short",
        "content": """- Irritable bowel syndrome (IBS) is a functional disorder of gut-brain interaction, affecting up to 3% of school-aged children, causing recurrent crampy abdominal pain with altered bowel habits, without long-term structural damage.
- IBS is classified into the same subtypes as adult IBS by stool pattern: IBS with constipation (IBS-C), IBS with diarrhea (IBS-D, about a third of pediatric IBS), IBS with mixed constipation and diarrhea, and unspecified IBS.
- Diagnostic criteria (Rome IV) require abdominal pain at least 4 days per month for at least 2 months, associated with defecation and/or a change in stool frequency and/or a change in stool form, without alarm features such as rectal bleeding, anemia, weight loss, or fever.
- Children with IBS do not have nighttime diarrhea, unlike infectious or secretory diarrhea; characteristic features include partially formed or liquid first-morning stool, increased daytime frequency, a bowel movement after each meal (a prominent gastrocolic reflex), 3-10 mucus-containing stools per day, and alternating constipation.
- Affected children remain well overall — good appetite, no weight loss, growth impairment, fever, leukocytosis, steatorrhea, or protein malabsorption — which is the key distinction from inflammatory bowel disease or celiac disease.
- Pathophysiology involves altered GI motility (abnormally forceful small-intestine contractions) and visceral hypersensitivity (pain at lower balloon-inflation volumes than controls), modulated by psychosocial factors like stress and anxiety; symptoms can be precipitated by a prior GI infection, and a positive family history is common.
- Conditions to rule out before diagnosing IBS: late-onset lactose intolerance, excess fructose/sorbitol ingestion, celiac disease, and inflammatory bowel disease — all of which can mimic IBS symptoms.
- For a child with both constipation and abdominal pain, treat the constipation first; only if discomfort persists should the child be treated for IBS-constipation-predominant subtype.
- Treatment is largely supportive and often challenging: a high-residue/high-fiber diet is first-line for diarrhea-predominant IBS, with anticholinergics, tricyclic antidepressants (for diarrhea-predominant IBS under experienced supervision), probiotics, peppermint oil, elimination diets, behavioral treatments, and psychotherapy all showing some evidence of benefit."""
    }],
    "long": [
        {"title": "Definition",
         "content": "Irritable bowel syndrome (IBS) is a chronic, benign, functional disorder of gut-brain interaction that causes recurrent abdominal pain, bloating, discomfort, and altered frequency and consistency of bowel movements, without causing long-term structural damage. It can be managed supportively and is distinct from — and should not be confused with — inflammatory bowel disease, which is far more severe and causes chronic inflammatory damage."},
        {"title": "Epidemiology",
         "content": "IBS may affect up to 3% of school-aged children, with about one-third of this group having the diarrhea-predominant form (IBS-D)."},
        {"title": "Etiology",
         "content": "IBS is associated with altered gastrointestinal motility and an abnormal sensation of intra-abdominal events (visceral hypersensitivity). Studies of small-intestine pressure changes in children with IBS suggest abnormally forceful contractions occur, and affected individuals experience pain at substantially lower intestinal balloon-inflation volumes than controls — an interplay between motility and sensitivity, both modulated by psychosocial factors such as stress and anxiety. Symptoms may be precipitated by a preceding gastrointestinal infection, and a positive family history is often present."},
        {"title": "Clinical features",
         "content": "Children with IBS do not experience nighttime diarrhea, which instead suggests an infectious or secretory cause. Characteristic features include partially formed or liquid first-morning stool with increased frequency during the day, bowel movements after each meal (suggesting a prominent gastrocolic reflex), 3-10 mucus-containing stools per day, and alternating periods of constipation. Non-specific, often peri-umbilical abdominal pain that is worse before or relieved by defecation, explosive/loose/mucousy stools, bloating, and a feeling of incomplete defecation are typical, though not every patient has every symptom. Importantly, affected children appear well throughout the illness, without weight loss, growth impairment, fever, leukocytosis, steatorrhea, or protein malabsorption, and appetite remains good."},
        {"title": "Diagnostics",
         "content": "Rome IV diagnostic criteria require abdominal pain occurring at least 4 days per month for at least 2 months, associated with defecation and/or a change in stool frequency and/or a change in stool form/consistency, without the alarm features (rectal bleeding, anemia, weight loss, fever) that would suggest an organic cause. IBS is subclassified by stool pattern into IBS with constipation (IBS-C), IBS with diarrhea (IBS-D), IBS with mixed constipation and diarrhea, and unspecified IBS. Celiac disease should be ruled out as part of the workup. Overlapping functional constipation has separate diagnostic criteria (for children of developmental age 4 years or older) requiring two or more of: two or fewer toilet defecations per week, at least one weekly episode of fecal incontinence, retentive posturing or stool withholding, painful or hard bowel movements, a large fecal mass on rectal exam, or large-diameter stools that can obstruct the toilet — occurring for at least a month, without meeting full IBS criteria, and not explained by another condition."},
        {"title": "Differential diagnosis",
         "content": "Late-onset lactose intolerance and excess fructose or sorbitol ingestion are important to rule out, since they can produce symptoms mimicking IBS. Inflammatory bowel disease and celiac disease can also initially be mistaken for IBS, but these carry alarm features (rectal bleeding, anemia, weight loss, growth failure, elevated inflammatory markers) that IBS lacks. Abdominal migraine is a distinct entity, mainly in children 2-10 years old, causing poorly localized dull-to-severe abdominal pain accompanied by at least two of loss of appetite, nausea, vomiting, or pallor, with a strong family history of migraine and no symptoms between attacks; it is a clinical diagnosis. For a child with both constipation and abdominal pain, the constipation should be treated first — if discomfort persists despite this, the child should then be considered to have IBS with constipation."},
        {"title": "Treatment",
         "content": "Standard treatment includes increased dietary fiber (a high-residue diet is first-line for diarrhea-predominant IBS) and anticholinergic agents; tricyclic antidepressants can be used for diarrhea-predominant IBS under experienced supervision. Additional approaches with some supporting evidence, though treatment overall remains challenging, include probiotics (with variable success), peppermint oil, elimination diets, and behavioral treatments/psychotherapy, which are among the more effective interventions reported."},
    ],
    "clinical": [
        {"title": "Distinguishing IBS from organic disease at the bedside",
         "content": "In a child with recurrent, crampy abdominal pain and altered bowel habits, apply the Rome IV framework: abdominal pain at least 4 days per month for 2 months, tied to defecation or a change in stool frequency/form, in a child who otherwise looks well. Confirm the reassuring pattern: no nighttime diarrhea, good appetite, normal growth, and no weight loss, fever, rectal bleeding, or anemia. Any of these alarm features — or nighttime symptoms — should prompt evaluation for inflammatory bowel disease or celiac disease rather than a presumptive IBS diagnosis. Also rule out late-onset lactose intolerance and excess fructose/sorbitol intake, common IBS mimics, with a careful dietary history, and check celiac serologies as part of the workup. If constipation and pain coexist, treat the constipation first before attributing ongoing symptoms to IBS-constipation-predominant subtype."},
        {"title": "Stepwise supportive management",
         "content": "Start with dietary measures: a high-residue/high-fiber diet for diarrhea-predominant symptoms, and address any specific dietary triggers identified (excess fructose, sorbitol, or lactose). Add anticholinergic medication for pain, and consider a tricyclic antidepressant for diarrhea-predominant IBS specifically, under experienced supervision given the need for careful monitoring in children. Offer probiotics or peppermint oil as adjuncts, recognizing variable response, and refer for behavioral treatment or psychotherapy, since these are among the more effective interventions and address the stress/anxiety component of the gut-brain interaction underlying IBS. Set expectations with families that IBS is a benign, functional condition without long-term structural damage, but that management is often a process of trial and adjustment rather than a single definitive fix."},
    ],
}

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/irritable-bowel-syndrome.article.json")
out.write_text(json.dumps(article, indent=1))
print(out)
