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
7 changes: 7 additions & 0 deletions nirc_ehr/resources/data/calculated_status_codes.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
code
Alive
Alive - In Progress
Dead
ERROR
No Record
Shipped
1 change: 1 addition & 0 deletions nirc_ehr/resources/data/editable_lookups.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nirc_ehr/resources/data/lookup_sets.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nirc_ehr/resources/data/lookupsManifest.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nirc_ehr/resources/data/lookupsManifestTest.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions nirc_ehr/resources/queries/study/aliases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

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
FROM nirc_ehr.IdHistory
UNION
SELECT Id,
Alias as alias
FROM study.alias
FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress'
'
2 changes: 2 additions & 0 deletions nirc_ehr/resources/queries/study/arrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion nirc_ehr/resources/queries/study/birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
83 changes: 83 additions & 0 deletions nirc_ehr/resources/queries/study/housing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<housingRecords.length;i++){
if (row.objectid == housingRecords[i].objectid){
console.log ('same housing record');
continue;
}

if (!housingRecords[i].enddate){
EHR.Server.Utils.addError(scriptErrors, 'enddate', 'Cannot enter multiple open-ended housing records for the same animal', 'WARN');
}
}
}
}

if (!helper.isETL() && row && row.Id && row.date && !row.enddate){
var objectid = row.objectid || null;
//if this record is active and public, deactivate any old housing records
var map = helper.getProperty('housingInTransaction');
var housingRecords = [];
if (map && map[row.Id]){
housingRecords = map[row.Id];
}

//NOTE: downstream java code should handle type conversion of housingInTransaction
var msg = helper.getJavaHelper().validateFutureOpenEndedHousing(row.Id, row.date, objectid, housingRecords);
if (msg){
EHR.Server.Utils.addError(scriptErrors, 'Id', msg, 'WARN');
}
}
}

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_INSERT, 'study', 'housing', function (helper, scriptErrors, row, oldRow) {

if (helper.isETL()) {
Expand Down
38 changes: 23 additions & 15 deletions nirc_ehr/resources/queries/study/observationSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ SELECT
g.id,
g.scheduledDate,
COUNT(g.caseid) cases,
GROUP_CONCAT(g.observations, ';') AS observations,
SUM(obsCount) AS obsCount,
GROUP_CONCAT(g.obsOrderIds, ';') AS orderIds,
GROUP_CONCAT(g.status, ';') AS status,
GROUP_CONCAT(g.taskids, ';') AS taskids,
o.observations,
SUM(g.obsCount) AS obsCount,
o.orderIds,
o.status,
o.taskids,
MAX(g.type) AS type,
MAX(g.caseid) AS caseid
FROM
Expand All @@ -16,21 +16,29 @@ FROM
sch.date AS scheduledDate,
sch.caseid,
sch.type,
GROUP_CONCAT(sch.objectid, ';') AS obsOrderIds,
GROUP_CONCAT(sch.category, ';') AS observations,
GROUP_CONCAT(obsStatus, ';') AS status,
GROUP_CONCAT(DISTINCT(sch.taskid), ';') AS taskids,
COUNT(sch.category) AS obsCount,
COUNT(sch.obsStatus) AS statusCount
FROM (
SELECT * FROM observationOrdersByDate
) sch
COUNT(sch.category) AS obsCount
FROM observationOrdersByDate sch
GROUP BY
sch.animalId,
sch.date,
sch.caseid,
sch.type
) g
LEFT JOIN (
SELECT
obs.animalId AS id,
obs.date AS scheduledDate,
GROUP_CONCAT(DISTINCT obs.category, ';') AS observations,
GROUP_CONCAT(obs.objectid, ';') AS orderIds,
GROUP_CONCAT(obs.obsStatus, ';') AS status,
GROUP_CONCAT(DISTINCT(obs.taskid), ';') AS taskids
FROM observationOrdersByDate obs
GROUP BY obs.animalId, obs.date
) o ON g.id = o.id AND g.scheduledDate = o.scheduledDate
GROUP BY
g.id,
g.scheduledDate
g.scheduledDate,
o.observations,
o.orderIds,
o.status,
o.taskids
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.nirc_ehr.dataentry.form;

import org.json.JSONObject;
import org.labkey.api.ehr.dataentry.AbstractFormSection;
import org.labkey.api.ehr.dataentry.DataEntryFormContext;
import org.labkey.api.ehr.dataentry.FormSection;
Expand Down Expand Up @@ -117,4 +118,18 @@ protected List<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -48,4 +49,18 @@ protected List<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -71,4 +72,18 @@ protected List<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ protected List<HistoryRow> 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);
Expand All @@ -73,6 +75,7 @@ protected List<HistoryRow> processRows(Container c, TableSelector ts, final bool
for (String key : idMap.keySet())
{
List<Map<String, Object>> toAdd = idMap.get(key);
toAdd.sort(Comparator.comparing(m -> String.valueOf(m.getOrDefault("category", "")), String.CASE_INSENSITIVE_ORDER));

Date date = null;
String subjectId = null;
Expand Down
Loading