Skip to content
Open
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
18 changes: 11 additions & 7 deletions nbri_ehr/resources/data/pairing_formation_types.tsv
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
value
Full Contact Pair
Group Formation
Introduction
Limited Contact Pair
Pair Formation
Other
value title date_disabled
C Compatible 2026-08-06
CF CF
CP Continuous pair
F Fought 2026-08-06
FC Full Contact
IC Intermittent Contact
IG Indoor Group Housing
PC Protected Contact
S Single Housing
U Unsuccessful
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="animalGroupHousingSummary" tableDbType="TABLE">
<tableTitle>Animal Groups Housing Summary</tableTitle>
<columns>
<column columnName="totalAnimals">
<columnTitle>Total Animals</columnTitle>
<url>/query/executeQuery.view?schemaName=study&amp;query.queryName=demographics&amp;query.id/curLocation/room~eq=${room}&amp;query.id/activeAnimalGroups/groups~contains=${groupId/title}</url>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
13 changes: 13 additions & 0 deletions nbri_ehr/resources/queries/study/animalGroupHousingSummary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT
m.groupId,
m.id.curLocation.room,
count(distinct m.id) as totalAnimals

FROM study.animal_group_members m
WHERE m.isActive = true
GROUP BY m.groupId, m.id.curLocation.room
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="animalGroupOverlapSummary" tableDbType="TABLE">
<tableTitle>Animal Group Member Summary</tableTitle>
<description>This query identifies the total distinct animals that were part of a group over the provided date range</description>
<columns>
<column columnName="totalAnimals">
<url>/query/executeQuery.view?schemaName=study&amp;query.queryName=animalGroupOverlaps&amp;query.param.StartDate=${StartDate}&amp;query.param.EndDate=${EndDate}&amp;query.groupId/title~eq=${groupId/title}</url>
<columnTitle>Total Animals</columnTitle>
</column>
<column columnName="startDate">
<isHidden>true</isHidden>
</column>
<column columnName="endDate">
<isHidden>true</isHidden>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
15 changes: 15 additions & 0 deletions nbri_ehr/resources/queries/study/animalGroupOverlapSummary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT
o.groupId,
count(distinct o.id) as totalAnimals,

max(o.StartDate) as StartDate,
max(o.EndDate) as EndDate

FROM study.animalGroupOverlaps o

GROUP BY o.groupId
18 changes: 18 additions & 0 deletions nbri_ehr/resources/queries/study/animalGroupOverlaps.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="animalGroupOverlaps" tableDbType="TABLE">
<tableTitle>Animal Group Overlaps</tableTitle>
<description>This query identifies distinct animals that were part of a group over the provided date range</description>
<columns>
<column columnName="startDate">
<isHidden>true</isHidden>
</column>
<column columnName="endDate">
<isHidden>true</isHidden>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
34 changes: 34 additions & 0 deletions nbri_ehr/resources/queries/study/animalGroupOverlaps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/

/**
* This query is designed to find distinct animals that were part of a group at a given point in time
*/
PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP)

SELECT
m.Id,
m.groupId,

max(StartDate) as StartDate,
max(EndDate) as EndDate
FROM study.animal_group_members m

WHERE (
/* entered startdate must be <= entered enddate */
coalesce( StartDate , cast('1900-01-01 00:00:00.0' as timestamp)) <= coalesce(EndDate, now())
AND

/* entered startdate must be less than record's enddate */
cast(coalesce( StartDate , cast('1900-01-01 00:00:00.0' as DATE)) AS DATE) <= m.enddateCoalesced

and

/* entered enddate must be greater than record's startdate */
cast(coalesce(EndDate, curdate()) AS DATE) >= m.dateOnly
)

GROUP BY m.groupId, m.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="animalGroupsPivoted" tableDbType="TABLE">
<tableTitle>Active Groups</tableTitle>
</table>
</tables>
</metadata>
</query>
17 changes: 17 additions & 0 deletions nbri_ehr/resources/queries/study/animalGroupsPivoted.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT
g.id,
g.groupId.title as name,
cast('yes' as varchar) as valueField

FROM study.animal_group_members g

WHERE (g.enddate IS NULL OR COALESCE(g.enddate, curdate()) >= curdate())

GROUP BY g.id, g.groupId.title

PIVOT valueField by name IN (select title FROM ehr_lookups.breeding_type)
42 changes: 42 additions & 0 deletions nbri_ehr/resources/queries/study/animal_group_members.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="animal_group_members" tableDbType="TABLE" useColumnOrder="true">
<tableTitle>Animal Group Members</tableTitle>
<columns>
<column columnName="Id"/>
<column columnName="date">
<columnTitle>Date Added</columnTitle>
</column>
<column columnName="enddate">
<columnTitle>Date Removed</columnTitle>
<isHidden>false</isHidden>
</column>
<column columnName="groupId">
<columnTitle>Group</columnTitle>
<fk>
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>breeding_type</fkTable>
<fkColumnName>value</fkColumnName>
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="qcstate">
<fk>
<fkDbSchema>core</fkDbSchema>
<fkTable>qcstate</fkTable>
<fkColumnName>rowid</fkColumnName>
</fk>
</column>
<column columnName="project">
<isHidden>true</isHidden>
</column>
<column columnName="performedBy">
<shownInUpdateView>false</shownInUpdateView>
<shownInInsertView>false</shownInInsertView>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="demographicsActiveAnimalGroups" tableDbType="NOT_IN_DB">
<tableTitle>Active Animal Groups</tableTitle>
<columns>
<column columnName="Id"/>
<column columnName="totalGroups">
<facetingBehavior>ALWAYS_OFF</facetingBehavior>
<columnTitle>Total Groups</columnTitle>
</column>
<column columnName="groups">
<columnTitle>Groups</columnTitle>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT
m.Id,
count(distinct m.objectid) as totalGroups,
group_concat(distinct m.name, chr(10)) as groups

