Skip to content

Commit 37150ec

Browse files
Merge 26.3 to develop
2 parents ad22d56 + 25e8816 commit 37150ec

File tree

14 files changed

+173
-19
lines changed

14 files changed

+173
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
code
2+
Alive
3+
Alive - In Progress
4+
Dead
5+
ERROR
6+
No Record
7+
Shipped

nirc_ehr/resources/data/editable_lookups.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ehr_lookups blood_draw_tube_type Clinical Blood Draw Tube Type Used in blood dra
2323
ehr_lookups blood_sample_type Clinical Blood Sample Types Used in blood draw datasets.
2424
ehr_lookups blood_tube_volumes Clinical Blood Tube Volumes Used in blood draw datasets.
2525
ehr_lookups cage_type Colony Management Cage Type Used in cage details.
26+
ehr_lookups calculated_status_codes Colony Management Calculated Status Animal status values.
2627
ehr_lookups capillary_refill_time Clinical Capillary Refill Times Used clinical observations.
2728
ehr_lookups card_format Colony Management Card Format
2829
ehr_lookups census_activity_status Colony Management Census Activity Status

nirc_ehr/resources/data/lookup_sets.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ behavior_mgmt_codes Behavior Management Codes value
1818
behavior_types Behavior Types value
1919
blood_draw_reason Blood Draw Reason value
2020
blood_sample_type Blood Sample Types value
21-
card_format Card Format value title
2221
cage_type Cage Type value title
2322
capillary_refill_time Capillary Refill Time value
23+
card_format Card Format value title
2424
census_activity_status Census Activity Status value title
2525
clinremarks_category Clinremarks Category value title
2626
congenital_abnormalities Congenital Abnormalities value title

nirc_ehr/resources/data/lookupsManifest.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ blood_draw_tube_type
2323
blood_sample_type
2424
blood_tube_volumes
2525
cage_type
26+
calculated_status_codes
2627
capillary_refill_time
2728
card_format
2829
census_activity_status

nirc_ehr/resources/data/lookupsManifestTest.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ blood_draw_tube_type
2222
blood_sample_type
2323
blood_tube_volumes
2424
cage_type
25+
calculated_status_codes
2526
capillary_refill_time
2627
card_format
2728
census_activity_status

nirc_ehr/resources/queries/study/aliases.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
SELECT Id,
44
Id as alias
5-
FROM study.Animal
5+
FROM study.Animal where Dataset.Demographics.calculated_status != 'Alive - In Progress'
66
UNION
77
SELECT Id,
88
Name as alias
99
FROM nirc_ehr.IdHistory
1010
UNION
1111
SELECT Id,
1212
Alias as alias
13-
FROM study.alias
13+
FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress'
14+
'

nirc_ehr/resources/queries/study/arrival.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
9696
}
9797
}
9898

99+
row.calculated_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive';
100+
99101
if(!oldRow) {
100102
//if not already present, insert into demographics
101103
helper.getJavaHelper().createDemographicsRecord(row.Id, row, extraDemographicsFieldMappings);

nirc_ehr/resources/queries/study/birth.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
7878
'qcstate': helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId()
7979
}
8080

81+
var calc_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive';
82+
8183
var obj = {
8284
Id: row.Id,
8385
date: row.date,
84-
calculated_status: 'Alive',
86+
calculated_status: calc_status,
8587
dam: row['Id/demographics/dam'] || null,
8688
sire: row['Id/demographics/sire'] || null,
8789
species: row['Id/demographics/species'] || null,

nirc_ehr/resources/queries/study/housing.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,89 @@ var prevDate;
55
let triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
66
let animalIds = [];
77

8+
function onInit(event, helper){
9+
helper.setScriptOptions({
10+
skipHousingCheck: true
11+
});
12+
13+
helper.decodeExtraContextProperty('housingInTransaction');
14+
15+
helper.registerRowProcessor(function(helper, row){
16+
if (!row)
17+
return;
18+
19+
if (!row.Id || !row.room){
20+
return;
21+
}
22+
23+
var housingInTransaction = helper.getProperty('housingInTransaction');
24+
housingInTransaction = housingInTransaction || {};
25+
housingInTransaction[row.Id] = housingInTransaction[row.Id] || [];
26+
27+
// this is a failsafe in case the client did not provide housing JSON. it ensures
28+
// the current row is part of housingInTransaction
29+
var shouldAdd = true;
30+
if (row.objectid){
31+
LABKEY.ExtAdapter.each(housingInTransaction[row.Id], function(r){
32+
if (r.objectid == row.objectid){
33+
shouldAdd = false;
34+
return false;
35+
}
36+
}, this);
37+
}
38+
39+
if (shouldAdd){
40+
housingInTransaction[row.Id].push({
41+
objectid: row.objectid,
42+
date: row.date,
43+
enddate: row.enddate,
44+
qcstate: row.QCState,
45+
room: row.room,
46+
cage: row.cage,
47+
divider: row.divider
48+
});
49+
}
50+
51+
helper.setProperty('housingInTransaction', housingInTransaction);
52+
});
53+
}
54+
55+
function onUpsert(helper, scriptErrors, row, oldRow){
56+
//verify we dont have 2 opened records for the same ID
57+
if (!helper.isETL() && !row.enddate && row.Id){
58+
var map = helper.getProperty('housingInTransaction');
59+
if (map && map[row.Id]){
60+
var housingRecords = map[row.Id];
61+
for (var i=0;i<housingRecords.length;i++){
62+
if (row.objectid == housingRecords[i].objectid){
63+
console.log ('same housing record');
64+
continue;
65+
}
66+
67+
if (!housingRecords[i].enddate){
68+
EHR.Server.Utils.addError(scriptErrors, 'enddate', 'Cannot enter multiple open-ended housing records for the same animal', 'WARN');
69+
}
70+
}
71+
}
72+
}
73+
74+
if (!helper.isETL() && row && row.Id && row.date && !row.enddate){
75+
var objectid = row.objectid || null;
76+
//if this record is active and public, deactivate any old housing records
77+
var map = helper.getProperty('housingInTransaction');
78+
var housingRecords = [];
79+
if (map && map[row.Id]){
80+
housingRecords = map[row.Id];
81+
}
82+
83+
//NOTE: downstream java code should handle type conversion of housingInTransaction
84+
var msg = helper.getJavaHelper().validateFutureOpenEndedHousing(row.Id, row.date, objectid, housingRecords);
85+
if (msg){
86+
EHR.Server.Utils.addError(scriptErrors, 'Id', msg, 'WARN');
87+
}
88+
}
89+
}
90+
891
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_INSERT, 'study', 'housing', function (helper, scriptErrors, row, oldRow) {
992

1093
if (helper.isETL()) {

nirc_ehr/resources/queries/study/observationSchedule.sql

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ SELECT
22
g.id,
33
g.scheduledDate,
44
COUNT(g.caseid) cases,
5-
GROUP_CONCAT(g.observations, ';') AS observations,
6-
SUM(obsCount) AS obsCount,
7-
GROUP_CONCAT(g.obsOrderIds, ';') AS orderIds,
8-
GROUP_CONCAT(g.status, ';') AS status,
9-
GROUP_CONCAT(g.taskids, ';') AS taskids,
5+
o.observations,
6+
SUM(g.obsCount) AS obsCount,
7+
o.orderIds,
8+
o.status,
9+
o.taskids,
1010
MAX(g.type) AS type,
1111
MAX(g.caseid) AS caseid
1212
FROM
@@ -16,21 +16,29 @@ FROM
1616
sch.date AS scheduledDate,
1717
sch.caseid,
1818
sch.type,
19-
GROUP_CONCAT(sch.objectid, ';') AS obsOrderIds,
20-
GROUP_CONCAT(sch.category, ';') AS observations,
21-
GROUP_CONCAT(obsStatus, ';') AS status,
22-
GROUP_CONCAT(DISTINCT(sch.taskid), ';') AS taskids,
23-
COUNT(sch.category) AS obsCount,
24-
COUNT(sch.obsStatus) AS statusCount
25-
FROM (
26-
SELECT * FROM observationOrdersByDate
27-
) sch
19+
COUNT(sch.category) AS obsCount
20+
FROM observationOrdersByDate sch
2821
GROUP BY
2922
sch.animalId,
3023
sch.date,
3124
sch.caseid,
3225
sch.type
3326
) g
27+
LEFT JOIN (
28+
SELECT
29+
obs.animalId AS id,
30+
obs.date AS scheduledDate,
31+
GROUP_CONCAT(DISTINCT obs.category, ';') AS observations,
32+
GROUP_CONCAT(obs.objectid, ';') AS orderIds,
33+
GROUP_CONCAT(obs.obsStatus, ';') AS status,
34+
GROUP_CONCAT(DISTINCT(obs.taskid), ';') AS taskids
35+
FROM observationOrdersByDate obs
36+
GROUP BY obs.animalId, obs.date
37+
) o ON g.id = o.id AND g.scheduledDate = o.scheduledDate
3438
GROUP BY
3539
g.id,
36-
g.scheduledDate
40+
g.scheduledDate,
41+
o.observations,
42+
o.orderIds,
43+
o.status,
44+
o.taskids

0 commit comments

Comments
 (0)