diff --git a/nirc_ehr/resources/queries/study/housing.js b/nirc_ehr/resources/queries/study/housing.js index 2e919eda..bb10fa77 100644 --- a/nirc_ehr/resources/queries/study/housing.js +++ b/nirc_ehr/resources/queries/study/housing.js @@ -5,6 +5,89 @@ var prevDate; let triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id); let animalIds = []; +function onInit(event, helper){ + helper.setScriptOptions({ + skipHousingCheck: true + }); + + helper.decodeExtraContextProperty('housingInTransaction'); + + helper.registerRowProcessor(function(helper, row){ + if (!row) + return; + + if (!row.Id || !row.room){ + return; + } + + var housingInTransaction = helper.getProperty('housingInTransaction'); + housingInTransaction = housingInTransaction || {}; + housingInTransaction[row.Id] = housingInTransaction[row.Id] || []; + + // this is a failsafe in case the client did not provide housing JSON. it ensures + // the current row is part of housingInTransaction + var shouldAdd = true; + if (row.objectid){ + LABKEY.ExtAdapter.each(housingInTransaction[row.Id], function(r){ + if (r.objectid == row.objectid){ + shouldAdd = false; + return false; + } + }, this); + } + + if (shouldAdd){ + housingInTransaction[row.Id].push({ + objectid: row.objectid, + date: row.date, + enddate: row.enddate, + qcstate: row.QCState, + room: row.room, + cage: row.cage, + divider: row.divider + }); + } + + helper.setProperty('housingInTransaction', housingInTransaction); + }); +} + +function onUpsert(helper, scriptErrors, row, oldRow){ + //verify we dont have 2 opened records for the same ID + if (!helper.isETL() && !row.enddate && row.Id){ + var map = helper.getProperty('housingInTransaction'); + if (map && map[row.Id]){ + var housingRecords = map[row.Id]; + for (var i=0;i getMoreActionButtonConfigs() configs.remove("DISCARD"); return configs; } + + @Override + public JSONObject toJSON() + { + JSONObject ret = super.toJSON(); + + //this form involves extra work on save, so relax warning thresholds to reduce error logging + ret.put("perRowWarningThreshold", 0.5); + ret.put("totalTransactionWarningThrehsold", 60); + ret.put("perRowValidationWarningThrehsold", 6); + ret.put("totalValidationTransactionWarningThrehsold", 60); + + return ret; + } } \ No newline at end of file diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalObservationsFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalObservationsFormType.java index 5cb8d4f0..1294ebfa 100644 --- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalObservationsFormType.java +++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalObservationsFormType.java @@ -1,5 +1,6 @@ package org.labkey.nirc_ehr.dataentry.form; +import org.json.JSONObject; import org.labkey.api.ehr.dataentry.DataEntryFormContext; import org.labkey.api.ehr.dataentry.FormSection; import org.labkey.api.module.Module; @@ -48,4 +49,18 @@ protected List getButtonConfigs() return ret; } + + @Override + public JSONObject toJSON() + { + JSONObject ret = super.toJSON(); + + //this form involves extra work on save, so relax warning thresholds to reduce error logging + ret.put("perRowWarningThreshold", 0.5); + ret.put("totalTransactionWarningThrehsold", 60); + ret.put("perRowValidationWarningThrehsold", 6); + ret.put("totalValidationTransactionWarningThrehsold", 60); + + return ret; + } } \ No newline at end of file diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCDeathNecropsyFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCDeathNecropsyFormType.java index 82901772..1ccde992 100644 --- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCDeathNecropsyFormType.java +++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCDeathNecropsyFormType.java @@ -1,5 +1,6 @@ package org.labkey.nirc_ehr.dataentry.form; +import org.json.JSONObject; import org.labkey.api.ehr.dataentry.DataEntryFormContext; import org.labkey.api.ehr.dataentry.FormSection; import org.labkey.api.ehr.security.EHRVeterinarianPermission; @@ -71,4 +72,18 @@ protected List getMoreActionButtonConfigs() configs.remove("DISCARD"); return configs; } + + @Override + public JSONObject toJSON() + { + JSONObject ret = super.toJSON(); + + //this form involves extra work on save, so relax warning thresholds to reduce error logging + ret.put("perRowWarningThreshold", 0.5); + ret.put("totalTransactionWarningThrehsold", 60); + ret.put("perRowValidationWarningThrehsold", 6); + ret.put("totalValidationTransactionWarningThrehsold", 60); + + return ret; + } } diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/history/NIRCObservationsDataSource.java b/nirc_ehr/src/org/labkey/nirc_ehr/history/NIRCObservationsDataSource.java index 2448c0d8..269800c4 100644 --- a/nirc_ehr/src/org/labkey/nirc_ehr/history/NIRCObservationsDataSource.java +++ b/nirc_ehr/src/org/labkey/nirc_ehr/history/NIRCObservationsDataSource.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -56,6 +57,7 @@ protected List processRows(Container c, TableSelector ts, final bool rowMap.put("taskRowId", results.getInt(FieldKey.fromString("taskId/rowid"))); rowMap.put("formType", results.getString(FieldKey.fromString("taskId/formtype"))); rowMap.put("objectId", results.getString(FieldKey.fromString("objectId"))); + rowMap.put("category", results.getString(FieldKey.fromString("category"))); rowMap.put("html", html); Date roundedDate = DateUtils.truncate((Date)rowMap.get("date"), Calendar.MINUTE); @@ -73,6 +75,7 @@ protected List processRows(Container c, TableSelector ts, final bool for (String key : idMap.keySet()) { List> toAdd = idMap.get(key); + toAdd.sort(Comparator.comparing(m -> String.valueOf(m.getOrDefault("category", "")), String.CASE_INSENSITIVE_ORDER)); Date date = null; String subjectId = null;