Fix: Rx module meds list should display all meds#153
Merged
Conversation
…ing correctly to localStorage
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 persistencesequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
dfa98c3
into
MagentaHealth:release/2026-03-17
1 of 2 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.drugListTableConfigDataTables config inListDrugs.jsp:No default page length. The
aLengthMenu/iDisplayLengthlines were commented out, so DataTables used its default of 10 rows.Page-length persistence was effectively broken. The config used
bStateSavewithfnStateSave/fnStateLoadcallbacks. 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 intendeddrugListTablelocalStorage key was never written. DataTables' built-in default state-save ran instead and wrote the full state blob toDataTables_Drug_table_<path>, but the drug list is destroyed and rebuilt on every load (rebuildDrugProfileinSearchDrug3.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):
pageLength: -1) when the user has no saved preference, restoring the pre-upgrade full-list behaviour.localStorage['drugListPageLength'], written on an explicitlength.dtchange (i.e. only when the user actually changes the dropdown).pageLengthgetter (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.lengthMenuoffers25, 50, 75, 100, All, with "All" in the last position to match the tickler and consultation tables.Resulting behaviour (exactly the requested spec):
Old
DataTables_Drug_table_*/drugListTablelocalStorage entries are simply never read anymore, so existing users land on "All" with no manual cache clear.Testing
Verified in-browser (DataTables 1.13.4, demographic with 133 meds):
drugListPageLength=50)-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 customdrugListTablekey was never written.Scope / safety
src/main/webapp/oscarRx/ListDrugs.jsp(10 additions, 8 deletions).pageLengthdefault lives only indrugListTableConfig, and the tickler (ticklerPageLength, default 50) and consultation (default 10) tables use their own separate keys/pages.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: