Skip to content

Commit 439341f

Browse files
committed
Added new functionality to the weights data
1 parent 34222c2 commit 439341f

File tree

5 files changed

+336
-143
lines changed

5 files changed

+336
-143
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="Demographics_NotInMMA" tableDbType="NOT_IN_DB">
5+
<tableTitle>Animals not in weight management regimen</tableTitle>
6+
</table>
7+
</tables>
8+
</metadata>
9+
</query>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Created by Kollil in Dec 2025
3+
Tkt # 13461
4+
Added two filters to the Demographics dataset:
5+
1. Filter out any animal with the following SNOMED Codes:
6+
Begin active weight management regimen (P-YY961)
7+
However, we would need to include animals that have this additional SNOMED Code if it's entered AFTER the one above
8+
Release from active weight management regimen (P-YY960)
9+
2. Remove Shelters, Corral and Hospital locations from the lists
10+
*/
11+
Select
12+
d.Id.curlocation.area as Area,
13+
d.Id.curlocation.room as Room,
14+
d.Id.curlocation.cage as Cage,
15+
d.Id,
16+
d.Id.utilization.use as ProjectsAndGroups,
17+
d.species,
18+
d.geographic_origin,
19+
d.gender as Sex,
20+
d.calculated_status,
21+
d.birth,
22+
d.Id.Age.YearAndDays,
23+
d.Id.MostRecentWeight.MostRecentWeight,
24+
d.Id.MostRecentWeight.MostRecentWeightDate,
25+
d.Id.viral_status.viralStatus,
26+
d.history
27+
From Demographics d
28+
Where d.Id Not In (
29+
SELECT DISTINCT t.Id
30+
FROM study.WeightManagementMMAData t
31+
WHERE NOT EXISTS (
32+
-- Find animals whose latest 'Weight MMA BEGIN' has no later 'Weight MMA RELEASE'
33+
SELECT 1
34+
FROM study.WeightManagementMMAData b
35+
WHERE b.Id = t.Id
36+
AND b.code = 'P-YY961'
37+
AND b.date = (SELECT MAX(b2.date)
38+
FROM study.WeightManagementMMAData b2
39+
WHERE b2.Id = t.Id
40+
AND b2.code = 'P-YY961')
41+
AND NOT EXISTS (SELECT 1
42+
FROM study.WeightManagementMMAData r
43+
WHERE r.Id = t.Id
44+
AND r.code = 'P-YY960'
45+
AND r.date > b.date))
46+
)
47+
AND d.Id.curlocation.area NOT IN ('Shelters', 'Corral', 'Hospital')-- Exclude animals from these locations
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="weightRelChange_NotInMMA" tableDbType="NOT_IN_DB">
5+
<tableTitle>Animals(Not in Weight Management Regimen) with Weight Change, Relative to Current Weight</tableTitle>
6+
<description>This query shows the percent change of each weight, relative to the current weight</description>
7+
<columns>
8+
<column columnName="lsid">
9+
<isKeyField>true</isKeyField>
10+
<isHidden>true</isHidden>
11+
</column>
12+
<column columnName="Id">
13+
<isHidden>true</isHidden>
14+
<fk>
15+
<fkDbSchema>study</fkDbSchema>
16+
<fkTable>animal</fkTable>
17+
<fkColumnName>id</fkColumnName>
18+
</fk>
19+
</column>
20+
<column columnName="date">
21+
<isHidden>true</isHidden>
22+
<columnTitle>Date of Last Weight</columnTitle>
23+
</column>
24+
<column columnName="weight">
25+
<columnTitle>Old Weight (kg)</columnTitle>
26+
</column>
27+
<column columnName="PctChange">
28+
<columnTitle>% Change Relative To Current</columnTitle>
29+
<conditionalFormats>
30+
<conditionalFormat>
31+
<filters>
32+
<filter operator="lte" value="-10"/>
33+
</filters>
34+
<bold>true</bold>
35+
<backgroundColor>FF0000</backgroundColor>
36+
</conditionalFormat>
37+
<conditionalFormat>
38+
<filters>
39+
<filter operator="gte" value="10"/>
40+
</filters>
41+
<bold>true</bold>
42+
<backgroundColor>458B00</backgroundColor>
43+
</conditionalFormat>
44+
</conditionalFormats>
45+
</column>
46+
<column columnName="IntervalInDays">
47+
<columnTitle>Days Since Weight</columnTitle>
48+
</column>
49+
<column columnName="IntervalInMonths">
50+
<columnTitle>Months Since Weight</columnTitle>
51+
</column>
52+
<column columnName="LatestWeight">
53+
<columnTitle>Latest Weight (kg)</columnTitle>
54+
<url>/query/executeQuery.view?schemaName=study&amp;
55+
query.queryName=weight&amp;
56+
query.date~eq=${LatestWeightDate}&amp;
57+
query.sort=-date
58+
</url>
59+
</column>
60+
<column columnName="LatestWeightDate">
61+
<columnTitle>Latest Weight Date</columnTitle>
62+
</column>
63+
</columns>
64+
<titleColumn>PctChange</titleColumn>
65+
</table>
66+
</tables>
67+
</metadata>
68+
</query>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Created by Kollil in Dec 2025
3+
Tkt # 13461
4+
This query is the ONPRC version of the core LK EHR query called, weightRelChange. In addition to the original one, this new query has two filters:
5+
1. Filter out any animal with the following SNOMED Codes:
6+
Begin active weight management regimen (P-YY961)
7+
However, we would need to include animals that have this additional SNOMED Code if it's entered AFTER the one above
8+
Release from active weight management regimen (P-YY960)
9+
2. Remove Shelters, Corral and Hospital locations from the lists
10+
*/
11+
SELECT
12+
w.lsid,
13+
w.Id,
14+
w.date,
15+
w.Id.MostRecentWeight.MostRecentWeightDate as LatestWeightDate,
16+
w.Id.MostRecentWeight.MostRecentWeight AS LatestWeight,
17+
18+
timestampdiff('SQL_TSI_DAY', w.date, w.Id.MostRecentWeight.MostRecentWeightDate) AS IntervalInDays,
19+
age_in_months(w.date, w.Id.MostRecentWeight.MostRecentWeightDate) AS IntervalInMonths,
20+
21+
w.weight,
22+
CASE WHEN w.date >= timestampadd('SQL_TSI_DAY', -730, w.Id.MostRecentWeight.MostRecentWeightDate) THEN
23+
Round(((w.Id.MostRecentWeight.MostRecentWeight - w.weight) * 100 / w.weight), 1)
24+
ELSE
25+
null
26+
END AS PctChange,
27+
28+
CASE WHEN w.date >= timestampadd('SQL_TSI_DAY', -730, w.Id.MostRecentWeight.MostRecentWeightDate) THEN
29+
Abs(Round(((w.Id.MostRecentWeight.MostRecentWeight - w.weight) * 100 / w.weight), 1))
30+
else
31+
null
32+
END AS AbsPctChange,
33+
w.qcstate
34+
35+
FROM study.weight w
36+
WHERE w.qcstate.publicdata = true
37+
AND w.Id NOT IN
38+
(SELECT DISTINCT t.Id
39+
FROM study.WeightManagementMMAData t
40+
WHERE NOT EXISTS
41+
(
42+
-- Find animals whose latest 'Weight MMA BEGIN' has no later 'Weight MMA RELEASE'
43+
SELECT 1
44+
FROM study.WeightManagementMMAData b
45+
WHERE b.Id = t.Id
46+
AND b.code = 'P-YY961'
47+
AND b.date = (SELECT MAX(b2.date)
48+
FROM study.WeightManagementMMAData b2
49+
WHERE b2.Id = t.Id
50+
AND b2.code = 'P-YY961')
51+
AND NOT EXISTS (SELECT 1
52+
FROM study.WeightManagementMMAData r
53+
WHERE r.Id = t.Id
54+
AND r.code = 'P-YY960'
55+
AND r.date > b.date)
56+
)
57+
)
58+
-- Exclude animals from these locations
59+
AND w.Id.curlocation.area NOT IN ('Shelters', 'Corral', 'Hospital')

0 commit comments

Comments
 (0)