|
55 | 55 | import org.labkey.api.query.QueryService; |
56 | 56 | import org.labkey.api.query.QueryUpdateServiceException; |
57 | 57 | 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; |
58 | 61 | import org.labkey.api.security.User; |
59 | 62 | import org.labkey.api.security.UserManager; |
60 | 63 | import org.labkey.api.security.UserPrincipal; |
|
64 | 67 | import org.labkey.api.util.MailHelper; |
65 | 68 | import org.labkey.api.util.PageFlowUtil; |
66 | 69 | import org.labkey.api.util.Pair; |
| 70 | +import org.labkey.api.util.logging.LogHelper; |
67 | 71 | import org.labkey.onprc_ehr.ONPRC_EHRManager; |
68 | 72 | import org.labkey.onprc_ehr.ONPRC_EHRModule; |
69 | 73 | import org.labkey.onprc_ehr.ONPRC_EHRSchema; |
70 | 74 | import org.labkey.onprc_ehr.notification.CullListNotification; |
71 | 75 | import org.labkey.onprc_ehr.notification.MensesTMBNotification; |
72 | 76 | import org.labkey.onprc_ehr.notification.ProjectAlertsNotification; |
73 | 77 | import org.labkey.onprc_ehr.notification.ProtocolAlertsNotification; |
| 78 | +import org.labkey.api.util.DateUtil; |
74 | 79 |
|
75 | 80 | import java.sql.ResultSet; |
76 | 81 | import java.sql.SQLException; |
|
100 | 105 | */ |
101 | 106 | public class ONPRC_EHRTriggerHelper |
102 | 107 | { |
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"); |
104 | 109 | private static final String NONRESTRICTED = "Nonrestricted"; |
105 | 110 | private static final String EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, EXPERIMENTAL"; |
106 | 111 | private static final String NON_EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, NONEXPERIMENTAL"; |
@@ -2601,7 +2606,6 @@ public void updateArrivalrecords(String id, Date date) throws Exception |
2601 | 2606 | keys.add(FieldKey.fromString("lsid")); |
2602 | 2607 | final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, keys); |
2603 | 2608 |
|
2604 | | - |
2605 | 2609 | final List<Map<String, Object>> toUpdate = new ArrayList<>(); |
2606 | 2610 | final List<Map<String, Object>> oldKeys = new ArrayList<>(); |
2607 | 2611 | 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 |
2634 | 2638 | } |
2635 | 2639 | } |
2636 | 2640 |
|
| 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); |
2637 | 2668 |
|
| 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 | + } |
2638 | 2787 |
|
2639 | 2788 | //Added 9-30-2025 |
2640 | 2789 | public String retrieveGeographic_Origin(String Id) |
|
0 commit comments