From a5a1ef6b5168b91c1f6bff94d9f6dde4d56958ab Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Wed, 26 Aug 2026 05:30:47 -0600 Subject: [PATCH] Normalize employeeid, unit, and category on write in compliance tables employeeperunit was the only table in ehr_compliancedb with no trigger script, so its employeeid, unit, and category values were never canonicalized against their lookups - the reason the ONPRC report procedures had to wrap every unit and category comparison in lower(). Its schema metadata already declares all three columns as lookups, so the script is a drop-in copy of the ten siblings. sopdates had no trigger script either. sopid is deliberately left out of its lookupFields: the fk to sops is commented out in ehr_compliancedb.xml, and getLookupValue returns null for a column with no fk, which would reject every row. Pairs with the lower() removal in onprcEHRModules (PR 1859). Merge this first, or those reports will silently drop rows whose unit or category differs only by case. Existing rows carrying off-lookup values need a backfill before this deploys, since beforeUpdate revalidates the merged old row and will otherwise block edits that work today. --- .../ehr_compliancedb/employeeperunit.js | 40 ++++++++++++++++++ .../queries/ehr_compliancedb/sopdates.js | 41 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeeperunit.js create mode 100644 EHR_ComplianceDB/resources/queries/ehr_compliancedb/sopdates.js diff --git a/EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeeperunit.js b/EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeeperunit.js new file mode 100644 index 000000000..856213fb6 --- /dev/null +++ b/EHR_ComplianceDB/resources/queries/ehr_compliancedb/employeeperunit.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2026 LabKey Corporation +* +* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 +*/ + +var LABKEY = require("labkey"); + +var helper = org.labkey.ldk.query.LookupValidationHelper.create(LABKEY.Security.currentContainer.id, LABKEY.Security.currentUser.id, 'ehr_compliancedb', 'employeeperunit'); + +function beforeInsert(row, errors){ + beforeUpsert(row, errors); +} + +function beforeUpdate(row, oldRow, errors){ + //NOTE: this is designed to merge the old row into the new one. + for (var prop in oldRow){ + if(!row.hasOwnProperty(prop) && LABKEY.ExtAdapter.isDefined(oldRow[prop])){ + row[prop] = oldRow[prop]; + } + } + + beforeUpsert(row, errors); +} + +function beforeUpsert(row, errors){ + var lookupFields = ['employeeid', 'unit', 'category']; + for (var i=0;i