{"id":137,"date":"2025-04-09T05:17:44","date_gmt":"2025-04-09T05:17:44","guid":{"rendered":"https:\/\/radap.medrad.lv\/?page_id=137"},"modified":"2025-04-09T05:18:04","modified_gmt":"2025-04-09T05:18:04","slug":"mugurkaulas-mr-izmeklejums-v2-tests","status":"publish","type":"page","link":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/","title":{"rendered":"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"lv\">\n<head>\n  <meta charset=\"UTF-8\">\n  <title>Mugurkaula jostas da\u013ca \u2013 Radiolo\u0123iskais zi\u0146ojums<\/title>\n  <style>\n    body { margin: 0; padding: 0; box-sizing: border-box; }\n    *, *:before, *:after { box-sizing: inherit; }\n    .container {\n      display: flex;\n      max-width: 1200px;\n      margin: 20px auto;\n      font-family: Arial, sans-serif;\n    }\n    .main-content { flex: 1; padding: 20px; }\n    .sidebar {\n      width: 350px;\n      border-left: 1px solid #ccc;\n      padding: 20px;\n      max-height: calc(100vh - 40px);\n      overflow-y: auto;\n    }\n    .textarea-block { margin-bottom: 20px; }\n    label { font-weight: bold; display: block; margin-bottom: 5px; }\n    #apraksta-teksts {\n      width: 100%;\n      min-height: 500px;\n      border: 1px solid #ccc;\n      padding: 10px;\n      line-height: 1.6;\n      overflow-y: auto;\n      border-radius: 4px;\n      background-color: #fdfdfd;\n    }\n    textarea#secinajums {\n      width: 100%;\n      height: 250px;\n      resize: vertical;\n      line-height: 1.6;\n      padding: 10px;\n      border-radius: 4px;\n      border: 1px solid #ccc;\n    }\n    .note { font-size: 0.9em; color: #666; margin-top: 10px; }\n    .highlight-addition {\n        background-color: #ffff99;\n        padding: 1px 0;\n        margin: -1px 0;\n        border-radius: 2px;\n        transition: background-color 0.5s ease;\n    }\n    .sidebar-buttons button {\n      padding: 8px 10px;\n      border: 1px solid #ccc;\n      background-color: #f1f1f1;\n      cursor: pointer;\n      text-align: left;\n      margin-bottom: 5px;\n      border-radius: 4px;\n      font-size: 0.95em;\n      transition: background-color 0.2s ease, border-color 0.2s ease;\n      width: auto; \/* Allow button width to be based on content *\/\n      margin-right: 4px; \/* Space between buttons in horizontal row *\/\n    }\n    \/* Ensure main category buttons span width *\/\n     .group-section > button {\n       width: 100%;\n       margin-right: 0; \/* No right margin for full-width buttons *\/\n     }\n\n    .sidebar-buttons button:hover { background-color: #e0e0e0; border-color: #bbb; }\n    .sidebar-buttons button.active {\n      background-color: #a3c1ad;\n      border-color: #6f8f80;\n      color: black;\n      font-weight: bold;\n    }\n    .group-section {\n      border: 1px solid #aaa;\n      padding: 10px;\n      margin-bottom: 12px;\n      border-radius: 5px;\n    }\n    .group-section h3 {\n      margin: 0 0 10px 0;\n      font-size: 1em;\n      color: #333;\n      border-bottom: 1px solid #ccc;\n      padding-bottom: 5px;\n    }\n    \/* Color-coded groups *\/\n    .group-kurvaturas { background-color: #EBF5FB; }\n    .group-skriemeli { background-color: #E8F8F5; }\n    .group-faseti { background-color: #FEF9E7; }\n    .group-diski { background-color: #F4ECF7; }\n    .group-stenoze { background-color: #FDEDEC; }\n    .group-cita { background-color: #F6DDCC; }\n\n    \/* --- Nested buttons containers --- *\/\n    \/* Base style for nested areas *\/\n    .nested-container {\n        margin-top: 8px;\n        padding: 8px 5px 5px 8px; \/* Top, R, B, L *\/\n        border-left: 2px solid #ccc;\n        margin-left: 5px;\n        overflow-x: auto; \/* Enable horizontal scroll *\/\n        background-color: rgba(0,0,0,0.02); \/* Slight background tint *\/\n        border-radius: 0 4px 4px 0; \/* Rounded corners *\/\n        white-space: nowrap; \/* Keep items in one line for scrolling *\/\n    }\n    \/* Specific style for simple horizontal level selectors *\/\n    .nested-buttons-horizontal {\n        display: flex;\n        flex-direction: row;\n        flex-wrap: nowrap; \/* Ensure single line *\/\n    }\n     \/* Container for complex selectors (level+side\/severity) *\/\n    .nested-buttons-complex {\n       white-space: normal; \/* Allow wrapping within this container if needed *\/\n    }\n    \/* Ensure buttons within horizontal layout don't take full width *\/\n    .nested-buttons-horizontal button {\n        width: auto;\n        flex-shrink: 0; \/* Prevent shrinking *\/\n    }\n\n     \/* Specific container for level + side\/severity buttons (vertical stack per level) *\/\n    .level-detail-container {\n        display: flex;\n        align-items: center;\n        gap: 5px; \/* Increased gap *\/\n        margin-bottom: 6px; \/* Space below each level row *\/\n        padding-bottom: 4px; \/* Space below buttons *\/\n        border-bottom: 1px dashed #eee; \/* Separator *\/\n        flex-wrap: wrap; \/* Allow wrapping if screen is too narrow *\/\n    }\n     .level-detail-container:last-child {\n         border-bottom: none; \/* No border for the last item *\/\n     }\n\n    .level-label {\n        min-width: 45px;\n        text-align: right;\n        font-weight: bold;\n        font-size: 0.9em;\n        padding-right: 5px;\n        white-space: nowrap; \/* Prevent label text wrapping *\/\n    }\n    \/* Level selection buttons *\/\n    .level-select-button {\n      min-width: 45px; \/* Slightly wider *\/\n      padding: 5px 8px; \/* Adjusted padding *\/\n      background-color: #f9e79f;\n      border: 1px solid #f3d97e;\n      text-align: center;\n      font-size: 0.9em;\n    }\n    .level-select-button.active {\n      background-color: #f7c34b; color: #333; border-color: #e0a82d;\n    }\n    \/* Side selection buttons (L\/R) *\/\n    .side-select-button {\n        min-width: 30px; \/* Slightly wider *\/\n        padding: 4px 6px;\n        font-size: 0.85em; \/* Slightly larger *\/\n        background-color: #d6eaf8;\n        border: 1px solid #aed6f1;\n        text-align: center;\n    }\n    .side-select-button.active {\n        background-color: #5dade2; color: white; border-color: #3498db;\n    }\n    .severity-select-button { \/* Added distinct class for severity *\/\n        min-width: 35px;\n        padding: 4px 6px;\n        font-size: 0.85em;\n        background-color: #e8daef; \/* Light purple *\/\n        border: 1px solid #d8bde4;\n        text-align: center;\n    }\n    .severity-select-button.active {\n        background-color: #a569bd; \/* Darker purple *\/\n        color: white;\n        border-color: #8e44ad;\n    }\n    \/* Styling for radio-like button groups *\/\n    .button-group { display: flex; gap: 4px; }\n    .button-group button { flex: 1; text-align: center; }\n    .button-row { display: flex; gap: 4px; margin-bottom: 4px; }\n\n    \/* Style for Spondylolisthesis details container *\/\n     .spondy-level-container {\n        display: inline-block; \/* Keep level button and details together *\/\n        vertical-align: top; \/* Align top *\/\n        margin-right: 5px; \/* Space between level blocks *\/\n        margin-bottom: 5px;\n     }\n    .spondy-details {\n        padding: 8px; \/* Increased padding *\/\n        margin-top: 4px;\n        background-color: #f8f9f9;\n        border: 1px solid #e9ecef; \/* Added border *\/\n        border-radius: 4px;\n        min-width: 200px; \/* Ensure details have some width *\/\n        display: block; \/* Ensure it takes block space below button *\/\n        white-space: normal; \/* Allow content wrapping *\/\n    }\n    .spondy-details .button-group { margin-top: 4px; }\n    .spondy-details label {\n        font-size: 0.9em; margin-bottom: 3px; font-weight: bold; color: #555; display: block; \/* Make label block *\/\n    }\n\n  <\/style>\n<\/head>\n<body>\n<div class=\"container\">\n  <div class=\"main-content\">\n    <h1>Mugurkaula jostas da\u013ca \u2013 Apraksta pievieno\u0161ana<\/h1>\n    <div class=\"textarea-block\">\n      <label for=\"apraksta-teksts\">Apraksta teksts<\/label>\n      <div id=\"apraksta-teksts\" contenteditable=\"true\" placeholder=\"Ievadiet aprakstu...\"><\/div>\n    <\/div>\n    <div class=\"textarea-block\">\n      <label for=\"secinajums\">Secin\u0101jums<\/label>\n      <textarea id=\"secinajums\" placeholder=\"Ievadiet secin\u0101jumu...\"><\/textarea>\n    <\/div>\n    <div class=\"note\">\n      *bold* = <strong>bold<\/strong>, _italic_ = <em>italic<\/em>. Tekstu var br\u012bvi redi\u0123\u0113t.\n    <\/div>\n  <\/div>\n  <div class=\"sidebar\">\n    <h2>Formas<\/h2>\n    <div id=\"sidebar-content\"><\/div>\n  <\/div>\n<\/div>\n\n<script>\n\/* ---------------- Constants ---------------- *\/\nconst LEVELS_VERTEBRA = [\"L1\", \"L2\", \"L3\", \"L4\", \"L5\", \"S1\"];\nconst LEVELS_SEGMENT = [\"L1\/L2\", \"L2\/L3\", \"L3\/L4\", \"L4\/L5\", \"L5\/S1\"];\nconst SPONDY_GRADES = [\"I\", \"II\", \"III\", \"IV\"];\nconst SPONDY_TYPES = [\"de\u0123enerat\u012bva\", \"istmiska\", \"cits\"];\nconst SEVERITIES = [\"m\u0113rena\", \"izteikta\"]; \/\/ Define severities\n\n\/* ---------------- Default Lumbar Template Lines (Parts) ---------------- *\/\nconst defaultLumbarText = {\n  technique: [ \"*MR mugurkaula jostas da\u013cai.*\", \"*Cor T2 FRFSE, Sag T2 FRFSE, Sag T1 FSE, Sag STIR, Ax T2 FRFSE (no L2 l\u012bdz S1 l\u012bmenim).*\" ],\n  lordosisDefault: \"Mugurkaula jostas da\u013cas fiziolo\u0123isk\u0101 lordoze taisnota.\",\n  vertebraeDefault: \"Skrieme\u013cu \u0137erme\u0146i saglab\u0101ta augstuma, ar nelieliem ventr\u0101liem un dors\u0101liem spondilof\u012btiem no L2 l\u012bdz L5.\",\n  facetsDefault: \"Fase\u0161u loc\u012btavas bez izteikt\u0101m de\u0123enerat\u012bv\u0101m p\u0101rmai\u0146\u0101m.\",\n  discsDefault: \"Starpskrieme\u013cu diski bez izteiktas de\u0123ener\u0101cijas.\",\n  cordDefault: \"Muguras smadzen\u0113s jostas da\u013c\u0101 patolo\u0123iskas p\u0101rmai\u0146as nekonstat\u0113. Conus medullaris L1 l\u012bmen\u012b.\",\n  stenosisDefault: \"Spin\u0101lais kan\u0101ls nav sa\u0161aurin\u0101ts.\", \/\/ Default if no specific finding\n  foraminalDefault: \"Neir\u0101l\u0101s atveres nav sa\u0161aurin\u0101tas.\",\n  nerveRootDefault: \"Nervu sakn\u012btes br\u012bvas.\"\n};\n\n\/* ---------------- Lumbar State ---------------- *\/\nlet lumbarState = {\n  lordosis: \"taisnots\", scoliosis: \"none\",\n  showHeightReductionLevels: false, vertebraHeightReduced: [],\n  showModic2Levels: false, vertebraModic2: [],\n  showHemangiomaLevels: false, vertebraHemangioma: [],\n  showSchmorlLevels: false, vertebraSchmorl: [],\n  showFacetArthrosisLevels: false, facetArthrosis: [],\n  showFacetCystLevels: false, facetCyst: [],\n  discDehydration: [], discHeightReduced: [], discProtrusion: [], discExtrusion: [], discSequestration: [], discAnnularFissure: [],\n  showSpinalStenosisLevels: false,\n  spinalStenosis: [], \/\/ Array of objects { level: \"L4\/L5\", severity: \"m\u0113rena\" } - CHANGED TO SEGMENT\n  showForaminalStenosisLevels: false, foraminalStenosis: [],\n  showNerveCompressionLevels: false, nerveCompression: [],\n  showSpondyLevels: false, spondylolisthesis: [],\n  showTarlovLevels: false, tarlovCysts: [],\n  showDiscDehydrationLevels: false, showDiscHeightReducedLevels: false, showDiscProtrusionLevels: false, showDiscExtrusionLevels: false, showDiscSequestrationLevels: false, showDiscAnnularFissureLevels: false,\n};\n\n\/* ---------------- Helper Functions ---------------- *\/\nfunction sortLevels(levels) { \/* ... as before ... *\/\n    return levels.sort((a, b) => {\n        const numA = parseInt(a.match(\/\\d+\/)[0], 10);\n        const numB = parseInt(b.match(\/\\d+\/)[0], 10);\n        if (numA !== numB) return numA - numB;\n        return a.length - b.length;\n    });\n}\nfunction formatLevelList(levels) { \/* ... as before ... *\/\n    if (!levels || levels.length === 0) return \"\";\n    const sorted = sortLevels([...levels]);\n    if (sorted.length === 1) return sorted[0];\n    return sorted.slice(0, -1).join(\", \") + \" un \" + sorted[sorted.length - 1];\n}\nfunction formatModicLevels(levels) { \/* ... as before ... *\/\n    if (!levels || levels.length === 0) return \"\";\n    return sortLevels([...levels]).join('\/');\n}\nfunction groupFindingsByLevel(findingsArray) { \/* ... as before ... *\/\n    const grouped = {};\n    findingsArray.forEach(finding => {\n        if (!grouped[finding.level]) grouped[finding.level] = [];\n        grouped[finding.level].push(finding);\n    });\n    return grouped;\n}\n\n\/* ---------------- Render Lumbar Report ---------------- *\/\nfunction renderLumbarReport() {\n  let lines = [...defaultLumbarText.technique];\n\n  \/\/ --- Kurvat\u016bras ---\n  \/\/ ... (no changes) ...\n    if (lumbarState.lordosis === \"mereni_taisnots\") lines.push(\"Mugurkaula jostas da\u013cas fiziolo\u0123isk\u0101 lordoze m\u0113reni taisnota.\");\n    else if (lumbarState.lordosis === \"pastiprinats\") lines.push(\"Mugurkaula jostas da\u013cas fiziolo\u0123isk\u0101 lordoze pastiprin\u0101ta.\");\n    else lines.push(defaultLumbarText.lordosisDefault);\n    if (lumbarState.scoliosis === \"pa_labi\") lines.push(\"Jostas da\u013cas skoliotisks liekums pa labi.\");\n    else if (lumbarState.scoliosis === \"pa_kreisi\") lines.push(\"Jostas da\u013cas skoliotisks liekums pa kreisi.\");\n\n\n  \/\/ --- Skrieme\u013cu \u0137erme\u0146i ---\n  \/\/ ... (no changes) ...\n    let vertebraeLines = [];\n    if (lumbarState.vertebraHeightReduced.length === 0 && lumbarState.vertebraModic2.length === 0 && lumbarState.vertebraHemangioma.length === 0 && lumbarState.vertebraSchmorl.length === 0) {\n        vertebraeLines.push(defaultLumbarText.vertebraeDefault);\n    } else {\n        vertebraeLines.push(\"Skrieme\u013cu \u0137erme\u0146os:\");\n        if (lumbarState.vertebraHeightReduced.length > 0) {\n            sortLevels(lumbarState.vertebraHeightReduced).forEach(level => { vertebraeLines.push(`- ${level} skriemelis samazin\u0101ta augstuma.`); });\n        }\n        if (lumbarState.vertebraModic2.length > 0) {\n            vertebraeLines.push(`- Modic II tipa izmai\u0146as ${formatModicLevels(lumbarState.vertebraModic2)}.`);\n        }\n        if (lumbarState.vertebraHemangioma.length > 0) {\n             vertebraeLines.push(`- Hemangioma(-s) ${formatLevelList(lumbarState.vertebraHemangioma)} skrieme\u013cu \u0137ermen\u012b(-os).`);\n         }\n         if (lumbarState.vertebraSchmorl.length > 0) {\n             vertebraeLines.push(`- \u0160mor\u013ca tr\u016bce(-s) ${formatLevelList(lumbarState.vertebraSchmorl)} skrieme\u013cu nosl\u0113dzo\u0161aj\u0101s platn\u012bt\u0113s.`);\n         }\n        vertebraeLines.push(\"- Nelieli ventr\u0101li un dors\u0101li spondilof\u012bti no L2 l\u012bdz L5.\");\n    }\n    lines.push(...vertebraeLines);\n\n\n  \/\/ --- Fase\u0161u loc\u012btavas ---\n  \/\/ ... (no changes) ...\n    let facetLines = [];\n    if (lumbarState.facetArthrosis.length === 0 && lumbarState.facetCyst.length === 0) {\n        facetLines.push(defaultLumbarText.facetsDefault);\n    } else {\n        if (lumbarState.facetArthrosis.length > 0) {\n            facetLines.push(`Fase\u0161u loc\u012btavu artroze ${formatLevelList(lumbarState.facetArthrosis)} l\u012bmen\u012b(-os).`);\n        }\n        if (lumbarState.facetCyst.length > 0) {\n            lumbarState.facetCyst.forEach(cyst => {\n                facetLines.push(`Fase\u0161u loc\u012btavas sinovi\u0101la cista ${cyst.level} l\u012bmen\u012b ${cyst.side === 'right' ? 'pa labi' : 'pa kreisi'}.`);\n            });\n        }\n        if (lumbarState.facetArthrosis.length === 0 && lumbarState.facetCyst.length > 0) {\n             facetLines.push(\"P\u0101r\u0113j\u0101s fase\u0161u loc\u012btavas bez izteikt\u0101m p\u0101rmai\u0146\u0101m.\");\n        }\n    }\n    lines.push(...facetLines);\n\n  \/\/ --- Starpskrieme\u013cu diski ---\n  \/\/ ... (no changes) ...\n    let discLines = [];\n    const allDiscFindings = [ \/* ... *\/ ].flat(); \/\/ Combine all disc state arrays\n    if (allDiscFindings.length === 0) {\n        discLines.push(defaultLumbarText.discsDefault);\n    } else {\n        discLines.push(\"Starpskrieme\u013cu diskos:\");\n        let findingsByLevel = {};\n        LEVELS_SEGMENT.forEach(level => {\n            let levelFindings = [];\n            if (lumbarState.discDehydration.includes(level)) levelFindings.push(\"dehidrat\u0101cija\");\n            if (lumbarState.discHeightReduced.includes(level)) levelFindings.push(\"augstuma samazin\u0101jums\");\n            if (lumbarState.discProtrusion.includes(level)) levelFindings.push(\"protr\u016bzija\");\n            if (lumbarState.discExtrusion.includes(level)) levelFindings.push(\"ekstr\u016bzija\");\n            if (lumbarState.discSequestration.includes(level)) levelFindings.push(\"sekvestr\u0101cija\");\n            if (lumbarState.discAnnularFissure.includes(level)) levelFindings.push(\"gredzena pl\u012bsums\");\n            if (levelFindings.length > 0) findingsByLevel[level] = levelFindings;\n        });\n        Object.keys(findingsByLevel).sort(sortLevels).forEach(level => {\n            discLines.push(`- ${level}: ${findingsByLevel[level].join(', ')}.`);\n            if (findingsByLevel[level].some(f => ['protr\u016bzija', 'ekstr\u016bzija', 'sekvestr\u0101cija'].includes(f))) {\n                discLines.push(`  _(Ietekme uz strukt\u016br\u0101m j\u0101preciz\u0113 manu\u0101li)_`); \/\/ Shorter note\n            }\n        });\n        discLines.push(\"P\u0101r\u0113jos l\u012bme\u0146os diski bez noz\u012bm\u012bg\u0101m p\u0101rmai\u0146\u0101m.\");\n    }\n    lines.push(...discLines);\n\n\n  \/\/ --- Stenoze \/ Kompresija ---\n    let stenosisLines = [];\n    let hasSpinalStenosis = lumbarState.spinalStenosis.length > 0;\n    let hasForaminalStenosis = lumbarState.foraminalStenosis.length > 0;\n    let hasNerveCompression = lumbarState.nerveCompression.length > 0;\n\n    \/\/ Spinal Stenosis - NOW USES SEGMENT LEVELS\n    if (hasSpinalStenosis) {\n        const grouped = groupFindingsByLevel(lumbarState.spinalStenosis);\n        Object.keys(grouped).sort(sortLevels).forEach(level => { \/\/ level is \"L4\/L5\" etc.\n            const severities = grouped[level].map(s => s.severity).join('\/');\n            stenosisLines.push(`Spin\u0101l\u0101 kan\u0101la ${severities} stenoze ${level} l\u012bmen\u012b.`);\n        });\n    } else {\n        stenosisLines.push(defaultLumbarText.stenosisDefault);\n    }\n\n    \/\/ Foraminal Stenosis - (no level logic changes, already segment)\n    if (hasForaminalStenosis) {\n        const grouped = groupFindingsByLevel(lumbarState.foraminalStenosis);\n        Object.keys(grouped).sort(sortLevels).forEach(level => {\n            let rightSeverities = grouped[level].filter(s => s.side === 'right').map(s => s.severity);\n            let leftSeverities = grouped[level].filter(s => s.side === 'left').map(s => s.severity);\n            let lineParts = [];\n            if (rightSeverities.length > 0) lineParts.push(`pa labi (${rightSeverities.join('\/')})`);\n            if (leftSeverities.length > 0) lineParts.push(`pa kreisi (${leftSeverities.join('\/')})`);\n            if (lineParts.length > 0) stenosisLines.push(`Foramin\u0101la stenoze ${level} l\u012bmen\u012b ${lineParts.join(', ')}.`);\n        });\n    } else {\n        stenosisLines.push(defaultLumbarText.foraminalDefault);\n    }\n\n    \/\/ Nerve Root Compression - (no level logic changes)\n    if (hasNerveCompression) {\n        const grouped = {};\n        lumbarState.nerveCompression.forEach(finding => {\n            if (!grouped[finding.root]) grouped[finding.root] = { right: false, left: false };\n            grouped[finding.root][finding.side] = true;\n        });\n        Object.keys(grouped).sort(sortLevels).forEach(root => {\n            let sides = [];\n            if (grouped[root].right) sides.push(\"pa labi\");\n            if (grouped[root].left) sides.push(\"pa kreisi\");\n            if (sides.length > 0) stenosisLines.push(`${root} sakn\u012btes kompresija ${sides.join(' un ')}.`);\n        });\n        stenosisLines.push(\"P\u0101r\u0113j\u0101s nervu sakn\u012btes br\u012bvas.\");\n    } else {\n        \/\/ Add default only if no compression AND some other stenosis was present\n        if (hasSpinalStenosis || hasForaminalStenosis) {\n             stenosisLines.push(defaultLumbarText.nerveRootDefault);\n        } else if (!hasSpinalStenosis && !hasForaminalStenosis) {\n             \/\/ If no stenosis of any kind, add default nerve root line too\n             stenosisLines.push(defaultLumbarText.nerveRootDefault);\n        }\n    }\n    lines.push(...stenosisLines);\n\n  \/\/ --- Muguras smadzenes ---\n  \/\/ ... (no changes) ...\n    lines.push(defaultLumbarText.cordDefault);\n\n  \/\/ --- Cita atrade ---\n  \/\/ ... (no changes) ...\n    let otherLines = [];\n    if (lumbarState.spondylolisthesis.length > 0) {\n        lumbarState.spondylolisthesis.forEach(spondy => {\n            otherLines.push(`${spondy.type === 'cits' ? 'Spondilolist\u0113ze' : spondy.type.charAt(0).toUpperCase() + spondy.type.slice(1) + ' spondilolist\u0113ze'} ${spondy.level} l\u012bmen\u012b, ${spondy.grade} pak\u0101pes.`);\n        });\n    }\n    if (lumbarState.tarlovCysts.length > 0) {\n        otherLines.push(`Tarlova cista(-s) ${formatLevelList(lumbarState.tarlovCysts)} l\u012bmen\u012b(-os) (preciz\u0113t lokaliz\u0101ciju).`);\n    }\n    if (otherLines.length > 0) {\n        lines.push(\"*Cita atrade:*\");\n        lines.push(...otherLines.map(l => `- ${l}`)); \/\/ Add bullet points\n    }\n\n  return {\n    aprakstsText: lines.filter(line => line && line.trim() !== '').join(\"\\n\"),\n    secinajumsText: buildLumbarConclusion()\n  };\n}\n\n\/* ---------------- Build Lumbar Conclusion ---------------- *\/\nfunction buildLumbarConclusion() {\n  let concl = [];\n  concl.push(\"MR mugurkaula jostas da\u013cai:\");\n\n  \/\/ ... (Degenerative changes summary logic - no changes) ...\n    let degenLevels = new Set([\n        ...lumbarState.facetArthrosis, ...lumbarState.discDehydration, ...lumbarState.discHeightReduced,\n        ...lumbarState.discProtrusion, ...lumbarState.discExtrusion, ...lumbarState.discSequestration,\n        ...lumbarState.discAnnularFissure,\n        ...lumbarState.spondylolisthesis.filter(s => s.type === 'de\u0123enerat\u012bva').map(s => s.level)\n    ]);\n    if (degenLevels.size > 0) { concl.push(`- De\u0123enerat\u012bvas izmai\u0146as ${formatLevelList(Array.from(degenLevels))} l\u012bmen\u012b(-os).`); }\n\n\n  \/\/ ... (Significant Disc Pathology logic - no changes) ...\n    let significantDiscLevels = new Set([...lumbarState.discExtrusion, ...lumbarState.discSequestration]);\n    if (lumbarState.discProtrusion.length > 0) { concl.push(`- Diska protr\u016bzija(-s) ${formatLevelList(lumbarState.discProtrusion)} l\u012bmen\u012b(-os).`); }\n    if (significantDiscLevels.size > 0) { concl.push(`- Diska ekstr\u016bzija\/sekvestr\u0101cija ${formatLevelList(Array.from(significantDiscLevels))} l\u012bmen\u012b(-os).`); }\n\n\n  \/\/ Stenosis - updated for spinal stenosis segment levels\n  if (lumbarState.spinalStenosis.length > 0) {\n      const levels = lumbarState.spinalStenosis.map(s => `${s.level} (${s.severity})`); \/\/ Level is now \"L4\/L5\" etc.\n      concl.push(`- Spin\u0101l\u0101 kan\u0101la stenoze ${formatLevelList(levels)}.`);\n  }\n  if (lumbarState.foraminalStenosis.length > 0) {\n      const levels = lumbarState.foraminalStenosis.map(s => `${s.level} ${s.side === 'right' ? 'dx' : 'sin'} (${s.severity})`);\n      concl.push(`- Foramin\u0101la stenoze ${formatLevelList(levels)}.`);\n  }\n\n  \/\/ ... (Nerve Compression logic - no changes) ...\n    if (lumbarState.nerveCompression.length > 0) {\n        const roots = lumbarState.nerveCompression.map(c => `${c.root} ${c.side === 'right' ? 'dx' : 'sin'}`);\n        concl.push(`- ${formatLevelList(roots)} sakn\u012btes kompresija.`);\n    }\n\n  \/\/ ... (Spondylolisthesis logic - no changes) ...\n    if (lumbarState.spondylolisthesis.length > 0) {\n        lumbarState.spondylolisthesis.forEach(spondy => { concl.push(`- ${spondy.type.charAt(0).toUpperCase() + spondy.type.slice(1)} spondilolist\u0113ze ${spondy.level}, ${spondy.grade} pak.`); });\n    }\n\n   \/\/ ... (Modic logic - no changes) ...\n    if (lumbarState.vertebraModic2.length > 0) { concl.push(`- Modic II izmai\u0146as ${formatModicLevels(lumbarState.vertebraModic2)}.`); }\n\n   \/\/ ... (Other significant findings logic - no changes) ...\n    if (lumbarState.facetCyst.length > 0) {\n        const cysts = lumbarState.facetCyst.map(c => `${c.level} ${c.side === 'right' ? 'dx' : 'sin'}`);\n        concl.push(`- Fase\u0161u sinovi\u0101la cista(-s) ${formatLevelList(cysts)}.`);\n    }\n     if (lumbarState.tarlovCysts.length > 0) { concl.push(`- Tarlova cista(-s) ${formatLevelList(lumbarState.tarlovCysts)} l\u012bmen\u012b(-os).`); }\n\n  if (concl.length === 1) concl.push(\"- Bez b\u016btisk\u0101m patolo\u0123isk\u0101m izmai\u0146\u0101m.\"); \/\/ Changed default conclusion text\n\n  return concl.join(\"\\n\");\n}\n\n\/* ---------------- Diff Highlighting ---------------- *\/\nfunction highlightReport(newText) { \/* ... as before ... *\/\n    const container = document.getElementById(\"apraksta-teksts\");\n    const newLines = newText.split(\"\\n\");\n    const prevLines = previousLumbarReportLines || [];\n    let htmlContent = '';\n    const maxLength = Math.max(newLines.length, prevLines.length);\n    for (let i = 0; i < maxLength; i++) {\n        const newLine = newLines[i] || '';\n        const prevLine = prevLines[i] || '';\n        if (newLine !== prevLine &#038;&#038; newLine !== '') {\n            htmlContent += `<span class=\"highlight-addition\">${newLine}<\/span>`;\n        } else {\n            htmlContent += newLine;\n        }\n        if (i < newLines.length - 1) htmlContent += '<br>';\n    }\n    container.innerHTML = htmlContent;\n    previousLumbarReportLines = newLines;\n    setTimeout(() => {\n        const spans = container.querySelectorAll('span.highlight-addition');\n        spans.forEach(span => { span.outerHTML = span.innerHTML; });\n    }, 1500);\n}\n\n\/* ---------------- Update Main Report ---------------- *\/\nfunction updateReport() { \/* ... as before ... *\/\n  const { aprakstsText, secinajumsText } = renderLumbarReport();\n  highlightReport(aprakstsText);\n  document.getElementById(\"secinajums\").value = secinajumsText;\n}\n\n\/* ---------------- Generic Toggle\/Set Functions ---------------- *\/\nfunction setLordosis(value) { lumbarState.lordosis = value; updateReportAndSidebar(); }\nfunction setScoliosis(value) { lumbarState.scoliosis = value; updateReportAndSidebar(); }\nfunction toggleShowLevels(stateKey) { lumbarState[stateKey] = !lumbarState[stateKey]; updateLumbarSidebar(); } \/\/ Only update sidebar\nfunction toggleArrayItem(stateKey, item) { \/* ... as before ... *\/\n    const index = lumbarState[stateKey].indexOf(item);\n    if (index === -1) lumbarState[stateKey].push(item);\n    else lumbarState[stateKey].splice(index, 1);\n    updateReportAndSidebar();\n}\nfunction toggleFacetCyst(level, side) { \/* ... as before ... *\/\n    const index = lumbarState.facetCyst.findIndex(item => item.level === level && item.side === side);\n    if (index === -1) lumbarState.facetCyst.push({ level, side });\n    else lumbarState.facetCyst.splice(index, 1);\n    updateReportAndSidebar();\n}\n\n\/\/ Updated for SEGMENT levels\nfunction toggleSpinalStenosis(level, severity) {\n    const index = lumbarState.spinalStenosis.findIndex(item => item.level === level && item.severity === severity);\n    const existingIndexSameLevel = lumbarState.spinalStenosis.findIndex(item => item.level === level);\n    if (index === -1) {\n        if (existingIndexSameLevel !== -1) { lumbarState.spinalStenosis.splice(existingIndexSameLevel, 1); }\n        lumbarState.spinalStenosis.push({ level, severity });\n    } else {\n        lumbarState.spinalStenosis.splice(index, 1);\n    }\n    updateReportAndSidebar();\n}\n\nfunction toggleForaminalStenosis(level, side, severity) { \/* ... as before ... *\/\n    const index = lumbarState.foraminalStenosis.findIndex(item => item.level === level && item.side === side && item.severity === severity);\n    const existingIndexSameLevelSide = lumbarState.foraminalStenosis.findIndex(item => item.level === level && item.side === side);\n    if (index === -1) {\n        if (existingIndexSameLevelSide !== -1) { lumbarState.foraminalStenosis.splice(existingIndexSameLevelSide, 1); }\n        lumbarState.foraminalStenosis.push({ level, side, severity });\n    } else {\n        lumbarState.foraminalStenosis.splice(index, 1);\n    }\n    updateReportAndSidebar();\n}\nfunction toggleNerveCompression(root, side) { \/* ... as before ... *\/\n    const index = lumbarState.nerveCompression.findIndex(item => item.root === root && item.side === side);\n    if (index === -1) lumbarState.nerveCompression.push({ root, side });\n    else lumbarState.nerveCompression.splice(index, 1);\n    updateReportAndSidebar();\n}\nfunction toggleSpondy(level) { \/* ... as before ... *\/\n    const index = lumbarState.spondylolisthesis.findIndex(item => item.level === level);\n    if (index === -1) lumbarState.spondylolisthesis.push({ level: level, grade: \"I\", type: \"de\u0123enerat\u012bva\" });\n    else lumbarState.spondylolisthesis.splice(index, 1);\n    updateReportAndSidebar();\n}\nfunction setSpondyDetail(level, detailKey, value) { \/* ... as before ... *\/\n    const index = lumbarState.spondylolisthesis.findIndex(item => item.level === level);\n    if (index !== -1) {\n        lumbarState.spondylolisthesis[index][detailKey] = value;\n        updateReportAndSidebar();\n    }\n}\n\n\/* ---------------- Helper: Create Sidebar Button ---------------- *\/\nfunction createSidebarButton(label, onClick, isActiveFunc = null, buttonClass = null) { \/* ... as before ... *\/\n  const btn = document.createElement(\"button\");\n  btn.textContent = label;\n  if (typeof isActiveFunc === 'function' && isActiveFunc()) { btn.classList.add(\"active\"); }\n  if (buttonClass) { buttonClass.split(' ').forEach(cls => btn.classList.add(cls)); }\n  btn.addEventListener(\"click\", onClick);\n  return btn;\n}\n\/* ---------------- Helper: Create Group Section ---------------- *\/\nfunction createGroupSection(title, groupClass, elements) { \/* ... as before ... *\/\n  const group = document.createElement(\"div\");\n  group.classList.add(\"group-section\", groupClass);\n  const header = document.createElement(\"h3\");\n  header.textContent = title;\n  group.appendChild(header);\n  elements.forEach(el => group.appendChild(el));\n  return group;\n}\n\n\/* ---------------- Helper: Create Level Selectors --- *\/\n\n\/\/ ** Simple Horizontal Level Selectors **\nfunction createLevelSelectorsHorizontal(levels, stateKey, toggleFunction, isActiveFunction) {\n    const container = document.createElement(\"div\");\n    \/\/ Apply base nested style AND horizontal specific style\n    container.classList.add(\"nested-container\", \"nested-buttons-horizontal\");\n    levels.forEach(level => {\n        container.appendChild(\n            createSidebarButton(\n                level,\n                () => toggleFunction(stateKey, level),\n                () => isActiveFunction(stateKey, level),\n                \"level-select-button\" \/\/ Style for level buttons\n            )\n        );\n    });\n    return container;\n}\n\n\/\/ ** Complex Selectors (Level + Side\/Severity) - Vertical stack per level inside scrollable container **\nfunction createComplexSelectors(levels, createDetailRowFunction) {\n    const container = document.createElement(\"div\");\n     \/\/ Apply base nested style AND complex style\n    container.classList.add(\"nested-container\", \"nested-buttons-complex\");\n    levels.forEach(level => {\n        container.appendChild(createDetailRowFunction(level)); \/\/ Add the row for each level\n    });\n    return container;\n}\n\n\/\/ Function to create ONE row for Level + L\/R (used by createComplexSelectors)\nfunction createLevelSideRow(level, toggleFunction, isActiveFunction) {\n    const row = document.createElement(\"div\");\n    row.classList.add(\"level-detail-container\");\n    const label = document.createElement(\"span\");\n    label.classList.add(\"level-label\"); label.textContent = level; row.appendChild(label);\n    row.appendChild(createSidebarButton(\"Kr\", () => toggleFunction(level, \"left\"), () => isActiveFunction(level, \"left\"), \"side-select-button\"));\n    row.appendChild(createSidebarButton(\"Lb\", () => toggleFunction(level, \"right\"), () => isActiveFunction(level, \"right\"), \"side-select-button\"));\n    return row;\n}\n\n\/\/ Function to create ONE row for Level + Severities (used by createComplexSelectors)\nfunction createLevelSeverityRow(level, toggleFunction, isActiveFunction) {\n    const row = document.createElement(\"div\");\n    row.classList.add(\"level-detail-container\");\n    const label = document.createElement(\"span\");\n    label.classList.add(\"level-label\"); label.textContent = level; row.appendChild(label);\n    SEVERITIES.forEach(severity => {\n        const severityLabel = severity === 'm\u0113rena' ? 'M\u0113r.' : 'Izt.';\n         row.appendChild(createSidebarButton(severityLabel, () => toggleFunction(level, severity), () => isActiveFunction(level, severity), \"severity-select-button\"));\n    });\n    return row;\n}\n\n\/\/ Function to create ONE row for Level + L\/R + Severities (used by createComplexSelectors)\nfunction createLevelSideSeverityRow(level, toggleFunction, isActiveFunction) {\n    const row = document.createElement(\"div\");\n    row.classList.add(\"level-detail-container\");\n    const label = document.createElement(\"span\");\n    label.classList.add(\"level-label\"); label.textContent = level; row.appendChild(label);\n\n    ['left', 'right'].forEach(side => {\n        const sideLabelShort = side === 'left' ? 'Kr' : 'Lb';\n        SEVERITIES.forEach(severity => {\n             const severityLabelShort = severity === 'm\u0113rena' ? 'M\u0113r.' : 'Izt.';\n            const combinedLabel = `${sideLabelShort} ${severityLabelShort}`;\n             \/\/ Use severity-select-button style or side-select-button style? Let's use severity\n            row.appendChild(createSidebarButton(combinedLabel, () => toggleFunction(level, side, severity), () => isActiveFunction(level, side, severity), \"severity-select-button\"));\n        });\n    });\n    return row;\n}\n\n\n\/* ---------------- Build Lumbar Sidebar ---------------- *\/\nfunction buildLumbarSidebar() {\n  const container = document.createElement(\"div\");\n  container.classList.add(\"sidebar-buttons\");\n\n  \/\/ --- Kurvat\u016bras Group ---\n    const lordosisRow = document.createElement(\"div\"); lordosisRow.classList.add('button-row', 'button-group');\n    [ \/* ...lordosis buttons... *\/\n      createSidebarButton(\"Taisnota (Def.)\", () => setLordosis(\"taisnots\"), () => lumbarState.lordosis === \"taisnots\"),\n      createSidebarButton(\"M\u0113reni taisnota\", () => setLordosis(\"mereni_taisnots\"), () => lumbarState.lordosis === \"mereni_taisnots\"),\n      createSidebarButton(\"Pastiprin\u0101ta\", () => setLordosis(\"pastiprinats\"), () => lumbarState.lordosis === \"pastiprinats\")\n    ].forEach(btn => lordosisRow.appendChild(btn));\n   const scoliosisRow = document.createElement(\"div\"); scoliosisRow.classList.add('button-row', 'button-group');\n    [ \/* ...scoliosis buttons... *\/\n      createSidebarButton(\"Nav skoliozes (Def.)\", () => setScoliosis(\"none\"), () => lumbarState.scoliosis === \"none\"),\n      createSidebarButton(\"Skolioze pa labi\", () => setScoliosis(\"pa_labi\"), () => lumbarState.scoliosis === \"pa_labi\"),\n      createSidebarButton(\"Skolioze pa kreisi\", () => setScoliosis(\"pa_kreisi\"), () => lumbarState.scoliosis === \"pa_kreisi\")\n    ].forEach(btn => scoliosisRow.appendChild(btn));\n  container.appendChild(createGroupSection(\"Kurvat\u016bras\", \"group-kurvaturas\", [lordosisRow, scoliosisRow]));\n\n  \/\/ --- Skrieme\u013cu \u0137erme\u0146i Group ---\n  const skriemeliElements = [];\n  const skriemeliSimpleLevelsConfig = [\n      { key: 'vertebraHeightReduced', label: 'Samazin\u0101ta augstuma', levelsStateKey: 'showHeightReductionLevels', levels: LEVELS_VERTEBRA },\n      { key: 'vertebraModic2', label: 'Modic II izmai\u0146as', levelsStateKey: 'showModic2Levels', levels: LEVELS_VERTEBRA }, \/\/ Usually segment, but state stores vertebra level\n      { key: 'vertebraHemangioma', label: 'Hemangioma', levelsStateKey: 'showHemangiomaLevels', levels: LEVELS_VERTEBRA },\n      { key: 'vertebraSchmorl', label: '\u0160mor\u013ca tr\u016bces', levelsStateKey: 'showSchmorlLevels', levels: LEVELS_VERTEBRA }, \/\/ Often segment, using vertebra\n  ];\n    skriemeliSimpleLevelsConfig.forEach(config => {\n        skriemeliElements.push(createSidebarButton(`${config.label}...`, () => toggleShowLevels(config.levelsStateKey), () => lumbarState[config.levelsStateKey]));\n        if (lumbarState[config.levelsStateKey]) {\n            skriemeliElements.push(createLevelSelectorsHorizontal(config.levels, config.key, toggleArrayItem, (key, lvl) => lumbarState[key].includes(lvl)));\n        }\n    });\n  container.appendChild(createGroupSection(\"Skrieme\u013cu \u0137erme\u0146i\", \"group-skriemeli\", skriemeliElements));\n\n  \/\/ --- Fase\u0161u loc\u012btavas Group ---\n  const fasetiElements = [];\n  \/\/ Arthrosis (Simple levels - horizontal)\n  fasetiElements.push(createSidebarButton(\"Fase\u0161u artroze...\", () => toggleShowLevels('showFacetArthrosisLevels'), () => lumbarState.showFacetArthrosisLevels));\n  if (lumbarState.showFacetArthrosisLevels) {\n      fasetiElements.push(createLevelSelectorsHorizontal(LEVELS_SEGMENT, 'facetArthrosis', toggleArrayItem, (key, lvl) => lumbarState[key].includes(lvl)));\n  }\n  \/\/ Cyst (Complex - Level+Side - vertical stack inside scrollable container)\n  fasetiElements.push(createSidebarButton(\"Sinovi\u0101la cista...\", () => toggleShowLevels('showFacetCystLevels'), () => lumbarState.showFacetCystLevels));\n  if (lumbarState.showFacetCystLevels) {\n       fasetiElements.push(createComplexSelectors(LEVELS_SEGMENT, (level) =>\n           createLevelSideRow(level, toggleFacetCyst, (lvl, side) => lumbarState.facetCyst.some(item => item.level === lvl && item.side === side))\n       ));\n  }\n  container.appendChild(createGroupSection(\"Fase\u0161u loc\u012btavas\", \"group-faseti\", fasetiElements));\n\n  \/\/ --- Starpskrieme\u013cu diski Group ---\n    const diskiElements = [];\n    const discFindingsConfig = [\n        { key: 'discDehydration', label: 'Dehidrat\u0101cija', levelsStateKey: 'showDiscDehydrationLevels' },\n        { key: 'discHeightReduced', label: 'Augstuma samazin.', levelsStateKey: 'showDiscHeightReducedLevels' },\n        { key: 'discProtrusion', label: 'Protr\u016bzija', levelsStateKey: 'showDiscProtrusionLevels' },\n        { key: 'discExtrusion', label: 'Ekstr\u016bzija', levelsStateKey: 'showDiscExtrusionLevels' },\n        { key: 'discSequestration', label: 'Sekvestr\u0101cija', levelsStateKey: 'showDiscSequestrationLevels' },\n        { key: 'discAnnularFissure', label: 'Gredzena pl\u012bsums', levelsStateKey: 'showDiscAnnularFissureLevels' },\n    ];\n    \/\/ All disc findings use simple horizontal level selectors\n    discFindingsConfig.forEach(config => {\n        diskiElements.push(createSidebarButton(`${config.label}...`, () => toggleShowLevels(config.levelsStateKey), () => lumbarState[config.levelsStateKey]));\n        if (lumbarState[config.levelsStateKey]) {\n            diskiElements.push(createLevelSelectorsHorizontal(LEVELS_SEGMENT, config.key, toggleArrayItem, (key, lvl) => lumbarState[key].includes(lvl)));\n        }\n    });\n    container.appendChild(createGroupSection(\"Starpskrieme\u013cu diski\", \"group-diski\", diskiElements));\n\n  \/\/ --- Stenoze \/ Kompresija Group ---\n    const stenozeElements = [];\n    \/\/ Spinal Stenosis (Complex: Level(Segment) + Severity)\n    stenozeElements.push(createSidebarButton(\"Spin\u0101l\u0101 kan\u0101la stenoze...\", () => toggleShowLevels('showSpinalStenosisLevels'), () => lumbarState.showSpinalStenosisLevels));\n    if (lumbarState.showSpinalStenosisLevels) {\n        \/\/ USE SEGMENT LEVELS NOW\n        stenozeElements.push(createComplexSelectors(LEVELS_SEGMENT, (level) =>\n            createLevelSeverityRow(level, toggleSpinalStenosis, (lvl, sev) => lumbarState.spinalStenosis.some(item => item.level === lvl && item.severity === sev))\n        ));\n    }\n    \/\/ Foraminal Stenosis (Complex: Level(Segment) + Side + Severity)\n    stenozeElements.push(createSidebarButton(\"Foramin\u0101la stenoze...\", () => toggleShowLevels('showForaminalStenosisLevels'), () => lumbarState.showForaminalStenosisLevels));\n    if (lumbarState.showForaminalStenosisLevels) {\n         stenozeElements.push(createComplexSelectors(LEVELS_SEGMENT, (level) =>\n            createLevelSideSeverityRow(level, toggleForaminalStenosis, (lvl, side, sev) => lumbarState.foraminalStenosis.some(item => item.level === lvl && item.side === side && item.severity === sev))\n        ));\n    }\n    \/\/ Nerve Root Compression (Complex: Root(Vertebra Level for simplicity) + Side)\n    stenozeElements.push(createSidebarButton(\"Sakn\u012btes kompresija...\", () => toggleShowLevels('showNerveCompressionLevels'), () => lumbarState.showNerveCompressionLevels));\n    if (lumbarState.showNerveCompressionLevels) {\n        stenozeElements.push(createComplexSelectors(LEVELS_VERTEBRA, (level) => \/\/ Using L1-S1 as root identifiers\n             createLevelSideRow(level, toggleNerveCompression, (root, side) => lumbarState.nerveCompression.some(item => item.root === root && item.side === side))\n        ));\n    }\n    container.appendChild(createGroupSection(\"Stenoze \/ Kompresija\", \"group-stenoze\", stenozeElements));\n\n  \/\/ --- Cita atrade Group ---\n    const citaElements = [];\n    \/\/ Spondylolisthesis (Horizontal levels, vertical details)\n    citaElements.push(createSidebarButton(\"Spondilolist\u0113ze...\", () => toggleShowLevels('showSpondyLevels'), () => lumbarState.showSpondyLevels));\n    if (lumbarState.showSpondyLevels) {\n        const spondyContainer = document.createElement(\"div\");\n        \/\/ Use base nested style + horizontal specific style\n        spondyContainer.classList.add(\"nested-container\", \"nested-buttons-horizontal\");\n\n        LEVELS_SEGMENT.forEach(level => {\n             const spondyLevelContainer = document.createElement(\"div\"); \/\/ Container for button + details\n             spondyLevelContainer.classList.add('spondy-level-container');\n\n            const isActive = lumbarState.spondylolisthesis.some(s => s.level === level);\n            const spondyLevelButton = createSidebarButton(level, () => toggleSpondy(level), () => isActive, \"level-select-button\");\n            spondyLevelContainer.appendChild(spondyLevelButton);\n\n            if (isActive) {\n                const detailsDiv = document.createElement(\"div\");\n                detailsDiv.classList.add('spondy-details');\n                const currentSpondy = lumbarState.spondylolisthesis.find(s => s.level === level);\n                \/\/ Grade selectors\n                const gradeLabel = document.createElement('label'); gradeLabel.textContent = 'Pak\u0101pe:'; detailsDiv.appendChild(gradeLabel);\n                const gradeGroup = document.createElement('div'); gradeGroup.classList.add('button-group');\n                SPONDY_GRADES.forEach(grade => { gradeGroup.appendChild(createSidebarButton(grade, () => setSpondyDetail(level, 'grade', grade), () => currentSpondy.grade === grade, 'level-select-button')); });\n                detailsDiv.appendChild(gradeGroup);\n                 \/\/ Type selectors\n                const typeLabel = document.createElement('label'); typeLabel.textContent = 'Tips:'; detailsDiv.appendChild(typeLabel);\n                const typeGroup = document.createElement('div'); typeGroup.classList.add('button-group');\n                SPONDY_TYPES.forEach(type => { typeGroup.appendChild(createSidebarButton(type, () => setSpondyDetail(level, 'type', type), () => currentSpondy.type === type, 'level-select-button')); });\n                detailsDiv.appendChild(typeGroup);\n                \/\/ Append details DIV to the spondyLevelContainer, not the main horizontal container\n                spondyLevelContainer.appendChild(detailsDiv);\n            }\n             \/\/ Append the container for this level (button + optional details) to the main horizontal scroller\n             spondyContainer.appendChild(spondyLevelContainer);\n        });\n         citaElements.push(spondyContainer);\n    }\n\n    \/\/ Tarlov Cysts (Simple levels - horizontal)\n    citaElements.push(createSidebarButton(\"Tarlova cistas...\", () => toggleShowLevels('showTarlovLevels'), () => lumbarState.showTarlovLevels));\n    if (lumbarState.showTarlovLevels) {\n        citaElements.push(createLevelSelectorsHorizontal(LEVELS_SEGMENT, 'tarlovCysts', toggleArrayItem, (key, lvl) => lumbarState[key].includes(lvl)));\n    }\n    container.appendChild(createGroupSection(\"Cita atrade\", \"group-cita\", citaElements));\n\n  return container;\n}\n\n\/* ---------------- Update Sidebar & Report---------------- *\/\nfunction updateLumbarSidebar() { \/* ... as before ... *\/\n  const sidebarContent = document.getElementById(\"sidebar-content\");\n  sidebarContent.innerHTML = \"\";\n  sidebarContent.appendChild(buildLumbarSidebar());\n}\nfunction updateReportAndSidebar() { \/* ... as before ... *\/\n    updateReport();\n    updateLumbarSidebar();\n}\n\n\/* ---------------- Initialize ---------------- *\/\nfunction initLumbarExam() { \/* ... as before, state reset updated ... *\/\n  lumbarState = {\n    lordosis: \"taisnots\", scoliosis: \"none\",\n    showHeightReductionLevels: false, vertebraHeightReduced: [], showModic2Levels: false, vertebraModic2: [], showHemangiomaLevels: false, vertebraHemangioma: [], showSchmorlLevels: false, vertebraSchmorl: [],\n    showFacetArthrosisLevels: false, facetArthrosis: [], showFacetCystLevels: false, facetCyst: [],\n    discDehydration: [], discHeightReduced: [], discProtrusion: [], discExtrusion: [], discSequestration: [], discAnnularFissure: [],\n    showSpinalStenosisLevels: false, spinalStenosis: [], showForaminalStenosisLevels: false, foraminalStenosis: [], showNerveCompressionLevels: false, nerveCompression: [],\n    showSpondyLevels: false, spondylolisthesis: [], showTarlovLevels: false, tarlovCysts: [],\n    showDiscDehydrationLevels: false, showDiscHeightReducedLevels: false, showDiscProtrusionLevels: false, showDiscExtrusionLevels: false, showDiscSequestrationLevels: false, showDiscAnnularFissureLevels: false,\n  };\n  const initialReport = renderLumbarReport();\n  document.getElementById(\"apraksta-teksts\").innerHTML = initialReport.aprakstsText.replace(\/\\n\/g, '<br>');\n  document.getElementById(\"secinajums\").value = initialReport.secinajumsText;\n  previousLumbarReportLines = initialReport.aprakstsText.split('\\n');\n  updateLumbarSidebar();\n}\n\n\/\/ Initial call\ninitLumbarExam();\n\n<\/script>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>Mugurkaula jostas da\u013ca \u2013 Radiolo\u0123iskais zi\u0146ojums Mugurkaula jostas da\u013ca \u2013 Apraksta pievieno\u0161ana Apraksta teksts Secin\u0101jums *bold* = bold, _italic_ = italic. Tekstu var br\u012bvi redi\u0123\u0113t. Formas<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-137","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti\" \/>\n<meta property=\"og:description\" content=\"Mugurkaula jostas da\u013ca \u2013 Radiolo\u0123iskais zi\u0146ojums Mugurkaula jostas da\u013ca \u2013 Apraksta pievieno\u0161ana Apraksta teksts Secin\u0101jums *bold* = bold, _italic_ = italic. Tekstu var br\u012bvi redi\u0123\u0113t. Formas\" \/>\n<meta property=\"og:url\" content=\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/\" \/>\n<meta property=\"og:site_name\" content=\"Radiolo\u0123iskie Struktur\u0113tie apraksti\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-09T05:18:04+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/\",\"url\":\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/\",\"name\":\"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti\",\"isPartOf\":{\"@id\":\"https:\/\/radap.medrad.lv\/#website\"},\"datePublished\":\"2025-04-09T05:17:44+00:00\",\"dateModified\":\"2025-04-09T05:18:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/radap.medrad.lv\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/radap.medrad.lv\/#website\",\"url\":\"https:\/\/radap.medrad.lv\/\",\"name\":\"Radiolo\u0123iskie Struktur\u0113tie apraksti\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/radap.medrad.lv\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti","og_description":"Mugurkaula jostas da\u013ca \u2013 Radiolo\u0123iskais zi\u0146ojums Mugurkaula jostas da\u013ca \u2013 Apraksta pievieno\u0161ana Apraksta teksts Secin\u0101jums *bold* = bold, _italic_ = italic. Tekstu var br\u012bvi redi\u0123\u0113t. Formas","og_url":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/","og_site_name":"Radiolo\u0123iskie Struktur\u0113tie apraksti","article_modified_time":"2025-04-09T05:18:04+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/","url":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/","name":"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini - Radiolo\u0123iskie Struktur\u0113tie apraksti","isPartOf":{"@id":"https:\/\/radap.medrad.lv\/#website"},"datePublished":"2025-04-09T05:17:44+00:00","dateModified":"2025-04-09T05:18:04+00:00","breadcrumb":{"@id":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/radap.medrad.lv\/index.php\/mugurkaulas-mr-izmeklejums-v2-tests\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/radap.medrad.lv\/"},{"@type":"ListItem","position":2,"name":"Mugurkaulas MR izmekl\u0113jums v2-tests-Gemini"}]},{"@type":"WebSite","@id":"https:\/\/radap.medrad.lv\/#website","url":"https:\/\/radap.medrad.lv\/","name":"Radiolo\u0123iskie Struktur\u0113tie apraksti","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/radap.medrad.lv\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/pages\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":2,"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/radap.medrad.lv\/index.php\/wp-json\/wp\/v2\/media?parent=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}