Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1473,16 +1473,17 @@ public List<EChartNoteEntry> filterNotes1(String providerNo, Collection<EChartNo
filteredNotes.add(cmNote);
continue;
}
String noteRole = null;
String noteRoleName = "";

String noteRole;
String noteRoleName;
if (cmNote.getType().equals("local_note")) {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
noteRole = cmNote.getRole();
noteRoleName = RoleCache.getRole(Long.valueOf(noteRole)).getName().toLowerCase();
}
if (cmNote.getType().equals("remote_note")) {
noteRoleName = safeGetRoleName(noteRole);
} else { // remote_note
noteRole = cmNote.getRole();
noteRoleName = cmNote.getRole();
}

ProgramAccess pa = null;
boolean add = false;

Expand Down Expand Up @@ -2707,4 +2708,30 @@ public String listNotes(String code, String providerNo, String demoNo) {
return noteStr.toString();
}

/**
* Helper method to safely extract role name from role ID string with proper error handling and logging.
*
* @param roleIdStr The role ID as a string
* @return The lowercase role name, or empty string if role ID is invalid or role not found
*/
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: " + name + " for ID: " + roleId);
return name;
}
} catch (NumberFormatException e) {
logger.warn("Invalid role format: '" + roleIdStr + "' - not a valid Long");
}
return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class CaseManagementPrint {

Expand All @@ -68,17 +69,22 @@ public void doPrint(LoggedInInfo loggedInInfo, Integer demographicNo, boolean pr

String providerNo = loggedInInfo.getLoggedInProviderNo();


if (printAllNotes) {
noteIds = getAllNoteIds(loggedInInfo, request, "" + demographicNo);
// Get all or date range noteIds.
if (printAllNotes && useDateRange) {
List<CaseManagementNote> dateRangeNotes = caseManagementMgr.getNotesInDateRange(String.valueOf(demographicNo), startDate.getTime(), endDate.getTime());
noteIds = dateRangeNotes.stream()
.map(note -> note.getId().toString())
.toArray(String[]::new);
} else if (printAllNotes) {
List<CaseManagementNote> allNotes = caseManagementMgr.getNotes(String.valueOf(demographicNo));
noteIds = allNotes.stream()
.map(note -> note.getId().toString())
.toArray(String[]::new);
}

if (useDateRange) {
noteIds = getAllNoteIdsWithinDateRange(loggedInInfo, request, "" + demographicNo, startDate.getTime(), endDate.getTime());
}
logger.debug("NOTES2PRINT: " + noteIds);

String demono = "" + demographicNo;
String demono = String.valueOf(demographicNo);
request.setAttribute("demoName", getDemoName(demono));
request.setAttribute("demoSex", getDemoSex(demono));
request.setAttribute("demoAge", getDemoAge(demono));
Expand All @@ -89,15 +95,15 @@ public void doPrint(LoggedInInfo loggedInInfo, Integer demographicNo, boolean pr
request.setAttribute("demoDOB", dob);


List<CaseManagementNote> notes = new ArrayList<CaseManagementNote>();
List<String> remoteNoteUUIDs = new ArrayList<String>();
List<CaseManagementNote> notes = new ArrayList<>();
List<String> remoteNoteUUIDs = new ArrayList<>();
String uuid;
for (int idx = 0; idx < noteIds.length; ++idx) {
if (noteIds[idx].startsWith("UUID")) {
uuid = noteIds[idx].substring(4);
for (String noteIdStr : noteIds) {
if (noteIdStr.startsWith("UUID")) {
uuid = noteIdStr.substring(4);
remoteNoteUUIDs.add(uuid);
} else {
Long noteId = ConversionUtils.fromLongString(noteIds[idx]);
Long noteId = ConversionUtils.fromLongString(noteIdStr);
if (noteId > 0) {
CaseManagementNote note = this.caseManagementMgr.getNote(noteId.toString());
if (note != null && note.getProviderNo() != null
Expand All @@ -108,7 +114,7 @@ public void doPrint(LoggedInInfo loggedInInfo, Integer demographicNo, boolean pr
}
}

if (loggedInInfo.getCurrentFacility().isIntegratorEnabled() && remoteNoteUUIDs.size() > 0) {
if (loggedInInfo.getCurrentFacility().isIntegratorEnabled() && !remoteNoteUUIDs.isEmpty()) {
DemographicWs demographicWs = CaisiIntegratorManager.getDemographicWs(loggedInInfo, loggedInInfo.getCurrentFacility());
List<CachedDemographicNote> remoteNotes = demographicWs.getLinkedCachedDemographicNotes(Integer.parseInt(demono));
for (CachedDemographicNote remoteNote : remoteNotes) {
Expand All @@ -132,35 +138,44 @@ public void doPrint(LoggedInInfo loggedInInfo, Integer demographicNo, boolean pr
Collections.sort(notes, CaseManagementNote.noteObservationDateComparator);
}

//How should i filter out observation dates?
if (!printAllNotes && (startDate != null && endDate != null)) {
List<CaseManagementNote> dateFilteredList = new ArrayList<CaseManagementNote>();
logger.debug("start date " + startDate);
logger.debug("end date " + endDate);
// Filter notes by date range if specified and not already filtered by caseManagementMgr
if (useDateRange && (startDate != null && endDate != null) && !printAllNotes) {
logger.debug("Filtering notes by date range - start date: " + startDate + ", end date: " + endDate);

for (CaseManagementNote cmn : notes) {
logger.debug("cmn " + cmn.getId() + " -- " + cmn.getObservation_date() + " ? start date " + startDate.getTime().before(cmn.getObservation_date()) + " end date " + endDate.getTime().after(cmn.getObservation_date()));
if (startDate.getTime().before(cmn.getObservation_date()) && endDate.getTime().after(cmn.getObservation_date())) {
dateFilteredList.add(cmn);
}
}
notes = dateFilteredList;
notes = notes.stream()
.filter(cmn -> {
Date noteDate = cmn.getObservation_date();
if (noteDate == null) {
logger.debug("Note " + cmn.getId() + " has null observation date - excluding");
return false;
}

boolean afterStart = !startDate.getTime().after(noteDate);
boolean beforeEnd = !endDate.getTime().before(noteDate);
boolean inRange = afterStart && beforeEnd;

logger.debug("Note " + cmn.getId() + " date " + noteDate +
" - after start: " + afterStart + ", before end: " + beforeEnd + ", in range: " + inRange);

return inRange;
})
.collect(Collectors.toList());
}

List<CaseManagementNote> issueNotes;
List<CaseManagementNote> tmpNotes;
HashMap<String, List<CaseManagementNote>> cpp = null;
if (printCPP) {
cpp = new HashMap<String, List<CaseManagementNote>>();
cpp = new HashMap<>();
String[] issueCodes = {"OMeds", "SocHistory", "MedHistory", "Concerns", "Reminders", "FamHistory", "RiskFactors"};
for (int j = 0; j < issueCodes.length; ++j) {
List<Issue> issues = caseManagementMgr.getIssueInfoByCode(providerNo, issueCodes[j]);
String[] issueIds = getIssueIds(issues);// = new String[issues.size()];
for (String issueCode : issueCodes) {
List<Issue> issues = caseManagementMgr.getIssueInfoByCode(providerNo, issueCode);
String[] issueIds = getIssueIds(issues);
tmpNotes = caseManagementMgr.getNotes(demono, issueIds);
issueNotes = new ArrayList<CaseManagementNote>();
for (int k = 0; k < tmpNotes.size(); ++k) {
if (!tmpNotes.get(k).isLocked() && !tmpNotes.get(k).isArchived()) {
List<CaseManagementNoteExt> exts = caseManagementMgr.getExtByNote(tmpNotes.get(k).getId());
issueNotes = new ArrayList<>();
for (CaseManagementNote tmpNote : tmpNotes) {
if (!tmpNote.isLocked() && !tmpNote.isArchived()) {
List<CaseManagementNoteExt> exts = caseManagementMgr.getExtByNote(tmpNote.getId());
boolean exclude = false;
for (CaseManagementNoteExt ext : exts) {
if (ext.getKeyVal().equals("Hide Cpp")) {
Expand All @@ -170,11 +185,11 @@ public void doPrint(LoggedInInfo loggedInInfo, Integer demographicNo, boolean pr
}
}
if (!exclude) {
issueNotes.add(tmpNotes.get(k));
issueNotes.add(tmpNote);
}
}
}
cpp.put(issueCodes[j], issueNotes);
cpp.put(issueCode, issueNotes);
}
}
String demoNo = null;
Expand Down Expand Up @@ -370,7 +385,6 @@ private String[] getAllNoteIdsWithinDateRange(LoggedInInfo loggedInInfo, HttpSer
criteria.setProgramId(programId);
}


if (se.getAttribute("CaseManagementViewAction_filter_roles") != null) {
criteria.getRoles().addAll((List<String>) se.getAttribute("CaseManagementViewAction_filter_roles"));
}
Expand All @@ -379,27 +393,25 @@ private String[] getAllNoteIdsWithinDateRange(LoggedInInfo loggedInInfo, HttpSer
criteria.getProviders().addAll((List<String>) se.getAttribute("CaseManagementViewAction_filter_providers"));
}

if (se.getAttribute("CaseManagementViewAction_filter_providers") != null) {
if (se.getAttribute("CaseManagementViewAction_filter_issues") != null) {
criteria.getIssues().addAll((List<String>) se.getAttribute("CaseManagementViewAction_filter_issues"));
}


if (logger.isDebugEnabled()) {
logger.debug("SEARCHING FOR NOTES WITH CRITERIA: " + criteria);
}

NoteSelectionResult result = noteService.findNotes(loggedInInfo, criteria);


List<String> buf = new ArrayList<String>();
for (NoteDisplay nd : result.getNotes()) {
if (!(nd instanceof NoteDisplayLocal)) {
continue;
if (result != null && result.getNotes() != null) {
for (NoteDisplay nd : result.getNotes()) {
if (nd instanceof NoteDisplayLocal) {
buf.add(nd.getNoteId().toString());
}
}
buf.add(nd.getNoteId().toString());
}


return buf.toArray(new String[0]);
}

Expand Down Expand Up @@ -429,7 +441,8 @@ private String[] getAllNoteIds(LoggedInInfo loggedInInfo, HttpServletRequest req
criteria.setProgramId(programId);
}


// Apply session filters if they exist (set by CaseManagementView2Action)
// If no filters are present, criteria will have empty lists which means "no filtering" - get all notes
if (se.getAttribute("CaseManagementViewAction_filter_roles") != null) {
criteria.getRoles().addAll((List<String>) se.getAttribute("CaseManagementViewAction_filter_roles"));
}
Expand All @@ -448,16 +461,15 @@ private String[] getAllNoteIds(LoggedInInfo loggedInInfo, HttpServletRequest req

NoteSelectionResult result = noteService.findNotes(loggedInInfo, criteria);


List<String> buf = new ArrayList<String>();
for (NoteDisplay nd : result.getNotes()) {
if (!(nd instanceof NoteDisplayLocal)) {
continue;
if (result != null && result.getNotes() != null) {
for (NoteDisplay nd : result.getNotes()) {
if (nd instanceof NoteDisplayLocal) {
buf.add(nd.getNoteId().toString());
}
}
buf.add(nd.getNoteId().toString());
}


return buf.toArray(new String[0]);
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/webapp/js/newCaseManagementView.js.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,18 @@ function autoSave(async) {
if ($F("printRx") == "true")
printInfo("imgPrintRx", "printRx");

// Clear date fields
if ($("printStartDate"))
$("printStartDate").value = "";
if ($("printEndDate"))
$("printEndDate").value = "";

// Uncheck radio buttons
if ($("printopDates"))
$("printopDates").checked = false;
if ($("printopAllNotes"))
$("printopAllNotes").checked = false;

return false;

}
Expand Down
Loading