diff --git a/onprc_ehr/resources/queries/onprc_ehr/Procedures_Missing_PainLevels.sql b/onprc_ehr/resources/queries/onprc_ehr/Procedures_Missing_PainLevels.sql new file mode 100644 index 000000000..e01609faf --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/Procedures_Missing_PainLevels.sql @@ -0,0 +1,13 @@ +-- This query extracts the active procedures with missing USDA pain categories. +-- Set the date range to 1 year back from curr date +Select + e.id, + e.project, + e.date, + p.name, + p.PainCategories +From study.encounters e, ehr_lookups.procedures p +Where e.procedureid = p.rowid +And p.active = 'true' +And p.PainCategories IS NULL +And date > timestampadd(SQL_TSI_YEAR,-1,now()) \ No newline at end of file diff --git a/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js b/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js index f8d1f8ea6..417b1c01d 100644 --- a/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js +++ b/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js @@ -379,6 +379,30 @@ exports.init = function(EHR){ } }); + // Added by Kollil, 12/22/2022: USDA Pain category validation: + /* This is user input validation for Procedures panel + 1. Stop the user if the user attempts to fill in USDA pain level while creating / modifying a procedure other than the IS team personnel. + */ + EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'ehr_lookups', 'procedures', function(helper, scriptErrors, row, oldRow) { + //console.log(" 0. procedure: " + row.procedureid + ", ins: " + row.instructions); + + // When users other than IS team entering the procedure data, stop them until they clear the USDA pain level field data + /* + Lakshmi Kolli - 1008 + Gary Jones - 1011 + Raymond Blasa - 1007 + Lindsay Amor - 2217 + Brent Logan - 2933 + */ + if (row.PainCategories != null) { + if ( LABKEY.Security.currentUser.id !== 1008 || LABKEY.Security.currentUser.id !== 1007 || LABKEY.Security.currentUser.id !== 1011 || LABKEY.Security.currentUser.id !== 2217 || LABKEY.Security.currentUser.id !== 2933 ) + { + EHR.Server.Utils.addError(scriptErrors, 'PainCategories', 'The USDA pain category field must be left blank if the user is not from ISE team!', 'WARN'); + } + } + + }); + EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'encounters', function(helper, scriptErrors, row, oldRow) { if (row.chargetype == 'Research Staff' && !row.assistingstaff && row.procedureid && triggerHelper.requiresAssistingStaff(row.procedureid)) @@ -1155,7 +1179,6 @@ exports.init = function(EHR){ } }); - //Added 3-5-2019 R.Blasa EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_INSERT, 'ehr', 'project', function(helper, scriptErrors, row, oldRow){ diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java b/onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java index 90e2f2a96..fed9f9c61 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java @@ -200,6 +200,9 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext) //Added Mar 18th, 2021 Kollil ns.registerNotification(new HousingTransferNotification(this)); + //Added Dec 2022, Kollil + ns.registerNotification(new USDAPainNotification(this)); + //Added 8-7-2018 R.Blasa ns.registerNotification(new BirthHousingMismatchNotification(this)); diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java index 91540b6dc..7306ef851 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java @@ -722,7 +722,6 @@ protected void recordsEnteredMoreThan7DaysAfter(final Container c, User u, final } - /** * find the total finalized records with future dates */ @@ -1338,7 +1337,74 @@ protected void pmicServicesRequestAlert(final Container c, User u, final StringB msg.append("WARNING: There are no scheduled PMIC procedures!

"); } } - //End of PMIC services alert + //End of PMIC alert + + /** + * Kollil, 12/22/2022 : Find the procedure entries where the PainCategory on the procedure is not defined (IS NULL). + * This email notification is sent to Jeff every Thursday at 7:30am. + */ + protected void proceduresWithoutUSDAPainLevels(final Container c, User u, final StringBuilder msg) + { + if (QueryService.get().getUserSchema(u, c, "onprc_ehr") == null) { + msg.append("Warning: The onprc_ehr schema has not been enabled in this folder, so the alert cannot run!


