Skip to content

Commit

Permalink
Modified Compliance query to remove sql reusltset errors (#1169)
Browse files Browse the repository at this point in the history
* Modified Compliance query to remove sql reusltset errors

* Modified Compliance Overdue/Soon report the slower version.

* Modified Compliance Overdue/Soon report the slower version.

* Modified Compliance Overdue/Soon report the slower version.

* Modified Compliance Overdue/Soon report the slower version.

* Modified Compliance Overdue/Soon report the slower version.

* Modified Compliance OVerdue/Soon reports sql program.

* Modified Compliance OVerdue/Soon reports sql program.

* Modified Compliance OVerdue/Soon reports sql program.

* Modified Compliance OVerdue/Soon reports sql program.
  • Loading branch information
Ohsudev authored Nov 19, 2024
1 parent ec49906 commit 8162f52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="complianceProcedureRecentTests" tableDbType="NOT_IN_DB">
<tableTitle>Employee Procedure Requirement Summary</tableTitle>
<tableTitle>Employee Requirement Summary</tableTitle>
<columns>
<column columnName="employeeId">
<columnTitle>Employee ID</columnTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- Training that was completed by an employee and being recorded as completed as a Unit or Category
select b.requirementname,
a.employeeid,
group_concat(distinct b.unit,chr(10)) as unit,
group_concat(distinct a.unit,chr(10)) as unit,
group_concat(distinct a.category,chr(10)) as category,
group_concat(distinct b.trackingflag) as trackingflag,

Expand All @@ -24,14 +24,14 @@ select b.requirementname,

(Select group_concat(distinct yy.comment, chr(10)) from completiondates yy where yy.date in (select max(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid )
And yy.requirementname= b.requirementname and yy.employeeid= a.employeeid ) as comment,
(Select yy.snooze_date from completiondates yy where yy.snooze_date in (select max(zz.snooze_date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid )
(Select group_concat(distinct yy.snooze_date , chr(10)) from completiondates yy where yy.date in (select max(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid )
And yy.requirementname= b.requirementname and yy.employeeid= a.employeeid ) as snooze_date,

CAST(
CASE

WHEN (select max(st.date) from completiondates st where st.requirementname = b.requirementname and st.employeeid = a.employeeid ) IS NULL then 0
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = b.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod ) = 0 then Null
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = b.requirementname group by tt.expireperiod ) = 0 then Null


WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = b.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod, tt.reviewdate
Expand All @@ -53,7 +53,9 @@ from employeeperunit a ,requirementspercategory b
where ( a.unit = b.unit or a.category = b.category )
And b.requirementname not in (select distinct t.requirementname from ehr_compliancedb.employeerequirementexemptions t Where a.employeeid = t.employeeid
And b.requirementname = t.requirementname)
And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And b.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.datedisabled is null)

And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)



Expand Down Expand Up @@ -82,13 +84,13 @@ select a.requirementname,
(Select group_concat(distinct yy.comment, chr(10)) from completiondates yy where yy.date in (select max(zz.date) from completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid )
And yy.requirementname= a.requirementname and yy.employeeid= a.employeeid ) as comment,

(Select yy.snooze_date from completiondates yy where yy.snooze_date in (select max(zz.snooze_date) from completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid )
(Select group_concat(distinct yy.snooze_date , chr(10)) from completiondates yy where yy.date in (select max(zz.date) from completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid )
And yy.requirementname= a.requirementname and yy.employeeid= a.employeeid ) as snooze_date,

CAST(
CASE
WHEN (select max(st.date) from completiondates st where st.requirementname = a.requirementname and st.employeeid = a.employeeid ) IS NULL then 0
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = a.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod ) = 0 then Null
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = a.requirementname group by tt.expireperiod ) = 0 then Null


WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = a.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod, tt.reviewdate
Expand All @@ -111,6 +113,7 @@ where a.requirementname not in (select distinct h.requirementname from ehr_compl
And a.requirementname not in (select distinct t.requirementname from ehr_compliancedb.employeerequirementexemptions t Where a.employeeid = t.employeeid
And a.requirementname = t.requirementname)
And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And a.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = a.requirementname And k.datedisabled is null)

group by a.requirementname,a.employeeid

Expand All @@ -135,6 +138,7 @@ from ehr_compliancedb.RequirementsPerEmployee j
Where j.requirementname not in (select z.requirementname from ehr_compliancedb.completiondates z where z.requirementname = j.requirementname
and z.employeeid = j.employeeid and z.date is not null)
And j.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And j.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = j.requirementname And k.datedisabled is null)


group by j.requirementname,j.employeeid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- Training that was completed by an employee and being recorded as completed as a Unit or Category
select b.requirementname,
a.employeeid,
group_concat(distinct b.unit,chr(10)) as unit,
group_concat(distinct a.unit,chr(10)) as unit,
group_concat(distinct a.category,chr(10)) as category,
group_concat(distinct b.trackingflag) as trackingflag,

Expand All @@ -27,7 +27,7 @@ select b.requirementname,
CAST(
CASE
WHEN (select max(st.date) from completiondates st where st.requirementname = b.requirementname and st.employeeid = a.employeeid ) IS NULL then 0
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = b.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod ) = 0 then Null
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = b.requirementname group by tt.expireperiod ) = 0 then Null


WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = b.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod, tt.reviewdate
Expand All @@ -48,6 +48,7 @@ where ( a.unit = b.unit or a.category = b.category )
And b.requirementname not in (select distinct t.requirementname from ehr_compliancedb.employeerequirementexemptions t Where a.employeeid = t.employeeid
And b.requirementname = t.requirementname)
And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And b.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = b.requirementname And k.datedisabled is null)


group by b.requirementname,a.employeeid
Expand Down Expand Up @@ -80,7 +81,7 @@ select a.requirementname,
CAST(
CASE
WHEN (select max(st.date) from completiondates st where st.requirementname = a.requirementname and st.employeeid = a.employeeid ) IS NULL then 0
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = a.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod ) = 0 then Null
WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = a.requirementname group by tt.expireperiod ) = 0 then Null


WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = a.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = a.employeeid group by tt.expireperiod, tt.reviewdate
Expand All @@ -102,6 +103,7 @@ where a.requirementname not in (select distinct h.requirementname from ehr_compl
And a.requirementname not in (select distinct t.requirementname from ehr_compliancedb.employeerequirementexemptions t Where a.employeeid = t.employeeid
And a.requirementname = t.requirementname)
And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And a.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = a.requirementname And k.datedisabled is null)

group by a.requirementname,a.employeeid

Expand Down Expand Up @@ -130,6 +132,7 @@ from ehr_compliancedb.employeerequirementexemptions j
Where j.requirementname in (select z.requirementname from ehr_compliancedb.completiondates z where z.requirementname = j.requirementname
and z.employeeid = j.employeeid and z.date is not null)
And j.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And j.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = j.requirementname And k.datedisabled is null)


group by j.requirementname,j.employeeid
Expand All @@ -154,6 +157,7 @@ from ehr_compliancedb.RequirementsPerEmployee j
Where j.requirementname NOT in (select z.requirementname from ehr_compliancedb.completiondates z where z.requirementname = j.requirementname
and z.employeeid = j.employeeid and z.date is not null)
And j.employeeid in (select p.employeeid from ehr_compliancedb.employees p where p.enddate is null)
And j.requirementname in ( select k.requirementname from ehr_compliancedb.requirements k where k.requirementname = j.requirementname And k.datedisabled is null)


group by j.requirementname,j.employeeid
Expand Down

0 comments on commit 8162f52

Please sign in to comment.