Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathology assignments alert #1173

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,9 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="pathAssignmentData" tableDbType="NOT_IN_DB">
<tableTitle>Assignments for Pathology</tableTitle>
</table>
</tables>
</metadata>
</query>
16 changes: 16 additions & 0 deletions onprc_ehr/resources/queries/study/pathAssignmentData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT Id,
project,
date,
projectedRelease,
enddate,
assignmentType,
(Select meaning from ehr_lookups.animal_condition where code = assignment.assignCondition) as assignCondition,
(Select meaning from ehr_lookups.animal_condition where code = assignment.projectedReleaseCondition) as projectedReleaseCondition,
(Select meaning from ehr_lookups.animal_condition where code = assignment.releaseCondition) as releaseCondition,
releaseType,
remark,
description
FROM assignment
Where projectedReleaseCondition = 206 --'Terminal'
And date <= curdate() and date >= timestampadd(SQL_TSI_DAY, -35, curdate())

3 changes: 3 additions & 0 deletions onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext)
//Added Aug 9th, 2024 Kollil
ns.registerNotification(new AdminNotifications(this));

//Added Nov 5th, 2024 Kollil
ns.registerNotification(new PathAssignmentNotification(this));

//Added 8-7-2018 R.Blasa
ns.registerNotification(new BirthHousingMismatchNotification(this));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.labkey.onprc_ehr.notification;

import org.apache.commons.lang3.time.DateUtils;
import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.Results;
import org.labkey.api.data.ResultsImpl;
import org.labkey.api.data.Selector;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.Sort;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.module.Module;
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.QueryService;
import org.labkey.api.security.User;
import org.labkey.api.util.PageFlowUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
* Created by kollil on 10/24/2019.
*/

public class PathAssignmentNotification extends ColonyAlertsNotification
{
public PathAssignmentNotification(Module owner)
{
super(owner);
}

@Override
public String getName()
{
return "Pathology Assignemnt Notification";
}

@Override
public String getEmailSubject(Container c)
{
return "Animal assignment alerts for Pathology: " + getDateTimeFormat(c).format(new Date());
}

@Override
public String getCronString()
{
return "0 30 7 ? * MON";

}

@Override
public String getScheduleDescription()
{
return "every Monday at 7:30Am";
}

@Override
public String getDescription()
{
return "The report is designed to send animal assignments data to pathology every other Monday!";
}

@Override
public String getMessageBodyHTML(Container c, User u)
{
StringBuilder msg = new StringBuilder();

pathAssignmentAlert(c, u, msg);

return msg.toString();
}

/**
* Kollil, 11/05/2024 : Ticket # 11319, listing assignments made with release condition as 'terminal' with the anticipated release date. It could look something like this:
* a. Query: Assignment date = within the last 35 days, with 'projected release condition' = Terminal
* b. Report: Table with columns as attached (I created a custom view as an example, but you can include whatever info is relevant)
**/
private void pathAssignmentAlert(Container c, User u, final StringBuilder msg)
{
if (QueryService.get().getUserSchema(u, c, "study") == null)
{
msg.append("<b>Warning: The study schema has not been enabled in this folder, so the alert cannot run!<p><hr>");
return;
}
//Fasts query
TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("pathAssignmentData", ContainerFilter.Type.AllFolders.create(c, u));
TableSelector ts = new TableSelector(ti, null, null);
long count = ts.getRowCount();

//Get num of rows
if (count > 0)
{
msg.append("<b>" + count + " assignments found with projected release condition = Terminal in the last 35 days:</b>");
msg.append("<p><a href='" + getExecuteQueryUrl(c, "study", "pathAssignmentData", null) + "&query.containerFilterName=AllFolders'>Click here to view the assignments in PRIME</a></p>\n");
msg.append("<hr>");
}
else
{
msg.append("<b> There are no assignments found with projected release condition = Terminal in the last 35 days </b>");
msg.append("<hr>");
}

//Display the daily report in the email
if (count > 0)
{
Set<FieldKey> columns = new HashSet<>();
columns.add(FieldKey.fromString("Id"));
columns.add(FieldKey.fromString("project"));
columns.add(FieldKey.fromString("date"));
columns.add(FieldKey.fromString("projectedRelease"));
columns.add(FieldKey.fromString("enddate"));
columns.add(FieldKey.fromString("assignmentType"));
columns.add(FieldKey.fromString("assignCondition"));
columns.add(FieldKey.fromString("projectedReleaseCondition"));
columns.add(FieldKey.fromString("releaseCondition"));
columns.add(FieldKey.fromString("releaseType"));
columns.add(FieldKey.fromString("remark"));
columns.add(FieldKey.fromString("description"));

final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, columns);
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null);

msg.append("<hr><b>Assignments:</b><br><br>\n");
msg.append("<table border=1 style='border-collapse: collapse;'>");
msg.append("<tr bgcolor = " + '"' + "#FFD700" + '"' + "style='font-weight: bold;'>");
msg.append("<td>Id </td><td>Center Project </td><td>Assign Date </td><td>Projected Release Date </td><td>Release Date </td><td>Assignment Type </td><td>Condition At Assignment </td><td>Projected Release Condition </td><td>Condition At Release </td><td>Release Type </td><td>Remark </td><td>Description </td></tr>");

ts2.forEach(object -> {
Results rs = new ResultsImpl(object, colMap);
String url = getParticipantURL(c, rs.getString("Id"));

msg.append("<tr bgcolor = " + '"' + "#FFFACD" + '"' + ">");
msg.append("<td><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("project")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("date")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("projectedRelease")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("enddate")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("assignmentType")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("assignCondition")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("releaseCondition")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("releaseType")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("remark")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("description")) + "</td>");
msg.append("</tr>");
});
msg.append("</table>");
}
}
}