Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8036820
Made changes to the Weights drop alert.
kollil Oct 10, 2025
34222c2
Added query.xml files for the db tables
kollil Dec 9, 2025
439341f
Added new functionality to the weights data
kollil Jan 9, 2026
9811c87
Added new exclusion clauses
kollil Jan 10, 2026
d49504c
Updated queries with more filters
kollil Jan 11, 2026
3fae10a
Updated queries
kollil Jan 15, 2026
c64648c
Updated query: Removed the animalid from the where clause
kollil Jan 15, 2026
ed95c68
Updated query: Removed the animalid from the where clause
kollil Jan 15, 2026
2e638a0
Updated query: Added new clauses,
kollil Jan 22, 2026
8978470
Updated query #2: Added new clauses,
kollil Jan 23, 2026
e2f0067
latest version
kollil Feb 13, 2026
dfa3148
Added a new area filter and fixed the duplicates issue in the email data
kollil Feb 27, 2026
dd35cde
Added another if clause
kollil Mar 2, 2026
fc81aee
Fixed the XML mismatches
kollil Mar 5, 2026
3a1a258
Deleted files that are not used and fixed the XML
kollil Mar 5, 2026
39a5ae7
Delete onprc_ehr/resources/queries/study/weightConsecutiveDrops_NotIn…
kollil Mar 5, 2026
33d2107
Delete onprc_ehr/resources/queries/study/weightConsecutiveDrops_NotIn…
kollil Mar 5, 2026
ab4a677
Update weightRelChange_NotInMMA.query.xml
kollil Mar 5, 2026
565fc50
Cleaned up the code
kollil Mar 5, 2026
9aee27c
Update WeightAlertsNotification.java
kollil Mar 5, 2026
29a9a4a
Created a new query as code based
kollil Mar 9, 2026
b28d172
Merge remote-tracking branch 'origin/25.7_fb_WeightDropAlertUpdate' i…
kollil Mar 9, 2026
d8a5b5f
Created a new query as code based
kollil Mar 9, 2026
0bbe714
updated query
kollil Mar 9, 2026
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
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="Demographics_NotInMMA" tableDbType="NOT_IN_DB">
<tableTitle>Demographics (Excluding animals in Weight MMA regimen)</tableTitle>
</table>
</tables>
</metadata>
</query>
54 changes: 54 additions & 0 deletions onprc_ehr/resources/queries/study/Demographics_NotInMMA.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Created by Kollil in Dec 2025
Tkt # 13461
Added two filters to the Demographics dataset:
1. Filter out any animal with the following SNOMED Codes:
Begin active weight management regimen (P-YY961)
However, we would need to include animals that have this additional SNOMED Code if it's entered AFTER the one above
Release from active weight management regimen (P-YY960)
2. Remove Shelters, Corral and Hospital locations from the lists
*/

SELECT
d.Id.curlocation.area AS Area,
d.Id.curlocation.room AS Room,
d.Id.curlocation.cage AS Cage,
d.Id,
d.Id.utilization.use AS ProjectsAndGroups,
d.species,
d.geographic_origin,
d.gender AS Sex,
d.calculated_status,
d.birth,
d.Id.Age.YearAndDays,
d.Id.MostRecentWeight.MostRecentWeight,
d.Id.MostRecentWeight.MostRecentWeightDate,
d.Id.viral_status.viralStatus,
d.history
FROM Demographics d
WHERE d.Id.curlocation.area NOT IN ('Shelters', 'Corral', 'Hospital', 'Catch Area')-- Exclude animals from these locations
AND NOT (-- Exclude females under 5yrs, males under 7yrs
(d.gender.code = 'f' AND d.Id.age.ageInYears < 5)
OR (d.gender.code = 'm' AND d.Id.age.ageInYears < 7)
)
AND NOT EXISTS (
-- -- Find animals whose latest 'Weight MMA BEGIN' has no later 'Weight MMA RELEASE'
SELECT 1
FROM study.WeightMMA b
WHERE b.Id = d.Id
AND b.code = 'P-YY961'
AND b.date = (
SELECT MAX(b2.date)
FROM study.WeightMMA b2
WHERE b2.Id = d.Id
AND b2.code = 'P-YY961'
)
AND NOT EXISTS (
SELECT 1
FROM study.WeightMMA r
WHERE r.Id = d.Id
AND r.code = 'P-YY960'
AND r.date > b.date
)
)

