Skip to content

Fix: Rx module meds list should display all meds#2477

Open
LiamStanziani wants to merge 1 commit into
developfrom
bug/rx-module-meds-list-should-display-all
Open

Fix: Rx module meds list should display all meds#2477
LiamStanziani wants to merge 1 commit into
developfrom
bug/rx-module-meds-list-should-display-all

Conversation

@LiamStanziani

@LiamStanziani LiamStanziani commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

After the DataTables upgrade (edac1715d5, "upgrade medication list to use DataTables and eliminate the server-side sorting"), the Rx medication list stopped showing the full medication list. With no page-length configured, DataTables fell back to its built-in default of 10 rows, so the list silently truncated. Before the upgrade the module displayed the full (filtered) list.

The reporter's workaround was to set the dropdown to "100" — but that still isn't "all", and the choice didn't survive a reload.

Fixes #2475

Root cause

Two separate problems in the window.drugListTableConfig DataTables config in ListDrugs.jsp:

  1. No default page length. The aLengthMenu / iDisplayLength lines were commented out, so DataTables used its default of 10 rows.

  2. Page-length persistence was effectively broken. The config used bStateSave with fnStateSave / fnStateLoad callbacks. Those callback names are from the DataTables 1.9 API and were renamed in 1.13.x (stateSaveCallback / stateLoadCallback), so they were never invoked — the intended drugListTable localStorage key was never written. DataTables' built-in default state-save ran instead and wrote the full state blob to DataTables_Drug_table_<path>, but the drug list is destroyed and rebuilt on every load (rebuildDrugProfile in SearchDrug3.jsp), and that rebuild re-draws the table at the config defaults — overwriting the saved state back to defaults before the user ever sees their value. The net effect: neither page length nor sort order survived a reload.

Fix

Replaced the broken full-state-save with a small, targeted page-length preference, mirroring the approach already used by the tickler table (the one table in the app that persists its length reliably):

  • Default to "All" (pageLength: -1) when the user has no saved preference, restoring the pre-upgrade full-list behaviour.
  • Persist only the page length to localStorage['drugListPageLength'], written on an explicit length.dt change (i.e. only when the user actually changes the dropdown).
  • A pageLength getter (rather than a static value) so the saved length is re-read from storage on every table init — important because the config object is created once but reused across the destroy/rebuild churn.
  • lengthMenu offers 25, 50, 75, 100, All, with "All" in the last position to match the tickler and consultation tables.

Resulting behaviour (exactly the requested spec):

  • Never changed the dropdown → no saved value → All.
  • Changed the dropdown → that value is restored on the next visit (and survives legend-filter rebuilds within a session).

Old DataTables_Drug_table_* / drugListTable localStorage entries are simply never read anymore, so existing users land on "All" with no manual cache clear.

image

Testing

Verified in-browser (DataTables 1.13.4, demographic with 133 meds):

Scenario Result
Fresh state (empty localStorage) Defaults to All (133 rows)
Change to 50 → reload Restores 50 (writes drugListPageLength=50)
Change to 25 → legend-filter rebuild Both rebuilt sections stay at 25 (getter re-reads per init)
"All" selection → reload Persists as "All" (-1)

For comparison, the original version was also rebuilt and tested: a changed length (50) and sort ([0,'asc']) were both clobbered back to defaults (length:10, order:[[1,'desc']]) on the next reload — confirming the prior persistence was non-functional, and that the custom drugListTable key was never written.

Scope / safety

  • Change is isolated to src/main/webapp/oscarRx/ListDrugs.jsp (10 additions, 8 deletions).
  • No other DataTables instances are affected: the pageLength default lives only in drugListTableConfig, and the tickler (ticklerPageLength, default 50) and consultation (default 10) tables use their own separate keys/pages.
  • No server-side, schema, or security-surface changes.

Summary by Sourcery

Persist and honor the user’s chosen page size for the Rx medications list, and expose an option to view all medications at once.

Bug Fixes:

  • Ensure the Rx medications list correctly loads using the user’s last selected page size or defaults to showing all medications when no preference exists.

Enhancements:

  • Update the Rx medications list pagination controls to offer 25, 50, 75, 100, and All page-size options and remember the selection between sessions.

Summary by cubic

Fixes the Rx meds list so it can display all medications and correctly remembers the user's page size.

  • Bug Fixes
    • Added length menu options: 25, 50, 75, 100, and "All" (-1), with "All" as the default when no preference is saved.
    • Persist page length to localStorage on change and restore it on table init.

Written for commit 16c6db9. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Drug list now persists your selected page length preference across sessions.
    • Added "All" option to display all items in the drug list view simultaneously.

