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
Expand Up @@ -24,15 +24,15 @@ function beforeDelete(row, errors){
var fields = ['categoryname'], fieldName;
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'category', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'category', row[fieldName], 'employeecategory')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table');
}

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

if (helper.verifyNotUsed('ehr_compliancedb', 'sopbycategory', 'category', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'sopbycategory', 'category', row[fieldName], 'employeecategory')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the sopbycategory table');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function beforeDelete(row, errors){
var fields = ['location'], fieldName;
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'location', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', 'location', row[fieldName], 'employeelocations')){
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ function beforeDelete(row, errors){
query = queries[j];
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', query, 'employeeid', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', query, 'employeeid', row[fieldName], 'employees')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
}
}
}

//also check trainer
if (helper.verifyNotUsed('ehr_compliancedb', 'completiondates', 'trainer', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'completiondates', 'trainer', row[fieldName], 'employees')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table completiondates');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function beforeDelete(row, errors){
var fields = ['title'], fieldName;
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName], 'employeetitles')){
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function beforeDelete(row, errors){
var fields = ['type'], fieldName;
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'employees', fieldName, row[fieldName], 'employeetypes')){
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the employees table'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function beforeDelete(row, errors){
query = queries[j];
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', query, 'requirementname', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', query, 'requirementname', row[fieldName], 'requirements')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function beforeDelete(row, errors){
var fields = ['type'], fieldName;
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', 'requirements', fieldName, row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', 'requirements', fieldName, row[fieldName], 'requirementtype')){
errors[fieldName] = ['Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the requirements table'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function beforeDelete(row, errors){
query = queries[j];
for (var i=0;i<fields.length;i++){
fieldName = fields[i];
if (helper.verifyNotUsed('ehr_compliancedb', query, 'unit', row[fieldName])){
if (helper.verifyNotUsed('ehr_compliancedb', query, 'unit', row[fieldName], 'unit_names')){
addError(errors, fieldName, 'Cannot delete row with value: ' + row[fieldName] + ' because it is referenced by the table ' + query);
}
}
Expand Down
12 changes: 7 additions & 5 deletions ehr/resources/queries/ehr_lookups/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

var console = require("console");
var LABKEY = require("labkey");
var triggers = require("ehr/triggers");
triggers.initScript(this);
var EHR = triggers.EHR;

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


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

function addError(errors, fieldName, msg){
if (!errors[fieldName])
Expand Down