Skip to content

Fix printing eChart notes#647

Merged
yingbull merged 6 commits intodevelop/dogfishfrom
issue-607-print-echart
Sep 29, 2025
Merged

Fix printing eChart notes#647
yingbull merged 6 commits intodevelop/dogfishfrom
issue-607-print-echart

Conversation

@sebastian-j-ibanez
Copy link
Copy Markdown
Collaborator

@sebastian-j-ibanez sebastian-j-ibanez commented Sep 26, 2025

Changes made

  • Refactored CaseManagementPrint.doPrint().
    • Gets filtered notes from CaseManagementPrint.caseManagementMgr directly, instead of using session attributes. These attributes are not consistently set between the CaseManagementView and CaseManagementEntry struts actions.
    • Used streams to improve readability.
  • Add several null checks in CaseManagementManagerImpl when getting role and roleName.

Additional changes as of 29/09/2025:

  • Fix date range filtering in CaseManagementPrint.doPrint().
  • Properly reset print dialog when clicking "Clear".

Summary by Sourcery

Improve the eChart notes printing workflow by refactoring note retrieval and filtering logic using streams, and harden role resolution in CaseManagementManagerImpl with null and format checks

Bug Fixes:

  • Add null and format checks when retrieving role and roleName in CaseManagementManagerImpl to prevent errors

Enhancements:

  • Refactor CaseManagementPrint.doPrint to fetch notes directly from the manager instead of session attributes
  • Replace manual loops with Java streams for note ID collection and date filtering
  • Simplify collection initializations and condition checks for cleaner code

  - Add null safety checks in CaseManagementPrint getAllNoteIds methods
  - Fix copy-paste bug in filter_issues session attribute check
  - Add defensive null handling for NoteSelectionResult and note collections
  - Improve role validation with proper null checks in filterNotes1 method
  - Ensure methods return empty arrays instead of null to prevent NPE
@sebastian-j-ibanez sebastian-j-ibanez self-assigned this Sep 26, 2025
@sebastian-j-ibanez sebastian-j-ibanez added area: echart Related to eChart functionality type: bug labels Sep 26, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Sep 26, 2025

Reviewer's Guide

This PR refactors CaseManagementPrint to fetch and filter notes directly from the manager using Java streams and cleans up session-based filtering, while also introducing null/format validation and logging when resolving note roles in CaseManagementManagerImpl.

Class diagram for updated CaseManagementPrint and CaseManagementManagerImpl

classDiagram
class CaseManagementPrint {
  +doPrint(LoggedInInfo, Integer, boolean, ...)
  -getAllNoteIds(LoggedInInfo, HttpServletRequest, String)
  -getAllNoteIdsWithinDateRange(LoggedInInfo, HttpServletRequest, String, Date, Date)
}
class CaseManagementManagerImpl {
  +filterNotes1(String, Collection<EChartNoteEntry>)
}
class CaseManagementNote {
  +getId()
  +getProviderNo()
  +getObservation_date()
  +isLocked()
  +isArchived()
  +getRole()
  +getType()
}
class CaseManagementNoteExt {
  +getKeyVal()
}
class NoteSelectionResult {
  +getNotes()
}
class NoteDisplay {
  +getNoteId()
}
class NoteDisplayLocal {
}
class Secrole {
  +getName()
}
class RoleCache {
  +getRole(Long)
}
CaseManagementPrint --> CaseManagementManagerImpl : uses
CaseManagementPrint --> CaseManagementNote : uses
CaseManagementPrint --> CaseManagementNoteExt : uses
CaseManagementPrint --> NoteSelectionResult : uses
CaseManagementPrint --> NoteDisplay : uses
NoteDisplayLocal --|> NoteDisplay
CaseManagementManagerImpl --> Secrole : uses
CaseManagementManagerImpl --> RoleCache : uses
Loading

File-Level Changes

Change Details Files
Refactor note retrieval and filtering in CaseManagementPrint
  • Fetch all notes via caseManagementMgr.getNotes and map IDs using streams
  • Replace manual loops with stream-based mapping and filtering for date ranges
  • Use enhanced for-each loops, diamond operators, String.valueOf conversions and isEmpty checks
  • Update session filter attribute keys and add null checks around NoteSelectionResult and its notes
