Skip to content

Commit 9e3c686

Browse files
authored
25.11 fb clinpath panic notifications (#1653)
* Created a new Clinpath Chemistry email notification to alert lab values that contains "Panic value" entries * Modified program to allow immediate notifcation when Panic entries were made onto the Chemistry lab results. * Modified Clinpath notification to include one set of recipeints. * Created clinpath notification for Chemistry results that shows "Panic values". * Created clinpath notification for Chemistry results that shows "Panic values". * Created clinpath notification for Chemistry results that shows "Panic values". * Modified program implement Chemistry email notifications. * Modified program implement Chemistry email notifications. * Modified program implement Chemistry email notifications. * Modified Chemistry Results to flag Panic values. * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created a email notification for Chemistry entries that shows a "qualresutl" values that contain string called"panic"/ * Created Clinpath email notification * Modified Clinpath panic value notifications. * Modified Clinpath panic value notifications. * Modified Clinpath panic value notification to include task ids. * Modified clinpath email notification vet name. * Modified Clinpath email notification process. * Modified Email notification to send email per "Panic values". * Modified Email notification to send email per "Panic values". * Modified Email notification to send email per "Panic values".
1 parent 543577d commit 9e3c686

4 files changed

Lines changed: 193 additions & 2 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
select a.Id,
2+
a.date,
3+
a.servicerequested,
4+
b.testid,
5+
b.qualresult,
6+
a.vet,
7+
a.created,
8+
b.objectid,
9+
b.runid,
10+
(select j.rowid from ehr.tasks j where j.taskid = a.taskid) as taskid,
11+
a.type
12+
13+
14+
from study.ClinpathRuns a, study.chemistryResults b
15+
Where a.objectid = b.runid
16+
And a.type = 'biochemistry'
17+
And b.qualresult like '%panic%'
18+
And a.qcstate = 18
19+
And b.qcstate = 18
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="Chemistry Panic Test Values" tableDbType="NOT_IN_DB">
5+
<columns>
6+
<column columnName="userId">
7+
<columnTitle>user ID</columnTitle>
8+
<isKeyField>true</isKeyField>
9+
</column>
10+
</columns>
11+
</table>
12+
</tables>
13+
</metadata>
14+
</query>

onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,15 @@ exports.init = function(EHR){
13781378
});
13791379
});
13801380

