diff --git a/nirc_ehr/resources/data/calculated_status_codes.tsv b/nirc_ehr/resources/data/calculated_status_codes.tsv new file mode 100644 index 00000000..49896812 --- /dev/null +++ b/nirc_ehr/resources/data/calculated_status_codes.tsv @@ -0,0 +1,7 @@ +code +Alive +Alive - In Progress +Dead +ERROR +No Record +Shipped \ No newline at end of file diff --git a/nirc_ehr/resources/data/editable_lookups.tsv b/nirc_ehr/resources/data/editable_lookups.tsv index 7f3ba907..8e2bf6df 100644 --- a/nirc_ehr/resources/data/editable_lookups.tsv +++ b/nirc_ehr/resources/data/editable_lookups.tsv @@ -23,6 +23,7 @@ ehr_lookups blood_draw_tube_type Clinical Blood Draw Tube Type Used in blood dra ehr_lookups blood_sample_type Clinical Blood Sample Types Used in blood draw datasets. ehr_lookups blood_tube_volumes Clinical Blood Tube Volumes Used in blood draw datasets. ehr_lookups cage_type Colony Management Cage Type Used in cage details. +ehr_lookups calculated_status_codes Colony Management Calculated Status Animal status values. ehr_lookups capillary_refill_time Clinical Capillary Refill Times Used clinical observations. ehr_lookups card_format Colony Management Card Format ehr_lookups census_activity_status Colony Management Census Activity Status diff --git a/nirc_ehr/resources/data/lookup_sets.tsv b/nirc_ehr/resources/data/lookup_sets.tsv index cea86af6..613eb8ec 100644 --- a/nirc_ehr/resources/data/lookup_sets.tsv +++ b/nirc_ehr/resources/data/lookup_sets.tsv @@ -18,9 +18,9 @@ behavior_mgmt_codes Behavior Management Codes value behavior_types Behavior Types value blood_draw_reason Blood Draw Reason value blood_sample_type Blood Sample Types value -card_format Card Format value title cage_type Cage Type value title capillary_refill_time Capillary Refill Time value +card_format Card Format value title census_activity_status Census Activity Status value title clinremarks_category Clinremarks Category value title congenital_abnormalities Congenital Abnormalities value title diff --git a/nirc_ehr/resources/data/lookupsManifest.tsv b/nirc_ehr/resources/data/lookupsManifest.tsv index 936ec52a..defb466b 100644 --- a/nirc_ehr/resources/data/lookupsManifest.tsv +++ b/nirc_ehr/resources/data/lookupsManifest.tsv @@ -23,6 +23,7 @@ blood_draw_tube_type blood_sample_type blood_tube_volumes cage_type +calculated_status_codes capillary_refill_time card_format census_activity_status diff --git a/nirc_ehr/resources/data/lookupsManifestTest.tsv b/nirc_ehr/resources/data/lookupsManifestTest.tsv index fde39961..b2006c8b 100644 --- a/nirc_ehr/resources/data/lookupsManifestTest.tsv +++ b/nirc_ehr/resources/data/lookupsManifestTest.tsv @@ -22,6 +22,7 @@ blood_draw_tube_type blood_sample_type blood_tube_volumes cage_type +calculated_status_codes capillary_refill_time card_format census_activity_status diff --git a/nirc_ehr/resources/queries/study/aliases.sql b/nirc_ehr/resources/queries/study/aliases.sql index 6b4df910..2652d6d0 100644 --- a/nirc_ehr/resources/queries/study/aliases.sql +++ b/nirc_ehr/resources/queries/study/aliases.sql @@ -2,7 +2,7 @@ SELECT Id, Id as alias -FROM study.Animal +FROM study.Animal where Dataset.Demographics.calculated_status != 'Alive - In Progress' UNION SELECT Id, Name as alias @@ -10,4 +10,5 @@ FROM nirc_ehr.IdHistory UNION SELECT Id, Alias as alias -FROM study.alias \ No newline at end of file +FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress' +' \ No newline at end of file diff --git a/nirc_ehr/resources/queries/study/arrival.js b/nirc_ehr/resources/queries/study/arrival.js index 5bf0b91b..b4e19ace 100644 --- a/nirc_ehr/resources/queries/study/arrival.js +++ b/nirc_ehr/resources/queries/study/arrival.js @@ -96,6 +96,8 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even } } + row.calculated_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive'; + if(!oldRow) { //if not already present, insert into demographics helper.getJavaHelper().createDemographicsRecord(row.Id, row, extraDemographicsFieldMappings); diff --git a/nirc_ehr/resources/queries/study/birth.js b/nirc_ehr/resources/queries/study/birth.js index 2596d43b..9d7b7f4a 100644 --- a/nirc_ehr/resources/queries/study/birth.js +++ b/nirc_ehr/resources/queries/study/birth.js @@ -78,10 +78,12 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even 'qcstate': helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId() } + var calc_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive'; + var obj = { Id: row.Id, date: row.date, - calculated_status: 'Alive', + calculated_status: calc_status, dam: row['Id/demographics/dam'] || null, sire: row['Id/demographics/sire'] || null, species: row['Id/demographics/species'] || null, 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;