Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,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())
25 changes: 24 additions & 1 deletion onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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){

Expand Down
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 @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ protected void recordsEnteredMoreThan7DaysAfter(final Container c, User u, final

}


/**
* find the total finalized records with future dates
*/
Expand Down Expand Up @@ -1338,7 +1337,74 @@ protected void pmicServicesRequestAlert(final Container c, User u, final StringB
msg.append("<b>WARNING: There are no scheduled PMIC procedures!</b><br><hr>");
}
}
//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("<b>Warning: The onprc_ehr schema has not been enabled in this folder, so the alert cannot run!<p><hr>");
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("<br><b>Active procedures with missing USDA categories:</b><br><br>");
msg.append("<b>" + count + " procedure(s) found:</b>");
msg.append("<p><a href='" + getExecuteQueryUrl(c, "onprc_ehr", "Procedures_Missing_PainLevels", null) + "'>Click here to view the procedures in PRIME</a></p>\n");
msg.append("<hr>");
}

if (count == 0) {
msg.append("<b>Currently, there are no active procedures with missing USDA categories!</b><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("name"));
columns.add(FieldKey.fromString("PainCategories"));

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

// Table header
msg.append("<br><br><table border=1 style='border-collapse: collapse;'>");
msg.append("<tr bgcolor = " + '"' + "#00FF7F" + '"' + "style='font-weight: bold;'>");
msg.append("<td> Id </td><td> Center Project </td><td> Date </td><td> Procedure </td><td> USDA Categories </td></tr>");

ts2.forEach(new Selector.ForEachBlock<ResultSet>()
{
@Override
public void exec(ResultSet object) throws SQLException
{
Results rs = new ResultsImpl(object, colMap);
String url = getParticipantURL(c, rs.getString("Id"));

msg.append("<td>" + PageFlowUtil.filter(rs.getString("Id")) + "</td>");
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("name")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("PainCategories")) + "</td>");
msg.append("</tr>");
}
});
msg.append("</table>");
}
}
//End of USDA Pain levels alert

/**
* Kollil, 03/18/2021 : Housing transfer notifications Daily
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}