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
278 changes: 277 additions & 1 deletion onprc_ehr/resources/queries/study/processingSerology.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ SELECT
t.isPCRRequired,
t.isPCRCurrent,

t.lastBchem,
t.daysSinceBchem,
t.isBchemRequired,
t.isBchemCurrent,


CASE
WHEN (t.isSRVRequired = true AND t.isSRVCurrent = false) THEN 4
ELSE 0
Expand All @@ -36,6 +42,61 @@ SELECT
ELSE 0
END as PCRbloodVol,

CASE
WHEN (t.isESPFRequired = true AND t.isESPFCurrent = false ) THEN 4
ELSE 0
END as ESPFbloodVol,

-----CBC
CASE
WHEN (t.isCBCRequired1 = true AND t.isCBCCurrent1 = false ) OR (t.isCBCRequired2 = true AND t.isCBCCurrent2 = false ) THEN 1
ELSE 0
END as CBCbloodVol1,


CASE
WHEN (t.isCBCRequired3 = true AND t.isCBCCurrent3 = false ) THEN 1
ELSE 0
END as CBCbloodVol3,

CASE
WHEN (t.isCBCRequired4 = true AND t.isCBCCurrent4 = false ) THEN 1
ELSE 0
END as CBCbloodVol4,

CASE
WHEN (t.isCBCRequired5 = true AND t.isCBCCurrent5 = false ) THEN 1
ELSE 0
END as CBCbloodVol5,



-----Comprehensive Chemistry
CASE
WHEN (t.isCChemRequired1 = true AND t.isCChemCurrent1 = false ) THEN 2
ELSE 0
END as CChembloodVol1,

CASE
WHEN (t.isCChemRequired2 = true AND t.isCChemCurrent2 = false ) THEN 2
ELSE 0
END as CChembloodVol2,

CASE
WHEN (t.isCChemRequired3 = true AND t.isCChemCurrent3 = false ) THEN 2
ELSE 0
END as CChembloodVol3,

CASE
WHEN (t.isCChemRequired4 = true AND t.isCChemCurrent4 = false ) THEN 2
ELSE 0
END as CChembloodVol4,

-----Basic Chemistry
CASE
WHEN (t.isBChemRequired = true AND t.isBChemCurrent = false ) THEN 2
ELSE 0
END as BchembloodVol,

FROM (

Expand Down Expand Up @@ -64,7 +125,158 @@ SELECT
CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isPCRRequired
END as isPCRRequired,

espf.lastDate as lastESPF,
timestampdiff('SQL_TSI_DAY', espf.lastDate, now()) as daysSinceESPF,
CASE
WHEN (year(now()) = year(espf.lastDate) AND (timestampdiff('SQL_TSI_DAY', espf.lastDate, now()) > 180) ) THEN true
ELSE false
END as isESPFCurrent,

CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isESPFRequired,


------ All CBC Sections

cbc.lastDate as lastCBC1,
timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) as daysSinceCBC1,
CASE
WHEN (year(now()) = year(cbc.lastDate) AND (timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) > 165 )AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) THEN true
ELSE false
END as isCBCCurrent1,

CASE
WHEN (d.Id.age.ageInDays > 20 ) THEN true
ELSE false
END as isCBCRequired1,

cbc.lastDate as lastCBC2,
timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) as daysSinceCBC2,
CASE
WHEN (year(now()) = year(cbc.lastDate) AND (timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) > 340) AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) AND (flg.Id is not null) ) THEN true
ELSE false
END as isCBCCurrent2,

CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isCBCRequired2,

cbc.lastDate as lastCBC3,
timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) as daysSinceCBC3,
CASE
WHEN (year(now()) = year(cbc.lastDate) AND (timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) > 340) AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) THEN true
ELSE false
END as isCBCCurrent3,

CASE
WHEN (d.Id.age.ageInDays > 12 ) THEN true
ELSE false
END as isCBCRequired3,


cbc.lastDate as lastCBC4,
timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) as daysSinceCBC4,
CASE
WHEN ( cbc.lastDate is null AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) THEN true
ELSE false
END as isCBCCurrent4,

CASE
WHEN (d.Id.age.ageInDays > 6 ) THEN true
ELSE false
END as isCBCRequired4,