src/main/java/ca/openosp/openo/casemgmt/service/CaseManagementPrint.java
Add null and format checks when resolving note roles
  • Validate noteRole string for null or emptiness before parsing
  • Wrap Long.valueOf conversion in try/catch to handle NumberFormatException with warning logs
  • Check RoleCache.getRole result for null and default roleName to empty
  • Log debug messages for missing or invalid role information
src/main/java/ca/openosp/openo/casemgmt/service/CaseManagementManagerImpl.java

Possibly linked issues


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

@sebastian-j-ibanez sebastian-j-ibanez linked an issue Sep 26, 2025 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 26, 2025

Dependency Review

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

Snapshot Warnings

⚠️: No snapshots were found for the head SHA e5bb12b.
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

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 there - I've reviewed your changes - here's some feedback:

  • The doPrint method is very large and handles multiple responsibilities (note retrieval, filtering, integration); consider extracting these into smaller helper methods for better readability and maintainability.
  • getAllNoteIds and getAllNoteIdsWithinDateRange share nearly identical logic for building criteria and collecting IDs; extract the common code into a single parameterized method to reduce duplication.
  • The enhanced null and format checks around role resolution in filterNotes1 are helpful, but consider moving the parsing and lookup logic into a dedicated utility to simplify the main filtering method.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The doPrint method is very large and handles multiple responsibilities (note retrieval, filtering, integration); consider extracting these into smaller helper methods for better readability and maintainability.
- getAllNoteIds and getAllNoteIdsWithinDateRange share nearly identical logic for building criteria and collecting IDs; extract the common code into a single parameterized method to reduce duplication.
- The enhanced null and format checks around role resolution in filterNotes1 are helpful, but consider moving the parsing and lookup logic into a dedicated utility to simplify the main filtering method.

## Individual Comments

### Comment 1
<location> `src/main/java/ca/openosp/openo/casemgmt/service/CaseManagementManagerImpl.java:1479` </location>
<code_context>

             if (cmNote.getType().equals("local_note")) {
                 noteRole = cmNote.getRole();
-                noteRoleName = RoleCache.getRole(Long.valueOf(noteRole)).getName().toLowerCase();
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the nested role name extraction logic into a helper method to flatten and clarify the loop body.

You’ve added a lot of nested checks/logging around turning a raw `String` into a lowercase role name. You can collapse all of that into one small helper and keep the loop body flat. For example:

```java
// in your class
private String safeGetRoleName(String roleIdStr) {
    if (roleIdStr == null || roleIdStr.trim().isEmpty()) {
        logger.debug("Note has null or empty role");
        return "";
    }
    try {
        Long roleId = Long.valueOf(roleIdStr);
        logger.debug("Looking up role ID: {}", roleId);
        Secrole secrole = RoleCache.getRole(roleId);
        if (secrole != null) {
            String name = secrole.getName().toLowerCase();
            logger.debug("Found role: {} for ID: {}", name, roleId);
            return name;
        }
    } catch (NumberFormatException e) {
        logger.warn("Invalid role format: '{}' - not a valid Long", roleIdStr);
    }
    return "";
}
```

Then simplify your loop to:

```java
for (EChartNoteEntry cmNote : notes) {
    if (!cmNote.getType().equals("local_note") &&
        !cmNote.getType().equals("remote_note")) {
        filteredNotes.add(cmNote);
        continue;
    }

    String noteRoleName;
    if (cmNote.getType().equals("local_note")) {
        noteRoleName = safeGetRoleName(cmNote.getRole());
    } else { // remote_note
        noteRoleName = cmNote.getRole();
    }

    ProgramAccess pa = (ProgramAccess) programAccessMap
        .get("read " + noteRoleName + " notes");
    if (pa != null && (pa.isAllRoles() || isRoleIncludedInAccess(pa, role))) {
        // ...
    }
}
```

This preserves all logging, exception handling, and behavior but removes deep nesting and makes the loop body much clearer.
</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 ad58f1c into develop/dogfish Sep 29, 2025
14 of 15 checks passed
@yingbull yingbull deleted the issue-607-print-echart branch September 29, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: echart Related to eChart functionality

Projects

None yet

2 participants