@LiamStanziani LiamStanziani self-assigned this Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR modifies the DataTables configuration in ListDrugs.jsp to replace full-table state persistence with a targeted page-length persistence mechanism. The pageLength is now restored from localStorage on initialization and saved back when the user changes it via the length menu.

Changes

Page-Length Persistence Configuration

Layer / File(s) Summary
DataTables pagination persistence with localStorage
src/main/webapp/oscarRx/ListDrugs.jsp
Removed full table state persistence (bStateSave, fnStateSave, fnStateLoad) and added a pageLength getter backed by localStorage (drugListPageLength). An initComplete handler listens for DataTables length.dt events to persist the user's selected page length. Updated lengthMenu options to include the persisted "All" value (-1).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • openo-beta/Open-O#2404: Both PRs modify ListDrugs.jsp's window.drugListTableConfig DataTables setup and pagination behavior.
  • openo-beta/Open-O#2415: Both PRs address localStorage state handling in the same ListDrugs.jsp DataTables configuration area.

Suggested reviewers

  • D3V41

Poem

🐰 A rabbit hops through localStorage deep,
Remembering page lengths that users keep,
No more full state—just pagination's way,
One length.dt event per day! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling the Rx module meds list to display all medications by default while persisting user page length preferences.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/rx-module-meds-list-should-display-all

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 16c6db9.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Rx drug list DataTables config is updated to use a custom page-length preference stored in localStorage, defaulting to showing all medications, and to offer an explicit "All" option along with several fixed page sizes.

Sequence diagram for Rx meds DataTable page length preference

sequenceDiagram
    actor User
    participant DataTable as drugListDataTable
    participant LocalStorage as localStorage

    rect rgb(230,230,230)
      Note over DataTable: Table initialization
      DataTable->>LocalStorage: getItem(drugListPageLength)
      LocalStorage-->>DataTable: storedLength or null
      DataTable->>DataTable: pageLength getter
      DataTable->>DataTable: use storedLength or -1 (All)
      DataTable->>DataTable: initComplete(settings)
      DataTable->>jQuery: jQuery(settings.nTable).on(length.dt)
    end

    rect rgb(230,230,230)
      Note over User,DataTable: User changes page size
      User->>DataTable: change length menu selection
      DataTable->>DataTable: length.dt event(len)
      DataTable->>LocalStorage: setItem(drugListPageLength, len)
    end
Loading

File-Level Changes

Change Details Files
Replace DataTables state saving with a dedicated page-length preference persisted in localStorage.
  • Remove bStateSave, fnStateSave, and fnStateLoad usage on the drug list table configuration.
  • Introduce a dynamic pageLength getter that reads the saved value from localStorage on each table initialization, defaulting to -1 when unset.
  • Add an initComplete handler that listens for DataTables length changes and writes the selected page length to localStorage.
src/main/webapp/oscarRx/ListDrugs.jsp
Expand and clarify the table length options, including a default "All" choice.
  • Define a lengthMenu with page size options 25, 50, 75, 100, and "All" (-1).
  • Ensure that when no page length is stored, the table defaults to showing all rows by using -1 as the default pageLength.
src/main/webapp/oscarRx/ListDrugs.jsp

Possibly linked issues

  • #[Regression]: Rx module meds list should display all meds: PR changes DataTables config to default Rx meds list to “All” and remember user’s chosen page length.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@LiamStanziani

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@LiamStanziani

Copy link
Copy Markdown
Collaborator Author

@SourceryAI review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the DataTables configuration in ListDrugs.jsp to persist the user's selected page length in localStorage. The reviewer points out potential compatibility issues if DataTables version 1.9.4 is loaded instead of 1.13.4, as the new properties and events would be ignored. They suggest using backward-compatible options like iDisplayLength, aLengthMenu, and fnDrawCallback to ensure the persistence feature works reliably across both versions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/webapp/oscarRx/ListDrugs.jsp

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • When reading the saved page length (parseInt(localStorage.getItem('drugListPageLength')) || -1), consider using Number(...) or parseInt(..., 10) with an explicit isNaN check to avoid relying on truthiness and to make the handling of invalid values clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When reading the saved page length (`parseInt(localStorage.getItem('drugListPageLength')) || -1`), consider using `Number(...)` or `parseInt(..., 10)` with an explicit `isNaN` check to avoid relying on truthiness and to make the handling of invalid values clearer.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LiamStanziani LiamStanziani marked this pull request as ready for review June 12, 2026 21:46
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression]: Rx module meds list should display all meds

2 participants