Skip to content

Commit

Permalink
Updates to current blood draw queries and adding visual plot (#703)
Browse files Browse the repository at this point in the history
* Add blood graph along with queries to support it, as well as new column for blood avail including thirty days in the future

* exclude today for next 30 days calculation of blood, fix blood summary calc, adjust labels

* use next 30 days since it does not include today

* use ehr version

* remove wnprc blood graph to use ehr instead

* Consolidate blood draw reports into currentBloodDraws.sql, adjust references

* ignore project type

* group up the blood draws if they are done at the same time

* Revert back to original AvailBlood calculation, add new calc for future draws in the new current blood report, fix ehr blood store so all records in transaction are used

* update notification to revert to old blood avail name, use species as lookups for blood queries

* restore demographicsBloodSummary query file

* update test comments

* restore old blood draw query

---------

Co-authored-by: Marty Pradere <martyp@labkey.com>
  • Loading branch information
csebranek and labkey-martyp committed Feb 4, 2025
1 parent c5729d5 commit 8f9759d
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 492 deletions.
113 changes: 0 additions & 113 deletions WNPRC_EHR/resources/queries/study/Current Blood.sql

This file was deleted.

42 changes: 0 additions & 42 deletions WNPRC_EHR/resources/queries/study/Current Blood/.qview.xml

This file was deleted.

71 changes: 71 additions & 0 deletions WNPRC_EHR/resources/queries/study/bloodDrawChanges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2016 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
--this query is designed to return any dates when allowable blood draw volume changes
--this includes dates of blood draws, plus the date those draws drop off
PARAMETERS(DATE_INTERVAL INTEGER DEFAULT 30)

SELECT
b2.id,
b2.status,
b2.dateOnly,
b2.quantity,
DATE_INTERVAL as blood_draw_interval,
TIMESTAMPADD('SQL_TSI_DAY', (-1 * DATE_INTERVAL), b2.dateOnly) as minDate,
TIMESTAMPADD('SQL_TSI_DAY', DATE_INTERVAL, b2.dateOnly) as maxDate,

FROM (
SELECT
b.id,
b.dateOnly,
b.status,
sum(b.quantity) as quantity

FROM (
--find all blood draws within the interval, looking backwards
SELECT
b.id,
b.qcstate as status,
b.dateOnly,
b.quantity,
FROM study.blood b
WHERE b.dateOnly > timestampadd('SQL_TSI_DAY', -1 * DATE_INTERVAL, curdate())

UNION ALL

--join 1 row for the current date
SELECT
d1.id,
null as status,
curdate() as dateOnly,
0 as quantity,
FROM study.demographics d1
WHERE d1.calculated_status = 'Alive'

UNION ALL

--add one row for each date when the draw drops off the record
SELECT
b.id,
null as status,
timestampadd('SQL_TSI_DAY', DATE_INTERVAL, b.dateOnly),
0 as quantity,
FROM study.blood b
WHERE timestampadd('SQL_TSI_DAY', DATE_INTERVAL, b.dateOnly) >= timestampadd('SQL_TSI_DAY', -1 * DATE_INTERVAL, curdate())

) b

GROUP BY b.id, b.dateOnly, b.status
) b2
72 changes: 36 additions & 36 deletions WNPRC_EHR/resources/queries/study/bloodSummary.query.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="bloodSummary" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Lsid">
<isKeyField>true</isKeyField>
<!--<isHidden>true</isHidden>-->
</column>
<column columnName="BloodLast30">
<columnTitle>Drawn in Previous 30 Days (inclusive)</columnTitle>
<url>/query/executeQuery.view?schemaName=study&amp;
query.queryName=Blood Draws&amp;
query.viewName=Blood Summary&amp;
query.Id~eq=${Id}&amp;
query.Date~lte=${Date}&amp;
query.Date~gte=${minDate}&amp;
query.sort=-Date&amp;
</url>
</column>
<column columnName="BloodNext30">
<columnTitle>Scheduled in Next 30 Days (inclusive)</columnTitle>
<url>/query/executeQuery.view?schemaName=study&amp;
query.queryName=Blood Draws&amp;
query.viewName=Blood Summary&amp;
query.Id~eq=${Id}&amp;
query.Date~gt=${Date}&amp;
query.sort=-Date&amp;
</url>
</column>
</columns>
<titleColumn>BloodLast30</titleColumn>
</table>
</tables>
</metadata>
</query>
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="bloodSummary" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Lsid">
<isKeyField>true</isKeyField>
<!--<isHidden>true</isHidden>-->
</column>
<column columnName="BloodLast30">
<columnTitle>Drawn in Previous 30 Days (including today)</columnTitle>
<url>/query/executeQuery.view?schemaName=study&amp;
query.queryName=Blood Draws&amp;
query.viewName=Blood Summary&amp;
query.Id~eq=${Id}&amp;
query.Date~lte=${Date}&amp;
query.Date~gte=${minDate}&amp;
query.sort=-Date&amp;
</url>
</column>
<column columnName="BloodNext30">
<columnTitle>Scheduled in Next 30 Days (excluding today)</columnTitle>
<url>/query/executeQuery.view?schemaName=study&amp;
query.queryName=Blood Draws&amp;
query.viewName=Blood Summary&amp;
query.Id~eq=${Id}&amp;
query.Date~gt=${Date}&amp;
query.sort=-Date&amp;
</url>
</column>
</columns>
<titleColumn>BloodLast30</titleColumn>
</table>
</tables>
</metadata>
</query>
Loading

0 comments on commit 8f9759d

Please sign in to comment.