diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.query.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.query.xml index 43b1f7031..63925bc28 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.query.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.query.xml @@ -4,7 +4,7 @@ <table tableName="complianceProcedureRecentTests" tableDbType="NOT_IN_DB"> <tableTitle>Employee Requirement Summary</tableTitle> <columns> - <column columnName="employeeId"> + <column columnName="employeeid"> <columnTitle>Employee ID</columnTitle> <isKeyField>true</isKeyField> <fk> @@ -14,9 +14,12 @@ </fk> </column> - <column columnName="requirementName"> + <column columnName="rowid"> + <columnTitle>Row ID</columnTitle> + </column> + <column columnName="requirementname"> <columnTitle>Requirement Name</columnTitle> - <displayWidth>90</displayWidth> + <displayWidth>250</displayWidth> <fk> <fkDbSchema>ehr_compliancedb</fkDbSchema> <fkTable>requirements</fkTable> @@ -24,7 +27,7 @@ </fk> <facetingBehavior>ALWAYS_OFF</facetingBehavior> </column> - <column columnName="timesCompleted"> + <column columnName="times_completed"> <columnTitle>Times Completed</columnTitle> <displayWidth>50</displayWidth> <url>/query/executeQuery.view?schemaName=ehr_compliancedb& @@ -33,21 +36,46 @@ query.requirementName~eq=${requirementName}& </url> </column> - <column columnName="ExpiredPeriod"> + <column columnName="expired_period"> <columnTitle>Expire Period (Months)</columnTitle> <displayWidth>70</displayWidth> </column> - - <column columnName="NewExpirePeriod"> + <column columnName="new_expired_period"> <columnTitle>New Expire Period (Months)</columnTitle> <displayWidth>70</displayWidth> </column> + + <column columnName="email"> + <columnTitle>Email</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="lastname"> + <columnTitle>Last Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="firstname"> + <columnTitle>First Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="host"> + <columnTitle>Host</columnTitle> + <displayWidth>110</displayWidth> + </column> + <column columnName="supervisor"> + <columnTitle>Supervisor</columnTitle> + <displayWidth>150</displayWidth> + </column> + <column columnName="unit"> <columnTitle>Unit</columnTitle> - <displayWidth>70</displayWidth> + <displayWidth>210</displayWidth> </column> - <column columnName="mostrecentdate"> + <column columnName="mostrecentcompleted_date"> <columnTitle>Most Recent Date</columnTitle> + <formatString>yyyy-MM-dd</formatString> <displayWidth>70</displayWidth> </column> <column columnName="comment"> @@ -58,7 +86,16 @@ <columnTitle>Category</columnTitle> <displayWidth>70</displayWidth> </column> - <column columnName="MonthsUntilRenewal"> + + <column columnName="trainee_type"> + <columnTitle>Trainee Type</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="requirement_name_type"> + <columnTitle>Requirement Name Type</columnTitle> + <displayWidth>180</displayWidth> + </column> + <column columnName="months_until_renewal"> <columnTitle>Months Until Renewal</columnTitle> <displayWidth>60</displayWidth> <conditionalFormats> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.sql b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.sql index 795082a50..c2ac75974 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.sql +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests.sql @@ -1,149 +1,2 @@ -/* - * Copyright (c) 2010-2014 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 - */ - --- Modified: 6-14-2022 R.Blasa ComplianceRecentTests.sql --- 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 a.unit,chr(10)) as unit, - group_concat(distinct a.category,chr(10)) as category, - group_concat(distinct b.trackingflag) as trackingflag, - - - (select count(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, - - (select k.expireperiod from Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, - - ( select (age_in_months(max(pq.date), tt.reviewdate) ) 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, - - (select max(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, - - (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 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 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate) )) > 0 THEN - - ( select ( age_in_months(max(pq.date), tt.reviewdate) - ( age_in_months(max(pq.date), curdate())) )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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) - - - - - ELSE ( select (tt.expireperiod) - ( age_in_months(max(pq.date), curdate())) 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 ) - - END AS double) AS MonthsUntilRenewal - - - -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 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) - - - - group by b.requirementname,a.employeeid - - -union - --- Training that was completed by an employee but not recorded as being completed as a Unit or Category -select a.requirementname, - a.employeeid, - null as unit, - null as category, - 'No' as trackingflag, - - - (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, - - (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, - - ( select (age_in_months(max(pq.date), tt.reviewdate) )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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, - - (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, - - (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 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 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate) )) > 0 THEN - - ( select ( age_in_months(max(pq.date), tt.reviewdate) - ( age_in_months(max(pq.date), curdate())) )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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) - - - - - ELSE ( select (tt.expireperiod) - ( age_in_months(max(pq.date), curdate())) 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 ) - - END AS double) AS MonthsUntilRenewal - - -from ehr_compliancedb.completiondates a -where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit - or k.category = h.category) And a.employeeid = k.employeeid ) - 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 - -UNION - --- Additional requirements for employees that have not completed training, but is required -select j.requirementname, - j.employeeid, - null as unit, - null as category, - 'Yes' as trackingflag, - null as timesCompleted, - null as ExpiredPeriod, - null as NewExpirePeriod, - null as MostRecentDate, - '' as comment, - null as snooze_date, - null AS MonthsUntilRenewal - - -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 - - - - - +Select * +from onprc_ehr_compliancedb.ComplianceProcedureReport diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/.qview.xml index 82fc59d49..c2b48d9ac 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/.qview.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/.qview.xml @@ -1,25 +1,25 @@ <customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All"> <columns> - <column name="employeeId/email"/> - <column name="employeeId"/> - <column name="employeeId/lastName"/> - <column name="employeeId/firstName"/> - <column name="employeeId/majorudds"/> + <column name="email"/> + <column name="employeeid"/> + <column name="lastname"/> + <column name="firstname"/> + <column name="host"/> <column name="unit"/> <column name="category"/> - <column name="requirementName"/> + <column name="requirementname"/> <column name="trackingflag"/> - <column name="timesCompleted"/> - <column name="ExpiredPeriod"/> - <column name="NewExpirePeriod"/> - <column name="MostRecentDate"/> + <column name="times_completed"/> + <column name="expired_period"/> + <column name="new_expired_period"/> + <column name="mostrecentcompleted_date"/> <column name="comment"/> - <column name="MonthsUntilRenewal"/> + <column name="months_until_renewal"/> <column name="snooze_date"/> </columns> <sorts> - <sort column="employeeId/lastName" descending="false"/> - <sort column="employeeId/firstName" descending="false"/> - <sort column="requirementName" descending="false"/> + <sort column="lastname" descending="false"/> + <sort column="firstName" descending="false"/> + <sort column="requirementname" descending="false"/> </sorts> </customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Occupational Health Compliance.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Occupational Health Compliance.qview.xml index 97934dc5a..cebd0518f 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Occupational Health Compliance.qview.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Occupational Health Compliance.qview.xml @@ -1,26 +1,26 @@ <customView xmlns="http://labkey.org/data/xml/queryCustomView"> <columns> - <column name="employeeId"/> - <column name="employeeId/email"/> - <column name="employeeId/lastName"/> - <column name="employeeId/firstName"/> - <column name="employeeId/supervisor"/> + <column name="employeeid"/> + <column name="email"/> + <column name="lastname"/> + <column name="firstname"/> + <column name="supervisor"/> <column name="employeeId/location"/> - <column name="employeeId/category"/> + <column name="category"/> <column name="employeeId/notes"/> <column name="employeeId/isActive"/> - <column name="requirementName"/> - <column name="requirementName/type"/> - <column name="MostRecentDate"/> - <column name="MonthsUntilRenewal"/> + <column name="requirementname"/> + <column name="requirement_name_type"/> + <column name="mostrecentcompleted_date"/> + <column name="months_until_renewal"/> </columns> <sorts> - <sort column="employeeId/lastName" descending="false"/> - <sort column="employeeId/firstName" descending="false"/> - <sort column="requirementName" descending="false"/> + <sort column="lastname" descending="false"/> + <sort column="firstname" descending="false"/> + <sort column="requirementname" descending="false"/> </sorts> <filters> - <filter column="MonthsUntilRenewal" operator="lte" value="2"/> + <filter column="months_until_renewal" operator="lte" value="2"/> <filter column="employeeid/isActive" operator="eq" value="true"/> <filter column="requirementName/datedisabled" operator="isblank"/> <filter column="requirementName/type" operator="eq" value="Occupational Health"/> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon withNoEHRS OccHealth.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon withNoEHRS OccHealth.qview.xml index 192608c90..99f13ff8e 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon withNoEHRS OccHealth.qview.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon withNoEHRS OccHealth.qview.xml @@ -1,15 +1,13 @@ <customView xmlns="http://labkey.org/data/xml/queryCustomView"> <sorts> - <sort column="employeeId/lastName" descending="false"/> - <sort column="employeeId/firstName" descending="false"/> - <sort column="requirementName" descending="false"/> + <sort column="lastname" descending="false"/> + <sort column="firstName" descending="false"/> + <sort column="requirementname" descending="false"/> </sorts> <filters> - <filter column="MonthsUntilRenewal" operator="lte" value="2"/> - <filter column="employeeid/isActive" operator="eq" value="true"/> - <filter column="requirementName/datedisabled" operator="isblank"/> - <filter column="requirementName/type" operator="containsnoneof" value="EHRS;Occupational Health"/> + <filter column="months_until_renewal" operator="lte" value="2"/> + <filter column="requirement_name_type" operator="containsnoneof" value="EHRS;Occupational Health"/> <filter column="category" operator="doesnotcontain" value="Vendor / Contractor"/> </filters> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon.qview.xml index bc93d1734..9c5d83de1 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon.qview.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTests/Overdue and Due Soon.qview.xml @@ -1,12 +1,12 @@ <customView xmlns="http://labkey.org/data/xml/queryCustomView"> <sorts> - <sort column="employeeId/lastName" descending="false"/> - <sort column="employeeId/firstName" descending="false"/> - <sort column="requirementName" descending="false"/> + <sort column="lastname" descending="false"/> + <sort column="firstName" descending="false"/> + <sort column="requirementname" descending="false"/> </sorts> <filters> - <filter column="MonthsUntilRenewal" operator="lte" value="2"/> - <filter column="employeeid/isActive" operator="eq" value="true"/> + <filter column="months_until_renewal" operator="lte" value="2"/> <filter column="requirementName/datedisabled" operator="isblank"/> + <filter column="employeeid/isActive" operator="eq" value="true"/> </filters> </customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.query.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.query.xml new file mode 100644 index 000000000..b3e75afd8 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.query.xml @@ -0,0 +1,126 @@ +<query xmlns="http://labkey.org/data/xml/query"> + <metadata> + <tables xmlns="http://labkey.org/data/xml"> + <table tableName="complianceProcedureRecentTests" tableDbType="NOT_IN_DB"> + <tableTitle>Employee Requirement Summary -- Original version</tableTitle> + <columns> + <column columnName="employeeid"> + <columnTitle>Employee ID</columnTitle> + <isKeyField>true</isKeyField> + <fk> + <fkDbSchema>ehr_compliancedb</fkDbSchema> + <fkTable>employees</fkTable> + <fkColumnName>employeeId</fkColumnName> + + </fk> + </column> + <column columnName="rowid"> + <columnTitle>Row ID</columnTitle> + </column> + <column columnName="requirementName"> + <columnTitle>Requirement Name</columnTitle> + <displayWidth>250</displayWidth> + <fk> + <fkDbSchema>ehr_compliancedb</fkDbSchema> + <fkTable>requirements</fkTable> + <fkColumnName>requirementName</fkColumnName> + </fk> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> + <column columnName="timesCompleted"> + <columnTitle>Times Completed</columnTitle> + <displayWidth>50</displayWidth> + <url>/query/executeQuery.view?schemaName=ehr_compliancedb& + query.queryName=CompletionDates& + query.EmployeeId~eq=${employeeId}& + query.requirementName~eq=${requirementName}& + </url> + </column> + <column columnName="expired_period"> + <columnTitle>Expire Period (Months)</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="new_expired_period"> + <columnTitle>New Expire Period (Months)</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="email"> + <columnTitle>Email</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="lastname"> + <columnTitle>Last Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="firstname"> + <columnTitle>First Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="host"> + <columnTitle>Host</columnTitle> + <displayWidth>110</displayWidth> + </column> + <column columnName="supervisor"> + <columnTitle>Supervisor</columnTitle> + <displayWidth>150</displayWidth> + </column> + + <column columnName="unit"> + <columnTitle>Unit</columnTitle> + <displayWidth>210</displayWidth> + </column> + <column columnName="MostRecentDate"> + <columnTitle>Most Recent Date</columnTitle> + <formatString>yyyy-MM-dd</formatString> + <displayWidth>70</displayWidth> + </column> + <column columnName="comment"> + <columnTitle>Comments</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="category"> + <columnTitle>Category</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="trainee_type"> + <columnTitle>Trainee Type</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="requirement_name_type"> + <columnTitle>Requirement Name Type</columnTitle> + <displayWidth>180</displayWidth> + </column> + <column columnName="MonthsUntilRenewal"> + <columnTitle>Months Until Renewal</columnTitle> + <displayWidth>60</displayWidth> + <conditionalFormats> + <conditionalFormat> + <filters> + <filter operator="lte" value="0.0"/> + </filters> + <backgroundColor>FBEC5D</backgroundColor> + </conditionalFormat> + </conditionalFormats> + </column> + + <column columnName="trackingflag"> + <columnTitle>Essential</columnTitle> + <displayWidth>60</displayWidth> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> + <column columnName="snooze_date"> + <columnTitle>Snooze Until</columnTitle> + <displayWidth>60</displayWidth> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> + + </columns> + </table> + </tables> + </metadata> +</query> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.sql b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.sql new file mode 100644 index 000000000..585ed1c0e --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg.sql @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2010-2014 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 + */ + +-- Modified: 6-14-2022 R.Blasa ComplianceRecentTests.sql +-- 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 a.unit,chr(10)) as unit, + group_concat(distinct a.category,chr(10)) as category, + group_concat(distinct b.trackingflag) as trackingflag, + + + (select count(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (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 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 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) ) > 0 THEN + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate) - (TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now()) ) ) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) + + + ELSE ( select (tt.expireperiod) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now())) 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 ) + + END AS DECIMAL ) AS MonthsUntilRenewal + + + +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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = b.requirementname And q.dateDisabled is null ) + + + + + group by b.requirementname,a.employeeid + + +union + +-- Training that was completed by an employee but not recorded as being completed as a Unit or Category +select a.requirementname, + a.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (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 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 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) ) > 0 THEN + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now()) ) ) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) + + + + + ELSE ( select (tt.expireperiod) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now())) 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 ) + + END AS DECIMAL) AS MonthsUntilRenewal + + + from ehr_compliancedb.completiondates a +where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit + or k.category = h.category) And a.employeeid = k.employeeid ) + 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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = a.requirementname And q.dateDisabled is null ) + +group by a.requirementname,a.employeeid + +UNION + +-- Additional requirements for employees that have not completed training, but is required +select j.requirementname, + j.employeeid, + null as unit, + null as category, + 'Yes' as trackingflag, + null as timesCompleted, + null as ExpiredPeriod, + null as NewExpirePeriod, + null as MostRecentDate, + '' as comment, + null as snooze_date, + null AS MonthsUntilRenewal + + +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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = j.requirementname And q.dateDisabled is null ) + + + +group by j.requirementname,j.employeeid + + + + + diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/.qview.xml new file mode 100644 index 000000000..82fc59d49 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/.qview.xml @@ -0,0 +1,25 @@ +<customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All"> + <columns> + <column name="employeeId/email"/> + <column name="employeeId"/> + <column name="employeeId/lastName"/> + <column name="employeeId/firstName"/> + <column name="employeeId/majorudds"/> + <column name="unit"/> + <column name="category"/> + <column name="requirementName"/> + <column name="trackingflag"/> + <column name="timesCompleted"/> + <column name="ExpiredPeriod"/> + <column name="NewExpirePeriod"/> + <column name="MostRecentDate"/> + <column name="comment"/> + <column name="MonthsUntilRenewal"/> + <column name="snooze_date"/> + </columns> + <sorts> + <sort column="employeeId/lastName" descending="false"/> + <sort column="employeeId/firstName" descending="false"/> + <sort column="requirementName" descending="false"/> + </sorts> +</customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Occupational Health Compliance.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Occupational Health Compliance.qview.xml new file mode 100644 index 000000000..97934dc5a --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Occupational Health Compliance.qview.xml @@ -0,0 +1,28 @@ +<customView xmlns="http://labkey.org/data/xml/queryCustomView"> + <columns> + <column name="employeeId"/> + <column name="employeeId/email"/> + <column name="employeeId/lastName"/> + <column name="employeeId/firstName"/> + <column name="employeeId/supervisor"/> + <column name="employeeId/location"/> + <column name="employeeId/category"/> + <column name="employeeId/notes"/> + <column name="employeeId/isActive"/> + <column name="requirementName"/> + <column name="requirementName/type"/> + <column name="MostRecentDate"/> + <column name="MonthsUntilRenewal"/> + </columns> + <sorts> + <sort column="employeeId/lastName" descending="false"/> + <sort column="employeeId/firstName" descending="false"/> + <sort column="requirementName" descending="false"/> + </sorts> + <filters> + <filter column="MonthsUntilRenewal" operator="lte" value="2"/> + <filter column="employeeid/isActive" operator="eq" value="true"/> + <filter column="requirementName/datedisabled" operator="isblank"/> + <filter column="requirementName/type" operator="eq" value="Occupational Health"/> + </filters> +</customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon withNoEHRS OccHealth.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon withNoEHRS OccHealth.qview.xml new file mode 100644 index 000000000..192608c90 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon withNoEHRS OccHealth.qview.xml @@ -0,0 +1,16 @@ +<customView xmlns="http://labkey.org/data/xml/queryCustomView"> + + <sorts> + <sort column="employeeId/lastName" descending="false"/> + <sort column="employeeId/firstName" descending="false"/> + <sort column="requirementName" descending="false"/> + </sorts> + <filters> + <filter column="MonthsUntilRenewal" operator="lte" value="2"/> + <filter column="employeeid/isActive" operator="eq" value="true"/> + <filter column="requirementName/datedisabled" operator="isblank"/> + <filter column="requirementName/type" operator="containsnoneof" value="EHRS;Occupational Health"/> + <filter column="category" operator="doesnotcontain" value="Vendor / Contractor"/> + </filters> + +</customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon.qview.xml new file mode 100644 index 000000000..bc93d1734 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceProcedureRecentTestsorg/Overdue and Due Soon.qview.xml @@ -0,0 +1,12 @@ +<customView xmlns="http://labkey.org/data/xml/queryCustomView"> + <sorts> + <sort column="employeeId/lastName" descending="false"/> + <sort column="employeeId/firstName" descending="false"/> + <sort column="requirementName" descending="false"/> + </sorts> + <filters> + <filter column="MonthsUntilRenewal" operator="lte" value="2"/> + <filter column="employeeid/isActive" operator="eq" value="true"/> + <filter column="requirementName/datedisabled" operator="isblank"/> + </filters> +</customView> \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.query.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.query.xml index de9c0af17..d85eb7bac 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.query.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.query.xml @@ -4,7 +4,7 @@ <table tableName="complianceRecentTests" tableDbType="NOT_IN_DB"> <tableTitle>Employee Requirement Summary</tableTitle> <columns> - <column columnName="employeeId"> + <column columnName="employeeid"> <columnTitle>Employee ID</columnTitle> <isKeyField>true</isKeyField> <fk> @@ -14,7 +14,10 @@ </fk> </column> - <column columnName="requirementName"> + <column columnName="rowid"> + <columnTitle>Row ID</columnTitle> + </column> + <column columnName="requirementname"> <columnTitle>Requirement Name</columnTitle> <displayWidth>90</displayWidth> <fk> @@ -24,7 +27,7 @@ </fk> <facetingBehavior>ALWAYS_OFF</facetingBehavior> </column> - <column columnName="timesCompleted"> + <column columnName="times_completed"> <columnTitle>Times Completed</columnTitle> <displayWidth>50</displayWidth> <url>/query/executeQuery.view?schemaName=ehr_compliancedb& @@ -33,21 +36,46 @@ query.requirementName~eq=${requirementName}& </url> </column> - <column columnName="ExpiredPeriod"> + <column columnName="expired_period"> <columnTitle>Expire Period (Months)</columnTitle> <displayWidth>70</displayWidth> </column> - - <column columnName="NewExpirePeriod"> + <column columnName="new_expired_period"> <columnTitle>New Expire Period (Months)</columnTitle> <displayWidth>70</displayWidth> </column> + + <column columnName="email"> + <columnTitle>Email</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="lastname"> + <columnTitle>Last Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="firstname"> + <columnTitle>First Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="host"> + <columnTitle>Host</columnTitle> + <displayWidth>110</displayWidth> + </column> + <column columnName="supervisor"> + <columnTitle>Supervisor</columnTitle> + <displayWidth>150</displayWidth> + </column> + <column columnName="unit"> <columnTitle>Unit</columnTitle> - <displayWidth>70</displayWidth> + <displayWidth>210</displayWidth> </column> - <column columnName="mostrecentdate"> + <column columnName="mostrecentcompleted_date"> <columnTitle>Most Recent Date</columnTitle> + <formatString>yyyy-MM-dd</formatString> <displayWidth>70</displayWidth> </column> <column columnName="comment"> @@ -58,7 +86,16 @@ <columnTitle>Category</columnTitle> <displayWidth>70</displayWidth> </column> - <column columnName="MonthsUntilRenewal"> + + <column columnName="trainee_type"> + <columnTitle>Trainee Type</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="requirement_name_type"> + <columnTitle>Requirement Name Type</columnTitle> + <displayWidth>180</displayWidth> + </column> + <column columnName="months_until_renewal"> <columnTitle>Months Until Renewal</columnTitle> <displayWidth>60</displayWidth> <conditionalFormats> @@ -76,6 +113,11 @@ <displayWidth>60</displayWidth> <facetingBehavior>ALWAYS_OFF</facetingBehavior> </column> + <column columnName="snooze_date"> + <columnTitle>Snooze Until</columnTitle> + <displayWidth>60</displayWidth> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> </columns> </table> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.sql b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.sql index e20555134..1e12aa52e 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.sql +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests.sql @@ -1,164 +1,2 @@ -/* - * Copyright (c) 2010-2014 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 - */ - --- Modified: 6-14-2022 R.Blasa ComplianceRecentTests.sql --- 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 a.unit,chr(10)) as unit, - group_concat(distinct a.category,chr(10)) as category, - group_concat(distinct b.trackingflag) as trackingflag, - - - (select count(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, - - (select k.expireperiod from Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, - - ( select (age_in_months(max(pq.date), tt.reviewdate) ) 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, - - (select max(zz.date) from completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, - - (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, - 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 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate) )) > 0 THEN - - ( select ( age_in_months(max(pq.date), tt.reviewdate) - ( age_in_months(max(pq.date), curdate())) )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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) - - - ELSE ( select (tt.expireperiod) - ( age_in_months(max(pq.date), curdate())) 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 ) - - END AS double) AS MonthsUntilRenewal - - - -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.requirementname = b.requirementname And k.datedisabled is null) - - -group by b.requirementname,a.employeeid - -union - --- Training that was completed by an employee but not recorded as being completed as a Unit or Category -select a.requirementname, - a.employeeid, - null as unit, - null as category, - 'No' as trackingflag, - - - (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, - - (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, - - - ( select (age_in_months(max(pq.date), tt.reviewdate) ) 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, - - (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, - - (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, - - - - 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 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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate) )) > 0 THEN - - ( select ( age_in_months(max(pq.date), tt.reviewdate) - ( age_in_months(max(pq.date), curdate())) )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 - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) - - - - - ELSE ( select (tt.expireperiod) - ( age_in_months(max(pq.date), curdate())) 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 ) - - END AS double) AS MonthsUntilRenewal - -from ehr_compliancedb.completiondates a -where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit - or k.category = h.category) And a.employeeid = k.employeeid ) - 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 - - -union - --- Training that was completed by as an employee training exemptions, and at least completed one, or more times -select j.requirementname, - j.employeeid, - null as unit, - null as category, - 'No' as trackingflag, - (select count(zz.date) from completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as timesCompleted, - (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = j.requirementname) as ExpiredPeriod, - - ( select (age_in_months(max(pq.date),tt.reviewdate) ) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate - having (tt.expireperiod) > (age_in_months(max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, - - (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as MostRecentDate, - (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= j.requirementname and zz.employeeid= j.employeeid ) - And yy.requirementname= j.requirementname and yy.employeeid= j.employeeid ) as comment, - null AS MonthsUntilRenewal - - -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 - -UNION - --- Additional requirements for employees that have not completed training, but is required -select j.requirementname, - j.employeeid, - null as unit, - null as category, - 'Yes' as trackingflag, - null as timesCompleted, - null as ExpiredPeriod, - null as NewExpirePeriod, - null as MostRecentDate, - '' as comment, - null AS MonthsUntilRenewal - - -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 - +Select * +from onprc_ehr_compliancedb.ComplianceRecentReport \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests/.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests/.qview.xml index 750c4460d..b2c68ae6f 100644 --- a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests/.qview.xml +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTests/.qview.xml @@ -1,23 +1,24 @@ <customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All"> <columns> - <column name="employeeId"/> - <column name="employeeId/email"/> - <column name="employeeId/lastName"/> - <column name="employeeId/firstName"/> - <column name="employeeId/isActive"/> - <column name="requirementName"/> + <column name="employeeid"/> + <column name="email"/> + <column name="lastname"/> + <column name="firstname"/> + <column name="requirementname"/> <column name="unit"/> <column name="category"/> <column name="trackingflag"/> - <column name="timesCompleted"/> - <column name="ExpiredPeriod"/> - <column name="NewExpirePeriod"/> - <column name="MostRecentDate"/> - <column name="MonthsUntilRenewal"/> + <column name="times_completed"/> + <column name="expired_period"/> + <column name="new_expired_period"/> + <column name="comment"/> + <column name="mostrecentcompleted_date"/> + <column name="months_until_renewal"/> + </columns> <sorts> - <sort column="employeeId/lastName" descending="false"/> - <sort column="employeeId/firstName" descending="false"/> - <sort column="requirementName" descending="false"/> + <sort column="lastname" descending="false"/> + <sort column="firstname" descending="false"/> + <sort column="requirementname" descending="false"/> </sorts> </customView> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.query.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.query.xml new file mode 100644 index 000000000..46cb8fc00 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.query.xml @@ -0,0 +1,121 @@ +<query xmlns="http://labkey.org/data/xml/query"> + <metadata> + <tables xmlns="http://labkey.org/data/xml"> + <table tableName="complianceRecentTests" tableDbType="NOT_IN_DB"> + <tableTitle>Employee Requirement Summary - Original version</tableTitle> + <columns> + <column columnName="employeeid"> + <columnTitle>Employee ID</columnTitle> + <isKeyField>true</isKeyField> + <fk> + <fkDbSchema>ehr_compliancedb</fkDbSchema> + <fkTable>employees</fkTable> + <fkColumnName>employeeId</fkColumnName> + + </fk> + </column> + <column columnName="rowid"> + <columnTitle>Row ID</columnTitle> + </column> + <column columnName="requirementName"> + <columnTitle>Requirement Name</columnTitle> + <displayWidth>90</displayWidth> + <fk> + <fkDbSchema>ehr_compliancedb</fkDbSchema> + <fkTable>requirements</fkTable> + <fkColumnName>requirementName</fkColumnName> + </fk> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> + <column columnName="timesCompleted"> + <columnTitle>Times Completed</columnTitle> + <displayWidth>50</displayWidth> + <url>/query/executeQuery.view?schemaName=ehr_compliancedb& + query.queryName=CompletionDates& + query.EmployeeId~eq=${employeeId}& + query.requirementName~eq=${requirementName}& + </url> + </column> + <column columnName="ExpiredPeriod"> + <columnTitle>Expire Period (Months)</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="NewExpirePeriod"> + <columnTitle>New Expire Period (Months)</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="email"> + <columnTitle>Email</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="lastname"> + <columnTitle>Last Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="firstname"> + <columnTitle>First Name</columnTitle> + <displayWidth>110</displayWidth> + </column> + + <column columnName="host"> + <columnTitle>Host</columnTitle> + <displayWidth>110</displayWidth> + </column> + <column columnName="supervisor"> + <columnTitle>Supervisor</columnTitle> + <displayWidth>150</displayWidth> + </column> + + <column columnName="unit"> + <columnTitle>Unit</columnTitle> + <displayWidth>210</displayWidth> + </column> + <column columnName="MostRecentDate"> + <columnTitle>Most Recent Date</columnTitle> + <formatString>yyyy-MM-dd</formatString> + <displayWidth>70</displayWidth> + </column> + <column columnName="comment"> + <columnTitle>Comments</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="category"> + <columnTitle>Category</columnTitle> + <displayWidth>70</displayWidth> + </column> + + <column columnName="trainee_type"> + <columnTitle>Trainee Type</columnTitle> + <displayWidth>70</displayWidth> + </column> + <column columnName="requirement_name_type"> + <columnTitle>Requirement Name Type</columnTitle> + <displayWidth>180</displayWidth> + </column> + <column columnName="MonthsUntilRenewal"> + <columnTitle>Months Until Renewal</columnTitle> + <displayWidth>60</displayWidth> + <conditionalFormats> + <conditionalFormat> + <filters> + <filter operator="lte" value="0.0"/> + </filters> + <backgroundColor>FBEC5D</backgroundColor> + </conditionalFormat> + </conditionalFormats> + </column> + + <column columnName="trackingflag"> + <columnTitle>Essential</columnTitle> + <displayWidth>60</displayWidth> + <facetingBehavior>ALWAYS_OFF</facetingBehavior> + </column> + + </columns> + </table> + </tables> + </metadata> +</query> diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.sql b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.sql new file mode 100644 index 000000000..1ff4baac6 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg.sql @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2010-2014 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 + */ + +-- Modified: 6-14-2022 R.Blasa ComplianceRecentTests.sql +-- 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.category,chr(10)) as category, + group_concat(distinct b.trackingflag) as trackingflag, + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (Select group_concat(distinct yy.comment, chr(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) + And yy.requirementname= b.requirementname and yy.employeeid= a.employeeid ) as comment, + CAST( + CASE + WHEN (select max(st.date) from ehr_compliancedb.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 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) ) > 0 THEN + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate) - (TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now()) ) ) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) + + + ELSE ( select (tt.expireperiod) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now())) 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 ) + + END AS double) AS MonthsUntilRenewal + + + +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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = b.requirementname And q.dateDisabled is null ) + + + +group by b.requirementname,a.employeeid + +union + +-- Training that was completed by an employee but not recorded as being completed as a Unit or Category +select a.requirementname, + a.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, + + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (Select group_concat(distinct yy.comment, chr(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) + And yy.requirementname= a.requirementname and yy.employeeid= a.employeeid ) as comment, + + + + CAST( + CASE + WHEN (select max(st.date) from ehr_compliancedb.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 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) ) > 0 THEN + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now()) ) ) 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 + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) + + + + + ELSE ( select (tt.expireperiod) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now())) 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 ) + + END AS double) AS MonthsUntilRenewal + +from ehr_compliancedb.completiondates a +where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit + or k.category = h.category) And a.employeeid = k.employeeid ) + 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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = a.requirementname And q.dateDisabled is null ) + + +group by a.requirementname,a.employeeid + + +union + +-- Training that was completed by as an employee training exemptions, and at least completed one, or more times +select j.requirementname, + j.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = j.requirementname) as ExpiredPeriod, + + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as MostRecentDate, + + (Select group_concat(distinct yy.comment, chr(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) + And yy.requirementname= j.requirementname and yy.employeeid= j.employeeid ) as comment, + + + + CAST( + CASE + WHEN (select max(st.date) from ehr_compliancedb.completiondates st where st.requirementname = j.requirementname and st.employeeid = j.employeeid ) IS NULL then 0 + WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = j.requirementname group by tt.expireperiod ) = 0 then Null + + + WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) ) > 0 THEN + + ( select ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now()) ) ) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) + + + + + ELSE ( select (tt.expireperiod) - ( TIMESTAMPDIFF('SQL_TSI_MONTH', max(pq.date), Now())) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod ) + + END AS double) AS MonthsUntilRenewal + +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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = j.requirementname And q.dateDisabled is null ) + + + +group by j.requirementname,j.employeeid + +UNION + +-- Additional requirements for employees that have not completed training, but is required +select j.requirementname, + j.employeeid, + null as unit, + null as category, + 'Yes' as trackingflag, + null as timesCompleted, + null as ExpiredPeriod, + null as NewExpirePeriod, + null as MostRecentDate, + '' as comment, + null AS MonthsUntilRenewal + + +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 q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = j.requirementname And q.dateDisabled is null ) + + + +group by j.requirementname,j.employeeid + diff --git a/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg/.qview.xml b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg/.qview.xml new file mode 100644 index 000000000..750c4460d --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/queries/EHR_ComplianceDB/ComplianceRecentTestsorg/.qview.xml @@ -0,0 +1,23 @@ +<customView xmlns="http://labkey.org/data/xml/queryCustomView" label="All"> + <columns> + <column name="employeeId"/> + <column name="employeeId/email"/> + <column name="employeeId/lastName"/> + <column name="employeeId/firstName"/> + <column name="employeeId/isActive"/> + <column name="requirementName"/> + <column name="unit"/> + <column name="category"/> + <column name="trackingflag"/> + <column name="timesCompleted"/> + <column name="ExpiredPeriod"/> + <column name="NewExpirePeriod"/> + <column name="MostRecentDate"/> + <column name="MonthsUntilRenewal"/> + </columns> + <sorts> + <sort column="employeeId/lastName" descending="false"/> + <sort column="employeeId/firstName" descending="false"/> + <sort column="requirementName" descending="false"/> + </sorts> +</customView> diff --git a/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.004-24.005.sql b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.004-24.005.sql new file mode 100644 index 000000000..4c2b7aa50 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.004-24.005.sql @@ -0,0 +1,250 @@ + + +EXEC core.fn_dropifexists 'p_ComplianceAccesscontainerUpdate', 'onprc_ehr_compliancedb', 'PROCEDURE'; +GO + +-- Author: R. Blasa +-- Created: 12-10-2024 + +/* +** +** Created by +** Blasa 12-10-2024 Storedprocedure to update string name "ARRS" to "DCM" +** +** +** +** +*/ + +CREATE Procedure onprc_ehr_compliancedb.p_ComplianceTranslatestringUpdate + + +AS + + + +BEGIN + + ------ Update container value and include as part of the main Compliance module + +If exists(select * from ehr_compliancedb.EmployeePerUnit ------> count= 496 + where unit like '%arrs%' + ) +BEGIN + + Update ehr_compliancedb.EmployeePerUnit + set unit = replace(unit,'arrs', 'DCM') + + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + If exists(select * from ehr_compliancedb.EmployeePerUnit ------> count= 496 + where category like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.EmployeePerUnit + set category = replace(category,'arrs', 'DCM') + + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + If exists(select * from ehr_compliancedb.Employees + where majorudds like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.Employees + set majorudds = replace(majorudds,'arrs', 'DCM') + + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + If exists(select * from ehr_compliancedb.Employees + where unit like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.Employees + set unit = replace(unit,'arrs', 'DCM') + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + If exists(select * from ehr_compliancedb.Employees + where category like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.Employees + set category = replace(category,'arrs', 'DCM') + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + If exists(select * from ehr_compliancedb.requirements + where requirementname like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.requirements + set requirementname = replace(requirementname,'arrs', 'DCM') + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + If exists(select * from ehr_compliancedb.EmployeeRequirementExemptions + where requirementname like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.EmployeeRequirementExemptions + set requirementname = replace(requirementname,'arrs', 'DCM') + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + + If exists(select * from ehr_compliancedb.unit_names + where unit like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.unit_names + set unit = replace(unit,'arrs', 'DCM') + + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + If exists(select * from ehr_compliancedb.RequirementsPerCategory + where RequirementName like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.RequirementsPerCategory + set requirementname = replace(requirementname,'arrs', 'DCM') + + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + If exists(select * from ehr_compliancedb.RequirementsPerCategory + where category like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.RequirementsPerCategory + set category = replace(category,'arrs', 'DCM') + + If @@Error <> 0 + GoTo Err_Proc + + END + + + If exists(select * from ehr_compliancedb.RequirementsPerCategory + where unit like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.RequirementsPerCategory + set unit = replace(unit,'arrs', 'DCM') + + + If @@Error <> 0 + GoTo Err_Proc + + END + + If exists(select * from ehr_compliancedb.completiondates + where requirementname like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.completiondates + set requirementname = replace(requirementname,'arrs', 'DCM') + + + If @@Error <> 0 + GoTo Err_Proc + + END + + If exists(select * from ehr_compliancedb.EmployeeCategory + where categoryname like '%arrs%' + ) + BEGIN + + Update ehr_compliancedb.EmployeeCategory + set categoryname = replace(categoryname ,'arrs', 'DCM') + + + If @@Error <> 0 + GoTo Err_Proc + + END + + + + + + + + +No_Records: + + RETURN 0 + + +Err_Proc: + -- + RETURN 1 + + +END + +GO \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.005-24.006.sql b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.005-24.006.sql new file mode 100644 index 000000000..0a739ae44 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.005-24.006.sql @@ -0,0 +1,261 @@ +-- Author: R. Blasa +-- Created: 9-20-2024-2024 +-- Description: Stored procedure program to create a static data set for Compliance Procedure Recent Test .sql + + + CREATE TABLE onprc_ehr_compliancedb.ComplianceProcedureReport( + [rowid] [int] IDENTITY(1,1) NOT NULL, + [employeeid] varchar(300) NULL, + [requirementname] [varchar](4000) NULL, + [unit] [varchar](500) NULL, + [category] [varchar](500) NULL, + [trackingflag] [varchar](100) NULL, + [email] [varchar](500) NULL, + [lastname] [varchar](500) NULL, + [firstname] [varchar](500) NULL, + [host] [varchar](500) NULL, + [supervisor] [varchar](500) NULL, + [trainee_type] [varchar](500) NULL, + [times_completed] [smallint] NULL, + [expired_period] [smallint] NULL, + [new_expired_period] [smallint] NULL, + [mostrecentcompleted_date] [smalldatetime] NULL, + [comment] [varchar](4000) NULL, + [snooze_date] [smalldatetime] NULL, + [months_until_renewal] [Float] NULL, + [requirement_name_type] [varchar](1000) NULL + + ) ON [PRIMARY] + GO + +-- Author: R. Blasa +-- Created: 9-20-2024 + +/* +** +** Created by +** Blasa 9-20-2024 Created a storedprocedure to create a static set of data from +** the ComplianceProcedureRecentTest.sql query +** +** +** +*/ + +CREATE Procedure onprc_ehr_compliancedb.p_ComplianceProcedureOverDueSoon_Process + + +AS + + + ----- Reset Reporting table + Delete onprc_ehr_compliancedb.ComplianceProcedureReport + + If @@Error <> 0 + GoTo Err_Proc + + + +BEGIN + + Insert into onprc_ehr_compliancedb.ComplianceProcedureReport + ( + requirementname, + employeeid, + unit, + category, + trackingflag, + email, + lastname, + firstname, + host, + supervisor, + trainee_type, + requirement_name_type, + times_completed, + expired_period, + new_expired_Period, + mostrecentcompleted_date, + comment, + snooze_date, + months_until_renewal + + ) + + + + + + select b.requirementname, + a.employeeid, + string_agg(a.unit,char(10)) as unit, + string_agg(a.category,char(10)) as category, + (select top 1 h.trackingflag from ehr_compliancedb.requirementspercategory h where h.requirementname = b.requirementname) as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = b.requirementname) as requirement_type, + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as times_Completed, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) ) 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as mostrecentcompleted_date, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 ehr_compliancedb.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 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 + having (tt.expireperiod) > ( datediff(month,max(pq.date), tt.reviewdate) )) > 0 THEN + + ( select (datediff(month,max(pq.date), tt.reviewdate) - ( datediff(month,max(pq.date), getdate()) ) )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 + having (tt.expireperiod) > ( datediff(month,max(pq.date), tt.reviewdate) ) ) + + + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate()) ) 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 ) + + END AS Float) AS MonthsUntilRenewal + + + + from ehr_Compliancedb.employeeperunit a ,ehr_compliancedb.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 a.employeeid = p.employeeid And p.enddate is null) + And b.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = b.requirementname And q.dateDisabled is null ) + + + group by b.requirementname,a.employeeid + + + union + + select a.requirementname, + a.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = a.requirementname) as requirement_type, ----- type trainee, or trainer + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) )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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 ehr_compliancedb.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 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 + having (tt.expireperiod) > ( datediff(month,max(pq.date), tt.reviewdate) )) > 0 THEN + + ( select ( datediff(month,max(pq.date), tt.reviewdate) - ( datediff(month,max(pq.date), getdate())) )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 + having (tt.expireperiod) > ( datediff(month,max(pq.date), tt.reviewdate) ) ) + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate()) ) 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 ) + + END AS Float) AS MonthsUntilRenewal + + + from ehr_compliancedb.completiondates a + where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit + or k.category = h.category) And a.employeeid = k.employeeid ) + 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 a.employeeid = p.employeeid And p.enddate is null) + And a.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = a.requirementname And q.dateDisabled is null ) + + group by a.requirementname,a.employeeid + + UNION + + -- Additional requirements for employees that have not completed training, but is required + select j.requirementname, + j.employeeid, + null as unit, + null as category, + 'Yes' as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = j.requirementname) as requirement_type, ----- type trainee, or trainer + null as timesCompleted, + null as ExpiredPeriod, + null as NewExpirePeriod, + null as MostRecentDate, + '' as comment, + null as snooze_date, + null AS MonthsUntilRenewal + + + + 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 j.employeeid = p.employeeid And p.enddate is null) + And j.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = j.requirementname And q.dateDisabled is null ) + + group by j.requirementname,j.employeeid + + order by employeeid,requirementname, mostrecentcompleted_date desc + + + If @@Error <> 0 + GoTo Err_Proc + + + + + RETURN 0 + + +Err_Proc: + + RETURN 1 + + +END + +GO \ No newline at end of file diff --git a/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.006-24.007.sql b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.006-24.007.sql new file mode 100644 index 000000000..24134b431 --- /dev/null +++ b/ONPRC_EHR_ComplianceDB/resources/schemas/dbscripts/sqlserver/onprc_ehr_compliancedb-24.006-24.007.sql @@ -0,0 +1,349 @@ +-- Author: R. Blasa +-- Created: 9-20-2024-2024 +-- Description: Stored procedure program to create a static data set for Compliance Recent Test .sql + + + CREATE TABLE onprc_ehr_compliancedb.ComplianceRecentReport( + [rowid] [int] IDENTITY(1,1) NOT NULL, + [employeeid] varchar(300) NULL, + [requirementname] [varchar](4000) NULL, + [unit] [varchar](500) NULL, + [category] [varchar](500) NULL, + [trackingflag] [varchar](100) NULL, + [email] [varchar](500) NULL, + [lastname] [varchar](500) NULL, + [firstname] [varchar](500) NULL, + [host] [varchar](500) NULL, + [supervisor] [varchar](500) NULL, + [trainee_type] [varchar](500) NULL, + [times_completed] [smallint] NULL, + [expired_period] [smallint] NULL, + [new_expired_period] [smallint] NULL, + [mostrecentcompleted_date] [smalldatetime] NULL, + [comment] [varchar](4000) NULL, + [snooze_date] [smalldatetime] NULL, + [months_until_renewal] [FLOAT] NULL, + [requirement_name_type] [varchar](1000) NULL + + ) ON [PRIMARY] + GO + + +-- Author: R. Blasa +-- Created: 9-20-2024 + +/* +** +** Created by +** Blasa 9-20-2024 Created a storedprocedure to create a static set of data from +** the ComplianceRecentTest.sql query +** +** +** +*/ + +CREATE Procedure onprc_ehr_compliancedb.p_ComplianceRecentOverDueSoon_Process + + +AS + + + + ----- Reset Reporting table + Delete onprc_ehr_compliancedb.ComplianceRecentReport + + If @@Error <> 0 + GoTo Err_Proc + + + +BEGIN + + Insert into onprc_ehr_compliancedb.ComplianceRecentReport + ( + requirementname, + employeeid, + unit, + category, + trackingflag, + email, + lastname, + firstname, + host, + supervisor, + trainee_type, + requirement_name_type, + times_completed, + expired_period, + new_expired_Period, + mostrecentcompleted_date, + comment, + snooze_date, + months_until_renewal + + ) + + + + + select b.requirementname, + a.employeeid, + string_agg(a.unit,char(10)) as unit, + string_agg(a.category,char(10)) as category, + (select top 1 h.trackingflag from ehr_compliancedb.requirementspercategory h where h.requirementname = b.requirementname) as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = b.requirementname) as requirement_type, ----- type trainee, or trainer + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as times_Completed, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = b.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) ) 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= b.requirementname and zz.employeeid= a.employeeid ) as mostrecentcompleted_date, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 ehr_compliancedb.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 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 + having (tt.expireperiod) > ( datediff(month,max(pq.date), tt.reviewdate) ) ) > 0 THEN + + ( select (datediff(month,max(pq.date), tt.reviewdate) - ( datediff(month,max(pq.date), getdate())) ) 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate) ) ) + + + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate())) 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 ) + + END AS FLOAT) AS MonthsUntilRenewal + + + + from ehr_Compliancedb.employeeperunit a ,ehr_compliancedb.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 a.employeeid = p.employeeid And p.enddate is null) + And b.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = b.requirementname And q.dateDisabled is null ) + + + group by b.requirementname,a.employeeid + + + union + + select a.requirementname, + a.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = a.requirementname) as requirement_type, ----- type trainee, or trainer + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) )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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 ehr_compliancedb.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 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate) )) > 0 THEN + + ( select (datediff(month,max(pq.date), tt.reviewdate) - ( datediff(month,max(pq.date), getdate())) ) 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate) ) ) + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate())) 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 ) + + END AS FLOAT) AS MonthsUntilRenewal + + + from ehr_compliancedb.completiondates a + where a.requirementname not in (select distinct h.requirementname from ehr_compliancedb.employeeperunit k, ehr_compliancedb.requirementspercategory h Where (k.unit = h.unit + or k.category = h.category) And a.employeeid = k.employeeid ) + 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 a.employeeid = p.employeeid And p.enddate is null) + And a.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = a.requirementname And q.dateDisabled is null ) + + group by a.requirementname,a.employeeid + + UNION + + --- Training that was completed by as an employee training exemptions, and at least completed one, or more times + + select a.requirementname, + a.employeeid, + null as unit, + null as category, + 'No' as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = a.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = a.requirementname) as requirement_type, ----- type trainee, or trainer + + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = a.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) )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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= a.requirementname and zz.employeeid= a.employeeid ) as MostRecentDate, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.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 ehr_compliancedb.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 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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate) )) > 0 THEN + + ( select ( datediff(month,max(pq.date), tt.reviewdate) - (datediff(month,max(pq.date), getdate())) )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 + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) ) + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate())) 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 ) + + END AS DECIMAL) AS MonthsUntilRenewal + + + from ehr_compliancedb.employeerequirementexemptions a + Where a.requirementname in (select z.requirementname from ehr_compliancedb.completiondates z where z.requirementname = a.requirementname + and z.employeeid = a.employeeid and z.date is not null) + And a.employeeid in (select p.employeeid from ehr_compliancedb.employees p where a.employeeid = p.employeeid And p.enddate is null) + And a.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = a.requirementname And q.dateDisabled is null ) + + group by a.requirementname,a.employeeid + + UNION + + --- Additional requirements for employees that have not completed training, but is required + + select j.requirementname, + j.employeeid, + null as unit, + null as category, + 'Yes' as trackingflag, + (select h.email from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as email, + (select h.lastname from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as lastname, + (select h.firstname from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as firstname, + (select h.majorudds from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as host, + (select h.supervisor from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as supervisor, + (select h.type from ehr_compliancedb.employees h where h.employeeid = j.employeeid) as trainee_type, ----- type trainee, or trainer + (select h.type from ehr_compliancedb.Requirements h where h.requirementname = j.requirementname) as requirement_type, ----- type trainee, or trainer + + (select count(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as timesCompleted, + + (select k.expireperiod from ehr_compliancedb.Requirements k where k.requirementname = j.requirementname) as ExpiredPeriod, + + ( select (datediff(month,max(pq.date), tt.reviewdate) )from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) and (tt.reviewdate is not null) ) as NewExpirePeriod, + + (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) as MostRecentDate, + + (Select distinct string_agg(yy.comment, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) + And yy.requirementname= j.requirementname and yy.employeeid= j.employeeid ) as comment, + + (Select distinct string_agg(yy.snooze_date, char(10)) from ehr_compliancedb.completiondates yy where yy.date in (select max(zz.date) from ehr_compliancedb.completiondates zz where zz.requirementname= j.requirementname and zz.employeeid= j.employeeid ) + And yy.requirementname= j.requirementname and yy.employeeid= j.employeeid ) as snooze_date, + + CAST( + CASE + WHEN (select max(st.date) from ehr_compliancedb.completiondates st where st.requirementname = j.requirementname and st.employeeid = j.employeeid ) IS NULL then 0 + WHEN ( select (tt.expireperiod) from ehr_compliancedb.requirements tt where tt.requirementname = j.requirementname group by tt.expireperiod ) = 0 then Null + + + WHEN ( select count(*) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate) )) > 0 THEN + + ( select ( datediff(month,max(pq.date), tt.reviewdate) - (datediff(month,max(pq.date), getdate())) )from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod, tt.reviewdate + having (tt.expireperiod) > (datediff(month,max(pq.date), tt.reviewdate)) ) + + + ELSE ( select (tt.expireperiod) - ( datediff(month,max(pq.date), getdate())) from ehr_compliancedb.requirements tt, ehr_compliancedb.completiondates pq where tt.requirementname = j.requirementname and pq.requirementname = tt.requirementname and pq.employeeid = j.employeeid group by tt.expireperiod ) + + END AS DECIMAL) AS MonthsUntilRenewal + + + + + + 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 j.employeeid = p.employeeid And p.enddate is null) + And j.requirementname in (select q.requirementname from ehr_compliancedb.Requirements q where q.requirementname = j.requirementname And q.dateDisabled is null ) + + group by j.requirementname,j.employeeid + + order by employeeid,requirementname, mostrecentcompleted_date desc + + + If @@Error <> 0 + GoTo Err_Proc + + + + + RETURN 0 + + +Err_Proc: + + RETURN 1 + + +END + +GO diff --git a/ONPRC_EHR_ComplianceDB/resources/schemas/onprc_ehr_compliancedb.xml b/ONPRC_EHR_ComplianceDB/resources/schemas/onprc_ehr_compliancedb.xml index 3e14b18cc..dd608fe56 100644 --- a/ONPRC_EHR_ComplianceDB/resources/schemas/onprc_ehr_compliancedb.xml +++ b/ONPRC_EHR_ComplianceDB/resources/schemas/onprc_ehr_compliancedb.xml @@ -157,5 +157,101 @@ </columns> </table> + <table tableName="ComplianceProcedureReport" tableDbType="TABLE" useColumnOrder="true"> + <tableTitle>Compliance Procedure Report</tableTitle> + <javaCustomizer class="org.labkey.ehr.table.DefaultEHRCustomizer" /> + <auditLogging>DETAILED</auditLogging> + <columns> + <column columnName="rowid"> + <columnTitle>Search ID</columnTitle> + </column> + <column columnName="employeeid"> + </column> + <column columnName="requirementname"> + </column> + <column columnName="unit"> + </column> + <column columnName="category"> + </column> + <column columnName="trackingflag"> + </column> + <column columnName="email"> + </column> + <column columnName="lastname"> + </column> + <column columnName="firstname"> + </column> + <column columnName="host"> + </column> + <column columnName="supervisor"> + </column> + <column columnName="trainee_type"> + </column> + <column columnName="times_completed"> + </column> + <column columnName="expired_period"> + </column> + <column columnName="new_expired_period"> + </column> + <column columnName="mostrecentcompleted_date"> + </column> + <column columnName="comment"> + </column> + <column columnName="snooze_date"> + </column> + <column columnName="months_until_renewal"> + </column> + <column columnName="requirement_name_type"> + </column> + </columns> + </table> + <table tableName="ComplianceRecentReport" tableDbType="TABLE" useColumnOrder="true"> + <tableTitle>Compliance Recent Report</tableTitle> + <javaCustomizer class="org.labkey.ehr.table.DefaultEHRCustomizer" /> + <auditLogging>DETAILED</auditLogging> + <columns> + <column columnName="rowid"> + <columnTitle>Search ID</columnTitle> + </column> + <column columnName="employeeid"> + </column> + <column columnName="requirementname"> + </column> + <column columnName="unit"> + </column> + <column columnName="category"> + </column> + <column columnName="trackingflag"> + </column> + <column columnName="email"> + </column> + <column columnName="lastname"> + </column> + <column columnName="firstname"> + </column> + <column columnName="host"> + </column> + <column columnName="supervisor"> + </column> + <column columnName="trainee_type"> + </column> + <column columnName="times_completed"> + </column> + <column columnName="expired_period"> + </column> + <column columnName="new_expired_period"> + </column> + <column columnName="mostrecentcompleted_date"> + </column> + <column columnName="comment"> + </column> + <column columnName="snooze_date"> + </column> + <column columnName="months_until_renewal"> + </column> + <column columnName="requirement_name_type"> + </column> + </columns> + </table> </tables> diff --git a/ONPRC_EHR_ComplianceDB/resources/views/begin.html b/ONPRC_EHR_ComplianceDB/resources/views/begin.html index 15f0bdbb2..d5422b833 100644 --- a/ONPRC_EHR_ComplianceDB/resources/views/begin.html +++ b/ONPRC_EHR_ComplianceDB/resources/views/begin.html @@ -30,6 +30,7 @@ name: 'Occupational Health - Requirements Overdue/Due Soon', url: '<%=contextPath%>' + container + '/query-executeQuery.view?schemaName=ehr_compliancedb&query.queryName=ComplianceProcedureRecentTests&query.viewName=Occupational%20Health%20Compliance' },{ name: 'Occupational Health - Measles Overdue/Due Soon', url: '<%=contextPath%>' + container + '/query-executeQuery.view?schemaName=ehr_compliancedb&query.queryName=Measles45DayAlert&query.DaysOverDue~neqornull=-1' + },{ name: 'Requirements Overdue/Due Soon (Full SSRS Reports)', url: ctx['SSRSServerURL'] +'%2fPrime+Reports%2fCompliance%2fOverdue_Soon_Report&rs:Command=Render' },{ diff --git a/ONPRC_EHR_ComplianceDB/src/org/labkey/ONPRCEHR_ComplianceDB/ONPRC_EHR_ComplianceDBModule.java b/ONPRC_EHR_ComplianceDB/src/org/labkey/ONPRCEHR_ComplianceDB/ONPRC_EHR_ComplianceDBModule.java index 52b481fdf..a03021ffb 100644 --- a/ONPRC_EHR_ComplianceDB/src/org/labkey/ONPRCEHR_ComplianceDB/ONPRC_EHR_ComplianceDBModule.java +++ b/ONPRC_EHR_ComplianceDB/src/org/labkey/ONPRCEHR_ComplianceDB/ONPRC_EHR_ComplianceDBModule.java @@ -55,7 +55,7 @@ public String getName() @Override public Double getSchemaVersion() { - return 24.004; + return 24.007; } @Override diff --git a/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql b/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql index ece5f0b8e..dd7919804 100644 --- a/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql +++ b/onprc_ehr/resources/queries/study/TreatmentSchedulePostOps.sql @@ -64,7 +64,7 @@ FROM ( FROM ehr_lookups.dateRange dr Join study."Treatment Orders" t1 - ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND + ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 ) @@ -93,7 +93,7 @@ WHERE t1.date is not null ) s ON (s.animalid = h.id) WHERE h.calculated_status = 'Alive' --account for date/time in schedule - and s.date >= s.startDate and s.date <= s.enddate + AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- /* diff --git a/onprc_ehr/resources/queries/study/treatmentSchedule.sql b/onprc_ehr/resources/queries/study/treatmentSchedule.sql index 6a0e2e993..2fc4bc5bd 100644 --- a/onprc_ehr/resources/queries/study/treatmentSchedule.sql +++ b/onprc_ehr/resources/queries/study/treatmentSchedule.sql @@ -85,7 +85,7 @@ FROM ehr_lookups.dateRange dr JOIN study."Treatment Orders" t1 --NOTE: should the enddate consider date/time? - ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND + ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND --technically the first day of the treatment is day 1, not day 0 ( (mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 And t1.frequency.intervalindays is not null And t1.frequency.dayofweek is null ) @@ -116,4 +116,4 @@ WHERE (d.lastDayatCenter Is Null or d.lastDayAtCenter > s.enddate) --account for date/time in schedule -and s.date >= s.startDate and s.date <= s.enddate \ No newline at end of file + AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- some treatment_orders can have NULL enddates diff --git a/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql b/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql index 56a16d278..2d513e4bb 100644 --- a/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql +++ b/onprc_ehr/resources/queries/study/treatmentScheduleMPA.sql @@ -62,7 +62,7 @@ FROM study.demographics h JOIN ( FROM ehr_lookups.dateRange dr Join study."Treatment Orders" t1 - ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND + ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 ) @@ -92,4 +92,4 @@ WHERE h.calculated_status = 'Alive' --account for date/time in schedule --and s.date >= s.startDate and s.date <= s.enddate --Added the enddate = null clause by Kollil, 10/25/24. Refer to ticket #11471 - and s.date >= s.startDate and (s.date <= s.enddate or s.enddate is null) + AND s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate is null) diff --git a/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql b/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql index 4efde2469..c8e70c90a 100644 --- a/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql +++ b/treatmentETL/resources/queries/study/treatmentScheduleUpdate.sql @@ -85,7 +85,7 @@ FROM dateRangedata dr JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.study."Treatment Orders" t1 --NOTE: should the enddate consider date/time? - ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND + ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND --technically the first day of the treatment is day 1, not day 0 mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 OR (t1.frequency.dayofweek is not null And t1.frequency.intervalindays is null And dr.DayOfWeek in (select k.value from onprc_ehr.Frequency_DayofWeek k where k.FreqKey = t1.frequency.rowid )) @@ -115,4 +115,4 @@ WHERE --d.calculated_status = 'Alive' --account for date/time in schedule --and -s.date >= s.startDate and s.date <= s.enddate +s.date >= s.startDate AND (s.date <= s.enddate OR s.enddate IS NULL) -- some treatment_orders can have NULL enddates