Skip to content

Fix: Encounter notes loading and saving issue#383

Merged
yingbull merged 2 commits intodevelop/coyotefrom
bugfix/encounter-notes-load-save
Jul 21, 2025
Merged

Fix: Encounter notes loading and saving issue#383
yingbull merged 2 commits intodevelop/coyotefrom
bugfix/encounter-notes-load-save

Conversation

@D3V41
Copy link
Copy Markdown
Collaborator

@D3V41 D3V41 commented Jul 21, 2025

This PR fixes an issue where encounter notes were not loading properly and new notes could not be saved.
The update ensures that:

  • Existing encounter notes are fetched and displayed correctly
  • New encounter notes can be successfully created and stored

Summary by Sourcery

Fix encounter notes loading and persistence by correcting JSP element IDs, initializing form beans, and cleaning up redundant form fields

Bug Fixes:

  • Correct dynamic note element ID generation in noteIssueList.jsp to use JSTL and EL
  • Initialize caseNote in CaseManagementEntry2Action to prevent null pointer during session restore
  • Remove extraneous hidden inputs in ChartNotes.jsp to prevent stale filter values

Enhancements:

  • Replace scriptlets in JSP with c:set and EL expressions for cleaner code

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Jul 21, 2025

Reviewer's Guide

This PR fixes encounter notes loading and saving by initializing the note object in session, exposing and binding the dynamic encounter selector, refactoring JSPs to use JSTL/EL instead of scriptlets, and cleaning up obsolete inputs.

Sequence diagram for loading and saving encounter notes

sequenceDiagram
    actor User
    participant JSP as noteIssueList.jsp
    participant Action as CaseManagementEntry2Action
    participant Session
    participant DB as Database

    User->>JSP: Load encounter notes page
    JSP->>Action: Request to load notes
    Action->>Session: restoreFromSession()
    alt caseNote is null
        Action->>Action: Initialize new CaseManagementNote
    end
    Action->>DB: Fetch existing notes
    DB-->>Action: Return notes
    Action-->>JSP: Return notes data
    JSP-->>User: Display notes

    User->>JSP: Save new note
    JSP->>Action: Submit new note
    Action->>DB: Save note
    DB-->>Action: Confirm save
    Action-->>JSP: Return success
    JSP-->>User: Show updated notes
Loading

Class diagram for CaseManagementEntry2Action and CaseManagementNote changes

classDiagram
    class CaseManagementEntry2Action {
        - Map<String, Object> mySessionMap
        - CaseManagementNote caseNote
        + void restoreFromSession()
    }
    class CaseManagementNote {
        + String encounter_type
        + String id
        ...
    }
    CaseManagementEntry2Action --> CaseManagementNote : uses
    CaseManagementEntry2Action --> mySessionMap : session access
Loading

File-Level Changes

Change Details Files
Initialize caseNote in restoreFromSession to prevent null pointer and ensure existing notes load
  • Check for null this.caseNote and instantiate new CaseManagementNote if needed
src/main/java/org/oscarehr/casemgmt/web/CaseManagementEntry2Action.java
Expose encSelect as a request attribute for proper dynamic binding
  • Add request.setAttribute("encSelect", encSelect) before rendering noteIssueList.jsp
src/main/webapp/casemgmt/noteIssueList.jsp
Refactor noteIssueList.jsp to use JSTL/EL for dynamic IDs and remove scriptlets
  • Replace <%=noteIndex%> concatenations with ${noteIndex}
  • Use <c:set> for encSelect concatenation
  • Remove redundant <script> tags around AJAX save logic
src/main/webapp/casemgmt/noteIssueList.jsp
Remove obsolete hidden filter inputs from ChartNotes.jsp
  • Delete unused hidden inputs: filter_providers, filter_roles, note_sort, issues
src/main/webapp/casemgmt/ChartNotes.jsp

Possibly linked issues

  • #0: PR fixes note loading/saving, resolving button errors. It initializes caseNote and refactors JSP for dynamic selectors.
  • Admin panel SQL error in PHCP - Go #404: PR fixes encounter note saving and loading, which resolves the 404 error when adding RX to notes.

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

@yingbull yingbull requested review from Copilot and yingbull July 21, 2025 15:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where encounter notes were not loading properly and new notes could not be saved. The changes address null pointer issues during session restoration and modernize JSP code by replacing scriptlet concatenations with JSTL/EL expressions.

Key changes include:

  • Initializing the caseNote object in the Java action class to prevent null pointer exceptions
  • Refactoring JSP code to use JSTL/EL instead of scriptlets for better maintainability
  • Removing obsolete hidden input fields from the chart notes interface

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
CaseManagementEntry2Action.java Added null check and initialization for caseNote object in restoreFromSession method
noteIssueList.jsp Replaced scriptlet code with JSTL/EL expressions and removed redundant script tags
ChartNotes.jsp Removed obsolete hidden filter input fields

@yingbull
Copy link
Copy Markdown

@sourcery-ai review

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @D3V41 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/main/webapp/casemgmt/noteIssueList.jsp:492` </location>
<code_context>
+    </c:if>


-    var c = "bgColour" + "<%=noteIndex%>";
+    var c = "bgColour" + "${noteIndex}";
     var txtStyles = $F(c).split(";");
     var txtColour = txtStyles[0].substr(txtStyles[0].indexOf("#"));
</code_context>

<issue_to_address>
Switching from scriptlet to EL for noteIndex in JavaScript may introduce type issues.

If noteIndex is undefined or not a string in the EL context, this could result in issues like 'bgColourundefined'. Consider casting or providing a default value in the EL expression.

Suggested implementation:

```
    var c = "bgColour" + "${empty noteIndex ? 0 : noteIndex}";

```

```
    var summary = "sumary" + "${empty noteIndex ? 0 : noteIndex}";

```
</issue_to_address>

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.

@yingbull yingbull merged commit 082d54a into develop/coyote Jul 21, 2025
11 checks passed
@yingbull yingbull deleted the bugfix/encounter-notes-load-save branch January 8, 2026 18:55
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.

3 participants