cbc.lastDate as lastCBC5,
timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) as daysSinceCBC5,
CASE
WHEN (year(now()) = year(cbc.lastDate) AND (timestampdiff('SQL_TSI_DAY', cbc.lastDate, now()) > 180) AND (nts.Id is not null) ) THEN true
ELSE false
END as isCBCCurrent5,

CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isCBCRequired5,



----- All Comp Chemistry sections


cchem.lastDate as lastCChem1,
timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) as daysSinceCChem1,
CASE
WHEN ( ( (year(now()) = year(cchem.lastDate) AND (timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) > 165)) OR cchem.lastDate is null ) AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) THEN true
ELSE false
END as isCChemCurrent1,

CASE
WHEN (d.Id.age.ageInDays > 20 ) THEN true
ELSE false
END as isCChemRequired1,


cchem.lastDate as lastCChem2,
timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) as daysSinceCChem2,
CASE
WHEN ( ( (year(now()) = year(cchem.lastDate) AND (timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) > 340) ) OR cchem.lastDate is null ) AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) AND (flg.Id is not null) ) THEN true
ELSE false
END as isCChemCurrent2,

CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isCChemRequired2,

cchem.lastDate as lastCChem3,
timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) as daysSinceCChem3,
CASE
WHEN ( year(now()) = year(cchem.lastDate) AND (timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) > 180) AND d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) THEN true
ELSE false
END as isCChemCurrent3,

CASE
WHEN (d.Id.age.ageInDays >= 18 ) THEN true
ELSE false
END as isCChemRequired3,

cchem.lastDate as lastCChem4,
timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) as daysSinceCChem4,
CASE
WHEN ( ( year(now()) = year(cchem.lastDate) AND (timestampdiff('SQL_TSI_DAY', cchem.lastDate, now()) > 180 )) AND (nts.Id is not null ) ) THEN true
ELSE false
END as isCChemCurrent4,

CASE
WHEN (d.Id.age.ageInDays > 180 ) THEN true
ELSE false
END as isCChemRequired4,


------------- Basic Chemistry


bchem.lastDate as lastBChem,
timestampdiff('SQL_TSI_DAY', bchem.lastDate, now()) as daysSinceBChem,
CASE
WHEN ( ( year(now()) = year(bchem.lastDate) AND (timestampdiff('SQL_TSI_DAY', bchem.lastDate, now()) > 340 ) ) AND (d.Id.curLocation.area in ('Corrals', 'Shelters', 'PENS' ) ) ) THEN true
ELSE false
END as isBChemCurrent,

CASE
WHEN (d.Id.age.ageInDays >= 6 AND d.Id.age.ageInDays < 18 ) THEN true
ELSE false
END as isBChemRequired





FROM study.demographics d

Expand All @@ -78,6 +290,16 @@ LEFT JOIN (

) srv ON (srv.id = d.id)

LEFT JOIN (
SELECT
k.id,
max(k.date) as lastDate
FROM study.blood k
WHERE (k.additionalservices = 'ESPF Surveillance - Semiannual')
GROUP BY k.id

) espf ON (espf.id = d.id)