"); + return; + } + + //procedures query + TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_ehr").getTable("Procedures_Missing_PainLevels", ContainerFilter.Type.AllFolders.create(c, u)); + //((ContainerFilterable) ti).setContainerFilter(ContainerFilter.Type.AllFolders.create(c, u)); + TableSelector ts = new TableSelector(ti, null, null); + long count = ts.getRowCount(); + + if (count > 0) {//procedures count + msg.append("
Active procedures with missing USDA categories:

"); + msg.append("" + count + " procedure(s) found:"); + msg.append("

Click here to view the procedures in PRIME

\n"); + msg.append("
"); + } + + if (count == 0) { + msg.append("Currently, there are no active procedures with missing USDA categories!
"); + } + + //Display the daily report in the email + if (count > 0) + { + Set columns = new HashSet<>(); + columns.add(FieldKey.fromString("Id")); + columns.add(FieldKey.fromString("project")); + columns.add(FieldKey.fromString("date")); + columns.add(FieldKey.fromString("name")); + columns.add(FieldKey.fromString("PainCategories")); + + final Map colMap = QueryService.get().getColumns(ti, columns); + TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null); + + // Table header + msg.append("

"); + msg.append(""); + msg.append(""); + + ts2.forEach(new Selector.ForEachBlock() + { + @Override + public void exec(ResultSet object) throws SQLException + { + Results rs = new ResultsImpl(object, colMap); + String url = getParticipantURL(c, rs.getString("Id")); + + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + msg.append(""); + } + }); + msg.append("
Id Center Project Date Procedure USDA Categories
" + PageFlowUtil.filter(rs.getString("Id")) + "" + PageFlowUtil.filter(rs.getString("project")) + "" + PageFlowUtil.filter(rs.getString("date")) + "" + PageFlowUtil.filter(rs.getString("name")) + "" + PageFlowUtil.filter(rs.getString("PainCategories")) + "
"); + } + } + //End of USDA Pain levels alert /** * Kollil, 03/18/2021 : Housing transfer notifications Daily diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/USDAPainNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/USDAPainNotification.java new file mode 100644 index 000000000..5b618450a --- /dev/null +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/USDAPainNotification.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2013-2016 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.onprc_ehr.notification; + +import org.apache.commons.lang3.StringUtils; +import org.labkey.api.data.AbstractTableInfo; +import org.labkey.api.data.CompareType; +import org.labkey.api.data.Container; +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.ehr.EHRService; +import org.labkey.api.ldk.LDKService; +import org.labkey.api.module.Module; +import org.labkey.api.query.FieldKey; +import org.labkey.api.query.QueryService; +import org.labkey.api.query.UserSchema; +import org.labkey.api.security.User; +import org.labkey.api.settings.AppProps; +import org.labkey.api.util.PageFlowUtil; +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.Results; +import org.labkey.api.data.ResultsImpl; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Date; +import java.util.Map; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +/** + * User: Kollil + * Date: 12/19/2022 + * Time: 2:25 PM + */ +public class USDAPainNotification extends ColonyAlertsNotification +{ + public USDAPainNotification(Module owner) + { + super(owner); + } + + @Override + public String getName() + { + return "USDA Categories Notification"; + } + + @Override + public String getEmailSubject(Container c) + { + return "Procedure(s) with missing USDA categories: " + getDateTimeFormat(c).format(new Date()); + } + + @Override + public String getCronString() + { + return "0 30 7 ? * THU"; + } + + @Override + public String getScheduleDescription() + { + return "every Thursday at 7:30Am"; + } + + @Override + public String getDescription() + { + return "The report is designed to provide a list of procedures with no USDA categories."; + } + + @Override + public String getMessageBodyHTML(Container c, User u) + { + StringBuilder msg = new StringBuilder(); + + proceduresWithoutUSDAPainLevels(c, u, msg); + + return msg.toString(); + } + +}