32 changes: 32 additions & 0 deletions onprc_ehr/resources/queries/study/WeightMMA.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="WeightMMA" tableDbType="NOT_IN_DB">
<tableTitle>Animals in weight management regimen</tableTitle>
<columns>
<column columnName="Id">
<isHidden>false</isHidden>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="date">
<isHidden>false</isHidden>
<columnTitle>Prev Weight Date</columnTitle>
</column>
<column columnName="set_number">
<columnTitle>Set Number</columnTitle>
</column>
<column columnName="code">
<columnTitle>Snomed Code</columnTitle>
</column>
<column columnName="qualifier">
<columnTitle>Qualifier</columnTitle>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
19 changes: 19 additions & 0 deletions onprc_ehr/resources/queries/study/WeightMMA.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Created by Kolli, March 2026
--New query created in the code base as the automated tests are failing.
SELECT s.Id,
s.date,
s.set_number,
s.code,
s.qualifier
FROM ehr.snomed_tags s
where s.code like 'P-YY961'

Union

SELECT s.Id,
s.date,
s.set_number,
s.code,
s.qualifier
FROM ehr.snomed_tags s
where s.code like 'P-YY960'
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="weightRelChange_NotInMMA" tableDbType="NOT_IN_DB">
<tableTitle>Weight Change, Relative to Current Weight (Excluding the animals enrolled in MMA)</tableTitle>
<description>This query shows the percent change of each weight, relative to the current weight</description>
<columns>
<column columnName="lsid">
<isKeyField>true</isKeyField>
<isHidden>true</isHidden>
</column>
<column columnName="Id">
<isHidden>false</isHidden>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="date">
<isHidden>false</isHidden>
<columnTitle>Prev Weight Date</columnTitle>
</column>
<column columnName="weight">
<columnTitle>Prev Weight (kg)</columnTitle>
</column>
<column columnName="PctChange">
<columnTitle>% Change Relative To Current</columnTitle>
</column>
<column columnName="AbsPctChange">
<columnTitle>Abs Pct Change</columnTitle>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
85 changes: 85 additions & 0 deletions onprc_ehr/resources/queries/study/weightRelChange_NotInMMA.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Created by Kollil in Dec 2025
Tkt # 13461
Added two filters to the Demographics dataset:
1. Filter out any animal with the following SNOMED Codes:
Begin active weight management regimen (P-YY961)
However, we would need to include animals that have this additional SNOMED Code if it's entered AFTER the one above
Release from active weight management regimen (P-YY960)
2. Remove Shelters, Corral and Hospital locations from the lists
*/

SELECT DISTINCT
l.lsid,
l.Id,

l.date AS LatestWeightDate,
l.weight AS LatestWeight,

p.date, -- AS PrevWeightDate
p.weight, -- AS PrevWeight

timestampdiff('SQL_TSI_DAY', p.date, l.date) AS IntervalInDays,
age_in_months(p.date, l.date) AS IntervalInMonths,

CASE
WHEN p.weight IS NOT NULL AND p.weight > 0 THEN
ROUND(((l.weight - p.weight) * 100 / p.weight), 1)
ELSE NULL
END AS PctChange,

CASE
WHEN p.weight IS NOT NULL AND p.weight > 0 THEN
ABS(ROUND(((l.weight - p.weight) * 100 / p.weight), 1))
ELSE NULL
END AS AbsPctChange,

l.qcstate AS LatestQcState,
p.qcstate AS PrevQcState

FROM
(SELECT Id, MAX(date) AS LatestDate
FROM study.weight
GROUP BY Id) lw

JOIN study.weight l
ON l.Id = lw.Id
AND l.date = lw.LatestDate

LEFT JOIN study.weight p
ON p.Id = lw.Id
AND p.date = (
SELECT MAX(w2.date)
FROM study.weight w2
WHERE w2.Id = lw.Id
AND w2.date <= timestampadd('SQL_TSI_DAY', -30, lw.LatestDate)
AND w2.date >= timestampadd('SQL_TSI_DAY', -100, lw.LatestDate)
)

WHERE l.Id.curlocation.area NOT IN ('Shelters', 'Corral', 'Hospital', 'Catch Area')-- Exclude animals from these locations
AND NOT (-- Exclude females under 5yrs, males under 7yrs
(l.Id.demographics.gender.code = 'f' AND l.Id.age.ageInYears < 5)
OR (l.Id.demographics.gender.code = 'm' AND l.Id.age.ageInYears < 7)
)
AND l.qcstate.publicdata = true
AND NOT EXISTS (
-- -- Find animals whose latest 'Weight MMA BEGIN' has no later 'Weight MMA RELEASE'
SELECT 1
FROM study.WeightMMA b
WHERE b.Id = l.Id
AND b.code = 'P-YY961'
AND b.date = (
SELECT MAX(b2.date)
FROM study.WeightMMA b2
WHERE b2.Id = l.Id
AND b2.code = 'P-YY961'
)
AND NOT EXISTS (
SELECT 1
FROM study.WeightMMA r
WHERE r.Id = l.Id
AND r.code = 'P-YY960'
AND r.date > b.date
)
)

Loading