LEFT JOIN (
SELECT
b.id,
Expand All @@ -88,6 +310,60 @@ LEFT JOIN (

) pcr ON (pcr.id = d.id)

LEFT JOIN (
SELECT
j.id,
max(j.date) as lastDate
FROM study.blood j
WHERE j.additionalservices like 'CBC with automated differential'
GROUP BY j.id

) cbc ON (cbc.id = d.id)

LEFT JOIN (
SELECT
m.id,
max(m.date) as lastDate
FROM study.blood m
WHERE m.additionalservices like 'Comprehensive Chemistry panel in-house'
GROUP BY m.id

) cchem ON (cchem.id = d.id)


LEFT JOIN (
SELECT
t.id,
max(t.date) as lastDate
FROM study.blood t
WHERE t.additionalservices like 'Basic Chemistry Panel'
GROUP BY t.id

) bchem ON (bchem.id = d.id)

LEFT JOIN (
SELECT
n.id,
max(n.date) as lastDate
FROM study.flags n
WHERE n.category ='Behavior Flag' And n.value = 'Socially important'
And n.enddate is null
GROUP BY n.id

) flg ON (flg.id = d.id)


LEFT JOIN (
SELECT
p.id,
max(p.date) as lastDate
FROM study.flags p
WHERE p.category ='Notes Pertaining to DAR' And p.value = 'Assignment pool'
And p.enddate is null
GROUP BY p.id

) nts ON (nts.id = d.id)


WHERE d.calculated_status = 'Alive'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@
<column columnName="PCRBloodVolume">
<columnTitle>PCR PTT (mL)</columnTitle>
</column>
<column columnName="ESPFbloodVol">
<columnTitle>ESPF PTT (mL)</columnTitle>
</column>
<column columnName="dnaBloodDrawVol">
<columnTitle>DNA Pink/PTT (mL)</columnTitle>
</column>
<column columnName="serologyBloodVol">
<columnTitle>Serology RTT (mL)</columnTitle>
</column>
<column columnName="totalCBCVol">
<columnTitle>CBC PTT (mL)</columnTitle>
</column>
<column columnName="totalCompChemBloodVol">
<columnTitle>COMP Chem RTT (mL)</columnTitle>
</column>
<column columnName="BasicChemBloodVol">
<columnTitle>BASIC Chem RTT (mL)</columnTitle>
</column>
<column columnName="geneticsBloodVol">
<columnTitle>Genetics Blood Vol (mL)</columnTitle>
</column>
Expand Down
24 changes: 22 additions & 2 deletions onprc_reports/resources/queries/study/processingBloodDraws.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,35 @@ SELECT
End as PCRBloodVolume,

s.srvBloodVol as serologyBloodVol,

Case when (a.Id IS NOT NULL) And (s.ESPFBloodVol > 0 ) then 4
ELSE
0
End as ESPFBloodVol,


( coalesce(s.CBCbloodVol1,0) + coalesce(s.CBCbloodVol2,0) + coalesce(s.CBCbloodVol3,0) + coalesce(s.CBCbloodVol4,0) + coalesce(s.CBCbloodVol5,0) ) as totalCBCVol,
(coalesce(s.CChembloodVol1,0) + coalesce(s.CChembloodVol2,0) + coalesce(s.CChembloodVol3,0) + coalesce(s.CChembloodVol4,0) ) as totalCompChemBloodVol,
(coalesce(s.BChembloodVol,0) ) as BasicChemBloodVol,

g.parentageBloodDrawVol,
g.mhcBloodDrawVol,
g.dnaBloodDrawVol,
g.totalBloodDrawVol as geneticsBloodVol,

coalesce(s.srvBloodVol, 0) + Case when (a.Id IS NOT NULL) And (s.pcrbloodVol > 0 ) then 2
coalesce(s.srvBloodVol, 0) +
Case when (a.Id IS NOT NULL) And (s.pcrbloodVol > 0 ) then 2
ELSE
0
End + coalesce(g.totalBloodDrawVol, 0) as totalBloodDrawVol,
End +
Case when (a.Id IS NOT NULL) And (s.ESPFBloodVol > 0 ) then 4
ELSE
0
End +
coalesce(s.CBCbloodVol1,0) + coalesce(s.CBCbloodVol3,0) + coalesce(s.CBCbloodVol4,0) + coalesce(s.CBCbloodVol5,0) +
coalesce(s.CChembloodVol1,0) + coalesce(s.CChembloodVol2,0) + coalesce(s.CChembloodVol3,0) + coalesce(s.CChembloodVol4,0) +
coalesce(s.BChembloodVol,0) +
coalesce(g.totalBloodDrawVol, 0) as totalBloodDrawVol,

(select k.room from study.housing k where k.Id =d.Id And k.enddate is null) as currentlocationroom,
(select coalesce(k.cage, ' ') from study.housing k where k.Id =d.Id And k.enddate is null) as currentlocationcage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<column name="spfStatus"/>
<column name="PCRBloodVolume"/>
<column name="serologyBloodVol"/>
<column name="ESPFbloodVol"/>
<column name="totalCompChemBloodVol"/>
<column name="totalCBCVol"/>
<column name="BasicChemBloodVol"/>
<column name="parentageBloodDrawVol"/>
<column name="mhcBloodDrawVol"/>
<column name="dnaBloodDrawVol"/>
Expand Down
Loading