FROM (SELECT Id,
objectid,
groupId.title as name
FROM study.animal_group_members
WHERE enddate is NULL AND qcstate.publicdata = true) m
GROUP BY m.Id
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/pairings.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>pairing_formation_types</fkTable>
<fkColumnName>value</fkColumnName>
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="remark">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<datasets metaDataFile="datasets_metadata.xml" xmlns="http://labkey.org/study/xml">
<datasets>
<dataset name="alias" id="1038" category="Colony Management" type="Standard"/>
<dataset name="animal_group_members" id="1042" category="Colony Management" type="Standard"/>
<dataset name="arrival" id="1001" category="Colony Management" type="Standard"/>
<dataset name="assignment" id="1002" category="Colony Management" type="Standard"/>
<dataset name="blood" id="1005" category="Clinical" type="Standard"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@
</column>
</columns>
</table>
<table tableName="animal_group_members" tableDbType="TABLE">
<tableTitle>Animal Group Members</tableTitle>
<description>Records membership of individual primates in named animal groups, with the date the animal joined and the date it was removed.</description>
<columns>
<column columnName="Id">
<datatype>varchar</datatype>
<propertyURI>http://cpas.labkey.com/Study#ParticipantId</propertyURI>
<importAliases>
<importAlias>ptid</importAlias>
</importAliases>
</column>
<column columnName="date">
<datatype>timestamp</datatype>
<propertyURI>http://cpas.labkey.com/Study#VisitDate</propertyURI>
<conceptURI>http://cpas.labkey.com/Study#VisitDate</conceptURI>
</column>
<column columnName="enddate">
<datatype>timestamp</datatype>
<propertyURI>urn:ehr.labkey.org/#EndDate</propertyURI>
</column>
<column columnName="groupId">
<columnTitle>Group</columnTitle>
<datatype>varchar</datatype>
</column>
</columns>
</table>
<table tableName="arrival" tableDbType="TABLE">
<tableTitle>Arrival</tableTitle>
<description>Tracks the arrival of primates into the research facility, including source, acquisition type, and associated documentation.</description>
Expand Down
12 changes: 10 additions & 2 deletions nbri_ehr/resources/scripts/nbri_triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.init = function (EHR) {
EHR.Server.TriggerManager.unregisterAllHandlersForQueryNameAndEvent('study', 'cases', EHR.Server.TriggerManager.Events.AFTER_DELETE);

helper.setScriptOptions({
datasetsToClose: ['assignment', 'protocolAssignment' , 'housing', 'treatment_order', 'observation_order', 'cases', 'pairings', 'exemptions', 'flags']
datasetsToClose: ['assignment', 'protocolAssignment' , 'housing', 'treatment_order', 'observation_order', 'cases', 'pairings', 'exemptions', 'flags', 'animal_group_members']
});
});

Expand All @@ -54,6 +54,14 @@ exports.init = function (EHR) {
});
});

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.INIT, 'study', 'animal_group_members', function(event, helper) {
// group memberships are routinely backdated, so historical dates must not raise a warning
helper.setScriptOptions({
requiresStatusRecalc: false,
allowDatesInDistantPast: true
});
});

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.INIT, 'study', 'assignment', function(event, helper) {
helper.setScriptOptions({
allowAnyId: isAllowAnyIdRequested(helper),
Expand Down Expand Up @@ -136,7 +144,7 @@ exports.init = function (EHR) {
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.INIT, 'study', 'deaths', function(event, helper) {

helper.setScriptOptions({
datasetsToClose: ['assignment', 'protocolAssignment' , 'housing', 'treatment_order', 'observation_order', 'cases', 'pairings', 'exemptions', 'flags'],
datasetsToClose: ['assignment', 'protocolAssignment' , 'housing', 'treatment_order', 'observation_order', 'cases', 'pairings', 'exemptions', 'flags', 'animal_group_members'],
allowShippedIds: false,
allowDeadIds: false,
requiresStatusRecalc: true,
Expand Down
16 changes: 16 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/data/AllowAnyIdClientStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
Ext4.define('NBRI_EHR.data.AllowAnyIdClientStore', {
extend: 'EHR.data.DataEntryClientStore',

getExtraContext: function () {
var ret = this.callParent(arguments) || {};

// Tell the trigger scripts to allow any Id. Requires handling in trigger script to fully enable.
ret['allowAnyId'] = true;
return ret;
}
});
Loading