1381+
// Added: 10-6-2025
1382+
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_UPSERT, 'study', 'chemistryResults', function (helper, scriptErrors, row, oldRow) {
1383+
1384+
if (row.Id && row.qualresult && row.qualresult.indexOf('panic') !== -1) {
1385+
console.log("panic values: " + row.qualresult);
1386+
triggerHelper.sendClinpathPanicEmail(row.Id, row.runid, row.objectid);
1387+
}
1388+
});
1389+
13811390
//Added: 10-4-2022 R.Blasa
13821391
EHR.Server.TriggerManager.registerHandler(EHR.Server.TriggerManager.Events.COMPLETE, function(event, errors, helper){
13831392
// Send notifications when requests approved

onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java

Lines changed: 151 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
import org.labkey.api.query.QueryService;
5656
import org.labkey.api.query.QueryUpdateServiceException;
5757
import org.labkey.api.query.UserSchema;
58+
import org.labkey.api.security.Group;
59+
import org.labkey.api.security.MemberType;
60+
import org.labkey.api.security.SecurityManager;
5861
import org.labkey.api.security.User;
5962
import org.labkey.api.security.UserManager;
6063
import org.labkey.api.security.UserPrincipal;
@@ -64,13 +67,15 @@
6467
import org.labkey.api.util.MailHelper;
6568
import org.labkey.api.util.PageFlowUtil;
6669
import org.labkey.api.util.Pair;
70+
import org.labkey.api.util.logging.LogHelper;
6771
import org.labkey.onprc_ehr.ONPRC_EHRManager;
6872
import org.labkey.onprc_ehr.ONPRC_EHRModule;
6973
import org.labkey.onprc_ehr.ONPRC_EHRSchema;
7074
import org.labkey.onprc_ehr.notification.CullListNotification;
7175
import org.labkey.onprc_ehr.notification.MensesTMBNotification;
7276
import org.labkey.onprc_ehr.notification.ProjectAlertsNotification;
7377
import org.labkey.onprc_ehr.notification.ProtocolAlertsNotification;
78+
import org.labkey.api.util.DateUtil;
7479

7580
import java.sql.ResultSet;
7681
import java.sql.SQLException;
@@ -100,7 +105,7 @@
100105
*/
101106
public class ONPRC_EHRTriggerHelper
102107
{
103-
private static final Logger _log = LogManager.getLogger(ONPRC_EHRTriggerHelper.class);
108+
private static final Logger _log = LogHelper.getLogger(ONPRC_EHRTriggerHelper.class, "Fill in description");
104109
private static final String NONRESTRICTED = "Nonrestricted";
105110
private static final String EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, EXPERIMENTAL";
106111
private static final String NON_EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, NONEXPERIMENTAL";
@@ -2601,7 +2606,6 @@ public void updateArrivalrecords(String id, Date date) throws Exception
26012606
keys.add(FieldKey.fromString("lsid"));
26022607
final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, keys);
26032608

2604-
26052609
final List<Map<String, Object>> toUpdate = new ArrayList<>();
26062610
final List<Map<String, Object>> oldKeys = new ArrayList<>();
26072611
TableSelector ts = new TableSelector(ti, colMap.values(), new SimpleFilter(FieldKey.fromString("Id"), id, CompareType.IN), null);
@@ -2634,7 +2638,152 @@ public void exec(ResultSet object) throws SQLException
26342638
}
26352639
}
26362640

2641+
public void sendClinpathPanicEmail(String id, String runid, String objectid)
2642+
{
2643+
String subject = "Chemistry Results with Panic values";
2644+
Container c = getContainer();
2645+
2646+
2647+
final TableInfo ti = getTableInfo("onprc_ehr", "ChemistryPanicNotification");
2648+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("Id"), id, CompareType.EQUAL);
2649+
filter.addCondition(FieldKey.fromString("runid"), runid, CompareType.EQUAL);
2650+
filter.addCondition(FieldKey.fromString("objectid"), objectid, CompareType.EQUAL);
2651+
2652+
2653+
List<FieldKey> names= new ArrayList<>();
2654+
FieldKey clinpathFieldKey = FieldKey.fromString("runid");
2655+
names.add(clinpathFieldKey);
2656+
names.add(FieldKey.fromString("qualResult"));
2657+
names.add(FieldKey.fromString("servicerequested"));
2658+
names.add(FieldKey.fromString("testid"));
2659+
names.add(FieldKey.fromString("date"));
2660+
names.add(FieldKey.fromString("Id"));
2661+
names.add(FieldKey.fromString("vet"));
2662+
names.add(FieldKey.fromString("taskid"));
2663+
2664+
2665+
final Map<FieldKey, ColumnInfo> colKeys = QueryService.get().getColumns(ti, names);
2666+
final ColumnInfo clinpathColumn = colKeys.get(clinpathFieldKey);
2667+
TableSelector ts = new TableSelector(ti, colKeys.values(), filter, null);
26372668

