Skip to content

Commit 0e15803

Browse files
Issue 53225: Unable to delete row from ehr_lookups.procedures (#1018)
* Use registerHandlerForQuery for a BEFORE_DELETE event. * Include the trigger script name as a parameter for a better error message.
1 parent d2da682 commit 0e15803

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeecategory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ function beforeDelete(row, errors){
2424
var fields = ['categoryname'], fieldName;
2525
for (var i=0;i<fields.length;i++){
2626
fieldName = fields[i];
27-
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'category', row[fieldName])){
27+
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'category', row[fieldName], 'employeecategory')){
2828
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table');
2929
}
3030

31-
if (helper.verifyNotUsed('ehr_compliancedb', 'requirementspercategory', 'category', row[fieldName])){
31+
if (helper.verifyNotUsed('ehr_compliancedb', 'requirementspercategory', 'category', row[fieldName], 'employeecategory')){
3232
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the requirementspercategory table');
3333
}
3434

35-
if (helper.verifyNotUsed('ehr_compliancedb', 'sopbycategory', 'category', row[fieldName])){
35+
if (helper.verifyNotUsed('ehr_compliancedb', 'sopbycategory', 'category', row[fieldName], 'employeecategory')){
3636
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the sopbycategory table');
3737
}
3838
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeelocations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function beforeDelete(row, errors){
2222
var fields = ['location'], fieldName;
2323
for (var i=0;i<fields.length;i++){
2424
fieldName = fields[i];
25-
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'location', row[fieldName])){
25+
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'location', row[fieldName], 'employeelocations')){
2626
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
2727
}
2828
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/employees.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ function beforeDelete(row, errors){
6363
query = queries[j];
6464
for (var i=0;i<fields.length;i++){
6565
fieldName = fields[i];
66-
if (helper.verifyNotUsed('ehr_compliancedb', query, 'employeeid', row[fieldName])){
66+
if (helper.verifyNotUsed('ehr_compliancedb', query, 'employeeid', row[fieldName], 'employees')){
6767
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
6868
}
6969
}
7070
}
7171

7272
//also check trainer
73-
if (helper.verifyNotUsed('ehr_compliancedb', 'completiondates', 'trainer', row[fieldName])){
73+
if (helper.verifyNotUsed('ehr_compliancedb', 'completiondates', 'trainer', row[fieldName], 'employees')){
7474
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table completiondates');
7575
}
7676
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeetitles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function beforeDelete(row, errors){
2222
var fields = ['title'], fieldName;
2323
for (var i=0;i<fields.length;i++){
2424
fieldName = fields[i];
25-
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName])){
25+
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName], 'employeetitles')){
2626
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
2727
}
2828
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeetypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function beforeDelete(row, errors){
2222
var fields = ['type'], fieldName;
2323
for (var i=0;i<fields.length;i++){
2424
fieldName = fields[i];
25-
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName])){
25+
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName], 'employeetypes')){
2626
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
2727
}
2828
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/requirements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function beforeDelete(row, errors){
6363
query = queries[j];
6464
for (var i=0;i<fields.length;i++){
6565
fieldName = fields[i];
66-
if (helper.verifyNotUsed('ehr_compliancedb', query, 'requirementname', row[fieldName])){
66+
if (helper.verifyNotUsed('ehr_compliancedb', query, 'requirementname', row[fieldName], 'requirements')){
6767
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
6868
}
6969
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/requirementtype.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function beforeDelete(row, errors){
2222
var fields = ['type'], fieldName;
2323
for (var i=0;i<fields.length;i++){
2424
fieldName = fields[i];
25-
if (helper.verifyNotUsed('ehr_compliancedb', 'requirements', fieldName, row[fieldName])){
25+
if (helper.verifyNotUsed('ehr_compliancedb', 'requirements', fieldName, row[fieldName], 'requirementtype')){
2626
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the requirements table'];
2727
}
2828
}

EHR_ComplianceDB/resources/queries/ehr_compliancedb/unit_names.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function beforeDelete(row, errors){
2626
query = queries[j];
2727
for (var i=0;i<fields.length;i++){
2828
fieldName = fields[i];
29-
if (helper.verifyNotUsed('ehr_compliancedb', query, 'unit', row[fieldName])){
29+
if (helper.verifyNotUsed('ehr_compliancedb', query, 'unit', row[fieldName], 'unit_names')){
3030
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
3131
}
3232
}

ehr/resources/queries/ehr_lookups/procedures.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
var console = require("console");
88
var LABKEY = require("labkey");
9+
var triggers = require("ehr/triggers");
10+
triggers.initScript(this);
11+
var EHR = triggers.EHR;
912

10-
var helper = org.labkey.ldk.query.LookupValidationHelper.create(LABKEY.Security.currentContainer.id, LABKEY.Security.currentUser.id, 'ehr_lookups', 'procedures');
13+
var lookupValidationHelper = org.labkey.ldk.query.LookupValidationHelper.create(LABKEY.Security.currentContainer.id, LABKEY.Security.currentUser.id, 'ehr_lookups', 'procedures');
1114

12-
13-
function beforeDelete(row, errors){
14-
if (helper.verifyNotUsed('study', 'encounters', 'procedureid', row['rowid'])){
15+
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_DELETE, 'ehr_lookups', 'procedures', function(helper, scriptErrors, row, oldRow){
16+
if (lookupValidationHelper.verifyNotUsed('study', 'encounters', 'procedureid', row['rowid'], 'procedures')) {
1517
addError(errors, 'name', 'Cannot delete row with ID: ' + row['rowid'] + ' because it is referenced by the table encounters. You should inactivate this item instead.');
1618
}
17-
}
19+
});
1820

1921
function addError(errors, fieldName, msg){
2022
if (!errors[fieldName])

0 commit comments

Comments
 (0)