Fix: auto formatting of patient DOB search field is too aggresive#142
Open
LiamStanziani wants to merge 1 commit into
Conversation
Reviewer's GuideRelaxes the DOB auto-formatting logic in the patient search field to preserve wildcards and caret position, and stops URL-encoding the search keyword on the backend so wildcard and special characters are passed through intact for DOB searches. Sequence diagram for wildcard DOB search flowsequenceDiagram
actor User
participant Browser as Browser_DOB_field
participant SearchBox as zdemographicfulltitlesearch_jsp
participant Controller as demographiccontrol_jsp
participant Dao as DemographicDao
User->>Browser: Type DOB with % (e.g. 2024-07-% )
Browser->>SearchBox: formatDateInput(input)
Note right of SearchBox: Keep digits, '-' and '%';
Note right of SearchBox: Auto-hyphenate only at end;
Note right of SearchBox: Preserve caret position
User->>Browser: Submit titlesearch form
Browser->>SearchBox: checkTypeIn()
alt dob contains %
SearchBox->>SearchBox: Pad parts to 3 segments
Note right of SearchBox: 2024-07 -> 2024-07-%
else no % in dob
SearchBox->>SearchBox: Validate full YYYYMMDD
end
Browser->>Controller: demographiccontrol_jsp with keyword
Note right of Controller: Use keyword verbatim
Note right of Controller: Do not URLEncoder.encode(keyword)
Controller->>Controller: Detect wildcard with indexOf("%") or indexOf("*")
Controller->>Dao: searchDemographicByDOB(keyword)
Dao->>Dao: Split keyword on '-'
Dao-->>Controller: DOB results
Controller-->>Browser: Render demographicsearchresults_jsp
Browser-->>User: Show patients matching wildcard DOB
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
formatDateInput, the caret logic assumesselectionStartis always available and the field is focused; consider guarding fornull/undefinedor non-focus cases to avoid runtime errors in older or nonstandard browsers. - The date sanitization regex in
formatDateInput(/[^0-9%-]/g) allows multiple or leading hyphens and percent signs; if those are not intended, you may want to normalize or validate the structure (e.g., at most two hyphens and up to three segments) before reformatting.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `formatDateInput`, the caret logic assumes `selectionStart` is always available and the field is focused; consider guarding for `null`/`undefined` or non-focus cases to avoid runtime errors in older or nonstandard browsers.
- The date sanitization regex in `formatDateInput` (`/[^0-9%-]/g`) allows multiple or leading hyphens and percent signs; if those are not intended, you may want to normalize or validate the structure (e.g., at most two hyphens and up to three segments) before reformatting.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary
Fixes the patient DOB search so wildcard (
%) searches work again, and soediting the query no longer yanks the cursor to the end of the field. Touches
the search box (
zdemographicfulltitlesearch.jsp) and the search controller(
demographiccontrol.jsp).Original PR: openo-beta#2450
Problem
The DOB search field auto-formats input as
yyyy-mm-dd, but the formatting wastoo aggressive and caused two regressions:
formatDateInputranvalue.replace(/\D/g, '')on every keystroke, deleting the
%character outright — so a search like2024-07-%(everyone born July 2024) was impossible; the%vanished as youtyped.
checkTypeInthen also required a full 8-digit date, rejecting anypartial/wildcard entry.
formatDateInputreassignedinput.valueon each keystroke without restoring the caret, so editing fromthe middle of the text (e.g. changing
2026→2025) bounced the cursor tothe end and made mid-field edits painful.
Separately, the controller URL-encoded the keyword
(
URLEncoder.encode(keyword, "UTF-8")), which turned%into%25andcorrupted other legitimate characters (e.g. apostrophes in names), further
breaking wildcard matching.
Solution
Frontend (
zdemographicfulltitlesearch.jsp):formatDateInputto keep digits, hyphens, and%. It now auto-insertshyphens only when a plain date is typed at the end of the field, and it
preserves the caret on mid-field edits instead of forcing it to the end.
checkTypeInso a%triggers a wildcard search: the value is paddedto three hyphen-separated segments (
2024-07→2024-07-%,2024→2024-%-%) to match what the backend expects. Non-wildcard searches stillrequire a complete
yyyy-mm-dddate.Backend (
demographiccontrol.jsp):URLEncoder.encode(keyword)call so%(and characters likeapostrophes) reach the query intact. The keyword is bound as a SQL parameter
downstream, so encoding it was both unnecessary and corrupting. Wildcard
detection is preserved.
How it works end-to-end
The live DOB query runs in
demographicsearchresults.jspviaDemographicDao.searchDemographicByDOB, which splits the keyword on-intoexactly three
LIKEparameters (year/month/day). Padding to2024-07-%therefore produces
year LIKE '2024%' AND month LIKE '07%' AND day LIKE '%%'→all patients born July 2024. Note:
%is the wildcard (standard SQLLIKE); theresults page and the add-a-record page both
<%@ include %>this same searchbox, so the fix covers those screens too.
Testing
Verified manually:
2024-07-15) — auto-hyphenation and submission still work.2024-07-%,2024-%) — return the expected patients.2026→2025) — caret stays where it was, after the edit.Summary by Sourcery
Relax auto-formatting of the patient DOB search field and preserve wildcard semantics while ensuring valid date input.
New Features:
Bug Fixes:
Enhancements:
Summary by Sourcery
Relax auto-formatting and validation of the patient DOB search field so wildcard searches work correctly and editing is not disruptive, while ensuring the backend preserves wildcard and special characters in search keywords.
New Features:
Bug Fixes:
Enhancements: