Skip to content

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

Merged
lacarmen merged 2 commits into
MagentaHealth:release/2026-03-17from
openo-beta:bug/rx-module-meds-list-should-display-all-base-release
Jun 18, 2026
Merged

Fix: Rx module meds list should display all meds#153
lacarmen merged 2 commits into
MagentaHealth:release/2026-03-17from
openo-beta:bug/rx-module-meds-list-should-display-all-base-release

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.

Original PR: openo-beta#2477

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 default the Rx medication list DataTables page length so the full list is shown by default and the user's length preference is restored on reloads.

Enhancements:

  • Default the Rx medication list to show all medications when no page-length preference is saved.
  • Persist the medication list page-length choice in localStorage and reapply it whenever the table is rebuilt.
  • Update the medication list length menu options to include 25, 50, 75, 100, and All.

@LiamStanziani LiamStanziani self-assigned this Jun 12, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

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

Reviewer's Guide

Updates the Rx medication list DataTables configuration to default to showing all medications and to persist the user-selected page length in localStorage using the modern 1.13.x API, replacing the broken legacy state-save callbacks.

Sequence diagram for Rx meds DataTable page length persistence

sequenceDiagram
    actor User
    participant Browser
    participant DrugListDataTable
    participant localStorage

    User->>Browser: Open Rx meds list
    Browser->>DrugListDataTable: Initialize with drugListTableConfig
    DrugListDataTable->>localStorage: getItem(drugListPageLength)
    localStorage-->>DrugListDataTable: saved length or null
    DrugListDataTable->>DrugListDataTable: pageLength = saved length or -1
    DrugListDataTable-->>User: Render meds list with pageLength

    User->>DrugListDataTable: Change page length dropdown
    DrugListDataTable->>DrugListDataTable: initComplete handler binds length.dt
    DrugListDataTable->>localStorage: setItem(drugListPageLength, len)

    User->>Browser: Reload Rx meds list
    Browser->>DrugListDataTable: Reinitialize with drugListTableConfig
    DrugListDataTable->>localStorage: getItem(drugListPageLength)
    localStorage-->>DrugListDataTable: previously saved length
    DrugListDataTable-->>User: Render meds list with restored pageLength
Loading

File-Level Changes

Change Details Files
Replace broken DataTables state saving with a page-length-specific preference persisted in localStorage.
  • Remove legacy bStateSave, fnStateSave, and fnStateLoad configuration that attempted to persist full table state under the drugListTable key.
  • Introduce a dynamic pageLength getter that reads the saved page length from localStorage['drugListPageLength'], defaulting to -1 (All) when unset.
  • Attach an initComplete handler that listens for length.dt events on the table and writes the new page length to localStorage whenever the user changes the dropdown.
src/main/webapp/oscarRx/ListDrugs.jsp
Align the Rx meds list page-length UI with other tables and ensure the default shows all meds.
  • Configure lengthMenu to offer 25, 50, 75, 100, and All (-1) options, with All last to match tickler/consultation tables.
  • Rely on the new default pageLength behaviour to show all medications when no prior page-length preference exists, restoring pre-upgrade full-list behaviour.
src/main/webapp/oscarRx/ListDrugs.jsp

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 LiamStanziani marked this pull request as ready for review June 12, 2026 21:52

@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 reviewed your changes and they look great!


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 requested a review from lacarmen June 12, 2026 21:54
@lacarmen lacarmen merged commit dfa98c3 into MagentaHealth:release/2026-03-17 Jun 18, 2026
1 of 2 checks passed
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.

2 participants