-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created a new alert to report any animal assignments where projected release condition is terminal in the last 35 days. * Updated the center project display. * Updated the display fields on the report Updated the cron job time
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
onprc_ehr/resources/queries/study/pathAssignmentData.query.xml
This file contains 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
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> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
SELECT Id, | ||
-- Id.demographics.gender as Sex, | ||
CASE | ||
WHEN Id.demographics.gender = 'F' THEN 'Female' | ||
WHEN Id.demographics.gender = 'M' THEN 'Male' | ||
ELSE 'Unknown' | ||
END AS Sex, | ||
Id.Age.ageinyearsrounded as AgeInYearsRounded, | ||
project.name as project, | ||
project.protocol.investigatorId.lastname as Investigator, | ||
project.title as Title, | ||
date, | ||
enddate, | ||
projectedRelease, | ||
(Select meaning from ehr_lookups.animal_condition where code = assignment.projectedReleaseCondition) as projectedReleaseCondition, | ||
(Select meaning from ehr_lookups.animal_condition where code = assignment.assignCondition) as assignCondition, | ||
(Select meaning from ehr_lookups.animal_condition where code = assignment.releaseCondition) as releaseCondition, | ||
FROM assignment | ||
Where projectedReleaseCondition = 206 --'Terminal' | ||
And date <= curdate() and date >= timestampadd(SQL_TSI_DAY, -35, curdate()) | ||
|
This file contains 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
160 changes: 160 additions & 0 deletions
160
onprc_ehr/src/org/labkey/onprc_ehr/notification/PathAssignmentNotification.java
This file contains 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
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 0 9 ? * MON"; | ||
|
||
} | ||
|
||
@Override | ||
public String getScheduleDescription() | ||
{ | ||
return "every Monday at 9Am"; | ||
} | ||
|
||
@Override | ||
public String getDescription() | ||
{ | ||
return "The report is designed to send animal assignments data to pathology every 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; | ||
} | ||
//assignments 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("Sex")); | ||
columns.add(FieldKey.fromString("AgeInYearsRounded")); | ||
columns.add(FieldKey.fromString("project")); | ||
columns.add(FieldKey.fromString("Investigator")); | ||
columns.add(FieldKey.fromString("Title")); | ||
columns.add(FieldKey.fromString("date")); | ||
columns.add(FieldKey.fromString("enddate")); | ||
columns.add(FieldKey.fromString("projectedRelease")); | ||
columns.add(FieldKey.fromString("projectedReleaseCondition")); | ||
columns.add(FieldKey.fromString("assignCondition")); | ||
columns.add(FieldKey.fromString("releaseCondition")); | ||
|
||
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>Sex </td><td>Age (Years, Rounded) </td><td>Center Project </td><td>Investigator </td><td>Title </td><td>Assign Date </td><td>Release Date </td><td>Projected Release Date </td><td>Projected Release Condition </td><td>Condition At Assignment </td><td>Condition At Release </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("Sex")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("AgeInYearsRounded")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("project")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Investigator")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Title")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("date")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("enddate")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("projectedRelease")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("assigncondition")) + "</td>"); | ||
msg.append("<td>" + PageFlowUtil.filter(rs.getString("releasecondition")) + "</td>"); | ||
msg.append("</tr>"); | ||
}); | ||
msg.append("</table>"); | ||
} | ||
} | ||
} |