2669+
final StringBuilder html = new StringBuilder();
2670+
2671+
2672+
if (ts.getRowCount() == 0)
2673+
{
2674+
html.append("There are no Chemistry Panlc Values to display");
2675+
2676+
return;
2677+
}
2678+
else
2679+
{
2680+
2681+
html.append("<table border=1 style='border-collapse: collapse;'>");
2682+
html.append("<tr style='font-weight: bold;'><td>Animal ID</td><td>Date</td><td>Service Requested</td><td> Panel Test Name</td><td> Qual Results</td><td>Task ID </td><td> Vet/PI Name</td></tr>\n");
2683+
ts.forEach(new Selector.ForEachBlock<ResultSet>()
2684+
{
2685+
2686+
@Override
2687+
public void exec(ResultSet rs) throws SQLException
2688+
{
2689+
2690+
String recDate = DateUtil.formatDate(c, rs.getDate("date"));
2691+
2692+
TableInfo ti2 = getTableInfo("onprc_ehr", "Labwork_Requestor_Vets");
2693+
SimpleFilter filter2 = new SimpleFilter(FieldKey.fromString("userid"), rs.getString("vet"));
2694+
filter2.addCondition(FieldKey.fromString("DisableDate"), true, CompareType.ISBLANK);
2695+
2696+
2697+
TableSelector ts2 = new TableSelector(ti2, PageFlowUtil.set("LastName"), filter2, null);
2698+
List<String> ret2 = ts2.getArrayList(String.class);
2699+
if (!ret2.isEmpty())
2700+
{
2701+
for (String Vetname : ret2)
2702+
{
2703+
2704+
html.append("<tr><td>" + PageFlowUtil.filter(rs.getString("Id")) +
2705+
"</td><td>" + PageFlowUtil.filter(recDate) +
2706+
"</td><td>" + PageFlowUtil.filter(rs.getString("servicerequested")) +
2707+
" </td><td>" + PageFlowUtil.filter(rs.getString("testid")) +
2708+
" </td><td>" + PageFlowUtil.filter(rs.getString("qualResult")) +
2709+
" </td><td>" + PageFlowUtil.filter(rs.getString("taskid")) +
2710+
"</td><td>" + PageFlowUtil.filter(Vetname) + "</td></tr>\n");
2711+
break;
2712+
2713+
}
2714+
}
2715+
2716+
}
2717+
2718+
}
2719+
2720+
);
2721+
2722+
}
2723+
2724+
2725+
final TableInfo tt = getTableInfo("study", "clinpathRuns");
2726+
SimpleFilter filtert = new SimpleFilter(FieldKey.fromString("objectid"), runid, CompareType.EQUAL);
2727+
filter.addCondition(FieldKey.fromString("id"), id, CompareType.EQUAL);
2728+
2729+
TableSelector tst = new TableSelector(ti, PageFlowUtil.set("vet"), filter, null);
2730+
tst.forEach(new Selector.ForEachBlock<>()
2731+
{
2732+
@Override
2733+
public void exec(ResultSet rs) throws SQLException
2734+
{
2735+
Integer vetId = rs.getInt("vet");
2736+
Set<UserPrincipal> recipients = getRecipients(vetId);
2737+
if (recipients.isEmpty())
2738+
{
2739+
_log.warn("No recipients, unable to send EHR trigger script email");
2740+
return;
2741+
}
2742+
else
2743+
{
2744+
html.append("</table>\n");
2745+
2746+
sendMessage(subject, html.toString(), recipients);
2747+
2748+
}
2749+
2750+
}
2751+
2752+
2753+
});
2754+
2755+
2756+
}
2757+
2758+
2759+
private Set<UserPrincipal> getRecipients(Integer... userIds)
2760+
{
2761+
Set<UserPrincipal> recipients = new HashSet<>();
2762+
for (Integer userId : userIds)
2763+
{
2764+
if (userId > 0)
2765+
{
2766+
UserPrincipal up = SecurityManager.getPrincipal(userId);
2767+
if (up != null)
2768+
{
2769+
if (up instanceof User)
2770+
{
2771+
recipients.add(up);
2772+
}
2773+
else
2774+
{
2775+
for (UserPrincipal u : SecurityManager.getAllGroupMembers((Group)up, MemberType.ACTIVE_USERS))
2776+
{
2777+
if (u.isActive())
2778+
recipients.add(u);
2779+
}
2780+
}
2781+
}
2782+
}
2783+
}
2784+
2785+
return recipients;
2786+
}
26382787

26392788
//Added 9-30-2025
26402789
public String retrieveGeographic_Origin(String Id)

0 commit comments

Comments
 (0)