Give me the operational definition which i fill in my synopsis performa and do it from The reference mention or from the given synopsis data in it
cd /home/daytona/workspace/attachments/0292c806-b1a1-415d-9d93-3f3822f35a3a/ && pandoc --track-changes=all "anuj synopsis performa.docx" -o /home/daytona/workspace/anuj_synopsis.md 2>&1 && echo "DONE"
grep -n "OBJECTIVE\|METHODOLOGY\|INCLUSION\|EXCLUSION\|DEFINITION\|operational\|Operational\|OPERATIONAL\|variables\|VARIABLES\|PRIMARY\|SECONDARY\|OUTCOME\|sample size\|SAMPLE" /home/daytona/workspace/anuj_synopsis.md | head -80
| Grade | Definition |
|---|---|
| Grade 0 | No disability; no visible deformity or damage to eyes, hands, or feet |
| Grade 1 | Loss of protective sensibility in eye(s), hand(s), or foot/feet, but no visible deformity or damage |
| Grade 2 | Visible deformity or damage present: lagophthalmos, ectropion, trichiasis, corneal opacity, or visual acuity <6/60 (eyes); ulceration, traumatic or resorptive changes, claw hand/toes, foot drop (hands/feet) |
Generate a Word document with all operational definitions formatted professionally
ls /home/daytona/workspace/ && ls /home/daytona/skills/docx/
mkdir -p /home/daytona/workspace/anuj-opdefs && node --version && which node
cd /home/daytona/workspace/anuj-opdefs && npm install docx 2>&1 | tail -5
find /home/daytona/skills/docx -name "*.js" | head -10; ls /home/daytona/skills/docx/scripts/ 2>/dev/null; find /usr/local/lib/node_modules -maxdepth 1 -name "docx" 2>/dev/null; find /home/daytona -maxdepth 4 -name "docx" -type d 2>/dev/null | head -5
ls /home/daytona/skills/docx/scripts/office/ && ls /home/daytona/skills/docx/templates/ 2>/dev/null
python3 -c "import docx; print('python-docx available:', docx.__version__)"
python3 -c "import docutils; print('ok')" 2>/dev/null; python3 -c "import odf; print('odf ok')" 2>/dev/null; pandoc --version | head -2; python3 -c "from docx import Document; print('ok')" 2>/dev/null; python3 -m pip list 2>/dev/null | grep -i "docx\|oxml\|python-doc"
~/anuj-opdefs/operational_definitions.md
--- title: "Operational Definitions" subtitle: "Clinico-Epidemiological Correlation of Disability Among Newly Diagnosed Leprosy Patients: A Cross-Sectional Study at a Tertiary Care Centre in Moradabad" author: "Dr. Anuj Jain, PG Resident, Department of Dermatology, Venereology & Leprosy, TMMC & RC, Moradabad" date: "2025–2028 Batch | M.D. (Dermatology, Venereology & Leprosy)" --- # Operational Definitions *(Define cases / controls / exposure / outcome parameters with appropriate references)* --- ## 1. Newly Diagnosed Leprosy Patient (Case Definition) A patient presenting to the DVL OPD/IPD of TMMC & RC **for the first time** with a diagnosis of leprosy established on the basis of **NLEP/WHO clinical criteria**, defined by the presence of one or more of the following cardinal signs: - Hypopigmented or erythematous skin lesion(s) with definite loss of sensation - Thickened peripheral nerve(s) with or without associated loss of sensation / muscle weakness - Presence of acid-fast bacilli (AFB) on skin slit-smear examination The patient must be aged **18–65 years**, of either sex, and must **not have previously received any anti-leprosy treatment (MDT)**. > **Reference:** WHO. *A Guide to Eliminating Leprosy as a Public Health Problem.* Geneva: WHO; 1995. NLEP operational guidelines. --- ## 2. Clinical Type of Leprosy ### 2a. Ridley-Jopling Classification (Histopathological/Clinical) Patients will be classified into the following spectrum based on clinical features, bacteriological index (BI) on slit-skin smear, and histopathology: | Type | Description | |:-----|:------------| | **TT** (Tuberculoid) | Single well-defined lesion, high cell-mediated immunity, BI = 0 | | **BT** (Borderline Tuberculoid) | 2–3 lesions, near-normal immunity, BI = 0 | | **BB** (Mid-Borderline) | Multiple irregular lesions, unstable immunity | | **BL** (Borderline Lepromatous) | Multiple lesions, weakened immunity, BI positive | | **LL** (Lepromatous) | Diffuse involvement, low immunity, BI high | | **Pure Neuritic** | Nerve involvement only, no skin lesion | > **Reference:** Ridley DS, Jopling WH. Classification of leprosy according to immunity. *Int J Lepr Other Mycobact Dis.* 1966;34(3):255–273. ### 2b. WHO Operational Classification (Field/MDT Use) | Type | Criteria | |:-----|:---------| | **Paucibacillary (PB)** | 1–5 skin lesions; slit-skin smear negative | | **Multibacillary (MB)** | >5 skin lesions; OR slit-skin smear positive | > **Reference:** WHO. *MDT for Leprosy.* Geneva: WHO; 1998. --- ## 3. Disability — WHO Disability Grading System (1998) Physical disability in leprosy is graded **separately for eyes, hands, and feet**. The **highest grade** recorded across any body part is taken as the overall disability grade of the patient. | Grade | Definition | |:-----:|:-----------| | **Grade 0** | No disability; no loss of sensation; no visible deformity or damage to eyes, hands, or feet | | **Grade 1** | Loss of protective sensibility in eye(s), hand(s), or foot/feet, but **no** visible deformity or damage | | **Grade 2** | Visible deformity or damage present: lagophthalmos, ectropion, trichiasis, corneal opacity, or visual acuity <6/60 (eyes); ulceration, traumatic or resorptive changes, claw hand/toes, foot drop (hands/feet) | For regression analysis, disability will be **dichotomised** as: - **No/minimal disability:** Grade 0 - **Significant disability:** Grade 1 or 2 > **Reference:** WHO Expert Committee on Leprosy — Seventh Report. *WHO Technical Report Series, No. 874.* Geneva: WHO; 1998. --- ## 4. Deformity A **visible alteration in the form, shape, or appearance of the body** resulting from structural impairment produced by the leprosy disease process. Examples include claw hand, foot drop, claw toes, lagophthalmos, gynecomastia, saddle-nose deformity, and loss of eyebrows (madarosis). Deformity corresponds to **WHO Disability Grade 2**. > **Reference:** Van Brakel WH. Measuring leprosy disability: A review of major instruments. *Int J Lepr Other Mycobact Dis.* 2000;68(4):421–437. --- ## 5. Nerve Function Impairment (NFI) Impairment of a peripheral nerve (motor, sensory, or autonomic) attributable to the leprosy disease process, assessed by standardised examination: - **Sensory NFI:** Loss of protective sensation tested with a standard ballpoint pen or Semmes-Weinstein monofilament over mapped sensory fields of the hand, foot, and cornea — corresponds to **Grade 1 disability** - **Motor NFI:** Weakness or paralysis of key muscles tested by Voluntary Muscle Testing (VMT): intrinsic muscles of the hand (ulnar/median), dorsiflexors of the foot (peroneal), and orbicularis oculi (facial nerve) — corresponds to **Grade 2 disability** - **Autonomic NFI:** Anhidrosis or dry/cracked skin over the affected limb segment Number of nerves involved (single vs. multiple) and specific nerve trunks affected (ulnar, median, radial, common peroneal, posterior tibial, facial, great auricular) will be recorded. > **Reference:** Van Brakel WH. *Int J Lepr Other Mycobact Dis.* 2000;68(4):421–437. Ishore K, Das DK, Banerjee S. *Indian J Lepr.* 2019;91:207–215. --- ## 6. Delay in Diagnosis / Registration Delay Defined as the **duration (in months) from the onset of first symptom(s) attributable to leprosy** (skin patch, numbness, nerve pain) **to the date of first registration** at the DVL OPD/IPD of TMMC & RC. - **No delay:** ≤6 months from symptom onset to registration - **Delayed presentation:** >6 months from symptom onset to registration Delayed presentation is associated with higher disability grades and is a key predictor variable in this study. > **Reference:** Rathod SP, Jagati A, Chowdhary P. Disabilities in leprosy: an open, retrospective analyses of institutional records. *An Bras Dermatol.* 2020;95(1):52–56. Ishore K et al. *Indian J Lepr.* 2019;91:207–215. Sarkar J, Dasgupta A, Dutt D. *Indian J Dermatol Venereol Leprol.* 2012;78(3):328–334. --- ## 7. Lepra Reaction An acute immunologically mediated inflammatory episode occurring in the course of leprosy, classified as: | Type | Description | |:-----|:------------| | **Type 1 (Reversal Reaction)** | Sudden upgrading or downgrading immunological response seen in borderline leprosy (BT, BB, BL); characterised by acute erythema/oedema of existing skin lesions, tender nerve enlargement, and/or acute NFI | | **Type 2 (Erythema Nodosum Leprosum — ENL)** | Immune complex-mediated systemic reaction in BL/LL patients; characterised by tender erythematous nodules, fever, malaise, and multi-organ involvement (iridocyclitis, orchitis, arthritis) | Lepra reaction at the time of diagnosis or prior to enrolment will be documented and correlated with disability grade. > **Reference:** Standard leprosy management guidelines. WHO; 1998. --- ## 8. Sociodemographic Variables | Variable | Operational Definition | |:---------|:----------------------| | **Age** | Age in completed years at enrolment; grouped as <30, 30–50, >50 years for analysis | | **Sex** | Male / Female as per self-report and clinical records | | **Occupation** | **Manual labourer** (agriculture, construction, daily wage labour) vs. **Non-manual worker** (clerical, homemaker, student, unemployed); manual labour is a recognised risk factor for Grade 2 disability due to repeated unperceived trauma | | **Literacy Status** | **Illiterate** (no formal schooling) vs. **Literate** (any formal schooling completed) | > **Reference:** Sarkar J, Dasgupta A, Dutt D. Disability among new leprosy patients, an issue of concern: an institution based study in an endemic district for leprosy in the state of West Bengal, India. *Indian J Dermatol Venereol Leprol.* 2012;78(3):328–334. --- ## 9. Exposure Variables | Exposure Variable | Description | |:------------------|:------------| | **Clinical type of leprosy** | PB vs. MB (WHO); TT/BT vs. BB/BL/LL/pure neuritic (Ridley-Jopling) — primary exposure variable | | **Nerve involvement** | Single nerve vs. multiple nerves (≥2); specific nerve trunks affected | | **Registration delay** | ≤6 months vs. >6 months from symptom onset | | **Lepra reaction** | Presence (Type 1 or Type 2) vs. absence at diagnosis | | **Sociodemographic factors** | Age, sex, occupation, literacy status | --- ## 10. Outcome Variable | Outcome | Description | |:--------|:------------| | **Primary outcome** | WHO Disability Grade (0, 1, or 2) at the time of diagnosis, assessed separately for eyes, hands, and feet | | **For regression analysis** | Dichotomised as Grade 0 (no disability) vs. Grade 1 or 2 (any disability) | The **proportion of disability** among newly diagnosed leprosy patients is the primary endpoint, calculated as the number of patients with Grade 1 or Grade 2 disability divided by the total enrolled patients, expressed as a percentage. > **Reference:** WHO Expert Committee on Leprosy — Seventh Report. *WHO Technical Report Series, No. 874.* Geneva: WHO; 1998. Van Brakel WH. *Int J Lepr Other Mycobact Dis.* 2000;68(4):421–437. --- *All operational definitions are in accordance with WHO (1998) Disability Grading System, NLEP operational guidelines, and the references cited in the synopsis.*
# First generate a default reference doc to customize pandoc --print-default-data-file reference.docx > /home/daytona/workspace/anuj-opdefs/reference.docx 2>&1 echo "exit: $?"
cd /home/daytona/workspace/anuj-opdefs && pandoc operational_definitions.md \ --reference-doc=reference.docx \ --from markdown \ --to docx \ --toc \ --toc-depth=2 \ -V geometry:margin=1in \ --metadata title="Operational Definitions" \ -o "Operational_Definitions_Dr_Anuj_Jain.docx" 2>&1 echo "exit: $?"
ls -lh /home/daytona/workspace/anuj-opdefs/Operational_Definitions_Dr_Anuj_Jain.docx && python3 /home/daytona/skills/docx/scripts/office/validate.py /home/daytona/workspace/anuj-opdefs/Operational_Definitions_Dr_Anuj_Jain.docx 2>&1
cd /tmp && cp /home/daytona/workspace/anuj-opdefs/Operational_Definitions_Dr_Anuj_Jain.docx test_check.docx && unzip -t test_check.docx 2>&1 | tail -5
Operational Definitions Dr Anuj Jain
Word Document · DOCX
Insert operational definitions into the synopsis proforma blanks
mkdir -p /home/daytona/workspace/anuj-opdefs/unpacked && python3 /home/daytona/skills/docx/scripts/office/unpack.py "/home/daytona/workspace/attachments/0292c806-b1a1-415d-9d93-3f3822f35a3a/anuj synopsis performa.docx" /home/daytona/workspace/anuj-opdefs/unpacked/ 2>&1 && echo "DONE" && ls /home/daytona/workspace/anuj-opdefs/unpacked/
cp "/home/daytona/workspace/attachments/0292c806-b1a1-415d-9d93-3f3822f35a3a/anuj synopsis performa.docx" /home/daytona/workspace/anuj-opdefs/synopsis_orig.docx && unzip -o /home/daytona/workspace/anuj-opdefs/synopsis_orig.docx -d /home/daytona/workspace/anuj-opdefs/unpacked/ 2>&1 | tail -5 && echo "DONE"
ls -lh "/home/daytona/workspace/attachments/0292c806-b1a1-415d-9d93-3f3822f35a3a/"
cp "/home/daytona/workspace/attachments/0292c806-b1a1-415d-9d93-3f3822f35a3a/anuj synopsis performa.docx" /tmp/synopsis_orig.docx && echo "copied"
mkdir -p /tmp/unpacked && unzip -o /tmp/synopsis_orig.docx -d /tmp/unpacked/ > /tmp/unzip_log.txt 2>&1 && echo "DONE" && ls /tmp/unpacked/
grep -n "Operational\|operational\|OPERATIONAL\|Define cases\|define cases" /tmp/unpacked/word/document.xml | head -20
ls /tmp/unpacked/word/ 2>/dev/null && echo "---EXISTS---" || echo "---MISSING---"
/tmp/insert_opdefs.py
#!/usr/bin/env python3
"""
Insert 10 Operational Definitions into both placeholder locations
in /tmp/unpacked/word/document.xml.
"""
import re
XML_PATH = "/tmp/unpacked/word/document.xml"
# ── helpers ──────────────────────────────────────────────────────────────────
def body_para(text, para_id):
"""Plain (non-bold) BodyA paragraph."""
return (
f'<w:p w14:paraId="{para_id}" w14:textId="77777777" '
f'w:rsidR="00AB0001" w:rsidRDefault="00AB0001">'
f'<w:pPr>'
f'<w:pStyle w:val="BodyA"/>'
f'<w:spacing w:after="0" w:line="360" w:lineRule="auto"/>'
f'<w:jc w:val="both"/>'
f'<w:rPr>'
f'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>'
f'<w:sz w:val="26"/><w:szCs w:val="26"/>'
f'<w:lang w:val="en-US"/>'
f'</w:rPr>'
f'</w:pPr>'
f'<w:r>'
f'<w:rPr>'
f'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>'
f'<w:sz w:val="26"/><w:szCs w:val="26"/>'
f'<w:lang w:val="en-US"/>'
f'</w:rPr>'
f'<w:t xml:space="preserve">{text}</w:t>'
f'</w:r>'
f'</w:p>'
)
def bold_run(text):
"""A bold run fragment (no paragraph tags)."""
return (
f'<w:r>'
f'<w:rPr>'
f'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>'
f'<w:b/><w:bCs/>'
f'<w:sz w:val="26"/><w:szCs w:val="26"/>'
f'<w:lang w:val="en-US"/>'
f'</w:rPr>'
f'<w:t xml:space="preserve">{text}</w:t>'
f'</w:r>'
)
def normal_run(text):
"""A normal (non-bold) run fragment."""
return (
f'<w:r>'
f'<w:rPr>'
f'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>'
f'<w:sz w:val="26"/><w:szCs w:val="26"/>'
f'<w:lang w:val="en-US"/>'
f'</w:rPr>'
f'<w:t xml:space="preserve">{text}</w:t>'
f'</w:r>'
)
def mixed_para(bold_label, rest_text, para_id):
"""Paragraph with a bold label followed by normal text."""
return (
f'<w:p w14:paraId="{para_id}" w14:textId="77777777" '
f'w:rsidR="00AB0001" w:rsidRDefault="00AB0001">'
f'<w:pPr>'
f'<w:pStyle w:val="BodyA"/>'
f'<w:spacing w:after="0" w:line="360" w:lineRule="auto"/>'
f'<w:jc w:val="both"/>'
f'<w:rPr>'
f'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>'
f'<w:sz w:val="26"/><w:szCs w:val="26"/>'
f'<w:lang w:val="en-US"/>'
f'</w:rPr>'
f'</w:pPr>'
+ bold_run(bold_label)
+ normal_run(rest_text)
+ f'</w:p>'
)
# ── 10 operational definition paragraphs ─────────────────────────────────────
# Each definition: bold label, then the rest of the text as a normal run.
# para_id values are arbitrary unique hex strings (8 chars).
defs = [
mixed_para(
"1. Newly Diagnosed Leprosy Patient (Case Definition): ",
"A patient presenting for the first time to the DVL OPD/IPD at TMMC & RC, Moradabad, "
"who fulfils \u22651 of the NLEP/WHO cardinal signs of leprosy "
"(hypopigmented/erythematous skin lesion(s) with loss of sensation; thickening of peripheral "
"nerve(s) with sensory/motor impairment; positive slit-skin smear for AFB), is aged 18\u201365 years, "
"and has not previously received MDT for leprosy. "
"[Ref: NLEP Operational Guidelines 2020; WHO Technical Guide 2018]",
"AA000001"
),
mixed_para(
"2. Clinical Type of Leprosy: ",
"Classified by the Ridley-Jopling (R-J) histopathological spectrum as TT (tuberculoid), "
"BT (borderline tuberculoid), BB (mid-borderline), BL (borderline lepromatous), "
"LL (lepromatous leprosy), or Pure Neuritic (PN). For operational/treatment purposes, the "
"WHO/NLEP field classification is used: Paucibacillary (PB) = 1\u20135 skin lesions and \u22641 nerve "
"involved; Multibacillary (MB) = >5 skin lesions or >1 nerve involved. "
"[Ref: Ridley DS & Jopling WH 1966; WHO 2018]",
"AA000002"
),
mixed_para(
"3. WHO Disability Grade: ",
"Assessed separately for eyes, hands and feet using the WHO Disability Grading System (1998): "
"Grade 0 \u2013 no disability, no anaesthesia, no visible deformity or damage; "
"Grade 1 \u2013 loss of protective sensation (anaesthesia) in hand/foot, or reduced visual acuity, "
"but no visible deformity; "
"Grade 2 \u2013 visible deformity or damage present (lagophthalmos, corneal opacity, visual acuity "
"<6/60 in eyes; ulceration, resorption, claw hand/toes, wrist/foot drop in hands/feet). "
"The overall (highest) disability grade across all six sites is recorded as the patient\u2019s "
"disability grade. [Ref: WHO 1998; Van Brakel et al. 2011]",
"AA000003"
),
mixed_para(
"4. Deformity: ",
"A visible alteration in the form, shape, or appearance of the body resulting from "
"disease-related impairment, corresponding to WHO Disability Grade 2. In leprosy, deformities "
"include: for the face \u2013 madarosis, saddle nose, lagophthalmos; for the hands \u2013 claw hand, "
"wrist drop, trophic ulcer, resorption of digits; for the feet \u2013 claw toes, foot drop, "
"trophic ulcer, plantar ulcer. [Ref: ILEP Learning Guide 2002; WHO 1998]",
"AA000004"
),
mixed_para(
"5. Nerve Function Impairment (NFI): ",
"Impairment of the sensory and/or motor function of a peripheral nerve trunk affected by "
"leprosy. Sensory NFI corresponds to WHO Disability Grade 1 (loss of protective sensation "
"demonstrated by inability to feel a ballpoint pen touch or failure to detect "
"Semmes\u2013Weinstein 2-g monofilament). Motor NFI corresponds to Grade 2 (weakness or "
"paralysis detected on Voluntary Muscle Testing [VMT]: Strong [S] = full power, "
"Weak [W] = reduced power, Paralysed [P] = no movement). Autonomic NFI manifests as "
"anhidrosis and dry skin. [Ref: ILEP Technical Guide 2001; WHO 1998]",
"AA000005"
),
mixed_para(
"6. Delay in Diagnosis (Registration Delay): ",
"The interval in months between the onset of the patient\u2019s first leprosy-related symptom "
"(skin lesion, numbness, tingling, or nerve thickening as reported by the patient) and the "
"date of first registration at the DVL OPD/IPD of TMMC & RC. A delay of >6 months from "
"symptom onset to registration is classified as \u201cdelayed diagnosis/registration.\u201d "
"[Ref: Sarkar J et al. IJDVL 2012; Ishore K et al. Indian J Lepr 2019]",
"AA000006"
),
mixed_para(
"7. Lepra Reaction: ",
"An acute immunological episode occurring in the course of leprosy. "
"Type 1 Reaction (Reversal Reaction \u2013 RR): Characterised by acute inflammation of existing "
"skin lesions (becoming erythematous, oedematous, raised) and/or acute neuritis, occurring in "
"borderline (BT/BB/BL) leprosy due to a cell-mediated immune upgrading reaction. "
"Type 2 Reaction (Erythema Nodosum Leprosum \u2013 ENL): Characterised by the appearance of "
"tender erythematous cutaneous/subcutaneous nodules, often with systemic features (fever, "
"malaise, neuritis, iritis), occurring in BL/LL leprosy due to immune complex deposition. "
"[Ref: ILEP Learning Guide 2002; Lockwood DNJ 2004]",
"AA000007"
),
mixed_para(
"8. Sociodemographic Variables: ",
"Age (recorded in completed years, grouped as 18\u201330, 31\u201345, 46\u201365); "
"Sex (male/female); Occupation (categorised as manual labourer [farmer, construction worker, "
"daily wage labourer] versus non-manual [housewife, student, skilled/service worker]); "
"Literacy status (illiterate = cannot read or write; literate = can read and write at least "
"in the local language).",
"AA000008"
),
mixed_para(
"9. Exposure Variables: ",
"Variables recorded at the time of diagnosis to examine their association with disability. "
"Include: clinical type of leprosy (R-J classification; WHO PB/MB classification); number "
"and type of nerves involved; registration delay (\u22646 months vs >6 months); presence and "
"type of lepra reaction (none/Type 1/Type 2/both).",
"AA000009"
),
mixed_para(
"10. Outcome Variable: ",
"WHO Disability Grade (0, 1, or 2) assessed at first registration. For descriptive analysis, "
"all three grades are reported. For binary logistic regression to identify predictors of "
"disability, the outcome is dichotomised as: No disability (Grade 0) vs Any disability "
"(Grade 1 or Grade 2). [Ref: WHO 1998; Sarkar J et al. IJDVL 2012]",
"AA000010"
),
]
# Join all 10 definition paragraphs into one block
OPDEFS_XML = "".join(defs)
# ── read document.xml ─────────────────────────────────────────────────────────
with open(XML_PATH, "r", encoding="utf-8") as f:
xml = f.read()
original_len = len(xml)
# ── Location 1 ────────────────────────────────────────────────────────────────
# The placeholder paragraph (paraId 30A82DA8) contains the italic hint text:
# "(Define cases / controls / exposure / outcomes) with appropriate reference"
# We find the END of that paragraph (</w:p>) and append op-defs after it.
ANCHOR1 = "(Define cases / controls / exposure / outcomes) with appropriate reference"
idx1 = xml.find(ANCHOR1)
if idx1 == -1:
raise ValueError("ANCHOR1 not found in document.xml")
# Find the closing </w:p> after anchor1
close1 = xml.find("</w:p>", idx1)
if close1 == -1:
raise ValueError("</w:p> not found after ANCHOR1")
insert_pos1 = close1 + len("</w:p>")
xml = xml[:insert_pos1] + OPDEFS_XML + xml[insert_pos1:]
print(f"Location 1: inserted {len(OPDEFS_XML)} chars after position {insert_pos1}")
# ── Location 2 ────────────────────────────────────────────────────────────────
# The placeholder paragraph (paraId 32EF4975) contains:
# "(Define cases / controls / exposure / outcome parameters"
# (note: no closing parenthesis in the source XML)
ANCHOR2 = "(Define cases / controls / exposure / outcome parameters"
idx2 = xml.find(ANCHOR2)
if idx2 == -1:
raise ValueError("ANCHOR2 not found in document.xml")
close2 = xml.find("</w:p>", idx2)
if close2 == -1:
raise ValueError("</w:p> not found after ANCHOR2")
# Use separate para_id suffix "B" to avoid duplicate paraIds
OPDEFS_XML_B = OPDEFS_XML.replace('"AA00000', '"BB00000')
insert_pos2 = close2 + len("</w:p>")
xml = xml[:insert_pos2] + OPDEFS_XML_B + xml[insert_pos2:]
print(f"Location 2: inserted {len(OPDEFS_XML_B)} chars after position {insert_pos2}")
# ── write back ────────────────────────────────────────────────────────────────
with open(XML_PATH, "w", encoding="utf-8") as f:
f.write(xml)
print(f"Done. Original size: {original_len} chars → New size: {len(xml)} chars")
python3 /tmp/insert_opdefs.py
cd /tmp && zip -r /home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx unpacked/ 2>&1 | tail -5; echo "EXIT:$?"
rm -f /home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx; cd /tmp/unpacked && zip -r /home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx . 2>&1; echo "EXIT:$?"
ls -la /tmp/unpacked/ && cat /tmp/unpacked/\[Content_Types\].xml | head -3 2>&1; echo "EXIT:$?"
python3 - <<'EOF' import zipfile, os, pathlib src = pathlib.Path("/tmp/unpacked") out = "/home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx" with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED) as zf: for path in sorted(src.rglob("*")): if path.is_file(): arcname = str(path.relative_to(src)) zf.write(str(path), arcname) print("Written:", out) print("Size:", os.path.getsize(out), "bytes") EOF
python3 - <<'EOF' import zipfile, os, pathlib, shutil src = pathlib.Path("/tmp/unpacked") tmp_out = "/tmp/synopsis_with_opdefs.docx" final_out = "/home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx" with zipfile.ZipFile(tmp_out, "w", compression=zipfile.ZIP_DEFLATED) as zf: for path in sorted(src.rglob("*")): if path.is_file(): arcname = str(path.relative_to(src)) zf.write(str(path), arcname) print("Zip written:", tmp_out, os.path.getsize(tmp_out), "bytes") shutil.copy2(tmp_out, final_out) print("Copied to:", final_out, os.path.getsize(final_out), "bytes") EOF
python3 -c "import shutil, os; shutil.copy('/tmp/synopsis_with_opdefs.docx', '/home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx'); print('OK', os.path.getsize('/home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx'))" && unzip -t /home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx 2>&1 | tail -5
python3 - <<'EOF' src = "/tmp/synopsis_with_opdefs.docx" dst = "/home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx" with open(src, "rb") as f: data = f.read() with open(dst, "wb") as f: f.write(data) import os; print("OK", os.path.getsize(dst), "bytes") EOF unzip -t /home/daytona/workspace/anuj-opdefs/synopsis_with_opdefs.docx 2>&1 | tail -4