// MyChart Bedside AI Agent case study (Epic). Adds its project entry and case
// study page on top of src/data.jsx, which must load first.

(function () {
  window.PROJECT_PAGE.epic = {
    title: "MyChart Bedside AI Agent",
    subtitle: "Reducing setup burden with an AI agent to drive adoption",
    subtitleMaxWidth: 760,
    cover: "image",
    coverSrc: "assets/epic/thumbnail.png",
    coverVideoSrc: "assets/epic/mapping-fast.mp4",
    coverZoomVideoSrc: "assets/epic/mapping-agent-v2.mp4",
    coverPoster: "assets/epic/mapping-agent-v2.png",
    coverPosterDark: "assets/epic/mapping-agent-dark-v2.png",
    coverVideoDarkSrc: "assets/epic/mapping-fast-dark.mp4",
    coverZoomVideoDarkSrc: "assets/epic/mapping-agent-dark-v2.mp4",
    sectionGap: 120,
    eyebrowDate: "2026",
    live: { label: "Live since 2026" },
    tags: ["AI Agent", "Prompt Engineering", "Healthcare", "UX Design"],
    meta: [
      { label: "Role", value: "UX Design Quality Manager", sub: "AI Workflow Design,\nPrompt Engineering, Testing" },
      { label: "Team", value: "1 UX Design Quality Manager\n1 Developer\n1 Tech Lead (Advisor)" },
      { label: "Timeline", value: "3 Months" },
    ],
    sections: [
      {
        id: "overview",
        eyebrow: "01",
        navLabel: "Overview",
        title: "Overview",
        body: [
          "MyChart Bedside's adoption was held back by slow, manual setup. I designed an AI agent that suggests status mappings for analysts to review. Adoption is up over 30% since launch.",
        ],
        stats: [
          { value: "30%+", label: "increase in MyChart Bedside adoption since launch" },
          { value: "97.4%", label: "of AI mappings approved as-is, across 2,368 test cases" },
        ],
        figures: [
          { src: "assets/epic/bedside-tv-room.png", caption: "A patient using MyChart Bedside on a TV in their hospital room." },
        ],
      },
      {
        id: "context",
        eyebrow: "02",
        navLabel: "Context",
        title: "MyChart Bedside keeps patients informed, easing anxiety during their visit.",
        body: [
          "Patients and their visitors can see their **care team, vitals, medications, and current stage of care**.",
          "Which devices are available depends on the hospital. On a phone, patients can use the MyChart app, or open a web version through a secure link with no download or account needed.",
        ],
        figures: [
          { src: "assets/epic/bedside-devices.jpg", caption: "MyChart Bedside works across several devices: a hospital room TV, bedside iPad, or a patient's phone." },
        ],
        subsections: [
          {
            unnumbered: true,
            spaceAbove: 96,
            title: "MyChart Bedside was free, proven, and still underused.",
            body: [],
            highlights: [
              { icon: "smile", title: "Raises patient satisfaction", body: "Real-time transparency into their care reduces patient anxiety." },
              { icon: "funding", title: "Increases Medicare funding", body: "Higher HCAHPS satisfaction scores mean more Medicare reimbursement." },
              { icon: "included", title: "No extra cost", body: "Included in all hospitals' existing MyChart plans." },
            ],
            alert: {
              title: "Yet setup burden held adoption back.",
              body: "Manually mapping hundreds of hospital statuses was so time-consuming that **only about 30% of eligible hospitals had completed setup and implemented MyChart Bedside**."
            },
            alertSpaceBelow: 0,
          },
        ],
      },
      {
        id: "problem",
        eyebrow: "03",
        navLabel: "The Problem",
        title: "Analysts had to map hundreds of hospital statuses to 12 patient-facing ones, by hand, without a medical background.",
        highlight: true,
        highlightLabel: "Main Problem",
        workflow: {
          kicker: "Analyst workflow",
          label: "Before",
          sub: "Every status mapped by hand",
          steps: [
            { title: "Pull every ED status", chips: ["Admit Hold", "Bed Req", "+ 100s more"], chipsStack: true },
            { title: "Decode clinical shorthand", chips: ["MLP Dispo?", "PES?", "DOA?"], chipTone: "red" },
            { title: "Pick 1 of 12 patient-facing statuses", picker: true },
            { title: "Repeat for every status", repeat: "\u00d7 100s" },
          ],
        },
        body: [],
        // Diagram sits right under the Main Problem box, before the quote.
        leadFigures: [
          { src: "assets/epic/mapping-diagram.png", srcDark: "assets/epic/mapping-diagram-dark.png", caption: "Each hospital status has to be mapped to one of 12 patient-facing statuses." },
        ],
        figures: [],
        pullQuote: { spaceAbove: 70, text: "Our analyst team is already stretched thin. We know Bedside helps patients, but it's one more task we could get wrong, so it's easier and safer not to touch it.", author: "Hospital analyst", avatar: "assets/epic/analyst.png", avatarDark: "assets/epic/analyst-dark-v2.png" },
        subsections: [
          {
            unnumbered: true,
            spaceAbove: 180,
            showKicker: true,
            kicker: "Clinical jargon",
            navLabel: "Clinical jargon",
            title: "Analysts struggled to understand clinical terms, so it was difficult to map statuses correctly.",
            body: [
              "Most analysts have **no medical background**, yet they had to decide every hospital status mapping.",
              "Acronyms and subtle differences between treatment stages aren't obvious, so mapping 100+ statuses was very difficult and daunting.",
            ],
            figures: [
              { videoSrc: "assets/epic/manual-mapping-not-sure.mp4", videoDarkSrc: "assets/epic/manual-mapping-not-sure-dark.mp4", src: "assets/epic/manual-not-sure.png", srcDark: "assets/epic/manual-not-sure-dark.png", caption: "An analyst stuck on what to map different hospital statuses to." },
            ],
          },
          {
            unnumbered: true,
            spaceAbove: 120,
            showKicker: true,
            kicker: "Slow clinician help",
            navLabel: "Slow clinician help",
            title: "Getting a clinician's help was slow, causing delays and frustration.",
            body: [
              "When analysts got stuck, their only option was reaching out to clinicians who were busy treating patients, so questions sat for days.",
              "Analysts found it difficult to even ask for clinician help when they **weren't sure how to get started** with so many statuses. This made lots of analysts give up shortly after opening the configuration settings.",
              "With no way to flag a status in the system, analysts had to **track on their own which statuses they'd asked about** and were still waiting on.",
            ],
            figures: [
              { videoSrc: "assets/epic/manual-mapping-ask-help.mp4", videoDarkSrc: "assets/epic/manual-mapping-ask-help-dark.mp4", src: "assets/epic/manual-asking.png", srcDark: "assets/epic/manual-asking-dark.png", caption: "Waiting on a clinician to help with mappings, and the delays that followed." },
            ],
          },
          {
            unnumbered: true,
            spaceAbove: 120,
            showKicker: true,
            kicker: "High stakes",
            navLabel: "High stakes",
            title: "A wrong mapping could show a patient or their visitors something harmful or inappropriate.",
            body: [
              "Internal statuses like \"Deceased\" or \"Psych Evaluation\" should never reach a patient's screen.",
              "When a status is sensitive, it has to map to a neutral one like \"Care in Progress.\"",
            ],
            figures: [
              { src: "assets/epic/high-stakes-mappings.png", srcDark: "assets/epic/high-stakes-mappings-dark.png", caption: "Two sensitive hospital statuses: a wrong mapping misleads the family, while \"Care in Progress\" keeps details private." },
            ],
          },
        ],
      },
      {
        id: "improvements",
        eyebrow: "04",
        navLabel: "Solution",
        title: "An AI agent suggests a mapping for every status, so analysts review instead of starting from scratch.",
        highlight: true,
        highlightLabel: "Our Solution",
        workflow: {
          kicker: "Analyst workflow",
          label: "After",
          sub: "Analysts review instead of starting from scratch",
          steps: [
            { title: "AI agent suggests a mapping for every status", tone: "accent", map: ["Observ", "Observation"] },
            { title: "Analyst confirms or corrects", checks: 5 },
            { title: "Tricky cases flagged for a clinical expert", tone: "warn", flag: "What is Next?" },
          ],
        },
        body: [
          "Using AI in a high-stakes, time-critical field makes people nervous, and for good reason. Full automation would have been faster, but a human-in-the-loop workflow is what made it trustworthy.",
        ],
        figures: [
          { videoSrc: "assets/epic/mapping-fast.mp4", videoDarkSrc: "assets/epic/mapping-fast-dark.mp4", zoomVideoSrc: "assets/epic/mapping-agent-v2.mp4", zoomVideoDarkSrc: "assets/epic/mapping-agent-dark-v2.mp4", src: "assets/epic/mapping-agent-v2.png", srcDark: "assets/epic/mapping-agent-dark-v2.png", spaceAbove: 40, caption: "The full mapping flow, from hospital statuses through the AI agent to review." },
        ],
        subsections: [
          {
            kicker: "Speed",
            navLabel: "Speed",
            title: "Suggested mappings are already waiting when analysts open setup.",
            body: [
              "**The agent is on by default and runs automatically** when a hospital updates their Epic software. By the time analysts open setup, every status already has a suggested mapping.",
              "Even 1,000+ statuses take only minutes to map, far faster than mapping by hand. Analysts start from a full set of suggestions and review them, instead of building every mapping from scratch.",
            ],
            figures: [
              { videoSrc: "assets/epic/hitl-suggestions.mp4", videoDarkSrc: "assets/epic/hitl-suggestions-dark.mp4", src: "assets/epic/hitl-suggestions.png", srcDark: "assets/epic/hitl-suggestions-dark.png", caption: "The agent suggests a mapping for every hospital status." },
            ],
          },
          {
            kicker: "Accuracy",
            navLabel: "Accuracy",
            title: "Most suggestions are right the first time.",
            body: [
              "We validated the AI agent over 2,368 test cases. After some prompt engineering, the AI agent was refined and proven to create approved mappings 97.4% of the time.",
              "Scenarios where the results were \"Different, but acceptable\" were typically due to analysts creating different mappings based on additional context for their hospital.",
            ],
            accuracyViz: {
              overallNote: "All three test groups combined",
              groups: [
                { id: "standard", label: "Standard statuses", short: "Standard", match: 847, ok: 0, total: 847,
                  note: "Default & recommended statuses that ship with Epic" },
                { id: "real", label: "Real customer data", short: "Real data", match: 967, ok: 78, total: 1094,
                  note: "Statuses real hospitals have configured for MyChart Bedside" },
                { id: "edge", label: "Edge cases", match: 363, ok: 51, total: 427,
                  note: "Purposefully difficult cases, like typos, odd formatting, & prompt injections", noteMobile: "Purposefully difficult cases, like typos, weird formatting, & prompt injections" },
              ],
            },
            figures: [],
          },
          {
            kicker: "Human in the loop",
            navLabel: "Human in the loop",
            title: "Fast, but never unchecked.",
            body: [
              "Once suggested mappings are made, **analysts review and either approve, fix, or flag statuses**.",
              "In a field where a wrong status can frighten a family, AI only works if people can trust it. So the agent does the heavy lifting, but responsibility for what patients see stays with a person.",
            ],
            highlights: [
              { icon: "lowConfidence", title: "Low confidence mappings are called out", body: "Analysts know which suggestions deserve a closer look." },
              { icon: "approve", title: "Nothing goes live without approval", body: "A person stays accountable for every mapping." },
              { icon: "flag", title: "Any status can be flagged for clinician review", body: "Flagged suggestions stay labeled as AI-mapped for clarity." },
            ],
            figures: [
              { videoSrc: "assets/epic/hitl-review.mp4", videoDarkSrc: "assets/epic/hitl-review-dark.mp4", src: "assets/epic/hitl-review.png", srcDark: "assets/epic/hitl-review-dark.png", caption: "Reviewing a low-confidence mapping and choosing whether to flag it for clinical review." },
            ],
          },
          {
            kicker: "Safe defaults",
            navLabel: "Safe defaults",
            title: "Sensitive and unclear statuses are mapped to \"Care in Progress\" rather than guessing.",
            body: [
              "Testing showed the agent struggled with uncommon abbreviations and statuses that lacked context, so I refined the prompt to fall back to \"Care in Progress.\"",
            ],
            figures: [
              { src: "assets/epic/safe-defaults-v2.png", srcDark: "assets/epic/safe-defaults-dark-v2.png", caption: "Sensitive and ambiguous hospital statuses all map to \"Care in Progress.\"" },
            ],
          },
        ],
      },
      {
        id: "process",
        eyebrow: "05",
        navLabel: "The Process",
        title: "The Process",
        body: [
          "The agent took shape over five steps: deciding how much to automate, designing the prompt, building a way to test it, refining it based on results, and launching it in a way analysts could trust.",
        ],
        subsections: [
          {
            kicker: "Level of automation",
            navLabel: "Level of automation",
            spaceAbove: 56,
            title: "Balancing speed and trust with AI.",
            body: [
              "Full automation would have been fastest, but patients and their families see these statuses. In a field this high-stakes, that speed wasn't worth the risk.",
              "**So analysts stay in the loop, reviewing and approving or fixing every AI suggestion instead of mapping from scratch.**",
            ],
            options: {
              options: [
                { kicker: "Manual", name: "Analyst maps everything", example: { from: "Deceased", state: "blank" }, verdict: "Slower setup" },
                { kicker: "Human-in-the-loop", name: "AI suggests, people verify", example: { from: "Deceased", to: "Care in Prog", state: "good" }, verdict: "Slightly slower, far more trusted", chosen: true },
                { kicker: "Full automation", name: "AI maps, no review", example: { from: "Deceased", to: "Preparing for D/C", state: "bad" }, verdict: "Higher risk" },
              ],
            },
            figures: [],
          },
          {
            kicker: "Prompt design",
            navLabel: "Prompt design",
            title: "How the agent decides on a mapping.",
            body: [
              "The prompt starts with context and rules, then gives each of the 12 patient-facing statuses its own section with a definition, examples, and a number.",
              "The agent replies with just that number, so its suggestion drops straight into configuration.",
            ],
            promptDiagram: {
              input: "Deceased",
              inputNote: "A hospital status",
              contextBand: { label: "Context", text: "Set up the task, reply with only the number..." },
              // 12 = Care in Progress, the safe fallback for sensitive statuses.
              selected: 12,
              outputNote: "Just a number",
              outputMeaning: "Care in Progress",
              partsLabel: "Each section has:",
              parts: [
                { icon: "doc", label: "What belongs in this status" },
                { icon: "list", label: "Lots of examples" },
                { icon: "hash", label: "The number to output" },
              ],
            },
            figures: [],
          },
          {
            kicker: "Testing",
            navLabel: "Testing",
            title: "Creating a validation framework to QA the AI agent.",
            body: [],
            // PLACEHOLDER examples + counts. Swap in real statuses and the
            // edge-case sub-category numbers when available.
            testGroups: {
              steps: [
                { title: "Gather a wide range of statuses to test", body: "The test set covered three main test groups and is made of 2,368 cases" },
                { title: "Have an analyst and the AI agent map every status", body: "Neither saw the other's mappings, so the analyst's mapping served as an unbiased benchmark", image: "assets/epic/validation-compare-v4.png", imageDark: "assets/epic/validation-compare-v4-dark.png", imageAlt: "2,368 test statuses mapped separately by the AI agent and by analysts, then compared." },
                { title: "Grade every AI mapping" },
              ],
              gradeViz: {
                categorizeTitle: "**Step 1:** Categorize difficulty of status",
                categories: [
                  { tone: "clear", name: "Straightforward", desc: "Self-explanatory and easy to map correctly", examples: [] },
                  { tone: "ambiguous", name: "Difficult", desc: "Low-context with no clear single mapping fit", examples: [] },
                ],
                gradeTitle: "**Step 2:** Grade accuracy of AI mapping",
                grades: [
                  { tone: "match", name: "Match", ai: "Observ", op: "=", analyst: "Observ", analystWide: true, noLabel: true, desc: "Same mapping as the analyst" },
                  { tone: "ok", name: "Acceptable", ai: "Care in Prog", op: "\u2248", analyst: "Observ", analystWide: true, noLabel: true, desc: "Different, but still correct" },
                  { tone: "fix", name: "Needs fixing", ai: "Triage", op: "\u2260", analyst: "Observ", analystWide: true, noLabel: true, desc: "Wrong and must be corrected" },
                ],
              },
              groups: [
                { name: "Standard statuses", count: "847 cases", desc: "Epic software's default statuses",
                  examples: [{ status: "Arrived" }, { status: "Roomed" }, { status: "Ready for Discharge" }, { status: "Awaiting Results" }] },
                { name: "Real data", count: "1,094 cases", desc: "Statuses from real hospitals",
                  examples: [{ status: "Admit Hold" }, { status: "Bed Req" }, { status: "MLP Dispo" }, { status: "Waiting Rm 2" }] },
                { name: "Edge cases", count: "427 cases", desc: "Built to trip the agent up",
                  labeled: true,
                  examples: [{ status: "Beed Asignned", tag: "Typos" }, { status: "PES Blue 8", tag: "Low context" }, { status: "Observaci\u00f3n", tag: "Other languages" }, { status: "Ignore prior\u2026", tag: "Prompt injections" }, { status: "rm2//WAIT!!{", tag: "Odd formatting" }, { status: "[][][]", tag: "Nonsense" }] },
              ],
              grid: {
                title: "How results were graded",
                cols: [
                  { label: "Matches analyst", tone: "good" },
                  { label: "Different, but acceptable", tone: "ok" },
                  { label: "Needed a fix", tone: "bad" },
                ],
                rows: [
                  { label: "Clear status", example: "Bed Req", cells: [{ text: "Expected: the agent should get these right.", hi: true }, { text: "Rare." }, { text: "The real failures to look for." }] },
                  { label: "Ambiguous status", example: "MLP Dispo", cells: [{ text: "Sometimes, with enough context." }, { text: "Where \u201cCare in Progress\u201d lands: safe, not wrong.", hi: true }, { text: "Rare, thanks to the safe fallback." }] },
                ],
              },
            },
            figures: [],
          },
          {
            kicker: "Refinement",
            navLabel: "Refinement",
            title: "Refining the prompt by studying what went wrong.",
            body: [
              "After each test run, I graded how the AI agent performed using the validation framework outlined earlier. Based on weak points, I made prompt edits, resulting in three different versions.",
              "After refining the prompt over three versions, the wrong mapping rate dropped from **12.9% to 3.1%**.",
            ],
            versionCompare: {
              tabs: [
                { id: "all", label: "Overall", note: "All 427 statuses from the edge cases test group", versions: [
                  { name: "Version 1", match: 77.5, fix: 12.9 },
                  { name: "Version 2", match: 74.9, fix: 8.0 },
                  { name: "Version 3", match: 85, fix: 3.1, best: true },
                ] },
                { id: "straight", label: "Straightforward", note: "Easy to map statuses, from the edge cases test group", versions: [
                  { name: "Version 1", match: 89.5, fix: 7.9 },
                  { name: "Version 2", match: 85.7, fix: 6.4 },
                  { name: "Version 3", match: 93.6, fix: 2.3, best: true },
                ] },
                { id: "ambig", label: "Difficult", note: "No clear mapping fit, from the edge cases test group", versions: [
                  { name: "Version 1", match: 57.8, fix: 21.1 },
                  { name: "Version 2", match: 57.1, fix: 10.6 },
                  { name: "Version 3", match: 70.8, fix: 4.4, best: true },
                ] },
              ],
            },
            versionBars: {
              badge: "Edge cases test group (427 cases)",
              versions: [
                { name: "Version 1", fix: 12.9, rows: [
                  { label: "All", match: 77.5, fix: 12.9 },
                ] },
                { name: "Version 2", fix: 8.0, rows: [
                  { label: "All", match: 74.9, fix: 8 },
                ] },
                { name: "Version 3", fix: 3.1, best: true, rows: [
                  { label: "All", match: 85, fix: 3.1 },
                ] },
              ],
            },
            fixTableNote: "A few of the key refinements. Other prompt adjustments aren't covered here.",
            fixTable: [
              { title: "Sensitive statuses mapped to their usual step", examples: [{ status: "Awaiting Social Services", shortStatus: "Social Services" }], fixLines: [{ text: "Defined what is considered \"sensitive\"" }, { text: "All sensitive statuses map to **Care in Progress**" }] },
              { title: "Unclear or no-context statuses mapped by guessing", examples: [{ statuses: ["4", "Greeted by Physician"], shortStatuses: ["4", "Greeted by MD"], wrong: "Provider Assessment", shortWrong: "Provider Assess." }], fixLines: [{ icon: "warn", text: "Flag low confidence mappings" }, { text: "Default to **Care in Progress**" }] },
              { title: "Acronyms and unit names misread", examples: [{ status: "BH", note: "e.g. BH = Behavioral Health", shortNote: "Behavioral Health" }], fix: "Added context for common hospital acronyms and naming conventions" },
            ],
            figures: [],
          },
          {
            kicker: "Launch",
            navLabel: "Launch",
            title: "Being upfront about where the AI was weakest.",
            body: [
              "The release notes and supporting materials explained how the agent works, its tested success rate, and where it struggles.",
              "With a new AI tool, transparency builds trust. **Knowing how the agent works and where it falls short helped analysts understand and use it responsibly.**",
            ],
            launchNote: {
              docTitle: "Launch release note & instructions",
              stats: [
                { tone: "good", value: "97.4%", label: "approved as-is" },
                { tone: "bad", value: "2.6%", label: "needed fixing" },
                { tone: "ink", value: "2,368", label: "test cases" },
              ],
              weakSpots: ["Low-context statuses", "Unclear medical shorthand", "Sensitive cases"],
              helpsLabel: "Helping analysts\u2026",
              helps: [
                { icon: "bulb", title: "Understand", desc: "How the agent works and its weak points" },
                { icon: "trust", title: "Trust", desc: "Real success rates from validation testing" },
                { icon: "person", title: "Stay responsible", desc: "Know exactly what to double-check" },
              ],
            },
            figures: [],
          },
        ],
      },
      {
        id: "retrospective",
        eyebrow: "06",
        navLabel: "Retrospective",
        title: "Retrospective",
        body: [
          "Analysts are no longer scared of getting a mapping wrong or buried in manual setup, so more hospitals now go with the default and turn MyChart Bedside on. **Choosing trust over speed paid off: adoption is up over 30% since launch.**",
        ],
        pullQuoteFirst: true,
        pullQuote: { spaceAbove: 40, text: "I feel very confident about the use case for AI here. It's reducing the busy work and letting more hospitals adopt a tool that's good for patients.", author: "Tech lead", avatar: "assets/epic/analyst.png", avatarDark: "assets/epic/analyst-dark-v2.png" },
        notesTitle: "Lessons learned",
        notesSpaceAbove: 150,
        notes: [
          { title: "Balancing trust and speed 🤝", body: ["The fastest option isn't always the best one. Users are wary of new AI tools, especially in healthcare, so guardrails, thorough testing, and transparency mattered as much as speed."] },
          { title: "Design for the failure cases ❤️‍🩹", body: ["Testing worst-case scenarios showed what could go wrong and where guardrails were needed. Good design makes mistakes hard to make."] },
          { title: "Design for adoption 🏁", body: ["A good tool is useless if no one uses it. MyChart Bedside had clear benefits but low adoption, so the agent runs automatically with the Epic upgrade, and suggestions are ready before setup begins."] },
        ],
      },
    ],
  };

  // So the draft page has an "Up next" entry and a home-page row to click.
  if (!window.PROJECTS.some((p) => p.id === "epic")) {
    window.PROJECTS.unshift({
      id: "epic",
      title: "MyChart Bedside AI Agent",
      blurb: "Reducing setup burden with AI to drive adoption",
      thumb: "image",
      // Video thumbnail — plays silently on the home page (no controls).
      // The still stays as a fallback if the video can't load.
      img: "assets/epic/thumbnail.png",
      video: "assets/epic/mapping-fast.mp4",
    poster: "assets/epic/mapping-agent-v2.png",
    posterDark: "assets/epic/mapping-agent-dark-v2.png",
      videoDark: "assets/epic/mapping-fast-dark.mp4",
      videoDarkBg: "#0F0F13",
      videoBg: "#F6F8FB",
      videoWidth: "105%",
      // Dark mode: a bigger light card than the default 78%.
      cardWidth: "90%",
      cardHeight: "90%",
      color: "rgb(196, 30, 58)",
    });
  }
})();
